Summary
The keypad module is sending out the first value of each column to a shift register, causing the seven segment displays to rapidly cycle between values when a key is not held down. The desired behavior is to capture a keystroke, send it to the shift register, and wait for another keystroke before shifting the value.
Root Cause
The root cause of this issue is that the keypad scanning process is not properly synchronized with the keystroke detection. The scanning process is running continuously, causing the shift register to shift the value immediately. The keystroke detection is not properly debounced, resulting in multiple keystrokes being detected when a key is held down.
Why This Happens in Real Systems
This issue occurs in real systems due to the following reasons:
- Insufficient debouncing: The keypad scanning process is not properly debounced, resulting in multiple keystrokes being detected when a key is held down.
- Incorrect synchronization: The keypad scanning process is not properly synchronized with the keystroke detection, causing the shift register to shift the value immediately.
- Lack of edge detection: The system is not detecting the rising edge of the keystroke, resulting in the shift register shifting the value continuously.
Real-World Impact
The real-world impact of this issue is:
- Unintended behavior: The seven segment displays will rapidly cycle between values when a key is not held down, causing unintended behavior.
- Incorrect output: The shift register will shift the value immediately, resulting in incorrect output.
- System instability: The system may become unstable due to the continuous shifting of the value.
Example or Code
-- Key decode process (combinational - detects current key)
process(state, row)
begin
case state is
-- Column 0 (state = "0111")
when "0111" =>
case row is
when "11110" => key_val key_val key_val key_val key_val key_val '1');
end case;
-- ...
end case;
end process;
How Senior Engineers Fix It
Senior engineers fix this issue by:
- Implementing proper debouncing: Adding a debouncing circuit to the keypad scanning process to prevent multiple keystrokes from being detected when a key is held down.
- Synchronizing the scanning process: Synchronizing the keypad scanning process with the keystroke detection to prevent the shift register from shifting the value immediately.
- Detecting the rising edge: Detecting the rising edge of the keystroke to ensure that the shift register only shifts the value when a keystroke is detected.
Why Juniors Miss It
Juniors may miss this issue due to:
- Lack of experience: Limited experience with keypad scanning and keystroke detection.
- Insufficient understanding: Inadequate understanding of the keypad scanning process and keystroke detection.
- Overlooking edge cases: Failing to consider edge cases, such as multiple keystrokes being detected when a key is held down.