Skip to content

Basic I/O-3: Keypad

Debouncing calculations for Keypad

We have alluded to the problem of bouncing in mechanical switches in chap. ??. As the keypad is constructed out of many mechanical switches, it also suffers from the debouncing problem.

Typical keypress duration is 100-200 ms. To be on the safe side, we will assume that the keypress duration is 50 ms.

Debounce time of a mechanical switch is 20ms. This means that after we detect a keypress, we must wait 20ms for the keypad output to stabilize, before we attempt to read the data at the start of the keypad output.. Also because of bouncing, it may take 20 ms after pressing down the key to discover that the key is pressed. This leaves 10ms to read the key.

If we scan the keypad with 1 KHz clock, we scan a row for every 1 ms. Hence a single scan of a 4×4 keypad will take 4 ms. The scan of a 2×2 keypad will take 2 ms.

After the keypad interface detects a keypress, it is required to wait for the keypad output to be stabilized before it exports the keypress data to the rest of hardware. In a 4×4 keyboard, this is 6 scans (24 ms). In a 2×2 keypad, that is 11 scans (22 ms).

Basic schematic of the 4×4 Keypad

Connecting Keypad to the Processor

The sequence 1110 -> 1101 -> 1011 -> 011 -> 1110 -> 1101 -> etc is sent to the port X1-X4 by the CPU. Keypresses is read from the port Y1-Y4 by the processor.

Some References

Keypad interface in Verilog

We will design a keypad interface for a 4×4 keypad.

This module sends 4 bit pressed key and ready signal to main module and reads acknowledgement signal from main module.


Main Module for Keypad

This module reads pressed key and ready signal from keypad and sent it to seven segment display





  1. Design a system in which the output of keypad is directly fed into the 4-digit seven segment display. When somebody presses a key that key will be displayed in 7-seg display. When the key is released, nothing will be displayed..
  2. Redesign the system above in such a way that a keypress will continue to be displayed until a new keypress.


Your email address will not be published. Required fields are marked *