Loading lessons...
Synchronous Counters: Up/Down, Mod-N & Counter Design
Synchronous Counters: Up/Down, Mod-N & Counter Design
In a synchronous counter every flip-flop receives the same clock, so all bits change together, one flip-flop delay after the edge. The price is a little logic that tells each flip-flop when to toggle. This lesson builds the standard binary and up/down counters, then designs counters for any sequence with the excitation-table method and checks them for lock-out.
1. The Synchronous Binary Counter
In binary counting, bit Qi toggles exactly when all lower bits are 1 (0111 → 1000). With T flip-flops (or JK with J = K = T):
Adding a count enable EN in front gives T0 = EN, T1 = EN · Q0, and so on; with EN = 0 the counter holds. The AND gates form a chain, so the enable can also be used to cascade counters: the last AND output of one 4-bit counter becomes the EN of the next.
4-bit synchronous binary counter with count enable
The chained AND gates in the figure add one gate delay per stage. Fast counters instead feed every AND gate directly from all the lower Q outputs (parallel carry), at the cost of wider gates.
2. Synchronous Down and Up/Down Counters
Counting down, bit Qi toggles when all lower bits are 0 (1000 → 0111): Ti = Q0' Q1' ·s Qi-1'.
An up/down counter with mode input M (M = 1 up, M = 0 down) combines both:
3-bit synchronous up/down counter
Because the mode only affects the T inputs, changing M between clock edges is safe, unlike the ripple up/down counter.
3. Designing a Counter for Any Sequence
A counter is a sequential circuit without inputs (other than the clock) whose state diagram is a single cycle. Use the design procedure of Lesson 18:
- List the sequence; the number of flip-flops is set by the largest state.
- Write the state table: present state → next state.
- Unused states are don't-cares.
- Use the excitation table of the chosen flip-flop to get each input.
- Simplify with K-maps and draw the circuit.
- Check where each unused state goes (self-starting test).
Design a counter that counts 0, 1, 2, 3, 4, 5, 0, ... using JK flip-flops A, B, C (A is the MSB).
| ABC | A⁺B⁺C⁺ | JA KA | JB KB | JC KC |
|---|---|---|---|---|
| 000 | 001 | 0 X | 0 X | 1 X |
| 001 | 010 | 0 X | 1 X | X 1 |
| 010 | 011 | 0 X | X 0 | 1 X |
| 011 | 100 | 1 X | X 1 | X 1 |
| 100 | 101 | X 0 | 0 X | 1 X |
| 101 | 000 | X 1 | 0 X | X 1 |
- Don't-cares: unused states 110 and 111 in every map.
- JA = BC, KA = C.
- JB = A'C, KB = C.
- JC = KC = 1.
- Unused states: 110 → (A holds, B holds, C toggles) 111 → (A toggles, B resets, C toggles) 000. Self-starting.
Design a counter with JK flip-flops for the repeating sequence 0, 1, 2, 4, 5, 6.
| ABC | A⁺B⁺C⁺ | JA KA | JB KB | JC KC |
|---|---|---|---|---|
| 000 | 001 | 0 X | 0 X | 1 X |
| 001 | 010 | 0 X | 1 X | X 1 |
| 010 | 100 | 1 X | X 1 | 0 X |
| 100 | 101 | X 0 | 0 X | 1 X |
| 101 | 110 | X 0 | 1 X | X 1 |
| 110 | 000 | X 1 | X 1 | 0 X |
- Unused states 011 and 111 are don't-cares.
- JA = B, KA = B; JB = C, KB = 1; JC = B', KC = 1.
- Check 011: JA = KA = 1 toggles A to 1; JB = KB = 1 toggles B to 0; JC = 0, KC = 1 resets C. Next state 100 (valid).
- Check 111: A toggles to 0, B toggles to 0, C resets. Next state 000 (valid).
K-maps for the six JK inputs
State diagram including the unused states
4. Lock-Out
If an unused state leads only to other unused states, a counter that lands there (at power-up, or after a noise pulse) never returns to its count cycle. This is lock-out. The cure is to give up some don't-cares and specify the next state of an unused state explicitly.
Design a counter for 0, 3, 5, 6 (repeating) with T flip-flops, check for lock-out and fix it.
- State table: 000 → 011 → 101 → 110 → 000. T = Q oplus Q+ for each flip-flop, unused states 001, 010, 100, 111 as don't-cares.
- Minimising: TA = B, TB = 1, TC = B'.
- Unused states: 001 → 010 → 100 → 111 → 001. They form a closed cycle of their own: lock-out.
- Fix: specify 111 → 000. The 111 row now gives TA = 1, TB = 1, TC = 1 (no longer don't-cares).
- Re-minimising: TA = B and TB = 1 are unchanged, and TC = ∑ m(0, 5, 7) + d(1, 2, 4) = AC + B'.
- New check: 001 → 010 → 100 → 111 → 000. Every unused state reaches the cycle.
Lock-out and the corrected design
5. The BCD (Decade) Synchronous Counter
Design a synchronous counter for 0 to 9 with T flip-flops Q8 Q4 Q2 Q1.
- Unused states 1010 to 1111 are don't-cares.
- TQ1 = 1 (the LSB toggles every count).
- TQ2 = Q8' Q1: like binary, except that 1001 → 0000 must not toggle Q2.
- TQ4 = Q2 Q1.
- TQ8 = Q8 Q1 + Q4 Q2 Q1: toggle on 0111 → 1000 and on 1001 → 0000.
Two BCD counters in cascade count 00 to 99; this is how digital clocks and frequency meters count in decimal.
6. Counters with Parallel Load
A counter IC such as the 74161 (4-bit synchronous binary) adds a load input: when load = 1, the next clock copies the data inputs D3 D2 D1 D0 into the counter instead of counting. This gives an easy mod-N counter: detect the last state and load 0 (or load 16 - N and count up to 15). Unlike the asynchronous clear of a ripple counter, a synchronous load acts on the clock edge, so no glitch state appears.
Make a mod-12 counter from a 4-bit synchronous counter with synchronous load, in two ways.
- Load 0 at 11: count 0 to 11; detect 11 = 1011 with an AND of Q3 Q1 Q0 and drive load with data 0000. The next clock gives 0.
- Load 4 at 15: count 4 to 15 (12 states); the carry output at 15 drives load with data 0100.
7. Synchronous Counters in Verilog
The counter of Example 2, written with its JK equations. The testbench forces three starting states, a valid one and both unused ones, to show that the design is self-starting:
// Counter for the sequence 0, 1, 2, 4, 5, 6 built from the JK equations of Example 2
module seq_counter (
input clk,
input load, // used only to force a start state for testing
input [2:0] start,
output [2:0] q // q = {A, B, C}
);
reg A, B, C;
wire JA = B, KA = B;
wire JB = C, KB = 1'b1;
wire JC = ~B, KC = 1'b1;
always @(posedge clk) begin
if (load) begin
{A, B, C} <= start;
end else begin
A <= (JA & ~A) | (~KA & A);
B <= (JB & ~B) | (~KB & B);
C <= (JC & ~C) | (~KC & C);
end
end
assign q = {A, B, C};
endmodule
module tb;
reg clk = 0, load = 1;
reg [2:0] start;
wire [2:0] q;
reg [8:0] starts = {3'd0, 3'd3, 3'd7}; // a valid state and the two unused states
integer k, i;
seq_counter dut (.clk(clk), .load(load), .start(start), .q(q));
task tick;
begin
#5 clk = 1;
#5 clk = 0;
end
endtask
initial begin
for (k = 2; k >= 0; k = k - 1) begin
start = starts[3 * k +: 3];
load = 1;
tick;
load = 0;
$write("start %0d:", q);
for (i = 0; i < 7; i = i + 1) begin
tick;
$write(" %0d", q);
end
$display("");
end
end
endmoduleFrom 3 the counter goes to 4 and from 7 to 0, exactly as the unused-state check predicted:
start 0: 1 2 4 5 6 0 1
start 3: 4 5 6 0 1 2 4
start 7: 0 1 2 4 5 6 0In practice, counters are written behaviourally. This 4-bit up/down counter has enable and a synchronous parallel load, like a 74191:
// 4-bit synchronous up/down counter with enable and parallel load (behavioural)
module updown4 (
input clk,
input rst_n,
input en,
input up, // 1 = count up, 0 = count down
input load,
input [3:0] d,
output reg [3:0] q
);
always @(posedge clk or negedge rst_n) begin
if (!rst_n)
q <= 4'd0;
else if (load)
q <= d; // load has priority over counting
else if (en)
q <= up ? q + 1'b1 : q - 1'b1;
end
endmodule
module tb;
reg clk = 0, rst_n = 0, en = 1, up = 1, load = 0;
reg [3:0] d = 4'd13;
wire [3:0] q;
integer i;
updown4 dut (.clk(clk), .rst_n(rst_n), .en(en), .up(up), .load(load), .d(d), .q(q));
task tick;
begin
#5 clk = 1;
#5 clk = 0;
$write(" %0d", q);
end
endtask
initial begin
#1 rst_n = 1;
$write("up: ");
for (i = 0; i < 5; i = i + 1) tick;
$write("\nload 13, up:");
load = 1; tick; load = 0;
for (i = 0; i < 4; i = i + 1) tick;
$write("\ndown:");
up = 0;
for (i = 0; i < 4; i = i + 1) tick;
$write("\nhold:");
en = 0;
for (i = 0; i < 2; i = i + 1) tick;
$display("");
end
endmoduleCounting wraps from 15 to 0 going up and from 0 to 15 going down:
up: 1 2 3 4 5
load 13, up: 13 14 15 0 1
down: 0 15 14 13
hold: 13 13Key points to remember
- Synchronous binary up counter: Ti = Q0 Q1 ·s Qi-1; down: Ti = Q0' ·s Qi-1'.
- Up/down: Ti = M(product of Q) + M'(product of Q').
- Counter design: state table, unused states as don't-cares, excitation table, K-maps.
- Always check unused states: lock-out means they cycle among themselves; fix by specifying their next state.
- BCD with T: T1 = 1, T2 = Q8'Q1, T4 = Q2Q1, T8 = Q8Q1 + Q4Q2Q1.
📝 IPU End-Term Exam Corner (5-10 Marks)
- Q1. Design a 4-bit synchronous binary counter using T (or JK) flip-flops. (5 Marks)
- Q2. Design a 3-bit synchronous up/down counter with a mode control input. (10 Marks)
- Write: state table for both modes, T1 = MQ0 + M'Q0', T2 = MQ0Q1 + M'Q0'Q1', the circuit.
- Q3. Design a synchronous counter for the sequence 0, 1, 2, 4, 5, 6 using JK flip-flops. Is it self-starting? (10 Marks)
- Q4. What is lock-out? How is it avoided? Explain with an example. (5 Marks)
- Q5. Design a synchronous mod-6 (or BCD) counter. (10 Marks)