AN-1179 Multiplexing a 4-Digit LED Drive and a 4x4 Keypad Scanner

This application note demonstrates a practical solution for four-digit 7-segment LED display control and a 4x4 keypad scanner. It will also demonstrate sending and receiving data via the I2C bus using one GreenPAK™ CMIC.

To connect the four-digit LED display and a 4x4 keypad to a microcontroller (MCU), one typically needs twenty I/O pins. However, using the GreenPAK SLG46538V CMIC allows us to save MCU hardware resources by using only three I/O pins. The main components used in the design are the asynchronous state machine (ASM), bidirectional I/O pins, the I2C serial communication block, and the combination function macrocells.

Theory of Operation

The basic idea of this app note is to use the bidirectional pins of the SLG46538V IC. This makes it possible to use the same ports simultaneously to connect to the cathodes of the digital LED display and to the sixteen keys, arranged in four rows and four columns. The LED display control and the keyboard scanning control occur at different times in multiplexing mode. The basic scheme is shown in Figure 1, and Figure 2 shows a timing diagram of the multiplexing mode.

External connections of the SLG46538V GreenPAK CMIC

Figure 1. External connections of the SLG46538V GreenPAK CMIC

Timing diagram of multiplexing mode

Figure 2. Timing diagram of multiplexing mode

In LED display control mode, the four digits of the display light up, one by one, in about two milliseconds each. Then, during the next ~2 ms, the keys are scanned in keypad scanning mode. The whole cycle continues for about 9.7 ms, after which the process is repeated. Transistors Q1-Q4 should be PNP type, with a collector current of at least 200 mA (e.g. PMBT5401).

The data that should be displayed on the digital display and the data that was obtained by scanning the keyboard is transmitted via the I2C bus. The CMIC generates an interrupt while scanning the keyboard if any key is pressed. The data obtained by scanning is updated at regular intervals when the chip generates an interrupt.

A standard 7-segment LED display can show numbers from 0 to 9, some letters of the alphabet, and a decimal point. The display has a common anode for each digit. In order to light up any segment, a logic LOW level signal has to be transmitted to its cathode.

Implementation - LED Display Circuit

LED display circuit design

Figure 3. LED display circuit design

In order to implement the multiplexed display mode in this design, we used the GreenPAK’s ASM (asynchronous state machine) block. The output signal comes from the RC Oscillator Block with frequency:

RC OSC Freq (25 kHz)/24 ≈1042 Hz

The Pipe Delay divides this frequency in half. The Pattern Generator (PGEN) and DFF0DFF2 blocks are synchronized from this signal. These blocks provide a signal to transition the ASM to another state, and switch in a low logic level to PIN6, PIN17, PIN15 and PIN12 (connected to transistors Q1-Q4) to show the relevant digits on the display. The ASM block has eight outputs that connect to the internal matrix. The logic level of each of the eight outputs is based on the current state of the ASM block, and are defined by the connection matrix output RAM. These eight outputs are connected to the following pins through the internal matrix: PIN13 (seg. a), PIN16 (seg. b), PIN18 (seg. c), PIN19 (seg. d), PIN3 (seg. e), PIN5 (seg. g) and PIN10 (seg. dp).

The sequence of switching states in ASM

Figure 4. The sequence of switching states in ASM

The microcontroller communicates with the chip via a 2-wire bus, the I2C Serial Communication Block. The MCU initiates the exchange of data with the following command sequence:

Start bit → Control byte ‘0x00’(write) → Address byte → Data byte →…→ Stop bit

In order to show data on the display, it must be written in the following registers of the Connection Matrix Output RAM:

Digits Address Byte, Hex Register Bit Signal Function
Digit 1(Common Anode 1) 0xD1 reg<1679:1672> RAM 8 outputs for ASM-Digit_1 output
Digit 2(Common Anode 2) 0xD2 reg<1687:1680> RAM 8 outputs for ASM-Digit_2 output
Digit 3(Common Anode 3) 0xD3 reg<1695:1688> RAM 8 outputs for ASM-Digit_3 output
Digit 4(Common Anode 4) 0xD4 reg<1703:1696> RAM 8 outputs for ASM-Digit_4 output

 

Table 1. The registers for data storage to indicate on LED display

These data are stored in the registers and displayed until they are overwritten via I2C again, or the IC is rebooted. In the latter case, these registers will resume the default value (‘0xFF’, stored in the NVM).

Connection Matrix Output RAM default configuration

Figure 5. Connection Matrix Output RAM default configuration

Figure 6 shows example data for transmission via the I2C bus, to be output to the LED display.

Example of LED display data registers from the connection matrix output RAM

Figure 6. Example of LED display data registers from the connection matrix output RAM

