Overloaded Matrix Keyboard - An idea of Pin Optimization
There are several ways to interface keys with a microcontroller to create a HMI. The matrix layout is known to be one of the most port-pin-optimized solutions for interfacing keys to a microcontroller. The maximum number of keys that can be connected through matrix layout is given by
This post proposes a solution for increasing the number of keys to (NC*NR)+NC without affecting the performance of the device. It can be effectively applied to scenarios where more number of keys is required to be applied with limited number of port-pins.
Matrix layout is one of the most efficient ways of interfacing keys to a logic device (it will be referenced as a microcontroller, for the sake of ease, from here onwards). The number of keys that can be connected to a microcontroller with matrix layout is given by the expression NC*NR; where NC is the number of columns and NR is the number of rows. The schematic of matrix layout is shown in figure 1.1.
Proposition of Overloaded Matrix Keyboard: With a little help from hardware and little help from software, it is possible to get another row of keys in the matrix keyboard. The total count now would be (NC*NR)+NC/R where NC/R is the number of columns or rows, whichever is configured as input. For the sake of simplicity, I will assume here that columns are always configured as input and rows as output.
An additional row is added the input of which is +Vcc. Each key is named corresponding to the intersection of row and column. The fourth row is named as ‘HI’ and the corresponding keys are referenced as HIC1, HIC2, HIC3 respectively after the corresponding column. Below flowchart outlines flow that needs to be implement to decode and identify the key-press. The fourth row, which is connected to +Vcc, has the highest priority
3. Software Flow:
- All the rows (output lines) are held low. In this condition, each of the input lines is checked. If C1 is high, it implies that, HIC1 key is pressed. Similarly, HIC2 & HIC3 key presses can be detected by checking C2 and C3 lines respectively.
- R1 is set high and R2 & R3 are kept low. In this condition, each of the columns is checked. If any of the columns is found high, it implies that either any of three keys in R1 or HI row is pressed.
- Assuming that C1 column is found high, it is now needed to filter out which of the conditions, explained in point 2, exists.
- For this, all the rows are immediately brought low by software once it is found that C1 is high and Column C1 is checked again.
- If C1 line is still high, it implies that it is high due to HIC1 key-press and not R1C1 key-press. Whereas, If C1 line is low, it implies that it was high due to R1C1 key-press and not HIC1 key-press.
- If any of the other column is found high, steps from 3 to 5 needs to be carried out to filter and find either of R1C2, R1C2, R1C3, HIC1, HIC2, HIC3 key-presses.
- Similarly R2 is set high and R1 & R3 are kept low, and steps from 2 to 6 are carried out to identify either of R2C1, R2C2, R2C3, HIC1, HIC2, HIC3 key presses.
- Similarly R3 is set high and R2 & R1 are kept low, and steps from 2 to 6 are carried out to identify either of R3C1, R3C2, R3C3, HIC1, HIC2, HIC3 key presses.
It is worthwhile to note the following:
- It is important to check for HICx (x=1,2,3) key presses while checking for each row to avoid incorrect interpretation.
- When one of the row is high and an HICx (x=1,2,3) key is pressed, the current will be limited by the inbuilt circuitry of the microcontroller.
- If a HICx (x=1,2,3) key is pressed & released between the software flow points 2 & 4 (within few microseconds for a controller clock above 1 MHZ) (refer software flow), it will be missed. But since a key-press by a human usually takes place in order of milli-seconds, this condition is out-ruled.