The T (toggle) flip-flop has one control input: with T = 0 it holds its state, and with T = 1 it inverts its output at every clock edge. Tie T high and the output toggles at half the clock frequency, a divide-by-2. Chains of T flip-flops are the classic binary counters, in two flavours: a ripple (asynchronous) counter and a synchronous counter.
12 min read | Intermediate Level
What You'll Learn
- The T flip-flop characteristic equation Q+ = T xor Q and how to build it from a D flip-flop
- How a T flip-flop divides the clock by two
- How ripple and synchronous binary counters are built, and how their delays differ
- Why chips use synchronous counters rather than ripple counters
Quick Answer: T Flip-Flop
| T | Q after the clock edge | Action |
|---|---|---|
| 0 | Q | Hold |
| 1 | Q' | Toggle |
Characteristic equation: Q(next) = T xor Q T flip-flop proportion rules T = 1 -> Q toggles at every clock edge Q toggles every edge -> Q has half the clock frequency n toggle stages in a chain -> clock divided by 2^n
Building a T Flip-Flop
A T flip-flop is a D flip-flop with an XOR gate in front of D: D = T xor Q. With T = 0 the XOR passes Q back (hold), and with T = 1 it passes Q' (toggle). It is also a JK flip-flop with J = K = T (see JK Flip-Flop).
| Clock edge | T | Q before | Q after | Action |
|---|---|---|---|---|
| 1 | 1 | 0 | 1 | Toggle |
| 2 | 1 | 1 | 0 | Toggle |
| 3 | 0 | 0 | 0 | Hold |
| 4 | 1 | 0 | 1 | Toggle |
| 5 | 1 | 1 | 0 | Toggle |
| 6 | 1 | 0 | 1 | Toggle |
Quick Check
Q: A T flip-flop with T = 1 is clocked at 100 MHz. What is the frequency of Q?
Show Answer
50 MHz. Q changes once per clock edge, so a full output cycle (0 to 1 to 0) takes two clock cycles.
Where Are Toggle Stages Used?
Clock dividers in microcontrollers, timers and frequency counters are chains of toggle stages. Every output of the chain is the clock divided by a power of two, which is a cheap way to derive slower clocks and time bases.
Ripple (Asynchronous) Counters
Use falling-edge-triggered T flip-flops with T = 1 and connect the Q output of each one to the clock input of the next: a stage toggles when the stage before it falls, and the chain counts clock pulses in binary. (With rising-edge flip-flops the next stage is clocked from the inverted output instead, because feeding Q straight in would count down.) Each stage divides by two, so the outputs form the count:
| Clock pulses | Q2 | Q1 | Q0 | Count |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 000 |
| 1 | 0 | 0 | 1 | 001 |
| 2 | 0 | 1 | 0 | 010 |
| 3 | 0 | 1 | 1 | 011 |
| 4 | 1 | 0 | 0 | 100 |
| 5 | 1 | 0 | 1 | 101 |
| 6 | 1 | 1 | 0 | 110 |
| 7 | 1 | 1 | 1 | 111 |
| 8 | 0 | 0 | 0 | 000 |
Ripple counter delay proportions each stage is clocked by the previous stage's output the count settles after n x t_cq (worst case, all bits change) illustrative t_cq = 40 ps: 3 bits -> 120 ps, 8 bits -> 320 ps while it settles, decoded outputs can show wrong intermediate counts
A ripple counter is small, but the stages do not change together: when the count goes 0111 to 1000 the outputs pass through intermediate values 0110, 0100 and 0000 before 1000. Logic that decodes a count from such a counter can glitch.
Synchronous Counters
A synchronous counter clocks every flip-flop with the same clock, so all bits change together after one clock-to-Q delay. Bit i must toggle when all lower bits are 1, so its T input is the AND of the lower bits:
3-bit synchronous up counter T0 = 1 T1 = Q0 T2 = Q0 . Q1
| Count | T2 = Q0.Q1 | T1 = Q0 | T0 | Next count |
|---|---|---|---|---|
| 000 | 0 | 0 | 1 | 001 |
| 001 | 0 | 1 | 1 | 010 |
| 010 | 0 | 0 | 1 | 011 |
| 011 | 1 | 1 | 1 | 100 |
| 100 | 0 | 0 | 1 | 101 |
| 101 | 0 | 1 | 1 | 110 |
| 110 | 0 | 0 | 1 | 111 |
| 111 | 1 | 1 | 1 | 000 |
The price is the AND gates, and the AND chain also limits the maximum clock rate for wide counters: the T input of the top bit must settle before the next edge.
| Ripple counter | Synchronous counter | |
|---|---|---|
| Clock | Each stage clocked by the previous stage | One common clock |
| Settling time | n x tcq | tcq + AND delay |
| Extra logic | None | AND gates for T inputs |
| Glitch-free decoding | No | Yes (all bits change together) |
| Timing analysis | Hard (generated clocks) | Standard |
Where Are the Two Counter Styles Used?
Ripple counters survive in low-power frequency dividers and simple prescalers, where only the last stage's output matters. Synchronous counters are the standard for program counters, address generators, timers and FIFO pointers.
Quick Check
Q: In the 3-bit synchronous up counter at count 011, what are T0, T1 and T2, and what is the next count?
Show Answer
T0 = 1, T1 = Q0 = 1 and T2 = Q0.Q1 = 1, so all three bits toggle: 011 becomes 100.
Ripple counters use derived clocks, which complicate clock-tree design and timing analysis. A synchronous counter is three D flip-flops with an incrementer in front of them (see Half-Adder), and that is the style used for counters in chips.
Common Mistakes
Mistake #1: Decoding a ripple counter without allowing for settling
Wrong: Using the decoded output for count 4 of a ripple counter as a clean pulse
Right: Use a synchronous counter, or register the decode result on a clock.
Why? The stages change one after another, so the outputs show intermediate counts (0111 to 0000 to 1000) that can produce glitches in decoded signals.
Mistake #2: Forgetting the reset
Wrong: A toggle flip-flop chain with no reset
Right: Give every flip-flop a reset so the counter starts from a known value.
Why? A toggle flip-flop in an unknown state toggles from an unknown value; in simulation x toggles to x forever.
Mistake #3: Wrong T input for the upper bits of a synchronous counter
Wrong: T2 = Q1 only
Right: T2 = Q0 . Q1 (all lower bits).
Why? Bit 2 must toggle only when all lower bits are 1. With T2 = Q1 it would toggle at the wrong counts.
Practice Exercise
Challenge: Design a 3-Bit Synchronous Down Counter
Design a 3-bit synchronous counter that counts down: 111, 110, 101, ..., 000, 111, ... using T flip-flops.
- When must each bit toggle in a down counter?
- Write the T input equations.
- Check the sequence from 000.
Hint
Bit i toggles in a down counter when all lower bits are 0.
Solution
1. A down counter borrows instead of carrying: bit i toggles when all lower bits are 0. 2. T0 = 1 T1 = Q0' T2 = Q0' . Q1' 3. From 000: T0 = 1, T1 = 1, T2 = 1, so every bit toggles -> 111. From 111: T0 = 1, T1 = 0, T2 = 0, so only Q0 toggles -> 110. From 110: T0 = 1, T1 = 1, T2 = 0 -> 101, and so on down to 000.
Summary
In this tutorial, you learned:
- A T flip-flop holds with T = 0 and toggles with T = 1: Q(next) = T xor Q; with T = 1 it divides the clock by 2
- A ripple counter chains toggle stages and settles after n clock-to-Q delays; its decoded outputs can glitch
- A synchronous counter uses one clock and T inputs equal to the AND of the lower bits, so all bits change together
- Chips use synchronous counters: one clock, no derived clocks, and glitch-free outputs