Ripple Counters

Chain T flip-flops so each one clocks the next. Watch the false counts between edges, and see why decoding them glitches.

You Will Be Able To

  • Explain how a ripple counter counts with one flip-flop clocking the next.
  • List the false values a ripple counter shows between two counts.
  • Explain why a decoded ripple-counter output glitches.
  • Compare a ripple counter with a synchronous counter.
Lesson
G6.3
Time
20 min
Runs on
Your browser
Check
5 questions

A board counts pulses with three toggle flip-flops in a chain. A second chip watches for the count 0. It fires twice before the count ever wraps to 0.

A 3-Bit Ripple Counter, 011 to 100
A 3-Bit Ripple Counter, 011 to 100n0 · NOTnq0=0DQf0 · DFFq0=1n1 · NOTnq1=1DQf1 · DFFq1=0n2 · NOTnq2=0DQf2 · DFFq2=1z · NORzero=0clk=1
clk=1
n0 · NOTq0=1 → nq0=0
f0 · DFFnq0=0, clk=1 → q0=1
n1 · NOTq1=0 → nq1=1
f1 · DFFnq1=1, nq0=0 → q1=0
n2 · NOTq2=1 → nq2=0
f2 · DFFnq2=0, nq1=1 → q2=1
z · NORq2=1, q1=0, q0=1 → zero=0
Read the connections
GateKindInputsOutput
n0NOTq0nq0
f0DFFnq0, clkq0
n1NOTq1nq1
f1DFFnq1, nq0q1
n2NOTq2nq2
f2DFFnq2, nq1q2
zNORq2, q1, q0zero

Outputs: q2, q1, q0, zero. MUX inputs: d0, d1, select. Latch/flip-flop inputs: data, enable/clock. Unknown values are marked x; high impedance is folded into x in this model.

Gate delay 20. Settled after 20 gate delays from t = 0.

Output values at each gate delay01234567891011121314151617181920q2000000000111111111111q1111111100000000000000q0111110000000000000011zerox00000001100000000000
Scroll horizontally ↔
Every computed frame
Timeq2q1q0zero
0011x
10110
20110
30110
40110
50100
60100
70000
80001
91001
101000
111000
121000
131000
141000
151000
161000
171000
181000
191010
201010

  1. Step 3 · Count 3. The counter holds 011. The clock is about to rise.
  2. Step 5 · Stage 0 flips. One gate delay after the edge, q0 falls. The outputs now read 010: a count of 2 that should never appear.
  3. Step 7 · Stage 1 flips. NOT q0 rose, so stage 1 toggles: q1 falls. The outputs read 000.
  4. Step 8 · A false zero. The NOR that decodes 000 goes to 1. Anything that listens to it sees a count of 0.
  5. Step 9 · Stage 2 flips. NOT q1 rose, so q2 rises. The outputs settle at 100, five delays after the edge.
  6. Step 10 · The glitch ends. zero falls again. It was 1 for two gate delays.
  7. Step 19 · Count 5. The next edge only flips q0, so 100 becomes 101 with no false value.

Unit-delay model: each DFF and each gate takes one delay. Press Step to move one delay at a time.

Each Flip-Flop Clocks the Next

A T flip-flop with T = 1 toggles at every active edge of its clock. So it divides its clock by two. Chain such stages, each clocked by the output of the one before, and they count in binary.

A Ripple Counter: The Clock Passes from Stage to StageArrows show signals. Only stage 0 sees the system clock.
  • Clock / reset
  • Storage
  • Clock
A ripple counter: the clock passes from stage to stageArrows show signals. Only stage 0 sees the system clock. clock reset clk input clock storage Stage 0 toggles on clk storage Stage 1 toggles when q0 falls storage Stage 2 toggles when q1 falls q0q1
  1. clock reset clkinput clock
    • Stage 0
  2. storage Stage 0toggles on clk
    • q0 → Stage 1
  3. storage Stage 1toggles when q0 falls
    • q1 → Stage 2
  4. storage Stage 2toggles when q1 falls
  1. Stage 0

    It toggles at every clock edge: q0 = 0, 1, 0, 1, ...

  2. Stage 1

    It toggles each time q0 falls from 1 to 0, so at half the rate.

  3. Stage 2

    It toggles each time q1 falls, at a quarter of the rate. Together q2 q1 q0 count 0 to 7.

Read the diagram as text
  • clk: input clock
  • Stage 0: toggles on clk
  • Stage 1: toggles when q0 falls
  • Stage 2: toggles when q1 falls
  • clk → Stage 0
  • Stage 0 → Stage 1: q0
  • Stage 1 → Stage 2: q1

A bit falling from 1 to 0 is exactly when binary counting carries into the next bit.

No logic gates are needed between stages. That is why ripple counters are small and draw little power.

False Counts Between Edges

Each stage waits for the one before it to switch. So the bits change one after another, and the outputs pass through values that are not counts.

Gate delays after the edge012345
q2 q1 q0011010010000000100

From the circuit above: 011 becomes 100 through 010 and 000. Each bit adds a stage delay.

The lab does the same with 2 ns flip-flops. It prints every value the outputs pass through. The change from 3 to 4 shows two false values and takes 6 ns.

Decoding a Ripple Counter Glitches

A decoder turns one count into a 1, for example "the count is 0". On a ripple counter it also sees the false values. In the circuit above the NOR for 000 is 1 for two gate delays while the count goes from 3 to 4.

The Lab: q and Its Decoder for 000One column per printed change, from the lab's output. is0 is 1 while q = 000.
0123456time (ns)12323452727476q001000010011010000100is0false 0false 0
Scroll horizontally ↔
  1. Cycle 1

    At 32 ns the count goes from 1 to 2. Stage 0 falls first, so q reads 000 for 2 ns.

  2. Cycle 5

    At 74 ns, during 3 to 4, q reads 000 again. The decoder pulsed twice; the count was never 0.

