The 2-bit counter: counting clock pulses
A counter adds one to the number it stores every time the clock rises. With 2 bits, Q1 Q0, it goes 00, 01, 10, 11 and then wraps around to 00. Counters keep time in watches, count events, and step a processor through its program.
Step by step
The order matters here: the checker sets the inputs one row at a time, top to bottom, and the outputs must match each row.
| Step | CLK | Q1 | Q0 |
|---|---|---|---|
| 1 | 0 | 0 | 0 |
| 2 | 1 | 0 | 1 |
| 3 | 0 | 0 | 1 |
| 4 | 1 | 1 | 0 |
| 5 | 0 | 1 | 0 |
| 6 | 1 | 1 | 1 |
| 7 | 0 | 1 | 1 |
| 8 | 1 | 0 | 0 |
How it works
Look at how binary numbers count: 00, 01, 10, 11. The lowest bit Q0 flips on every step. The next bit Q1 flips only when Q0 was 1 just before. A T flip-flop (T for toggle) flips its output on every clock edge while its T input is 1, and holds it while T is 0. So: one T flip-flop for Q0 with T always at 1, and one for Q1 with T connected to Q0.
Add more flip-flops following the same rule and you get counters of any size: a bit flips when all the bits below it are 1.
Hints and solution
Try on your own first. Each hint gives away a little more.
- A T flip-flop flips its output on every clock edge while T is 1.
- Q0 flips on every edge.
- Q1 flips only when Q0 was 1.