Synchronous Counter Design from Flip-Flops
Clock every flip-flop together and design its toggle logic. Then build a counter for any sequence that no unused state can trap.
You Will Be Able To
- Build a synchronous binary counter from T flip-flops and an AND chain.
- Design a counter for any sequence from a state table, an excitation table and K-maps.
- Check where every unused state goes, and fix a counter that locks up.
- Explain why every bit of a synchronous counter changes at the same moment.
- Lesson
- G6.4
- Time
- 30 min
- Runs on
- Your browser
- Check
- 5 questions
The ripple counter of G6.3 shows false counts because its flip-flops switch one after another. Give them all the same clock and they switch together. Then each one needs logic that says when to toggle.
The Synchronous Binary Counter
Count in binary and watch each bit. Bit 0 flips every time. Bit 1 flips when bit 0 is 1. Bit k flips when every bit below it is 1.
| Bit | Toggles when | T input |
|---|---|---|
| q0 | always | T0 = 1 |
| q1 | q0 = 1 | T1 = q0 |
| q2 | q0 = q1 = 1 | T2 = q0 q1 |
| qk | all lower bits are 1 | Tk = q0 q1 … q(k-1) |
Each T input is the AND of the bits below it, so the gates form an AND chain.
Every flip-flop gets the same clock. At the edge each one either toggles or holds, all at once. The lab builds this counter from T flip-flop cells and one AND gate.
A Counter for Any Sequence: The State Table
A counter can step through any sequence. Take 1, 3, 2, 6, 4 and back to 1, with three T flip-flops. List each state and its next state.
- Neutral
- Step
- Structure
- State table
One row per state of the sequence; the unused states start as don't-cares.
- Excitation
For each flip-flop, the input that makes each change happen.
- K-maps
Minimize each input over the don't-cares.
- Check
Work out where each unused state goes. If one never enters the sequence, pick another cover or give up a don't-care.
Read the diagram as text
- State table: present → next
- Excitation: T = Q xor Q+
- K-maps: one per input
- Check unused: every state enters?
- State table → Excitation
- Excitation → K-maps
- K-maps → Check unused
- Check unused → K-maps: locks up
The last step is the one most often skipped, and the one that finds lock-up.
| Present q2 q1 q0 | Next q2 q1 q0 | T2 T1 T0 = Q xor Q+ |
|---|---|---|
| 001 | 011 | 010 |
| 011 | 010 | 001 |
| 010 | 110 | 100 |
| 110 | 100 | 010 |
| 100 | 001 | 101 |
| 000 | unused | X X X |
| 101 | unused | X X X |
| 111 | unused | X X X |
For a T flip-flop the excitation is T = Q xor Q+: 1 where the bit must change. The unused states 0, 5 and 7 start as don't-cares.
With D flip-flops you would skip the last column: D is the next state itself. With JK, each bit gets two columns from the JK excitation table.
K-Maps for the T Inputs
Each T column is a function of q2 q1 q0 with three don't-cares. Minimize each one with a K-map (G3.1). Each has two minimum covers of the same size.
| Input | 1 in states | Minimum covers (2 terms, 4 literals each) |
|---|---|---|
| T2 | 2, 4 | q1'q0' + q2'q0' or q2'q0' + q2q1' |
| T1 | 1, 6 | q1'q0 + q2q1 or q2'q1' + q2q1 |
| T0 | 3, 4 | q1'q0' + q1q0 or q1q0 + q2q1' |
Computed with an exact minimizer over the don't-cares 0, 5 and 7.
Pick one cover for each input and the design is done. Or is it? The pick also decides what the unused states do.
Unused States and Lock-Up
A counter can land in an unused state at power-up or after a noise hit. It must find its way back into the sequence. A counter that stays out forever has locked up.
First pick
T2 = q1'q0' + q2'q0'
T1 = q2'q1' + q2q1
T0 = q1'q0' + q1q0
Unused states: 0 → 7, 5 → 5, 7 → 4. State 5 goes to itself: the counter locks up.
Fixed: the other T0 cover
T2 = q1'q0' + q2'q0'
T1 = q2'q1' + q2q1
T0 = q1q0 + q2q1'
Unused states: 0 → 6, 5 → 4, 7 → 4. Every one enters the sequence at the next edge.
Both picks cost the same. Only the check of the unused states tells them apart. When no minimum cover works, give up a don't-care: write the next state you want for that unused state.
Why the Bits Change Together
In the lab every changed bit moves 1 ns after the edge, the clock-to-Q delay of one cell. The next-state logic works between edges and has a whole period to settle.
The cost is the AND chain. For a wide counter it grows long, which is why G6.5 looks at lookahead enables.
Asked in interviews
How do you design a synchronous counter with T flip-flops?
Each bit toggles when every lower bit is 1, so T0 = 1 and Tk is the AND of q0 to q(k-1). All flip-flops share the clock.
What is lock-up in a counter?
The counter enters an unused state and never returns to its sequence. Check the next state of every unused state after minimizing, and fix the don't-cares if one loops.
Why do we use the excitation table to design a counter?
We know each change of state we want and need the inputs that cause it. The excitation table gives those inputs, with don't-cares that simplify the logic.
Try It
Each line is one edge. The count goes 001 to 111 and wraps to 000, and every changed bit moved 1 ns after its edge.
Even 011 to 100, where all three bits flip, moves in one step. Compare with the 6 ns ripple of G6.3.
Change t2 to come from q[1] alone and run again: the count goes wrong after 010.
q=001 (every changed bit moved 1 ns after the edge) q=010 (every changed bit moved 1 ns after the edge) q=011 (every changed bit moved 1 ns after the edge) q=100 (every changed bit moved 1 ns after the edge) q=101 (every changed bit moved 1 ns after the edge) q=110 (every changed bit moved 1 ns after the edge) q=111 (every changed bit moved 1 ns after the edge) q=000 (every changed bit moved 1 ns after the edge) q=001 (every changed bit moved 1 ns after the edge)Read included file: cells.sv
`timescale 1ns/1ns
// cells.sv: the cells of this lab (read-only).
// TFF: toggles 1 ns after a rising clk edge when t = 1; clr clears it at once.
module TFF (output reg q, input wire t, input wire clk, input wire clr);
always @(posedge clk or posedge clr)
if (clr) q <= #1 1'b0;
else if (t) q <= #1 ~q;
endmodule
module AND2 (output wire y, input wire a, input wire b); and #1 (y, a, b); endmodule
Read included file: tb.sv
// tb.sv: nine rising edges; after each, q and how long after the edge its bits moved (read-only).
`timescale 1ns/1ns
module tb;
logic clk = 0, clr = 0;
wire [2:0] q;
time t_edge, t_change;
count3 dut (.clk(clk), .clr(clr), .q(q));
always @(q) t_change = $time;
initial begin
#1 clr = 1; #1 clr = 0; // q = 000
repeat (9) begin
#8 clk = 1; t_edge = $time;
#2 clk = 0;
$display("q=%b (every changed bit moved %0d ns after the edge)", q, t_change - t_edge);
end
end
endmodule
Check Yourself
Common Mistakes
Wrong Leave the unused states as don't-cares and never check them.
The don't-cares decide the next state of the unused states. In the worked design one choice made 5 go to 5 forever.
Fix After minimizing, work out the next state of every unused state. Change a cover if one loops.
Wrong Clock the higher stages from the lower outputs, as in a ripple counter.
The bits then change one after another and the count passes through false values (G6.3).
Fix Give every flip-flop the system clock and compute when each one toggles.
Wrong Make bit k toggle when only bit k-1 is 1.
A binary count carries into bit k only when every lower bit is 1. With T3 = q0 a 4-bit counter jumps from 0001 to 1010.
Fix T for bit k is the AND of all the bits below it.
Wrong Read the characteristic table when designing the input logic.
It answers "what will Q become?" The design question is "which input gives this change?"
Fix Use the excitation table: for a T flip-flop, T = Q xor Q+ (G5.7).
Remember
- A synchronous counter clocks every flip-flop together; all changed bits move at one moment.
- In a binary counter bit k toggles when every lower bit is 1: Tk = q0 q1 … q(k-1).
- Any sequence: state table, excitation table (T = Q xor Q+), then a K-map per input.
- Don't-cares decide where unused states go: check every one, and fix a cover that locks up.