Latches & Flip-Flops
Digital Electronics · 12 min read
Digital Logic 101 covered combinational circuits — their output depends only on the current inputs. But what if a circuit needs to remember?
A traffic-light controller must know which light is currently on. A counter must know its current count. Sequential circuits add memory, and the fundamental memory element is the latch.
1. SR Latch
The SR (Set-Reset) latch is the simplest memory element. It stores one bit and offers two controls: S to set the output to 1, and R to reset it to 0.
| S | R | Q | Action |
|---|---|---|---|
| 0 | 0 | Q (hold) | No change |
| 1 | 0 | 1 | Set |
| 0 | 1 | 0 | Reset |
| 1 | 1 | ?? | Forbidden |
Worked trace: start with Q = 0. Apply [S=1, R=0] — Q becomes 1. Then [S=0, R=0] — Q holds at 1. Then [S=0, R=1] — Q resets to 0. Finally [S=0, R=0] — Q holds at 0.
NAND-Gate Implementation — Active-Low Inputs
The same feedback topology works with NAND gates, but the logic is inverted: the inputs become active-low. Pulling S LOW sets Q, and pulling R LOW resets Q. When both inputs sit HIGH the latch holds its state — the normal idle condition.
| S | R | Q | Action |
|---|---|---|---|
| 1 | 1 | Q (hold) | No change (idle) |
| 0 | 1 | 1 | Set |
| 1 | 0 | 0 | Reset |
| 0 | 0 | ?? | Forbidden |
Worked trace (active-low): start with Q = 0. Apply [S=0, R=1] — Q becomes 1 (set). Then [S=1, R=1] — Q holds at 1. Then [S=1, R=0] — Q resets to 0. Finally [S=1, R=1] — Q holds at 0.
2. D Latch
The SR latch has a forbidden state. The D latch fixes this by providing a single data input D and an Enable (EN) control.
| EN | D | Q |
|---|---|---|
| 0 | X | Q (hold) |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
“Transparent when enable is high” means data passes straight through. This is useful, but it creates a problem when multiple latches share a clock.
3. Edge Triggering — Why Latches Aren't Enough
The transparent latch problem
A latch is level-sensitive. When CLK (or EN) is HIGH, the latch is “open” — output Q follows input D continuously. Any change on D immediately appears at Q.
When CLK goes LOW, the latch “closes” — Q freezes at whatever value D had just before CLK fell.
Why is this a problem?
If two latches share the same clock and the output of Latch A feeds the input of Latch B, a signal can pass through both latches during one clock HIGH period. This is called a race-through or race condition — data moves farther than intended in one cycle.
The flip-flop solution
A flip-flop is edge-triggered. It samples the input only at the clock edge (usually the rising edge ↑). After that instant, the output stays fixed — even if D keeps changing. This prevents race-through completely.
See the difference — latch vs flip-flop
Watch what happens when D changes multiple times while CLK is HIGH:
- Latch (amber): Q follows D continuously while CLK is HIGH — every glitch on D passes through
- Flip-flop (green): Q changes only at the rising edge ↑ — all other D changes are ignored
How a flip-flop is built — the master-slave concept
A flip-flop is typically built from two latches in series: the “master” latch is transparent when CLK is HIGH, and the “slave” latch is transparent when CLK is LOW.
- CLK HIGH: Master is transparent (D passes to X), slave is closed (Q holds)
- CLK LOW: Master closes (X holds), slave opens (X passes to Q)
- Result: Q updates once per cycle, at the falling edge of CLK (from master's perspective) — which is the effective rising-edge trigger of the overall flip-flop
Key takeaway
Latches can allow uncontrolled propagation during an entire clock level. Flip-flops stop propagation except at discrete clock edges — that is why every synchronous digital system uses flip-flops, not latches, as its core storage elements.
4. D Flip-Flop
| CLK | D | Q (next) |
|---|---|---|
| No edge | X | Q (hold) |
| Rising | 0 | 0 |
| Rising | 1 | 1 |
On the rising edge, Q takes the value of D and holds it. Changes to D between edges are ignored — this is what makes flip-flops safe for synchronous design.
5. JK Flip-Flop
| J | K | Q (next) | Action |
|---|---|---|---|
| 0 | 0 | Q | Hold |
| 1 | 0 | 1 | Set |
| 0 | 1 | 0 | Reset |
| 1 | 1 | Q | Toggle |
The JK flip-flop solves the forbidden state problem. When J = K = 1, the output toggles instead of entering an invalid state.
- J = 0, K = 0 — hold (no change)
- J = 1, K = 0 — set (Q = 1)
- J = 0, K = 1 — reset (Q = 0)
- J = 1, K = 1 — toggle (Q flips)
6. T Flip-Flop
| T | Q (next) | Action |
|---|---|---|
| 0 | Q | Hold |
| 1 | Q | Toggle |
The T flip-flop is a special case of the JK flip-flop with J = K = T. When T = 0, Q holds; when T = 1, Q toggles. This makes it ideal for building counters.
7. Excitation Tables
A truth table answers “given these inputs, what is the next state?” An excitation table works backwards: “to get a desired state transition, what inputs do I need?”
| Q | Q(next) | D |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
| Q | Q(next) | J | K |
|---|---|---|---|
| 0 | 0 | 0 | X |
| 0 | 1 | 1 | X |
| 1 | 0 | X | 1 |
| 1 | 1 | X | 0 |
| Q | Q(next) | T |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
- D: Always set D equal to the desired next state — .
- JK: Multiple input combinations can produce the same transition, giving design flexibility.
- T: T = 0 when you want to hold, T = 1 when you want to toggle.