Sub topic 15
Ripple and Synchronous Counters, Modulus and Design
This chapter assumes you know how D, T and JK flip-flops behave (characteristic and excitation tables), what setup time and propagation delay mean, and how a shift register is built. A counter is a group of flip-flops whose outputs step through a fixed sequence of binary values, one step per clock event.
What a counter is
An n-bit counter has at most 2^n states. The modulus (MOD) is the number of distinct states in its cycle. A MOD-N counter counts 0, 1, ..., N-1 and returns to 0. The modulus is the first thing a GATE question tests. The second is how fast the counter can run.
Counters fall into two families:
- Asynchronous (ripple) counters. Only the first flip-flop receives the external clock. Each later flip-flop is clocked by the output of the one before it.
- Synchronous counters. All flip-flops share one clock. Combinational logic decides which flip-flops change at each edge.
Asynchronous (ripple) counters
Wire n T flip-flops with T = 1 (or JK flip-flops with J = K = 1). Each one toggles on its clock edge, so each one divides its input frequency by 2. Clock the first flip-flop with the external clock. Clock each later flip-flop from the previous Q output (falling-edge triggered) to count up.
For a falling-edge-triggered chain:
- Q0 toggles on every clock pulse.
- Q1 toggles when Q0 falls from 1 to 0.
- Q2 toggles when Q1 falls from 1 to 0.
This produces the natural binary up count. The frequency at output Qi is fclk / 2^(i+1). A 4-bit ripple counter is a MOD-16 counter, and its last output has frequency fclk / 16.
To count down, either clock each stage from the previous Q' output (with falling-edge flip-flops), or use rising-edge flip-flops clocked from Q for the up direction and from Q' for the down direction. A common error is to mix these up. Remember the rule: up counting needs a stage to toggle when the lower bit goes 1 to 0, and down counting needs it to toggle when the lower bit goes 0 to 1.
The ripple delay problem
The clock edge reaches the second flip-flop only after the first has changed. The delay accumulates:
- The worst-case settling time of an n-bit ripple counter is about n × tpd, where tpd is one flip-flop's propagation delay.
- The next clock edge must not arrive before all outputs have settled, so the minimum clock period is at least n × t_pd. If the outputs are decoded or sampled, add the decoder delay and setup time.
Between edges, the outputs pass through wrong intermediate values. For example, going from 0111 to 1000, the counter briefly shows 0110, 0100, 0000 and then 1000. These transient states are called glitches. They cause false outputs in any decoder attached to a ripple counter.
Synchronous counters
All flip-flops receive the same clock edge. Each flip-flop's input is computed from the current state, so every bit that should change does so at the same time.
For a synchronous binary up counter built from T flip-flops, flip-flop i toggles when all lower bits are 1:
- T0 = 1
- T1 = Q0
- T2 = Q0 · Q1
- T3 = Q0 · Q1 · Q2
The minimum clock period is now
Tmin = tpd(flip-flop) + tpd(AND gate) + tsetup
where the AND-gate delay is that of the widest gate in the chain. It no longer grows with n by a full flip-flop delay per stage, only by the delay of a wider AND gate (or a small chain of ANDs). This is why synchronous counters are used at high frequencies.
| Property | Ripple counter | Synchronous counter |
|---|---|---|
| Clock | Only the first stage | All stages |
| Hardware | Fewest gates | Extra gates per stage |
| Max frequency | Low, period ≥ n × t_pd | High, period ≈ t_pd + t_gate + t_setup |
| Glitches in outputs | Yes | No (outputs change together) |
| Design effort | Simple wiring | Needs excitation logic |
The following diagram shows the structure of a 3-bit ripple counter next to the timing relationship.
Modulus and how to change it
A natural n-bit counter has modulus 2^n. To get a modulus N that is not a power of 2, shorten the cycle. Use the smallest n with 2^n ≥ N, then force the counter back to 0 after state N-1. There are two common methods.
Asynchronous reset (ripple counters)
Detect the first unwanted state, N, with a NAND gate, and use its output to clear all flip-flops through their asynchronous clear inputs. For a MOD-6 counter, the first unwanted state is 6 = 110, so the NAND gate takes Q2 and Q1 (Q0 is a don't care, since no smaller state has both Q2 and Q1 equal to 1).
Consequences:
- The counter does enter state 6 for a very short time before clearing. This is a brief glitch. The sequence seen is 0, 1, 2, 3, 4, 5, (6), 0.
- The reset pulse is as short as the gate and flip-flop delays allow. This can be unreliable.
A frequent GATE trap: the number of states in the cycle is N, but the highest value reached is N (briefly), not N-1, in an asynchronous-clear design.
Synchronous design for any modulus
With a synchronous counter, detect state N-1 and make the next state 0. No illegal state is ever visible. This is the design shown in the next section.
Cascading counters
When two counters are cascaded, the overall modulus is the product of the moduli. A MOD-10 counter followed by a MOD-6 counter gives MOD-60 (a minutes counter, for example). The output frequency is f_clk / 60.
Designing a synchronous counter
The standard procedure:
- Draw the state sequence (state diagram).
- Choose the flip-flop type and write the state table with present state and next state.
- Use the excitation table to write the required flip-flop inputs for each transition.
- Simplify each input with a Karnaugh map. Treat unused states as don't cares.
- Draw the circuit, and check that unused states eventually lead into the main cycle (self-starting).
Worked example: MOD-6 counter with T flip-flops
States 0 to 5 use three bits Q2 Q1 Q0. States 6 and 7 are unused.
The T excitation is T = Q XOR Q_next. This gives the following table.
| Present Q2Q1Q0 | Next Q2Q1Q0 | T2 | T1 | T0 |
|---|---|---|---|---|
| 000 | 001 | 0 | 0 | 1 |
| 001 | 010 | 0 | 1 | 1 |
| 010 | 011 | 0 | 0 | 1 |
| 011 | 100 | 1 | 1 | 1 |
| 100 | 101 | 0 | 0 | 1 |
| 101 | 000 | 1 | 0 | 1 |
| 110 | X | X | X | X |
| 111 | X | X | X | X |
Simplify with the don't cares for 110 and 111:
- T0 = 1 (all valid rows are 1, so the don't cares can be set to 1).
- T1 = Q0 · Q2' (rows 001 and 011 are 1; row 101 is 0, rows 110 and 111 are chosen as 0).
- T2 = Q0 · (Q1 + Q2): rows 011 and 101 are 1, while 001, 000, 010, 100 are 0. Rows 111 is chosen as 1 and 110 as X.
Check the T2 expression: row 011 gives 1·(1+0) = 1; row 101 gives 1·(0+1) = 1; row 001 gives 1·(0+0) = 0; row 100 gives 0; row 010 gives 0. All correct.
Now check self-starting. From 110: T0 = 1, T1 = Q0·Q2' = 0, T2 = Q0·(Q1+Q2) = 0, so the next state is 111. From 111: T0 = 1, T1 = 0, T2 = 1, so the next state is 010, which is in the main cycle. The counter recovers within two clocks.
The same counter in Verilog
This is the synchronous MOD-6 counter with a synchronous reset. It returns to 0 after 5.
module mod6_counter(input clk, input rst, output reg [2:0] q);
always @(posedge clk) begin
if (rst || q == 3'd5)
q <= 3'd0;
else
q <= q + 3'd1;
end
endmoduleIf the counter powers up in state 6 or 7, the condition q == 3'd5 is false, so it counts to 7 and wraps to 0 through the normal adder overflow. Therefore this version also recovers from illegal states.
Special counters
Shift-register counters, covered in the previous chapter, have a modulus that depends on the feedback:
- A ring counter of n flip-flops has modulus n and uses n states out of 2^n.
- A Johnson (twisted-ring) counter of n flip-flops has modulus 2n. The 4-bit Johnson sequence is 0000, 1000, 1100, 1110, 1111, 0111, 0011, 0001.
- A decade counter is a MOD-10 binary counter that counts 0000 to 1001.
Ring and Johnson counters need no decoding gates to identify a state (at most a 2-input gate for Johnson), but they use many flip-flops and may not self-start without correction logic.
Timing a counter
For a synchronous counter, the maximum clock frequency is
fmax = 1 / (tpd,FF + tpd,logic + tsetup)
For a ripple counter with n stages, the settling time is approximately n × tpd,FF, so fmax ≈ 1 / (n × tpd,FF + tsetup) when the outputs are used. Worked numbers: with tpd,FF = 10 ns, tpd,AND = 5 ns and t_setup = 2 ns, a 4-bit synchronous counter has a period of 10 + 5 + 2 = 17 ns, about 58.8 MHz. A 4-bit ripple counter has 4 × 10 = 40 ns of settling time, plus setup, giving at least 42 ns, about 23.8 MHz.
Common errors
- Forgetting that ripple counters decoded with asynchronous reset pass briefly through state N.
- Using rising-edge triggering where the circuit expects falling-edge, which turns an up counter into a down counter.
- Applying the n × t_pd rule to a synchronous counter.
- Leaving unused states unspecified, so the counter can lock in an invalid loop.
- Treating T0 = Q0 for a binary up counter. The least significant bit toggles on every clock, so T0 = 1.
Exercise
A 4-bit asynchronous counter uses flip-flops with propagation delay 12 ns. It is reset by a NAND gate that detects state 1010 so that it counts as a decade counter. (a) What is its modulus? (b) What is the largest value that appears briefly? (c) A 3-bit synchronous counter uses the same flip-flops, an AND gate delay of 6 ns and setup time of 3 ns. What is its maximum clock frequency?
Show answer
(a) The cycle is 0000 to 1001, so the modulus is 10. (b) The counter reaches 1010 (decimal 10) for a very short time before the asynchronous clear returns it to 0. (c) The minimum period is 12 + 6 + 3 = 21 ns, so f_max = 1/21 ns ≈ 47.6 MHz.
Exercise
Design the input equations for a synchronous MOD-4 down counter (3, 2, 1, 0, 3, ...) using two T flip-flops. State the equations for T1 and T0.
Show answer
T0 = 1, because the least significant bit changes on every clock. Bit 1 toggles when Q0 = 0 (transitions 3 to 2 is not that; check: 3=11 to 2=10 changes only Q0, 2=10 to 1=01 changes both, 1=01 to 0=00 changes only Q0, 0=00 to 3=11 changes both). Q1 changes when Q0 is 0, so T1 = Q0'. Final answer: T0 = 1 and T1 = Q0'.
Exercise
A Johnson counter has 5 flip-flops. How many states are in its cycle, and how many of the 32 possible states are unused?
Show answer
A Johnson counter has modulus 2n = 10, so the cycle has 10 states. The other 32 - 10 = 22 states are unused.