Page 1 of 1
Adjusting the clock frequency of a PC keyboard.
Posted: 24 Sep 2018, 04:54
by new_castle_j
Hello, I'm looking for advice on a custom keyboard controller, like using a Teensy. My host PC was designed strangely, it samples (that is latching at fixed times) the keyboard clock using the horizontal sync of the video chip. This means that when the host system is in CGA mode, data from the keyboard is being polled at 15.750Khz. If I switch to EGA video mode, the keyboard data will be polled at 21.850Khz. So what I need is a keyboard that can also adjust it's clock line to accommodate this weirdo design. The host system also expects PC-XT scancodes, does anybody know if there is a way to use a Teensy based keyboard controller or anything else to change the keyboard clock frequency?
Many Thanks!
Posted: 24 Sep 2018, 11:07
by Findecanor
No. Actually, USB keyboards are polled at at most 1 kHz, and other protocols (XT, AT-PS/2) have a maximum transfer rate of roughly about one key press per kHz.
Your hardware is therefore apparently only latching incoming keyboard events to the horizontal video clock.
Tens or twenties of kilohertz would be crazy fast. "Fast" keyboard firmware may designed around a one-kilohertz loop, and just debouncing of a single key (waiting for a switch to stabilise in one state) often takes at least five milliseconds. Slower office keyboards may not even bothering to use a counter for debouncing, relying instead on the main loop being slow.
There are people who have got higher polling rate on their USB ports on Windows, but that involves hacking the driver for the USB host controller on the motherboard, and the "improvement" has been modest at best ... if the device on the other end have been able to handle it at all. And that was for mice that were able to provide a report every millisecond in the first place.
A USB "Human Interface Device" only provides a minimum delay interval between pollings, specified in milliseconds. Then the host is allowed to extend that interval to what it wants. On a PC with Windows, polling intervals are supposedly rounded up to a power-of-two milliseconds.
BTW. The hardware in a PC can only produce PC-XT scancodes. No IBM-compatible PC has actually received XT scancodes for decades. When the PC-AT was introduced in 1984, IBM added a small microcontroller which converted from AT codes produced by the keyboard into XT codes so as to be compatible with badly written DOS programs that had circumvented the BIOS and read the hardware directly. This has remained to this day and even Microsoft Windows uses XT scancodes internally.
Posted: 24 Sep 2018, 17:31
by new_castle_j
Thank you for the comprehensive reply. I should clarify that the host system I am dealing with is decades old and is a PC-XT clone. From the specs I've seen, the XT keyboard clock frequency should fall into a range between 10 - 16 khz. When I connect an XT keyboard and set my host to CGA mode, the keyboard works fine, this makes sense because the horizontal sync frequency of CGA is within the 10-16 khz range of the XT keyboard clock spec. If I switch the host to mono or EGA modes, then the keyboard produces garbage on the screen. Originally this system had an external adapter box for the keyboard that took care of dealing with these different frequencies, however that box is long gone. I'm attempting to find out if a Teensy or anything else can output keyboard data at a clock frequency of my choosing.
Posted: 24 Sep 2018, 19:15
by Engicoder
Yes, that is possible. The frequency of the clock signal that the keyboard/teensy generates can be controlled using a timer on the teensy. Did the original "external adapter box" have a switch on it to change frequencies? if so the same could be done with a teensy. If not, I would have to assume that the PC sends some type of signal to indicate a frequency change.
Posted: 24 Sep 2018, 20:41
by Findecanor
Hehe. I usually explain these things to pimpled kids. :-รพ
The Teensy has a AVR MCU with a USB device. The firmware ps2avr for AVR does talk PS/2-AT (PS/2 and AT are the same protocol, different connector) but I have not heard of any community firmware that talks XT ... Maybe you could start with ps2avr and adapt it to XT. There are some subtle differences between PS/2-AT and XT beside the scancodes though.