How to build a 4-bit ring counter from logic gates
A ring counter is a shift register with its last output fed back to its first input, so a single 1 circulates around the flip-flops: a 4-bit ring counter steps 1000, 0100, 0010, 0001 and back to 1000, one step per clock.
It counts in a one-hot code: exactly one output is 1 at any time, which is handy when each state should switch on one thing, such as one step of a processor's control sequence or one digit of a multiplexed display. Because it would happily circulate whatever pattern it powers up with, it needs a way to load the single 1 first; this one has a synchronous INIT input. In the live circuit the clock is already running: turn INIT on for one tick, then off, and watch the 1 go round.
Open this circuit in the lab →
What you need
- 4× D flip-flop: one stage per state, all on the same clock (each is two gated D latches plus a clock inverter)
- 1× OR: D0 = Q3 OR INIT, so INIT puts the 1 into the first stage
- 3× AND: D1..D3 = previous Q AND NOT INIT, so INIT clears the other stages
- 1× NOT: inverting INIT
Step by step
- Start from a 4-bit shift register: four D flip-flops on one clock
CLK, each Q feeding the next D. - Close the ring: wire the last output
Q3back toward the first stage'sD. - Add the initialization:
ORthe fed-back Q3 with anINITinput before it reaches D0, andANDeach of the other D inputs withNOT INIT. While INIT is 1 the next clock edge loads 1000. - Probe
Q0toQ3. Hold INIT high for one clock edge, release it, and the single 1 moves one stage per edge and wraps from Q3 back to Q0.
Ring counter sequence
| Clock edge | Q0 | Q1 | Q2 | Q3 |
|---|---|---|---|---|
| INIT | 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 2 | 0 | 0 | 1 | 0 |
| 3 | 0 | 0 | 0 | 1 |
| 4 | 1 | 0 | 0 | 0 |
An n-bit ring counter has n states, so four flip-flops give a count of 4 (a binary counter would get 16 from the same four). The trade is simplicity: no decoding is needed to know the state, because each state already has its own wire, and every output is a clean pulse one clock long, once every four clocks.
You can also read the full theory in the lesson on shift registers and ring counters. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.
Build more parts from gates
Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.
Open the 4-bit ring counter in the lab →Frequently asked
How does a ring counter work?
It is a shift register whose last output feeds back to its first input. Load a single 1 and, on every clock edge, that 1 shifts one stage along and wraps around from the last stage to the first, so the outputs take turns being 1.
How many states does a 4-bit ring counter have?
Four. An n-bit ring counter has n states (one per position of the circulating 1), compared with 2n for a Johnson counter and 2^n for a binary counter built from the same n flip-flops.
What is the difference between a ring counter and a Johnson counter?
Both are shift registers fed back on themselves. A ring counter feeds the last output straight back and circulates a single 1 (n states). A Johnson counter feeds back the inverted last output, so it fills with 1s and then with 0s, giving 2n states.
Why does a ring counter need to be initialized?
It circulates whatever pattern it holds. If it powers up with all 0s it stays at 0000 forever, and with two 1s it circulates both. A preset, clear or load input forces the single-1 starting state.