Mod-4 counter: a 2-bit counter from two flip-flops, live
A mod-4 counter counts 0, 1, 2, 3 and back to 0: four states, which is every state two flip-flops have, so it is simply a 2-bit binary counter. Its next-state logic is D0 = NOT Q0 and D1 = Q1 XOR Q0.
Counting in binary, the low bit flips on every clock and the high bit flips whenever the low bit is 1 before the clock. A D flip-flop that should flip gets its own output inverted, so D0 = NOT Q0, and D1 = Q1 XOR Q0 flips Q1 exactly when Q0 is 1. No state is unused, so unlike the mod-3 counter there are no don't-cares to design with and nothing to self-start from. Q0 is the clock divided by 2 and Q1 the clock divided by 4, which is why a mod-4 counter is also a divide-by-4 frequency divider. Both flip-flops share one clock, so this is a synchronous counter; each D is ANDed with NOT CLR, a synchronous clear that starts the count at 00. Add a third flip-flop with D2 = Q2 XOR (Q1 AND Q0) and you have the mod-8 counter; the 4-bit synchronous counter is mod 16.
Open this circuit in the lab →
What you need
- 2× D flip-flop: Q1 and Q0, on one clock
- 1× NOT: D0 = NOT Q0
- 1× XOR: D1 = Q1 XOR Q0
- 2× AND: synchronous clear: each D ANDed with NOT CLR
Step by step
- Place two D flip-flops on one clock, with probes
Q1andQ0. - Feed NOT Q0 into D0, so Q0 toggles on every clock.
- Feed Q1 XOR Q0 into D1, so Q1 toggles when Q0 is 1.
- AND each D with NOT CLR. Turn CLR on for one clock, then off.
- Clock it: Q1 Q0 goes 00, 01, 10, 11, 00 and repeats.
Mod-4 counter state table
| Q1 Q0 now | D1 = Q1 XOR Q0 | D0 = NOT Q0 | Q1 Q0 next |
|---|---|---|---|
| 00 | 0 | 1 | 01 |
| 01 | 1 | 0 | 10 |
| 10 | 1 | 1 | 11 |
| 11 | 0 | 0 | 00 |
Before the page is built, the live circuit runs 13 clocks (three laps of 0 to 3 with a clear in the middle), and both outputs are checked 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-4 counter in the lab →Frequently asked
How many flip-flops does a mod-4 counter need?
Two. Two flip-flops have exactly four states, 00 to 11, and a mod-4 counter uses all of them.
Is a mod-4 counter the same as a 2-bit counter?
Yes. A 2-bit binary counter counts 0 to 3 and wraps to 0, which is a count of four states: mod 4.
What is the next-state logic of a mod-4 counter?
With D flip-flops, D0 = NOT Q0 and D1 = Q1 XOR Q0. With T flip-flops it is T0 = 1 and T1 = Q0, and with JK flip-flops J0 = K0 = 1 and J1 = K1 = Q0.
What frequency does a mod-4 counter output?
Q1 completes one cycle every four clocks, so it is the clock frequency divided by 4; Q0 is the clock divided by 2.