An up/down counter combines a binary up counter and a down counter in one circuit. A control input U picks the direction at every edge: U = 1 counts up, U = 0 counts down.
With T flip-flops, each T input is an OR of the two toggle conditions, each gated by the direction:
- T0 = 1 (Q0 toggles either way)
- T1 =
- T2 =
The U term is the up rule (every lower bit is 1); the term is the down rule (every lower bit is 0). Only one of them can be active at a time.
U is sampled at each clock edge, just like a data input, so the direction can change from one edge to the next. U must be stable for the setup time before the edge. Up/down counters are used for position tracking (a rotary encoder turning either way), stack pointers and up/down timers.
| T2 | T1 | |||
|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 |
| 0 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 |