Two-flop synchronizer

Safely bring an asynchronous signal into your clock domain.

When to use it

Any time a 1-bit level crosses from another clock domain (or an external pin like a button) into yours, sample it through two flip-flops before any logic looks at it. Feed a raw asynchronous signal straight into your design and it will eventually change too close to a clock edge, violating setup/hold, and the capturing flop goes metastable, hovering between 0 and 1.

How it works

The first flop may go metastable, but it is given a full clock cycle to settle before the second flop samples it. By the time sync_out feeds your logic, the odds of it still being undecided are astronomically small.

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_sync_bit

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

Next recipe: Button debouncer