Counters
A counter is a register plus an adder that adds 1. On every rising clock edge the register saves the adder's answer, so a 4-bit counter goes 0, 1, 2 ... 15 and then wraps to 0. Watch it count in binary, wrap and reset, then compare it with a ripple counter built from toggle flip-flops, and see counters at work as clock dividers, timers and the CPU's program counter.
6 quick questions
Pick an answer to see why. Your score saves with your progress.
01A 4-bit counter shows 1111. What does it show after the next rising clock edge?
1111 + 1 = 10000 needs five bits. The register keeps only four, so the extra 1 is lost and the count wraps to 0000.
02How many different values can an 8-bit counter show before it wraps?
n bits give 2^n values. 2^8 = 256, from 0 to 255.
03In a ripple counter, what clocks the second toggle flip-flop?
Each stage is clocked by the one before it, so each bit runs at half the frequency of the previous bit.
04Why can a ripple counter briefly show a wrong number?
Going from 0111 to 1000 it passes through 0110, 0100 and 0000. A synchronous counter changes all bits on one clock edge.
05What does a CPU's program counter hold?
It counts through instruction addresses one by one; a jump loads a new address instead of adding one.
06A watch crystal ticks 32,768 times a second. It feeds a chain of 15 halving (toggle) stages. How often does the last stage tick?
Each stage halves the frequency. 32,768 = 2^15, so 32,768 ÷ 2^15 = 1 tick per second. This is how counters divide a clock to make timers.
Glossary
- Counter
- A circuit that steps through numbers in order, usually adding 1 on every clock edge.
- Register
- A group of flip-flops that share one clock and together hold a binary number.
- Clock edge
- The instant a clock signal changes; on a rising edge it goes from 0 to 1, and flip-flops copy their input then.
- Wrap around
- Going back to 0 after the largest value: a 4-bit counter goes from 15 (1111) to 0 (0000).
- Reset
- An input that forces every flip-flop of a counter to 0.
- Toggle (T) flip-flop
- A flip-flop that flips its output on every clock edge, so its output has half the clock's frequency.
- Ripple counter
- A chain of toggle flip-flops where each one is clocked by the one before; changes pass along the chain one stage at a time.
- Program counter (PC)
- The register in a CPU that holds the address of the next instruction to run.
Notes and sources
- A rising clock edge is the instant the clock signal goes from low (0) to high (1). Flip-flops in a register copy their input only at that instant (Harris and Harris, Digital Design and Computer Architecture, sections 3.2 and 5.4.1).
- An n-bit binary counter counts 0 to 2^n - 1 and then wraps to 0. In Python the same rule is count = (count + 1) % 16 for four bits.
- Real parts: Texas Instruments' SN74HC161 is a 4-bit synchronous binary counter whose clear input works without the clock; the SN74HC393 holds two 4-bit ripple counters built from toggle flip-flops, each clocked by the one before.
- The figure slows the ripple down so you can see it. In a 74HC393 each stage adds a delay of roughly 13 nanoseconds (typical), so a 4-bit ripple is wrong for only a few tens of nanoseconds.
- Nearly all quartz watches use a 32,768 Hz crystal; 32,768 is 2^15, so a 15-stage binary counter overflows once per second.
- In MIPS and RISC-V each instruction is 4 bytes long and memory is numbered in bytes, so the program counter usually adds 4. The figure uses one address per instruction, as many teaching CPUs do.
- Harris and Harris, Digital Design and Computer Architecture (sections 3.2, 5.4.1 and 7.3)
- Texas Instruments SN74HC161 datasheet: 4-bit synchronous binary counters
- Texas Instruments SN74HC393 datasheet: dual 4-bit binary (ripple) counters
- Nisan and Schocken, Nand2Tetris: sequential logic and the PC chip
- MIT OpenCourseWare 6.004 Computation Structures
- Quartz clock: the 32,768 Hz crystal and its 15-stage divider
- Python reference: arithmetic and bitwise operators
Quiz Unlocks after the last step.