Lesson 21 +40 XP

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):

T0 = 1 qquad T1 = Q0 qquad T2 = Q0 Q1 qquad T3 = Q0 Q1 Q2

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 enable4-bit synchronous binary counter with count enable

💡 Tip

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:

T0 = 1 qquad T1 = M Q0 + M' Q0' qquad T2 = M Q0 Q1 + M' Q0' Q1'

3-bit synchronous up/down counter3-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:

  1. List the sequence; the number of flip-flops is set by the largest state.
  2. Write the state table: present state → next state.
  3. Unused states are don't-cares.
  4. Use the excitation table of the chosen flip-flop to get each input.
  5. Simplify with K-maps and draw the circuit.
  6. Check where each unused state goes (self-starting test).
SolvedExample 1 · Mod-6 synchronous counter with JK flip-flops

Design a counter that counts 0, 1, 2, 3, 4, 5, 0, ... using JK flip-flops A, B, C (A is the MSB).

ABCA⁺B⁺C⁺JA KAJB KBJC KC
0000010 X0 X1 X
0010100 X1 XX 1
0100110 XX 01 X
0111001 XX 1X 1
100101X 00 X1 X
101000X 10 XX 1
  1. Don't-cares: unused states 110 and 111 in every map.
  2. JA = BC, KA = C.
  3. JB = A'C, KB = C.
  4. JC = KC = 1.
  5. Unused states: 110 → (A holds, B holds, C toggles) 111 → (A toggles, B resets, C toggles) 000. Self-starting.
AnswerJA = BC, KA = C, JB = A'C, KB = C, JC = KC = 1
SolvedExample 2 · Counter for the sequence 0, 1, 2, 4, 5, 6 (Mano)

Design a counter with JK flip-flops for the repeating sequence 0, 1, 2, 4, 5, 6.

ABCA⁺B⁺C⁺JA KAJB KBJC KC
0000010 X0 X1 X
0010100 X1 XX 1
0101001 XX 10 X
100101X 00 X1 X
101110X 01 XX 1
110000X 1X 10 X
  1. Unused states 011 and 111 are don't-cares.
  2. JA = B, KA = B; JB = C, KB = 1; JC = B', KC = 1.
  3. 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).
  4. Check 111: A toggles to 0, B toggles to 0, C resets. Next state 000 (valid).
AnswerJA = KA = B, JB = C, KB = 1, JC = B', KC = 1; self-starting

K-maps for the six JK inputsK-maps for the six JK inputs

State diagram including the unused statesState 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.

SolvedExample 3 · Detecting and fixing lock-out

Design a counter for 0, 3, 5, 6 (repeating) with T flip-flops, check for lock-out and fix it.

  1. 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.
  2. Minimising: TA = B, TB = 1, TC = B'.
  3. Unused states: 001 → 010 → 100 → 111 → 001. They form a closed cycle of their own: lock-out.
  4. Fix: specify 111 → 000. The 111 row now gives TA = 1, TB = 1, TC = 1 (no longer don't-cares).
  5. Re-minimising: TA = B and TB = 1 are unchanged, and TC = ∑ m(0, 5, 7) + d(1, 2, 4) = AC + B'.
  6. New check: 001 → 010 → 100 → 111 → 000. Every unused state reaches the cycle.
Answerlock-out with TC = B'; self-correcting with TC = AC + B'

Lock-out and the corrected designLock-out and the corrected design

5. The BCD (Decade) Synchronous Counter

SolvedExample 4 · BCD counter with T flip-flops

Design a synchronous counter for 0 to 9 with T flip-flops Q8 Q4 Q2 Q1.

  1. Unused states 1010 to 1111 are don't-cares.
  2. TQ1 = 1 (the LSB toggles every count).
  3. TQ2 = Q8' Q1: like binary, except that 1001 → 0000 must not toggle Q2.
  4. TQ4 = Q2 Q1.
  5. TQ8 = Q8 Q1 + Q4 Q2 Q1: toggle on 0111 → 1000 and on 1001 → 0000.
AnswerT1 = 1, T2 = Q8'Q1, T4 = Q2Q1, T8 = Q8Q1 + Q4Q2Q1

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.

SolvedExample 5 · Mod-12 with a loadable 4-bit counter

Make a mod-12 counter from a 4-bit synchronous counter with synchronous load, in two ways.

  1. 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.
  2. Load 4 at 15: count 4 to 15 (12 states); the carry output at 15 drives load with data 0100.
Answerload 0000 when the count is 1011, or load 0100 at the terminal count 1111

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:

VERILOG
// 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
endmodule

From 3 the counter goes to 4 and from 7 to 0, exactly as the unused-state check predicted:

OUTPUT
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 0

In practice, counters are written behaviourally. This 4-bit up/down counter has enable and a synchronous parallel load, like a 74191:

VERILOG
// 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
endmodule

Counting wraps from 15 to 0 going up and from 0 to 15 going down:

OUTPUT
up:   1 2 3 4 5
load 13, up: 13 14 15 0 1
down: 0 15 14 13
hold: 13 13
💡 Tip

Key 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.
🎯 END-TERM EXAM PREP

📝 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)