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

by GreenPAK™ in Circuits > LEDs

5 Views, 0 Favorites, 0 Comments

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

cover.png

This Instructable 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™ IC.

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

The complete design file created in the GreenPAK Designer software can be found here.

Theory of Operation

f1.JPG
f2.JPG

The basic idea of this Instructable 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.

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 GreenPAK IC 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

f3.JPG
f4.JPG
t1.JPG
f5.JPG
f6.JPG

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 DFF0 – DFF2 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 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 registers of the Connection Matrix Output RAM as shown in Table 1.

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

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

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

f7.JPG
t2.JPG
f8.JPG
t3.JPG

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.

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 data registers shown in Table 2.

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 as shown in Figure 8.

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

Conclusion

Using the SLG46538V GreenPAK IC 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.