In LED display control mode, all outputs of the SLG46538V IC (except those that provide data exchange via the I2C bus) are configured as digital push pull outputs.

Implementation - Keypad Scanning

After completing the LED display control mode, the IC goes into the keypad scanning mode. The DFF0 trigger output is set to a logic HIGH level, and the ASM goes into the “Scan column 1” state. In scanning mode, the transition of the ASM from state to state is done by the OSC0, EDGE DET0 and EDGE DET1 macro-cells. These edge detectors form a short pulse on the falling edge of the OSC0 signal output, and the transition frequency between the states of the machine in this mode is four times greater than in the display mode. In keypad scanning mode, the 4-bit LUT1 sets the output to a logic LOW level, which switches the PIN3, PIN5, PIN7, and PIN10 pins into digital input mode. These PINs are configured with10 kΩ pull-up resistors.

Keypad scanner circuit

Figure 7. Keypad scanner circuit

The ASM alternates between each pin (PIN13, PIN16, PIN18, PIN19) to send logic LOW level pulses. These PINs are connected to the four columns of the keyboard. The other four PINs (PIN3, PIN5, PIN7, and PIN10) are connected to the four rows of the keyboard. When any keypad button is pressed during the scanning process, a logic LOW level of the output pins is transferred to the corresponding input pins. At this time, the 4-bit LUT0 output gets a logic HIGH level.

This design allows the code to determine only one button press. Each button has a unique 4-bit code (see Figure 1), which is formed by the 3-bit LUTs (LUT4 - LUT9) when the button is pressed. This is then stored at the outputs of DFF3-DFF6 until the next scanning mode cycle. The code can be obtained by the microcontroller via the I2C bus, which should read the following data registers:

KEYPAD CODE Address Byte, Hex Register Bit Register Bit Definition
D0 0xF1 reg<1932> LUT3_0 / DFF3 Output
D1 0xF1 reg<1933> LUT3_1 / DFF4 Output
D3 0xF1 reg<1934> LUT3_2 / DFF5 Output
D4 0xF1 reg<1935> LUT3_3 / DFF6 Output

 

Table 2. The registers for storing data identifying the pressed button

To do this, the MCU must initiate the transfer of data via the I2C bus:

Start bit → Control byte ‘0x00’(write) → Start bit → Control byte ‘0x01’(read) → Address byte ‘0xF1’ → Data byte → Stop bit.

Interrupt signals come from PIN4 to the MCU whenever the keypad scanning cycle is active and any button is pressed. The MCU receives the interrupt and reads the button code (the four most significant bits in the ‘0xF1’ byte).

The algorithm for the analysis of button presses must be implemented in the controller’s program, along with the debounce filter.

The total time for the display scanning modes is approximately 9.7 ms, but if necessary this can be increased or decreased. To do this, the 'CLK’ predivider value and ‘OUT0’ second divider value in the OSC0 macrocell must be changed via I2C:

OSC0 default settings

Figure 8. OSC0 default settings

Address Byte Register Bit Signal Function Register Bit Definition
A7 reg<1340:1339> OSC Clock Pre-divider for 25kHz/2MHz 00: Div1
01: Div2
10: Div4
11: Div8
A8 reg<1349:1347> Internal OSC 25kHz/2MHz Frequency Divider Control for matrix input <27> (OUT0) 000: OSC/1
001: OSC/2
010: OSC/3
011: OSC/4
100: OSC/8
101: OSC/12
110: OSC/24
111: OSC/64

 

Table 3. The registers for the OSC0 macrocell dividers setting

Keep in mind that after restarting the IC, all settings and data registers return to their default values.

Conclusion

Using the SLG46538V GreenPAK CMIC and its resources (I2C, ASM, Bi-directional PINs, etc.), it is easy to build a device for displaying data on four 7-segment LED displays with a 4x4 keyboard scanner using only three MCU I/O pins. This is especially effective for the manufacturing of simple products in large quantities, because the free I/O pins of the MCU can be used for other tasks.

This solution can be used to develop devices such as an electronic code door lock, signaling devices, simple programmable power supplies, or clocks and timers. In addition, this device can be realized as a “shield” board for Arduino or other platforms.

About the Author

Name: Ivan Hnoievyi

Background: Ivan Hnoievyi joined Silego in 2017. Ivan has six years of work experience in electronics, radio communication equipment, and automated information systems. He began his career at State Enterprise LVIV STATE PLANT “LORTA”, working as a Developer Engineer. Ivan graduated from National University Lviv Polytechnic in 2010 as a specialist in Radio Communication Equipment Engineering.

Contact: appnotes@silego.com

 

Files


More on this topic:


See full list of Application Notes

© 2017 Silego Technology. 1515 Wyatt Drive, Santa Clara, CA 95054.
Facebook LinkedIn Twitter YouTube Google