Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksBuild a CPUToolsOpen the lab →

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.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

Embed or cite this circuit

Free to embed on a course page, blog or worksheet: paste this code. The circuit stays live, and the small digiwleea badge links back here.

To cite it: digiwleea, “Mod-7 counter”, https://digiwleea.wleeaf.dev/tools/build/mod-7-counter/

What you need

Step by step

  1. Place a clock CLK, an input CLR, three D flip-flops and probes Q2, Q1, Q0.
  2. Build a 3-bit synchronous counter: D0 = NOT Q0, D1 = Q1 XOR Q0, D2 = Q2 XOR Q1 Q0.
  3. 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.
  4. Turn CLR off and watch the count run 0 to 6 and wrap.

Mod-7 count sequence

CountQ2 Q1 Q0Next
00001
10012
20103
30114
41005
51016
61100

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.