Everything for Electronics

Tech Forum





May/June 2018

PS2 Emulation

My Sony CD changer has a PS2 keyboard port to enter the CD title, details, etc. Instead of typing, is there a way to emulate a PS2 interface on a PC or processor board to automate the key presses?

#5181
Lee
Schaumburg

Associated files:



Answers

I have successfully plugged an old PC keyboard into that CD changer to enter data. However, what is it that you want to automate? Every entry i.e. artist, titles, etc.; are different?

M. Herman
LaQ, CA

Yes, you can emulate a PS-2 keyboard. An SPI-master port will do the job as long as it can handle 11 bits, or two 8-bit values in rapid succession. Not all microcontrollers can. (If you lack a good SPI port, emulate it in software.) Use the MOSI signal for the key-code transmissions and use the SCLK signal to emulate the keyboard’s clock output. The bits transmitted when you press a key look much like those put out by a standard UART: a start bit, eight data bits, an odd-parity bit, and a stop bit.

The keyboard’s clock output produces a logic-1 in its idle state and created a positive edge for each of the 11 bits. An SPI port configured as CPOL=1, CPHA=1, provides the proper timing. Note: The least-significant bit of an 8-bit key value gets sent first. My old PS-2 keyboard produces clock signals at 13.7 kHz. That’s a good frequency to start with for the SPI port.

A PS-2 keyboard assigns a unique non-ASCII code to every key. Find a list of the keys and assigned codes here: https://techdocs.altium.com/display/FPGA/PS2+Keyboard+Scan+Codes. When you press the “A” key, for example, the keyboard’s circuit produces the hex code 1C. When you release the “A” key, the keyboard transmits a key-release code F0, followed by the key’s code again.

The shift key works the same way. To send an uppercase “A” your microcontroller or processor board would send the SHIFT-key code, the A key code (then a short delay) followed by the key release code and the A key code again. Then it would send the key release code followed by the shift-key code.

Remember, your code must calculate an odd-parity bit and insert it in the 11-bit value to send. You can find parity-generator code on the Internet. Also, ensure you send the key and release values in bit-reversed form. Thus, the 1C code (0001 1100) for “A” must get transmitted as 0011 1000. You can simply set up your code so it uses the “reverse-bit” values to start with.

Jon Titus
Herriman, UT