Idea for different Keyboard Matrix
Posted: 29 May 2020, 05:43
I had an idea for a way to read more keys than is typically possible using a conventional keyboard matrix. I haven't ever seen this done before, but if it has, I would appreciate it if someone could post a link.
In a conventional keyboard matrix the maximum number of keys is determined by the number of pins that are available on the controller that is being used. If a microcontroller like the ATtiny85 is being used then there are 6 General Purpose Input Output (GPIO) pins. If we are going to use the device over PS/2 (it is simpler to implement than USB) then that leaves us with 4 GPIO remaining. Using a typical matrix this would allow only 4 (2 x 2) keys to be read. If 8 were available, then 16 (4 x 4) could be read. If 11 were available, then 30 (5 x 6) could be read etc. But if we use diodes and are willing to make a more complex matrix, then I believe that this can be significantly increased.
Instead of having each pin as only an input or an output, we have each pin change between being an input and an output (and add some diodes). This way we can add a lot more keys to the matrix and still be able to be read them. If this is done, then the number of keys that can be read is n x (n - 1). If we go back to our example of using an ATtiny85, then the 4 free GPIO would allow us to read 12 keys! If we were using a pro micro with its 18 pins then we could read 18 x (18 - 1) = 306 keys instead of the normal 81 with a conventional matrix. This would mean that a $7 pro micro would be able to control just about any keyboard that you want. I also believe that you would be able to have NKRO but I'm not absolutely certain of this.
Looking at the schematic below, if PB0 (IO4) is being driven high then the other 3 GPIO will be able to read if SW1, SW4, or SW7 is pressed. At the same time, the diodes that correspond to SW10, SW11, and SW12 prevent any erroneous changes to the other tree pins. Next PB0 (IO4) is set back to an input and PB1 (IO3) is driven high allowing SW1, SW5, and SW10 to be read.
If you see any reason why this wouldn't work, or any mistake that I've made please point it out. I have not made a design using this principle yet but I'm really excited to experiment with it. The only thing that I can see being an issue is that the the four pins in the matrix might require an external pull-down resistor to prevent any reverse leakage current from the diodes causing pins to be read as high when they should not be.
If anyone on has Altium Designer and wants the project files feel free to PM me and I'll and send them over. Just keep in mind that I didn't bother making footprints or doing any layout so it is just a schematic.
In a conventional keyboard matrix the maximum number of keys is determined by the number of pins that are available on the controller that is being used. If a microcontroller like the ATtiny85 is being used then there are 6 General Purpose Input Output (GPIO) pins. If we are going to use the device over PS/2 (it is simpler to implement than USB) then that leaves us with 4 GPIO remaining. Using a typical matrix this would allow only 4 (2 x 2) keys to be read. If 8 were available, then 16 (4 x 4) could be read. If 11 were available, then 30 (5 x 6) could be read etc. But if we use diodes and are willing to make a more complex matrix, then I believe that this can be significantly increased.
Instead of having each pin as only an input or an output, we have each pin change between being an input and an output (and add some diodes). This way we can add a lot more keys to the matrix and still be able to be read them. If this is done, then the number of keys that can be read is n x (n - 1). If we go back to our example of using an ATtiny85, then the 4 free GPIO would allow us to read 12 keys! If we were using a pro micro with its 18 pins then we could read 18 x (18 - 1) = 306 keys instead of the normal 81 with a conventional matrix. This would mean that a $7 pro micro would be able to control just about any keyboard that you want. I also believe that you would be able to have NKRO but I'm not absolutely certain of this.
Looking at the schematic below, if PB0 (IO4) is being driven high then the other 3 GPIO will be able to read if SW1, SW4, or SW7 is pressed. At the same time, the diodes that correspond to SW10, SW11, and SW12 prevent any erroneous changes to the other tree pins. Next PB0 (IO4) is set back to an input and PB1 (IO3) is driven high allowing SW1, SW5, and SW10 to be read.
Spoiler:
If anyone on has Altium Designer and wants the project files feel free to PM me and I'll and send them over. Just keep in mind that I didn't bother making footprints or doing any layout so it is just a schematic.