Ring and Johnson Counters
Feed the end of a shift register back to its start. You get a ring with one hot bit, or a Johnson counter with twice the states.
You Will Be Able To
- Build a ring counter and a Johnson counter from a shift register.
- State how many states each has and how their outputs are decoded.
- Find the illegal states of a shift-register counter.
- Make a ring counter correct itself from any illegal state.
- Lesson
- G6.7
- Time
- 25 min
- Runs on
- Your browser
- Check
- 5 questions
A traffic controller needs four phases, one at a time, and each phase output must never glitch. A binary counter plus a decoder can glitch (G6.3). A counter whose bits are the phases cannot.
- Cycle 0
After reset the ring holds one 1; the Johnson counter holds all 0s.
- Cycle 4
The ring is back at 0001 after 4 edges. The Johnson counter has filled with 1s.
- Cycle 8
The Johnson counter is back at 0000 after 8 edges: twice the states of the ring.
Measured: the values are the lines the lab prints.
The Ring Counter
Feed the last stage of a shift register back to the first, and a single 1 circulates. An N-bit ring counter has N states, one per bit, so its value is one-hot.
Each output is already a decoded state: bit k is 1 in state k only. No decoder is needed, so nothing can glitch. The cost is one flip-flop per state.
- Storage
- Data
- Ring
q3 goes straight back to q0. A single 1 circulates: 4 states.
- Johnson
NOT q3 goes back to q0. The chain fills with 1s, then with 0s: 8 states.
Read the diagram as text
- q0: stage 0
- q1: stage 1
- q2: stage 2
- q3: stage 3
- q0 → q1
- q1 → q2
- q2 → q3
- q3 → q0: q3 or NOT q3
Only the feedback differs: straight for a ring counter, inverted for a Johnson counter.
The Johnson Counter
Feed the last stage back inverted, and the register fills with 1s, then empties. An N-bit Johnson counter has 2N states. Exactly one bit changes at each edge.
| State | q3 q2 q1 q0 | Decode with |
|---|---|---|
| 0 | 0000 | q3' q0' |
| 1 | 0001 | q1' q0 |
| 2 | 0011 | q2' q1 |
| 3 | 0111 | q3' q2 |
| 4 | 1111 | q3 q0 |
| 5 | 1110 | q1 q0' |
| 6 | 1100 | q2 q1' |
| 7 | 1000 | q3 q2' |
Every state is found by a 2-input AND of two neighbouring bits (or the two end bits). Only one input changes at a time, so the decode cannot glitch.
Illegal States
A 4-bit register has 16 values. The Johnson counter uses 8. The other 8 are illegal. If noise or a missing reset puts the counter in one, it follows a second loop and never comes back.
Self-Correction
A self-correcting counter changes its feedback so that every illegal state leads back to the legal loop. Legal states move as before.
Plain ring
q <= {q[2:0], q[3]};
Any number of 1s keeps circulating. 0000 and 0110 stay illegal forever.
Self-correcting ring
q <= {q[2:0], ~|q[2:0]};
A 1 enters only when q2, q1 and q0 are all 0. Extra 1s shift out; the legal loop is unchanged.
In a legal state the only 1 reaches q3 exactly when q2 to q0 are 0. So the NOR gives the same bit as before. From an illegal state, extra 1s leave at the top and no new one enters until the low bits are clear.
The same idea works for a Johnson counter. Change the input of one stage so that illegal states fall into the legal loop. G6.7.1 asks you to find such a change.
Asked in interviews
How many states does an N-bit ring counter, Johnson counter and binary counter have?
N, 2N and 2^N. The ring and Johnson counters trade density for outputs that decode without glitches.
What is a Johnson counter?
A shift register whose last output is fed back inverted to its input. It fills with 1s and then empties, giving 2N states with one bit changing per edge.
What happens if a ring counter starts in a wrong state?
It keeps circulating the wrong pattern forever. Reset it to one 1, or use self-correcting feedback.
Try It
The ring visits four states and repeats after edge 4. The Johnson counter visits eight and repeats after edge 8.
In each Johnson step exactly one bit changes. In each ring step one 1 moves, so two bits change.
Change the ring's reset to 4'b0000 and run again: it stays at 0000. Press Synthesize: the Johnson counter is four flip-flops and one inverter.
Synthesize the design to measure its cells and inspect the mapped gates.
edge 0: ring=0001 johnson=0000 edge 1: ring=0010 johnson=0001 edge 2: ring=0100 johnson=0011 edge 3: ring=1000 johnson=0111 edge 4: ring=0001 johnson=1111 edge 5: ring=0010 johnson=1110 edge 6: ring=0100 johnson=1100 edge 7: ring=1000 johnson=1000 edge 8: ring=0001 johnson=0000Original design · 5 cells · 4 flip-flops · 0 latches · 1 logic levels. Synthesis uses Yosys; counts depend on the toolchain.
Read included file: tb.sv
// tb.sv: both counters after a reset and eight edges (read-only).
`timescale 1ns/1ns
module tb;
logic clk = 0, rst = 1;
wire [3:0] r, j;
ring4 u1 (.clk(clk), .rst(rst), .q(r));
johnson4 u2 (.clk(clk), .rst(rst), .q(j));
initial begin
#5 clk = 1; #5 clk = 0; rst = 0;
$display("edge 0: ring=%b johnson=%b", r, j);
for (int k = 1; k <= 8; k++) begin
#5 clk = 1; #5 clk = 0;
$display("edge %0d: ring=%b johnson=%b", k, r, j);
end
end
endmodule
Check Yourself
Common Mistakes
Wrong Reset a ring counter to all zeros.
Rotating 0000 gives 0000 forever: a ring counter needs exactly one 1 to circulate.
Fix Reset it to one 1, such as 0001, or make it self-correcting.
Wrong Assume a Johnson counter can only be in its 2N legal states.
A 4-bit register has 16 states. The other 8 form their own loop, and a noise hit can put the counter there for good.
Fix Reset it, and where it matters, add logic that steers every illegal state back.
Wrong Expect 2^N states from an N-bit ring or Johnson counter.
A ring visits N states and a Johnson counter 2N. A 4-bit Johnson counter counts 8, not 16.
Fix Pick them for their decoding, not their density: use a binary counter when you need many states.
Remember
- A ring counter circulates one 1: N states from N flip-flops, already decoded.
- A Johnson counter feeds back the inverted last bit: 2N states, one bit changes per edge.
- Johnson states decode with 2-input ANDs that cannot glitch.
- Unused register values are illegal states; self-correcting feedback steers them back to the legal loop.