Clock divider (do it with an enable)

Run logic at a slower rate without gating the clock.

When to use it

You want part of your design to tick slower, once every N clocks. The right way on an FPGA is a clock enable: keep one fast clock everywhere and gate the logic with a one-cycle tick pulse. Do not build a divided net and use it as a clock, that skips the clock tree and invites skew and hold violations.

How it works

A counter rolls over every N clocks and pulses tick high for one cycle. Anywhere you'd want the slow clock, write if (tick) ... instead. If you genuinely need a slower square wave (say, to drive an LED), toggle a flop on tick, that's slow here.

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_clkdiv_frac

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

Next recipe: One-hot state machine