Button debouncer

Reject the mechanical bounce on a switch or button.

When to use it

A mechanical button doesn't switch cleanly, its contacts bounce for a few milliseconds, so a raw press can look like a dozen presses to your logic. A debouncer only accepts a new level once the input has held steady long enough.

How it works

First the noisy input is run through a synchronizer. Then a counter watches it: if the level differs from the current clean output, count; once it has been stable for COUNT clocks, commit the new level. Any bounce shorter than COUNT clocks resets the counter and is ignored.

Gotchas

Try it

Runs on our simulator, edit the code and press Run to see the waveform.

Open & fork in the playground → Ship the verified version: lfpga add lfpga_debounce

The runnable example above is a teaching version. The libfpga library ships a hardened, parameterised, CI-tested module (lfpga_debounce) for production use.

Next recipe: Edge detector