Debounce a button
A real button doesn't close cleanly: its contacts bounce for a few milliseconds, and the FPGA, fast enough to see every bounce, counts one press as several.
The starter counts presses on the LEDs, and it works for a clean press. Fix it so a press only counts once the button has stayed the same for 10 ms (CLK_HZ / 100 cycles).
lab.v
drag to turn · scroll to zoom
Loading the board…
Press Run on the board: your Verilog is turned into gates in this browser and runs here, cycle by cycle.
Goals
- ○A clean press adds one
- ○A bouncy press still adds one
- ○Holding the button down adds only one
Hints
- Keep a
stablecopy of the button and a timer. While the raw button differs fromstable, count; when the count reachesCLK_HZ / 100, copy it intostable. - Detect the press on
stablegoing from 0 to 1, not on the raw button.
Pin log
Run the design to see its outputs change.
Put it on a real board
- The clock is set to the board's 27 MHz, and its active-low buttons and LEDs are flipped for you.