My Wired World‎ > ‎

Enhanced Matrix Keyboard - An idea of Pin Optimization - An Experimentation

July 2011: Enhanced Matrix Keyboard - An idea of Pin Optimization - An Experimentation

Abstract: 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 the expression NC*NR; where NC is the number of columns and NR is the number of rows. This article addresses to this topic and proposes a novel 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.

1. Introduction: 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.


Figure 1.1: Matrix Layout

2. Proposition of Enhanced Matrix Keyboard: With a minor change in matrix keyboard hardware and software configuration, it is possible to get few more keys. The number of keys that are possible with the proposed solution is expressed by (NC*NR)+NC/R where NC is number of columns, NR is number of rows and NC/R is the number of columns or rows, whichever is configured as input. For the sake of simplicity, this paper will assume that columns are always configured as input and rows as output.

Figure 2.1

Figure 2.1 shows the hardware setup required to implement additional keys with the same number of pins. 


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. Figure 2.2 shows the software flowchart that needs to be implement to decode and identify the key-press. The fourth row, which is connected to +Vcc, has the highest priority.
 
Figure 2.2
Figure 2.2: Software flowchart for Enhanced Matrix Keyboard Setup

3. Software Flow: 

1.      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.

2.      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.

3.      Assuming that C1 column is found high, it is now needed to filter out which of the conditions, explained in point 2, exists.

4.      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.

5.      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.

6.      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.

7.      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.

8.      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:


1.      It is important to check for HICx (x=1,2,3) key presses while checking for each row to avoid incorrect interpretation.

2.      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.

3.      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.

Comments