AN-1088 Asynchronous State Machine 4x4 Keypad Encoder

This application note demonstrates how to design a Keypad Encoder using the asynchronous state machine in the SLG46531.

As shown in Figure 1, the design of this 4x4 keypad encoder is constructed on the basis of the Asynchronous State Machine Macrocell (ASMM). The ASMM is used as a serial connection to one of the 16 keys.

4-bit Counter on ASMM

A 4-bit counter is realized using 8-states Asynchronous state machine (ASM). To go through the full cycle and to return into 0th state, 16 state transitions should be done. Two Lower bits are decoded from binary code and control 4 lines, which are connected to the matrix buttons’ (switches) columns. If the counter code is equal to «XX00», then the first line will be LOW and three others will be HIGH. Similarly «XX01» code – the second line, «XX10» - the third, «XX11» - the fourth will be LOW and three others - HIGH.

Keypad encoder design

Figure 1. 4x4 Keypad encoder design

By the external connection each line is connected to the matrix column (1st – to the 1st and so on). The two higher bits control the MUX (sel1 and sel2 inputs), whose inputs are connected to the matrix buttons’ (switches) rows. If the counter code is «00XX», then the first row will be connected to the MUX input. Similarly: «01XX» code – the second row, «10XX» - the third row and «11XX» - the fourth row.

When the switched button is detected, the MUX output will go HIGH, which stops the generator and its value will be output to the D0..D3 outputs, or by the request of the MC using I2C protocol.

ASM block diagram design

Figure 2. ASM block diagram design

I2C Output

In this design the pressed button code transfer function on the two lines using I2C protocol is realized. To do this it is necessary to ask for the next MC address: 3rd MC bank, 247th data byte. The lowest bit of the byte will contain the information whether the button is pressed or not. From the 2nd to 5th bit (4 bits) – pressed button code (if the first bit is equal to “1”). The 6th, 7th and 8th bits information doesn’t matter to us and they should be ignored.

 External Expansion Keyboard

Figure 3. External Expansion Keyboard (16 Keys 4X4 Matrix)

The program code (for demo-board “Arduino UNO”) example implementation is provided in the attachment. This solution allows using only 2 line interface to a 16-button matrix, which is valuable when limited by a MC with a small number of free pins.

Conclusion

This keypad decoder design illustrates the ease of using asynchronous state machine design, and the advantage of freeing up MC pins when used for MC expansion.

About the Author

Name: Petro Levandovych

Background: Petro Levandovych joined Silego in 2012 and has more than 5 year experience in electronics, radio communication equipment, microcontrollers and automated information systems. He began his career with State Enterprise LVIV RADIO ENGINEERING RESEARCH INSTITUTE (SE LRERI), working as System Developer Engineer. Petro has graduated from the Lviv Polytechnic University as a specialist in Radio Communication Equipment Engineering in 2009.

Contact: appnotes@silego.com

Files


More on this topic:


See full list of Application Notes