Computer Architecture
How a countdown circuit counts down and stops at zero
A countdown circuit is a down counter with two extras: a load that puts the starting number in, and a zero detector that stops it at 0. Each tick takes one away, 3, 2, 1, 0, and at 0 the circuit holds still and lights its output until it's loaded again. Built from two flip-flops and a handful of gates, it's the hardware behind every timer and counted loop.
Counting down: the borrow
Counting up, a bit flips when every bit below it is 1: that's the carry. Counting down it's the reverse. A bit flips when every bit below it is 0, because the lower bits have nothing to give and must borrow. In two bits, 2 − 1 is 10 → 01: the 1s bit was 0, so the 2s bit flips as well.
XOR flips, GO stops
XOR with 1 flips a bit and XOR with 0 keeps it, so each flip-flop's D is its Q XOR "should I flip?":
ZERO is a NOR of the two bits, and GO is NOT ZERO. While the count isn't 0, GO is 1 and the counter steps down. At 0, GO drops, every XOR keeps its bit, and the count stays put. Nobody has to tell it to stop: its own flag does.
Live experiment
Count down and stop at zero
A microwave timer: LOAD puts 3 in, then each tick takes one away until ZERO lights the beep and GO, which is NOT ZERO, freezes the count. Tie GO to 1 and 0 wraps round to 3; take the borrow from the wrong pin and 3 drops straight to 0.
“Count down to zero” is lesson 2 of 6 in Program Peninsula, Computer Architecture World 3. Free with an account. Lessons unlock in order, so you’ll do the 15 before it first.
Loading the start
A fixed number is just wiring. Where it has a 1, OR the LOAD line into that bit's D; where it has a 0, AND NOT LOAD in. To load 3, both bits get LOAD OR their next value, so one tick with LOAD at 1 sets 11 whatever the counter held, because an OR with a 1 is 1.
Swap the fixed wiring for switches and it loads whatever you set, like a microwave keypad.
Synchronous, not ripple
Every flip-flop here shares one clock, and the gates decide which bits flip, so it's a synchronous counter: all its bits change together on the clock edge, and the zero detector never sees a half-finished count. A ripple down counter clocks each stage from the one before instead, which needs fewer gates but lets the bits settle one after another.
Where you'll meet it
The 74HC193 chip is a 4-bit up/down counter with a parallel load and a borrow output; chain a few to count down from any number. Microcontroller timers count down and raise an interrupt at zero. And the Z80 processor, inside the ZX Spectrum and TI graphing calculators, has one instruction for this whole idea: DJNZ, decrement and jump if not zero.
Free lesson
Now build it yourself
Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.
“Count down to zero” is lesson 2 of 6 in Program Peninsula, Computer Architecture World 3. Free with an account. Lessons unlock in order, so you’ll do the 15 before it first.
Or start from the very first lesson, no account neededPractice questions
Three quick questions from the lessons. Pick an answer to check it.
Show the answer
Answer: 0. Counting up it flips when the 1s bit is 1 (a carry). Counting down it flips when the 1s bit is 0 (a borrow).
- Why not “1”? That's counting up, when the 1s bit carries. Counting down, the 2s bit flips when the 1s bit has to borrow.
- Why not “Either”? If it flipped on every tick, the count would jump about instead of stepping down by one.
- Why not “Never”? Without the 2s bit flipping, 2 could never become 1: 10 to 01 needs both bits to change.
Show the answer
Answer: (its next count) AND NOT LOAD. Where the constant has a 1, OR LOAD in. Where it has a 0, AND NOT LOAD in, so a load forces that bit to 0.
- Why not “LOAD OR its next count”? OR LOAD forces the bit to 1, which is right where the number has a 1. 2 has a 0 in its 1s bit.
- Why not “Its next count, unchanged”? Left unchanged, a load would leave the 1s bit wherever the count had it, so you might load 3 instead of 2.
- Why not “LOAD”? D = LOAD alone would clear the bit on every tick that isn't a load, so it could never count.
Show the answer
Answer: Stays at 3: GO is 0 whenever the count isn't zero. At 3, ZERO is 0, so GO would be 0 and nothing flips. The NOT is what lets it count until zero.
- Why not “Counts down normally”? Counting down needs GO at 1 while the count isn't zero. Wired from ZERO, GO is 0 at 3, 2 and 1.
- Why not “Counts up”? Nothing in the circuit adds: the XORs flip bits only when GO says so, and here GO is 0.
- Why not “Shows X”? X means unknown, but GO is wired, just to the wrong signal, so every bit has a known value and holds.
“Count down to zero” is lesson 2 of 6 in Program Peninsula, Computer Architecture World 3. Free with an account. Lessons unlock in order, so you’ll do the 15 before it first.
Questions people ask
How does a down counter work?
Each tick it subtracts one. The lowest bit flips every time, and each higher bit flips when every bit below it is 0, because the lower bits have nothing to give and must borrow. 2, which is 10, becomes 01: the 1s bit was 0, so the 2s bit flips too.
How do you make a counter stop at zero?
Detect zero with a NOR of all the bits, and use its opposite, GO = NOT ZERO, to enable counting. Feed each bit's flip-flop Q XOR (GO AND its flip condition). At zero GO drops, every XOR passes Q straight through, and the count holds until it's loaded again.
What chip is a programmable down counter?
The 74HC193 is a classic: a synchronous 4-bit up/down counter with a parallel load and a borrow output for chaining. The 74HC191 is similar. Microcontroller timers can also count down and raise an interrupt when they reach zero.
Related topics
- How a binary counter divides a clock by 2, 4, 8 and 16Flip-flops that toggle, chained: each one halves the clock, together they count.
- Synchronous vs asynchronous countersBits that wait for each other, or bits that change on the same tick.
- How a D flip-flop worksCopy D to Q at the clock's rising edge, then hold it: one bit of memory.
- What are CPU flags? Zero, carry and the status registerOne-bit facts about the last answer, like zero or too big, that the next instruction uses to decide.