BitFlow
← Academy·Counters
⏲Core~40 min

Counters

Ripple and synchronous counters, designing any count sequence with K-maps, and ring and Johnson counters.

Ripple counters

A toggling flip-flop divides its clock by 2. Chain them, with each one's output clocking the next, and the chain counts in binary. That's a ripple counter, or asynchronous counter, because only the first stage sees the real clock. It takes almost no logic, but it comes at a price.

Binary count01234567clkq0q1q2
Each output runs at half the speed of the one before, and read together they count: q2 q1 q0 = 000, 001, 010, 011 and so on.

The price is delay. Each stage waits for the one before, so going from 0111 to 1000 passes through wrong values on the way.

Loading the animation…

f_max (ripple) = 1 / (n × t_pd)
The whole chain must settle before the next clock edge, if you need to read a correct value.
Practice

A 5-bit ripple counter uses flip-flops with a 10 ns delay. What's the highest clock frequency at which it can always be read correctly?

Synchronous counters

In a synchronous counter, all flip-flops share one clock, and logic decides which should toggle. Look at counting in binary: a bit toggles exactly when all the bits below it are 1. So T₀ = 1, T₁ = q₀, and T₂ = q₁q₀.

Loading the animation…

Loading the circuit…

A 3-bit synchronous counter, in slow motion. Press Clock edge.
  • Clock it up to 3, then once more, and watch all the outputs change together on the way to 4.

Now every flip-flop changes at the same time, so there are no wrong values, and the limit is one flip-flop delay plus the logic in front of it.

f_max (synchronous) = 1 / (t_pd + t_logic + t_setup)
TipNearly all counters in chips are synchronous. Use a ripple counter only where nothing reads the middle bits, such as a simple clock divider.

Designing any count sequence

Binary isn't the only sequence. To design a counter for any sequence, follow one recipe. Here's a mod-5 counter, counting 0, 1, 2, 3, 4 and back to 0, built from D flip-flops.

Now: q2 q1 q0Next: q2 q1 q0So D2 D1 D0 =
0 0 00 0 10 0 1
0 0 10 1 00 1 0
0 1 00 1 10 1 1
0 1 11 0 01 0 0
1 0 00 0 00 0 0
1 0 1, 1 1 0, 1 1 1never usedX X X
With D flip-flops, the input is simply the next state. States 5, 6 and 7 never occur, so they're don't-cares.

Each D input now gets its own K-map, with q2, q1 and q0 as variables.

q2q1q0000111100101103021405X7X6Xq2'·q0'q2'·q0'
Grouping

D0 = q2'·q0'

D0 is 1 in states 0 and 2.
q2q1q0000111100100113021405X7X6Xq1'·q0q1·q0'
Grouping

D1 = q1'·q0 + q1·q0'

D1 is 1 in states 1 and 2, which is an XOR of q1 and q0.
q2q1q0000111100100103120405X7X6Xq1·q0
Grouping

D2 = q1·q0

D2 is 1 only in state 3, and the don't-cares shrink it to two literals.

Loading the circuit…

The finished mod-5 counter, exactly as those three equations say. D0 = q2'q0' is drawn as a NOR gate.
  • Clock it and check that it goes 0, 1, 2, 3, 4, 0.

One more check: what if the counter powers up in an unused state? Follow the equations. State 5 goes to 2, state 6 goes to 2, and state 7 goes to 4. All return to the sequence, so this counter is self-starting. Using don't-cares can sometimes produce a design that gets stuck, so always check.

Challenge: Mod-6 counter →Run the same recipe yourself in the circuit editor, and earn XP.

Quick mod-N, and clock dividers

Another way to get mod-N is to use a binary counter and reset it when it reaches N. A synchronous reset uses state N − 1 to load 0 at the next edge, which is clean. An asynchronous reset waits for state N to appear, and then clears at once, so state N exists for a brief moment. That short pulse is a glitch you must not use for anything.

CounterFlip-flopsOutput frequency
Mod-21f / 2
Mod-10 (decade)4f / 10
Mod-164f / 16
Mod-100010f / 1000
A mod-N counter divides its clock by N. The flip-flops needed are the smallest n with 2ⁿ ≥ N.
Practice

How many flip-flops does a mod-60 counter need at least?

Practice

A 1 MHz clock goes through a mod-10 counter and then a mod-5 counter. What's the output frequency?

Ring and Johnson counters

A shift register with its output fed back to its input is also a counter, and one that needs little or no decoding.

Loading the animation…

Countern flip-flops giveDecoding
Binary2ⁿ statesNeeds an n-input decoder
Ringn statesNone: each output is one state
Johnson2n statesOne 2-input AND per state
Watch outA ring or Johnson counter must start in a valid state. A 4-bit Johnson uses only 8 of the 16 patterns, and the other 8 form a separate loop of their own. Start in the wrong one and it stays wrong forever, so real designs add logic to steer back.

Exam countingGATE: fine to skip at first

Exam questions often give a counter's circuit and ask for its sequence. Write the flip-flop inputs as equations, start from the reset state, and step: at each row use the current Q values to work out the next. Stop when a state repeats, and the number of states in the loop is its modulus.

Practice · GATE-style

How many states does a 5-bit Johnson counter cycle through?

Practice · GATE-style

How many unused states does a 4-bit ring counter have?

Practice · GATE-style

A synchronous counter has t_pd = 8 ns, logic of 6 ns and t_setup = 2 ns. What's its maximum clock frequency?

Practice · GATE-style

A 3-bit counter uses D flip-flops with D2 = q1, D1 = q0, D0 = q2'. Starting from 000, how many states are in its cycle?

Was this chapter helpful?