Mod-7 counter: count 0 to 6 and wrap, live
A mod-7 counter counts 0 to 6 and then returns to 0, seven states, using three flip-flops. This one is a 3-bit synchronous counter whose next state is forced to 000 when the count reaches 6 (110), detected as Q2 AND Q1.
Three flip-flops can count to 7, so a mod-7 counter uses all but one state. It is a normal 3-bit synchronous counter (D0 = NOT Q0, D1 = Q1 XOR Q0, D2 = Q2 XOR Q1 Q0) with a synchronous reset: when the count is 6, all three D inputs are forced to 0, so the next clock gives 000 instead of 111. Because 111 is never reached, Q2 AND Q1 is enough to recognise 6. The same pattern makes any mod-N counter: count normally and clear on N - 1, as in the mod-6 and mod-12 counters, while the mod-3 and mod-5 counters are designed from their state tables instead. A divide-by-7 is a common example of an odd divider; the days of the week are another seven-state cycle. The live circuit opens with CLR on, because flip-flops start in an unknown state.
Open this circuit in the lab →
What you need
- 3× D flip-flop: Q2, Q1 and Q0, on one clock
- 2× XOR: Q1 and Q2 toggle logic
- 1× AND: Q1 Q0, Q2's toggle condition
- 1× AND: detecting 6: Q2 AND Q1
- 1× OR: reset = CLR OR count is 6
- 2× NOT: NOT Q0 and NOT reset
- 3× AND: each D gated by NOT reset
Step by step
- Place a clock
CLK, an inputCLR, three D flip-flops and probesQ2,Q1,Q0. - Build a 3-bit synchronous counter: D0 = NOT Q0, D1 = Q1 XOR Q0, D2 = Q2 XOR Q1 Q0.
- Detect 6 with Q2 AND Q1, OR it with CLR, and AND each D with the inverse, so the next state after 6 is 000.
- Turn CLR off and watch the count run 0 to 6 and wrap.
Mod-7 count sequence
| Count | Q2 Q1 Q0 | Next |
|---|---|---|
| 0 | 000 | 1 |
| 1 | 001 | 2 |
| 2 | 010 | 3 |
| 3 | 011 | 4 |
| 4 | 100 | 5 |
| 5 | 101 | 6 |
| 6 | 110 | 0 |
Before the page is built, an 18-clock run (a clear, the count twice round, a clear mid-run) is checked on all three outputs after every clock.
You can also read the full theory in the lesson on counters. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.
More builds: Registers and counters
All 246 build guides, by topic
Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.
Open the Mod-7 counter in the lab →Frequently asked
How many flip-flops are needed for a mod 7 counter?
Three, since 2^3 = 8 states is the smallest power of two that holds 7.
How do you design a mod 7 counter?
Take a 3-bit counter and clear it after 6: detect 110 (Q2 AND Q1 is enough, because 111 never occurs) and use it to reset the counter at the next clock.
Is a mod 7 counter a divide by 7 circuit?
Yes. Its most significant bit, or a decoded state, goes through one cycle every seven clocks, so it divides the clock frequency by 7, though not with a 50% duty cycle.