Edge detector

Turn a level into a one-clock pulse on its rising (or falling) edge.

When to use it

Loads of logic wants to fire once when something happens: a button goes down, a flag is raised, a strobe arrives. An edge detector converts a level into a single one-clock-wide pulse, perfect for enabling a counter, kicking off a state machine, or generating a handshake.

How it works

Delay the signal by one flip-flop and compare. A rising edge is "high now AND low last cycle" (level & ~prev); a falling edge is the mirror image. That's it, one flop and two gates.

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_edge_detect

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

Next recipe: Clock divider (do it with an enable)