PS/2 keyboard auto-reset circuit - for keyboards that don't automatically enter PS/2 mode on startup

Posted Apr 2, 2021, 10:01 AM UTC

Posted Apr 2, 2021, 10:01 AM UTC
Sweet. It's convenient that the command for resetting the keyboard is all '1's with '1' as the (odd) parity.
My solution for sending arbitrary bytes is actually similar, except using a pair of 74HC165 parallel load shift registers with jumper wires to set the bits to be sent. I also included logic to prevent the data line being pulled low until the clock line is released (per what I've read about the protocol) but from your experience that's not necessary, at least with the Periboard-409P and quite likely in general.
According to what I read, it's meant to be OK to pull low during a read - the keyboard is supposed to buffer the data and resend it. It's meant to be open drain so also shouldn't break anything - neither the device nor the host should drive either the clock or the data high. However, the periboard certainly seems to do its own pulling-up, at varying strengths.
I've had varying results with this circuit on power-on, too - it doesn't always work. But triggering it later manually seems fine.
I knew that pulling the clock line low during a read - at least if done before the 10th clock pulse - causes the keyboard to buffer the data and resend later. My concern was whether it's OK to pull the data line low at the same time as the clock: sources such as this describe requesting to send data to the keyboard by first pulling clock low for X microseconds and then pulling data low and releasing clock - after which the keyboard begins generating clock pulses and reading data. I agree nothing's likely to break since the lines are never actively driven high (e.g. the diodes in this circuit prevent that) but conceivably some keyboards might fail to recognize the request to send - if they're expecting data to remain high during the X microseconds that clock is low.
That said, I looked again at the IBM AT technical reference and it includes the following (italics added):
While not 100% definitive, I think these portions of the manual imply that the state of the data line is not relevant while the host has the clock line pulled low prior to sending data, so we should expect this circuit to work fine with any PS/2 keyboard that can be 'woken up' by receiving the 0xFF 'reset' command.
Regarding the intermittent success at power on, I can think of a couple of possibilities:
With '~RESET' controlled by a 6522 VIA pin as u/gfoot360 suggests, generating these delays would be easy enough. Otherwise a couple of RC circuits combined Schmitt triggers could achieve the same thing without requiring software.
Yes, I'm probably wrong about the data line, and if keyboards do drive it high actively then I ought to be more careful.
I think the reason my circuit doesn't always work on power-on is that it reacts to glitches in the clock line while the keyboard is powering up, and starts the sequence before the keyboard is pulsing the clock. I'm sure software is the best way to go in the long term, as you can then send whatever commands you need to later on as well.
I think it's probably fine from an electrical standpoint at least, to pull the data line low at any time - the IBM technical reference I mentioned in my prior comment on this thread states that "The source of each of these [clock and data] lines is an open-collector device on the keyboard [...]" (top of page 4-14.)
I also noticed the varying strength pull-up from the Periboard; my wild guess is this is for power saving - no need to pull up as strongly when no pulses are being generated, but who knows? I did previously try putting in a weak pull down resistor to try to confirm the keyboard was not actively driving high at any time, but I forget if I checked both data and clock. I may look into this some more.
I agree the best solution ultimately will be software to send whatever commands are desired. I'm planning to try that out using the pair of 74HC165 shift registers for output to the keyboard, sharing data lines with the 74HC595 shift registers which Ben uses for input from the keyboard in his latest video.
Thanks for this! I ended up here because I also bought the same cheap PS/2 keyboard from Amazon as many others seem to have.
I realize this is a somewhat old post, so I'm not expecting an answer, but still hoping :-) Looking at your circuit, I was wondering what the D flip flop was actually doing since the data pin on the flip flop is pulled high, so it can only outputs 1s. But then I thought: if you want to send $FF to the keyboard, you need all 1s, except the first bit, with is the start bit, which is a 0. Is that what the D flip flop does here? It provides a way to get that first 0, because Q goes low when /R is pulled low by pushing the reset button?
Yes I think so, I don't remember exactly. I considered sending all 0s instead but that would still need a 1 for the parity bit I think? So I did it this way.
Thank you so much for this!! I was banging my head against the wall trying to figure out why it why the keyboard scan code wasn't showing up.
Hey, I'm very new to this stuff, only done very basic arduino circuitry before.
I've wired this up but it isn't working for me so far as I can tell (haven't done troubleshooting on all avenues yet).
However the more reading I do the more I think i should use a software solution as you've alluded to.
Forgive me if its a stupid question but how do you send commands to the keyboard instead of just listening for scan codes?
I was just starting a project with a PS/2 keyboard and found out my keyboard has the $AA scancode problem on power-up. I found this post right away and it is a great solution! It works perfectly. Thanks a lot!
As discussed by u/pjdennis and u/tmrob4 over here: https://www.reddit.com/r/beneater/comments/m836ul/ps2_keyboard_not_working_on_the_6502_but_is/
It sounds like u/pjdennis has a proper solution for sending arbitrary commands to the keyboard, but as most won't have that implemented yet, here's a simple circuit that at least sends an FF command to the keyboard on demand. I wired ~RESET to ground via a button, but it seems to automatically trigger on startup in any case, putting the keyboard into PS/2 mode, so I never need to press the button anyway.
You could equally well wired ~RESET to a VIA pin, or the same reset signal that resets the CPU (even better if you have a capacitor on this to slow it down) - it doesn't really matter where it comes from.
Thanks for the circuit. It will be fun trying it out.
My ultimate goal is a handheld 6502 with keypad. I've got the keypad interface working but it is somewhat limiting so I want to add a PS/2 keyboard connection for more serious work.
Please post pics of this project. :) I’d love to see it!
Still prototyping on breadboard so it's not much at this point. Here is a pic. The display is showing the result of the command F000L, which is my monitor routine for disassembling 20 lines beginning at address $F000.
The Keypad is able to detect simultaneous key presses so I've programmed the 0 key to be a shift key as well. This way I have an additional 9 keys to map to functions besides the basic 0-F hex digits.
The final stage will be a 3D printed enclosure for the display and 6502 circuitry. As you can see, I'm quite a ways from that. I haven't decided if I'll integrate the keypad into that or give it it's own enclosure. Since I'll also have a PS/2 keyboard connection I'm leaning toward keeping the keypad separate at this point..
The display manufacturer also makes a touch screen version so ultimately I might just ditch the separate input devices for an onscreen keyboard or maybe that will be a later project. BTW the 6502 communicates with the smart display through a serial interface so the display handles the hard parts. Actually it's a bit slow. The 6502 can spit out data faster than the display can process, requiring a good size buffer on the display side.
Awesome work!! Keep at it! I hope to see the final project once it’s done!!!