Measured: the times and values are the lab's printed lines.

A glitch is harmless when a flip-flop on the same clock samples the decoder later, after the count settles. It is harmful on a clock, a reset or a latch enable (G5.3).

Counting Down

Clock each stage from the rising edge of the stage before it, and the chain counts down. Subtracting 1 borrows from bit 1 exactly when bit 0 goes from 0 to 1.

The bits still change one after another, starting with bit 0. So a down counter shows false values too, but different ones.

Why Synchronous Counters Replaced Them

Ripple counter

stage i clocked by q[i-1]

No gates between stages. The count settles after N stage delays and passes through false values.

Synchronous counter (G6.4)

every stage on clk; T[i] = q[i-1] & ... & q[0]

All bits change one clock-to-Q after the edge. It needs an AND chain, but it never shows a false count.

Ripple counters survive where only the final count matters and power is tight, such as slow clock dividers. Inside a synchronous design, the rule is one clock for every flip-flop (G5.9).

Asked in interviews
  1. What is a ripple counter?

    A chain of toggle flip-flops where each stage is clocked by the output of the stage before it. Only the first stage sees the system clock.

  2. What is the main problem with a ripple counter?

    The bits change one after another, so the count settles only after N flip-flop delays and passes through false values. Decoding it glitches.

  3. How long does a 16-bit ripple counter take to settle?

    Up to 16 clock-to-Q delays, when a carry ripples through every stage, as in 0111...1 to 1000...0.

Try It

Each edge flips stage 0 after 2 ns. When q0 falls, stage 1 flips 2 ns later, and so on up the chain.

The change from 1 to 2 shows one false value (000). The change from 3 to 4 shows two (010 and 000) and settles 6 ns after the edge.

The decoder for 000 pulsed twice, though the count went only from 0 to 4. Change #2 to #5 and run again: the false values last longer.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: t=12 q=001 t=32 q=000 t=34 q=010 t=52 q=011 t=72 q=010 t=74 q=000 t=76 q=100 decoder for 000: 2 pulses
Read included file: tb.sv
// tb.sv: four falling clock edges; prints every value q passes through (read-only).
`timescale 1ns/1ns
module tb;
  logic clk = 1, clr = 0;
  wire  [2:0] q;
  wire  is0 = (q == 3'b000);            // a decoder for the count 0
  int   pulses = 0;
  ripple3 dut (.clk(clk), .clr(clr), .q(q));
  always #10 clk = ~clk;                // falling edges at 10, 30, 50, 70
  always @(q) if (!clr) $display("t=%0d q=%b", $time, q);
  always @(posedge is0) if (!clr) pulses++;
  initial begin
    #1 clr = 1;
    #4 clr = 0;                         // q = 000
    #75 $display("decoder for 000: %0d pulses", pulses);
    $finish;
  end
endmodule

Check Yourself

Predict the outputA 4-bit ripple counter with 3 ns stages counts 16 falling edges, 20 ns apart, from 0000. The program counts every change of q, false values included. Predict the exact line.
`timescale 1ns/1ns
module tffn (output logic q, input logic clk, input logic clr);
  always_ff @(negedge clk or posedge clr)
    if (clr) q <= 1'b0;
    else     q <= #3 ~q;                   // 3 ns per stage
endmodule
module tb;
  logic clk = 1, clr = 0;
  wire  [3:0] q;
  int   changes = 0;
  tffn s0 (q[0], clk,  clr);
  tffn s1 (q[1], q[0], clr);
  tffn s2 (q[2], q[1], clr);
  tffn s3 (q[3], q[2], clr);
  always @(q) if (!clr) changes++;
  initial begin
    #1 clr = 1; #1 clr = 0;               // q = 0000
    repeat (16) begin #5 clk = 0; #15 clk = 1; end   // 16 falling edges, 20 ns apart
    $display("%0d changes", changes);
  end
endmodule
Spot the bugEach option builds a 3-bit up counter from the tff cell (a T flip-flop with a 1 ns clock-to-Q). The bench fails a counter whose bits change at different moments after an edge. Which one fails?
ConceptA 10-bit ripple counter has 2 ns flip-flops. How long after the clock edge can the count still be changing?
ConceptWhere is a glitch on a decoded ripple-counter output harmless?
ConceptThe 3-bit ripple counter of this lesson wraps from 111 to 000. How many false values appear?

Common Mistakes

Wrong Assume every bit of a ripple counter changes at the clock edge.

Each stage waits for the stage before it. In the lab, 011 to 100 passed through 010 and 000 first.

Fix Read a ripple counter only after N stage delays, or use a synchronous counter.

Wrong Decode a count of a ripple counter and use the result as a clock or a reset.

The false values make real pulses on the decoder output. The lab's decoder for 000 pulsed twice in four counts that never held 0.

Fix Sample decoded outputs with a flip-flop on the system clock, or count synchronously.

Wrong Expect a ripple counter to settle in one flip-flop delay.

The worst change ripples through every stage: a 3-bit counter with 2 ns stages took 6 ns from 011 to 100.

Fix Budget N times the clock-to-Q delay before the count is valid.

Remember

  • In a ripple counter only stage 0 sees the clock; each other stage is clocked by the stage before it.
  • The bits change one after another, so the outputs pass through false counts between edges.
  • A ripple counter settles only after N stage delays, and decoding it glitches.
  • Synchronous counters change every bit at one edge; ripple counters remain for small, slow dividers.

Practice

Report a problem with this page