16. Counter-based debouncer
A push button bounces: for a short while after a press its signal flips between 0 and 1. Clean it up.
clean is a registered output. It changes only after noisy has been different from clean at 4 consecutive rising clock edges; on the fourth such edge clean takes the value of noisy. Any edge at which noisy equals clean restarts the count. The rule is the same for presses (0 to 1) and releases (1 to 0).
Assume noisy has already been synchronized to clk. rst (synchronous, active high) sets clean to 0 and restarts the count.
Ports
| Port | Dir | Bits | What it is |
|---|---|---|---|
clk | in | 1 | Clock. |
rst | in | 1 | Synchronous reset, active high. |
noisy | in | 1 | Bouncy input, already synchronized. |
clean | out | 1 | Debounced output. |
Example
clean = 0 and noisy goes 1 for three edges, 0 for one edge, then 1 for four edges: clean becomes 1 on the last of those four edges, not earlier.
Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.
Press Build to check your code with Yosys. Errors and warnings show here, and a clean build draws the logic diagram.
Build your design to drive it by hand and see its signals here.