| ||
27 May 2009 Author: Giorgos Lazaridis MAME Arcade-style console circuitThe Problem... I am sure that every one knows the MAME machine, the ROM arcade emulator. There are thousands of people that spend their time with the "oldies but goldies" arcade coin-up games. The problem when playing MAME is than when you play games such as street fighter or samurai shodown, games that require multiple keyboard keys to be pressed simultaneously in order a special move to be achieved, the keyboard cannot handle it. The key matrix of the keyboard can allow no more than 5-6 keys, in special cases, to be pressed simultaneously. The problem is harder when there are two players playing together. The annoying distinctive "BEEP" will be heard when one makes low defense and the other attacks from above... Particularly this problem, sent me directly to the lab, under the bright cool light, in order to design something that would allow enough keys for both players to be pressed simultaneously without any problem. The first idea was to have more than one USB keyboard and use some of the keys from each keyboard, but this idea was pretty lame. Other ideas like using keys from the keyboard matrix that do not really interact to each other came up to be easy but not-enough, as those keys are way too few. After hours of concentration and rejections, i discovered finally that what i really need is a keyboard replacement... A custom keyboard replacement The scenario was to copy the keyboard protocol and put it in a PIC. The inputs of the PIC would be also the inputs of the buttons. I found the keyboard protocol to be easy to re-create. I wrote a tutorial myself for PS2 keyboard protocol theory for those that would like to know how the keyboard talks with he computer. To make the keyboard replacement much more expandable, i decided not to use a big PIC with many inputs for the keys. Instead, i would use a 16F88 and from 3 I/O ports i would cascade 74166 TTL's to perform a PISO (Parallel In Serial Out) circuit that could be easily expanded with as many inputs as i wanted. The following circuit has up to 24 inputs. 4+4 inputs for the two joysticks, 12 buttons (6 for each player), 2 start buttons, 1 coin button and one pause button. That would be the original layout, but can be changed in terms of button count and functionality. To test this circuit, we run some extreme tests. No matter how many buttons where pressed simultaneously, the circuit responded fast and accurate to the PC. A big relief :D In action!!! I really like to see first a circuit in action and then the circuit itself, when i visit other site with electronic projects. This helps me understand through the action if it really worths to see the circuit itself :). Therefore, in every project that will follow, i will first demonstrate the construction working and then the how-to. The following video demonstrates the circuit capabilities. 11 keys (contacts) will be pressed simultaneously (as possible as that can be) to see how the computer will response to this flood. You will also see that using a conventional keyboard this is by far not possible to be done. The electronic circuit Following may you find the schematic circuit of the construction. IMPORTANT!!! The schematic is rather new, drawn during May 2009. The project was first created during October 2005. The original schematic circuit is lost, therefore i had to draw a new schematic. The new schematic is NOT 100% compatible with the PCB that will follow. That's why you will have to decide which one to follow if you wish to make the project yourself. The PIC program on the other hand will work for both the PCB and the schematic. The PIC is the heart of the circuit. The oscillation frequency (XTAL) is 4MHz. When no input from the 74166 is taken low (no button is pressed), the PIC will give always control to the external keyboard attached. Thus, the user will be able to use the keyboard normally. All the time, the PIC runs a loop internally to acquire the 24 inputs from the three TTL. If an input changes state, from HIGH to LOW or vice versa, it will cut-off the external keyboard and will give control to the PIC itself, by changing the bidirectional switches of the 4066. Then, it will send the appropriate data to the PC, according to the PS2 protocol. The circuit is clocked at 24KHz, a perfect tune for the PS2 (20-30KHz range). Right after, it shall give control back to the external keyboard. The loop shall run again after a short period of time, to avoid flooding the PC buffer due to switch bounces. You should NOT forget to connect an external PS2 keyboard to the "Keyboard" pads. This keyboard will handle all the communication needed to be done between this and the computer during the startup time, so that the PS2 will operate normally. And also, this keyboard will later operate as a normal keyboard attached to the PS2. The 5 Volts power supply is better to be taken from another source. I have tested myself this circuit with power supply taken directly from the PS2 port with no problem at all. This is not suggested though, as the PS2 can supply up to 100mA normally. Enough for one keyboard but not for a keyboard and PCB with 5 chips. My suggestion is to hack your old PS2 cheap keyboard, remove the useful wire with the PS2 connector on the edge, and solder another 4-core wire in it's place. This wire will be connected to your PCB ("Keyboard" pads). The wire that was taken from the keyboard, the one with the PS2 connector on one end, shall be used to connect your PCB with the computer ("PC" pads). Then, you will have a parallel male PCB mounted right angle connector mounted on the PCB. Hack you old parallel printer connection cable then. Remove completely the male connector and trash it. There will be 25 wires inside the cable. 24 for the keys and one with the LOW signal to actuate them. If you use a standard parallel printer cable, this wire should be the White-Blue wire. Your construction should be ready to work! Do not forget to connect the pull-up resistors otherwise funny things may happen. You could alter the PCB a little bit but i wanted to use resistor nets and that was very difficult for a small on-layer PCB. So i have not include them on the PCB. See bellow how i have connect them. I did some surgery-work on the bottom side (copper) of the PCB and soldered two resistor-nets of 9 and 6 more 1/4 Watt resistors, all 10K rated, directly to the pads of he 25-pin plug. You could do the same to save significant space on the PCB. Programming the keys There are 24 available inputs from the three 74166 TTL inputs. Those inputs correspond to 24 places of the EEPROM memory within the PIC controller. The key to be sent upon an input actuation (a LOW transition of the input) is defined within these 24 spaces of the EEPROM. So, you should program your EEPROM of the PIC accordingly. Those 24 places are located from 0x00 to 0x17, and could have a single byte number, Each number corresponds to a key that shall be sent. The following table show those number and key definitions:
For example, if you would like to send key "LEFT ARROW" when the first input is actuated, you should put the number 0x44 to the position 0x00 of the EEPROM and so on. Each time that the PIC requests to read the inputs, they are shifted in series. The first bit corresponds to EEPROM position 0x00, the seccond to 0x01 and so on. The very first bit comes from the IC1-A, the second from IC1-B and so on until the 8th bit. Then, the 9th bit comes from the IC2-A, the 10th from the IC2-B and so on until the 16th bit. The last 8 bits (17-24) comes from the IC3 inputs A to H. You should now be able to program the corresponding keys for your layout yourself. In any case, you can find flowing an attached file that has pre-programmed the inputs the way that i have the keys programmed. It's a good start if you really want to avoid this step. Just download the file data to the PIC EEPROM and that's all.
Just for the records, i use the key 5 for the coins, 1 and 2 for player 1 and 2 to start, arrow keys for the player 1 moves, DGRF for the player 2 moves, L Ctrl, L Alt, L Shift and Space for the player 1 keys (1-4) and QWAS for the player 2 keys. Almost the same as the MAME original setup that i have. For the one that wants to go deeper in programming the keys, i have also include a pdf to download and see all the scan codes for all the keys, even for the modern keyboards with multimedia and ACPI support.
The Printed Circuit Board Please read the note from the "electronic circuit" above before you start etching!!! As you may notice, there are no pull-up resistors (R1,R2 and R3) included in the above PCB. That is one of the differences that the actual schematic and this PCB have. The original design had the resistors soldered on each button. You may use the same PCB, but remember to add those resistors yourself. You could also make another small PCB that would be plugged between the 25pin input of the circuit and the 25pin cable of the buttons. Or any other way. Use your imagination. The PIC code Following you may find the complete PIC code for this project. The code is fully tested ONLY on a PIC 16F88 chip. You may need to alter it if you want to program another PIC. The Code.zip is the actual code files, and the HEX.zip is the same code assembled into hex-code so that you can easily program a chip. Please note that I use MPLAB and therefore, there could be problems reading the assembly code from another GUI.
ToDo It's not over yet. As you may have already notice, there are 5 I/O ports of the PIC that are not used, however they are wired to pads. Those pads are actually unused... Yet, there are some ideas for them. The upgrade of this circuit is an LCD monitor for the user to be able to program the EEPROM keys directly, without the need of re-programming the chip. Or it could work in a way that the external keyboard will be used to program the keys. Or maybe both! In any case, stay tuned! Also, the communication with the PC is still NOT bidirectional. It has been left from the test-runs like this. Until now, we had no problem with this. That's why i have not proceed with the other half of the protocol implementation. For educational reasons i may enrich it with 'ears' in later days. But i have to note here that during the PC startup, it requests an answer to some commands from the keyboard in order to consider it present. If no answer, the PS2 will not operate at all. Therefore, the external keyboard is very important to be connected to the appropriate inputs of the PCB. During startup, it will answer to all the questions of the PC and the PS2 will operate normally. That's the trick! Relative pages Comments
|
|
Contact
Forum
Projects
Experiments
Circuits
Theory
BLOG
PIC Tutorials
Time for Science
RSS
Site design: Giorgos Lazaridis © Copyright 2008 Please read the Terms of services and the Privacy policy |