Sequential Logic & State Machines
JK & T Flip-Flops
The D flip-flop stores whatever is on its input, but many circuits need something more flexible: a memory element that can set, reset, hold or toggle. The JK flip-flop does all four. Its close relative, the T flip-flop, only holds or toggles, which makes it ideal for counters. In this lesson you will learn how both work, how to convert one type into another, and how to use the excitation table to design a counter.
You should know the D flip-flop and the idea of edge triggering from the previous lesson.
Learning objectives
After this lesson you will be able to:
- Write the characteristic table and equation of a JK flip-flop.
- Explain what the toggle condition J = K = 1 does.
- Write the characteristic equation of a T flip-flop.
- Use the excitation table to find the inputs needed for a state change.
- Build a 2-bit counter from T flip-flops.
The JK flip-flop
A JK flip-flop has two data inputs, J and K, plus a clock. On the active clock edge the output changes according to the table below.
| J | K | Q (next) |
|---|---|---|
| 0 | 0 | Q (no change) |
| 0 | 1 | 0 (reset) |
| 1 | 0 | 1 (set) |
| 1 | 1 | Q' (toggle) |
J is the "set" input and K is the "reset" input. When both are 1, the output toggles. This removes the forbidden input of the SR latch, where S = R = 1 was not allowed. The characteristic equation is:
Q+ = JQ' + K'Q
The first term sets the flip-flop when it is 0, and the second term keeps it at 1 unless K resets it. An edge-triggered JK flip-flop toggles only once per clock edge. An older level-triggered design could toggle repeatedly while the clock was high, which is called the race-around problem, and edge triggering avoids it.
The T flip-flop
A T flip-flop has a single input T. When T = 0 it holds its value, and when T = 1 it toggles on the clock edge. Its characteristic equation is Q+ = T XOR Q. You can make one from a JK flip-flop by connecting J and K together to T. With T = 1 permanently, the output toggles on every edge, giving the divide-by-2 circuit from the previous lesson.
The excitation table
The characteristic table tells you the next state for given inputs. Designers often need the opposite: which inputs produce a wanted change. The excitation table answers that, and an x means "don't care".
| Q | Q (next) | J | K |
|---|---|---|---|
| 0 | 0 | 0 | x |
| 0 | 1 | 1 | x |
| 1 | 0 | x | 1 |
| 1 | 1 | x | 0 |
For example, to take a flip-flop from 0 to 1 you can use J = 1 and K = 0 (set) or J = 1 and K = 1 (toggle), so K is a don't care. The don't cares often make the input logic simpler.
Example 1: tracing a JK flip-flop
Starting with Q = 0, apply the five (J, K) pairs below at successive clock edges.
| Edge | J | K | Q before | Q after |
|---|---|---|---|---|
| 1 | 1 | 0 | 0 | 1 |
| 2 | 0 | 0 | 1 | 1 |
| 3 | 1 | 1 | 1 | 0 |
| 4 | 0 | 1 | 0 | 0 |
| 5 | 1 | 1 | 0 | 1 |
Result: the output sequence is 1, 1, 0, 0, 1. Edge 1 sets the flip-flop, edge 2 holds it, edge 3 toggles it to 0, edge 4 resets it (already 0), and edge 5 toggles it to 1.
Example 2: converting between flip-flop types
Any flip-flop can imitate another by adding a little logic. Two conversions are used constantly:
- T from JK: connect J = K = T. Then Q+ = TQ' + T'Q = T XOR Q, which is the T characteristic equation.
- D from JK: connect J = D and K = D'. Then Q+ = DQ' + DQ = D, which is the D characteristic equation.
Result: a JK flip-flop can act as a D or a T flip-flop, which is why it was a popular general-purpose part.
Example 3: a 2-bit counter with T flip-flops
A binary counter flips a bit whenever all the lower bits are 1. For a 2-bit counter, bit 0 toggles on every clock edge, so T0 = 1, and bit 1 toggles only when Q0 = 1, so T1 = Q0.
| Present Q1Q0 | T1 = Q0 | T0 = 1 | Next Q1Q0 |
|---|---|---|---|
| 00 | 0 | 1 | 01 |
| 01 | 1 | 1 | 10 |
| 10 | 0 | 1 | 11 |
| 11 | 1 | 1 | 00 |
The counter goes 00, 01, 10, 11 and then wraps back to 00. For a 3-bit counter the same rule gives T0 = 1, T1 = Q0 and T2 = Q1Q0. With JK flip-flops, connect J = K = T for each stage.
Result: two T flip-flops and no extra gates implement a 2-bit up counter.
Common mistakes
- Forgetting that J = K = 1 toggles. The output flips, and it does not stay the same.
- Mixing up J and K. J sets the output to 1 and K resets it to 0.
- Using the characteristic table when you need the excitation table. When you know the wanted change and need the inputs, use the excitation table.
- Treating don't cares as 0. The x entries give extra freedom in simplification.
- Triggering on the wrong edge. A flip-flop that is positive-edge triggered ignores the falling edge.
Practice problems
Check your logic with the truth table generator.
-
A JK flip-flop has Q = 1, J = 1 and K = 1. What is Q after the clock edge?
Answer: Q = 0, because J = K = 1 toggles the output.
-
Which J and K values change Q from 1 to 0?
Answer: J can be anything (x) and K must be 1.
-
A T flip-flop has Q = 1. What is Q after an edge with T = 1, and after an edge with T = 0?
Answer: With T = 1 it toggles to 0. With T = 0 it holds, so Q stays 1.
-
Write the T inputs of a 3-bit binary up counter.
Answer: T0 = 1, T1 = Q0 and T2 = Q1Q0.
Frequently asked questions
Why does the JK flip-flop have no forbidden state? The SR latch had an invalid input, S = R = 1. The JK flip-flop gives that input a useful meaning: it toggles the output. So every combination of J and K is allowed.
When should I use a T flip-flop? Use it when the circuit counts or divides frequency, because toggling is exactly what a counter bit does. Most chips build T behaviour from a D or JK flip-flop.
Which flip-flop is best for design? D flip-flops are the simplest to design with, because Q+ = D. JK and T flip-flops can need fewer gates in the input logic, because of the don't cares in the excitation table.
Try the next-state equations of your own counters in the Boolean calculator.
Next lesson: Asynchronous vs Synchronous Circuits