Keyboard Encoder

Cost: $18.00

Obtained from: Myself!  Custom engineered and built.

Condition: New

Current Status: Works flawlessly.  I'm working one the second generation of this product which will be a "PC to arcade controller".

Concept

I had built a control panel and several Mame cabinets using keyboard encoders taken from spare keyboards I had lying around.  The encoders worked well until I got greedy and wanted more and more controls.  At that point I couldn't work out a decent matrix setup without ghosting, lockups or crashing Mame.

My first thought was to purchase a keyboard encoder from a third party, which I did.  I tried 2 different models and neither worked well enough for me.  I ended up reverse engineering both of them to get ideas on why they wouldn't work.  I found some disgusting flaws and sloppiness in these encoders and decided that I'd just make my own.

(I'm working on getting some photos online for anyone who's interested.)

Design

This project was designed to use an 8051 based microcontroller from Atmel, the AT89S8252.  This MCU was selected because its 8051 based and contains 2k bytes of EEPROM.  This eliminated the need for external EEPROM and the additional I/O lines that would require.  EEPROM is needed to make the encoder "Programmable".  The MCU also has 8k of FLASH memory which was plenty of room for the program code.  I swiped the data sheet if you want to take a look.

The MCU has 32 I/O lines, 2 of which are reserved for transmitting data to the keyboard.  For programming, 2 lines are used to receive serial data (RS-232 from the PC) and the remaining 28 lines are dedicated to scanning arcade control switches.  The encoder program code contains default settings for keystrokes so that programming is not absolutely necessary.

To handle serial I/O for programming, a MAX-232 line driver was used to pull voltage levels up to 10vdc.  This required a few external capacitors and 2 I/O lines from the MCU.

A standard 9 pin d-sub connector is used for RS-232 I/O and a large 5-pin DIN connector is used for the keyboard.  Arcade controls are attached to the encoder using a 28 pin 2 row, inline pin header.  This allowed me to attach a 30 pin ribbon cable to the encoder.  The 2 additional pins are used for grounding, as all arcade controls are wired to the same ground plane.

Power is provided by an external 9v power supply (plug in the wall transformer).  An on-board regulator pulls it down to the required 5v and cleans it up.  This is always much easier.

Construction

Construction began with the schematic design.  I used Circuit Maker 6.0 from Microcode Engineering, Inc.  I would never use Electronics Workbench because those people are thieves.

Encoder1.jpg (51073 bytes)

After getting the schematic the way I wanted, I used Traxmaker (Microcode again) to translate the schematic into a PCB layout.  I changed the traces to be nice and fat and autorouted the board.

The PCB layout was printed on my laser printer.  I used 2 sheets of overhead transparency plastic and placed them on top of each other to get nice, dark traces.  This is essential for making PCB's with UV light.  A third sheet of transparency plastic was taped onto a copper board and used to drill the component holes for side one.  I printed 2 more sheets of transparency paper for the back side of the board.

After drilling, I placed the 2 transparency sheets on the copper board and covered them with a piece of glass.  Then I exposed the board, flipped it over and did the same with the back side pattern.  Finally I etched the board, leaving some very nice traces.

With my new PCB, I soldered on all components, wrote a quick test program and powered up.  The board worked perfectly although I can't say the test was very strenuous.  The entire construction process took about 4 hours.

Program Development

The program code was written in assembly using Microsoft Notepad and then compiled using the freely available a51 assembler.  I can't say that it was perfect the first time but it certainly is now.  I used an application note from Atmel on interfacing the PC AT Keyboard.  I translated the C code in that note to Assembly and modified it to transmit scan codes rather than simply receive.

About 6-8 hours were spent struggling with the code to ensure it was perfect.  I devoted most of the time to ensuring that the control polling was optimized and fair for each control.  I didn't want to have any controls being favored by the encoder.

The code was finally burned in using a programmer I bought from Iguana Labs.

Testing

After installing the programmed MCU into the encoder, I connected it to a joystick and 4 buttons on my control panel.  I quickly booted into DOS and started moving the stick and punching buttons.  Although I shouldn't have been, I was amazed to see the keystrokes showing up in DOS!

I rebooted the computer and loaded up MAME.  Then I switched the keyboard for the encoder and started playing.  I got into a volley of Joust games before I stopped to realize that my encoder was working so well.

I can't say that the initial code was without problems.  I did have a couple of stuck keys here and there and I had some timing issues that cropped up.  The serial programming also had some initial flaws.  After another 8 hours or so I had everything working just perfect.

I used the encoder off and on for about 6 months and made 5 others to give to people I know.  Only a few of those people actually got far enough in their projects to use them and that's because I ended up helping them.  I wanted them to get into Mame as much as I was but it wasn't going to happen if they weren't motivated enough to finish their projects.

The next time I do this I'll probably eliminate the external power and regulator and just pull Vcc and ground from the computer.

Bill Of Materials

Item

Quantity

Label-Value

Attributes

Designations

1

1

MCU

(none)

AT89S82

2

2

33pF

RAD0.2

C1,C2

3

5

1uF

POLAR0.6

C3,C4,C5,C6,C7

4

1

(none)

DIN 41524

5

1

Power

(none)

J1

6

1

CONN

DB9/F

J2

7

1

(none)

MAX232

8

1

IDC30

(none)

U4

9

1

78L05

TO-92

U5

10

1

11.0592MHZ

HC49

XTAL1

Conclusion

If you don't want to spend a lot of money on an encoder and have some skill with MCU development, I'd certainly recommend spending some time on an encoder project.  This would be perfect as a project for a EE student.  The nice thing is that I can replace the encoder if it breaks or I can fix the code if there's a problem.  I'm planning on expanding this design as well to allow more inputs, including 4 spinners and a trackball.  It's also much more rewarding to do it yourself.  Similar to the rewards you get when restoring an arcade game.