PS2 to USB Keyboard converter

I've been puttering around with an Arduino, using it to adapt an IBM Model M keyboard to a USB port. I started with the V-USB library and some other PS2 keyboard library (which I basically rewrote in order to make it robust.)

If you aren't familiar, the PS2 keyboard communicates with a data & clock pin, serially. The standard implementation is to have the clock tied to an interrupt, so you get an interrupt per bit. Makes good sense to me. To "make it robust", I add start/stop and parity checking and added the ability to send NACK commands back to the keyboard to get it to re-send on error.

I think I'm dead in the water. Even with the re-send requests, the adapter works almost all the time. That is, in a normal day of typing it makes about one mistake every 15 minutes. That one mistake is enough. I can reproduce the problem reliably just by mashing keys wildly for several seconds. Somewhere in all that flailing, I can get some kind of bit error that feels like dropped interrupts. If I disable the USB send, I don't get any errors no matter how much I flog the keyboard.

I believe what's going on is that while the USB is processing its interrupt it's skipping handling the PS2's interrupt. The USB code is fantastically timing-critical, and the PS2 is too - you have very few instructions after each clock tick interrupt to get the data line read or written.

What makes matters worse is that the USB interrupt is relatively long - as it processes the entire message in a single interrupt event... Well, I say that like a bad thing, but, from what I understand of the V-USB implementation, it has to be like that.

It just looks to me like it's just not possible to have USB communications and any other microsecond-resolution real-time process going on in a single Arduino.

I could fix it: I could use another Arduino to handle the PS2 and present a buffered stream to the USB-facing Arduino. I could go low-tech and get a shift register to do the same...

But before I chase down those options, I thought I'd ask if anybody thinks I've misread things. I'm pretty new to the Arduino, so I could be making a fundamental mistake.

Hi, Not to in any way discourage figuring it out...

I have 3 of these...

They work fine.

NOT giving up my Model M Keyboards. This one I'm typing on is from a 7532 IBM Industrial Computer that I used in about 1985. Been typing on it ever since :slight_smile:

It almost knows how to write 'C' by itself...

Well, now, what your bringing up here are facts. Facts are good, I'm not saying they're not, but I have pointless over-complication on my side, so I'm afraid you're outgunned. You see, while a Model M (what I have managed to get hold of at work) is good, the true pinnacle of keyboard perfection is what I have at home, the OmniKey 102. Why you ask? Because in addition to the wonder of clicky keys, with the 102 you can configure the Ctrl key to be to the left of the A, where God intended it to be.

Oh and many do ask, "Did God really put the Ctrl key to the left of the A when he molded the first keyboard out of Adam's 14th rib?" Surely it was so. One does not need more than six bits to program in Fortran; for at one time we knew that lowercase letters were the work of bourgeois capitalists. We didn't need lowercase letters to play Zork, but we did need a way to signal to the computer that we had grander ambitions than just typing a letter. Thus, the Ctrl key; it needed a place to go, and since we happened to have a convenient place with no particular mission, well, there it was.

And thus it was that the programmers were satisfied, but then the profiteers at IBM were not. They wanted Secretaries to buy PC's in their thousands. In their cunning, they did see that the programmers were much too busy hunting the wumpus to notice a switch, and they did stick the infernal Caps Lock key in the righeous place of the Ctrl key and began the Great Deception: they did claim that computers were now easy to use and thus we had no need of nerdist keys like the unwholesome Ctrl. A great many were led astray; those that were not were washed away in the rising tide of ignorance. But there are some who cling to the old religion.

Alas and forsooth, there are but few left.

I sometimes share my keyboard with the pitiful waifs who have never known the glory of the original home of the Ctrl key. I want to be a tolerant host and pass them a keyboard that matches their faulty teachings, but the devil has many forms. Windows allows for software re-mapping of the keys, but you have to reboot to get the settings to take effect.

Even if it could be done in software, nothing could show the righteousness of my point of view more than an Arduino buried in an incongruous snarl of poorly soldered wires festooned with a switch marked with two settings: "Path to Glory" and "Road to Perdition". The choice shall be clear.

Cheers, and may your fingers always find the home keys.

I suspect you would get much better results using a microcontroller with real native USB instead of this VUSB crap. VUSB is great and all, but it's a real hackjob; why not use a Micro?

DrAzzy:
I suspect you would get much better results using a microcontroller with real native USB instead of this VUSB crap. VUSB is great and all, but it's a real hackjob; why not use a Micro?

Dumb question I suppose, but what's a "Micro"? Like a Sketchfun Pro Micro? I've got one of those, it has a USB interface, but it's the board programming interface. I'm not sure how I could go about using it to ape a USB keyboard as well.

Use the keyboard library. https://www.arduino.cc/en/Reference/MouseKeyboard

The Arduino Micro (Or leonardo - but the micros - or "pro micro" are cheaper and smaller) - anything with a 32u4 as the processor.