3 ms·
Elaborating on this, in case anyone wants to know more details (I'd edit the original, but for some reason HN decides you can't edit comments after an annoyingl
by TheLoneWolfling 12y ago
Elaborating on this, in case anyone wants to know more details (I'd edit the original, but for some reason HN decides you can't edit comments after an annoyingly short time limit.)
Say you have N free pins on your controller, and you want to read K keys. Find the smallest integer number of columns such that log2(k/c) + k/c <= n - so, for example, with 108 keys and 20 pins, you can have 7 columns, with 16 rows (keys/column). This means a 3-bit mux, which is relatively easy to find.
Tie each row via diodes to 1 key in each column. Then tie each row to a pin on the controller.
Tie each column to an output of the mux, and tie the input of the mux to Vcc. You'll also probably want to tie each column to a grounding resister as well. Maybe a small cap. (Or just use the chip that does this directly, I can never remember the name. Output selector? Something along that line. "An IC that outputs Vcc on the selected pin and ground on all others".).
Then connect the selector of the mux to the remaining pins on the controller.
To operate, just loop through all valid outputs on the mux repeatedly - probably with gray code, as that way you don't need to make as many pin transitions. Each time you change the output of the mux, read the values of those keys. You'll probably need a mapping of row/column -> key, as well as the previous values of keys. Any time the value of a key changes, output the appropriate packet. (Note: most of the time most keys don't change. As such it may be faster to do a quick check that "old column values == new column values" before checking bits one by one.)
As long as your scan rate is sufficiently high, you shouldn't miss keypresses. (And if you want to get fancy, you can actually borrow a technique from dRAM. Have each key connected from ground to a cap (per-key) to a diode to Vcc. Potentially with a resistor, although the diode might be enough. Then do the above row/column, but tied to the caps / diodes as opposed to the keys themselves. This way you'll be able to read that there is voltage on the cap even if your scan missed when it was down. It also provides a certain amount of debouncing. The disadvantage is that there's a whole lot more per-key.)
- ChuckMcM 12y agoYou may be surprised to find that you can get microprocessors with over a hundred general purpose I/O pins if you're willing to solder them all down (the STM32Fx series in the QFP208 comes to mind) that would let you wire every key of a 104 or 107 key keyboard to a pin for monitoring. And you could read them all at close to a megahertz so you could get an effective state of all the keys at a given point in time. (the chip can run at 168Mhz and you're looking at basically 14 I/O ports.)
- TheLoneWolfling 12y agoWelp. I keep forgetting how absurd microprocessors are now. Still... That's got to be a fun soldering job. And those are 1.8v / 3v chips, whereas if you're using USB you've got 5v input. Does it support interrupts on the pins? Or just polling? Also, can you give me a specific example of a specific part? Searching "STM32Fx QFP208 package" gets me... a link to your comment. Great to know that HN gets crawled, but still...
- ptomato 12y agohttp://www.st.com/web/en/catalog/mmc/FM141/SC1169?sc=stm32 http://www.st.com/web/en/catalog/mmc/FM141/SC1169?sc=stm32 has the list. http://www.st.com/web/catalog/mmc/FM141/SC1169/SS1577/LN1806/PF254219 http://www.st.com/web/catalog/mmc/FM141/SC1169/SS1577/LN1806... is one chip you could use, though frankly using that much processor for a keyboard firmware is hilariously overkill. (Not that there's any reason not to for a hobby project, really...)
- TheLoneWolfling 12y agoI'm still astounded that you can pick up a chip like that for <15$ (well, ok, not including shipping). Huh. Something to consider. Thanks for the links!