A mod-N counter has a modulus of N: it counts 0, 1, … , N − 1 and then goes back to 0. When N isn't a power of 2 it still needs the smallest n with 2ⁿ ≥ N flip-flops, and the codes from N to 2ⁿ − 1 become unused states.
There are three usual ways to build one:
- Synchronous clear: watch for the last good state, N − 1. The clear waits for the next edge, which then goes to 0 instead of N.
- Asynchronous clear: watch for the first bad state, N. The flip-flops clear at once, so N appears only as a brief glitch state. Cheap, but risky.
- Design it directly: write a next-state table for the N real states and treat the unused codes as don't-cares when you simplify.
A loadable counter can also be shortened from the top: load S whenever the terminal count fires, which gives mod-(2ⁿ − S).
The single question that decides which state to detect: does the clear wait for the edge, or act straight away? Mod-N counters are everywhere as frequency dividers and timers.