Latches and Flip-Flops for GATE: SR, JK, D and T, Race-Around, Timing and Solved Examples

Latches and flip-flops for GATE: the SR latch, SR, JK, D and T equations, excitation tables, race-around, setup and hold time, conversions and practice questions.

Every circuit in the adders, multiplexers and decoders post had one thing in common: change the inputs and the output changes with them, with no memory of what came before. That's fine for adding two numbers, but a calculator also has to remember the number you typed a moment ago. For that we need sequential circuits, whose output depends on the present inputs and on what happened earlier.

The smallest piece of memory in digital electronics is the latch, and its better-behaved cousin, the flip-flop. Every counter, register and processor is built from them. GATE asks about them every year, usually on characteristic equations, race-around, conversions between flip-flop types, and timing.

Where the memory comes from: feedback

Take two NOR gates and feed each one's output into the other's input. That loop is all it takes to store one bit:

Recall that a NOR gate outputs 1 only when both its inputs are 0. Work through the four input combinations and you get

$S$ $R$ $Q$ next What happens ------------ 0 0 $Q$ hold: remembers the last value 0 1 0 reset 1 0 1 set 1 1 ? not allowed

The last row is the problem. With $S = R = 1$ both NOR gates output 0, so $Q$ and $\bar{Q}$ are both 0, which makes no sense for a bit and its complement. Worse, if $S$ and $R$ then drop to 0 together, the latch settles to 0 or 1 depending on which gate happens to be faster. That's why $S = R = 1$ is the forbidden input.

A latch built from NAND gates works the same way, but its inputs are active-low: it sets and resets on a 0, and $S = R = 0$ is the forbidden combination. GATE likes to check that you notice which kind is drawn.

From latch to flip-flop

A plain latch reacts the moment its inputs change. Add an enable, or clock, input and you get a gated latch, which only listens while the clock is high. The D latch is the most useful version:

But while the clock is high the latch is transparent: every wiggle on $D$ passes straight through to $Q$. In a system where one latch feeds another, data can race through several stages in a single clock pulse.

A flip-flop fixes this by responding only at a clock edge, the instant the clock goes from 0 to 1 (positive-edge triggered) or from 1 to 0 (negative-edge triggered). Between edges its output doesn't move, whatever $D$ does. That single change is what makes large synchronous systems possible.

The four flip-flops and their equations

Each flip-flop is described by a characteristic equation, which gives the next state $Q^+$ from the inputs and the present state $Q$:

Flip-flop Characteristic equation In words --------- D $Q^+ = D$ copies $D$ at the clock edge T $Q^+ = T \oplus Q$ toggles when $T = 1$, holds when $T = 0$ SR $Q^+ = S + \bar{R}\,Q$, with $SR = 0$ set, reset or hold JK $Q^+ = J\bar{Q} + \bar{K}\,Q$ like SR, but $J = K = 1$ toggles

The JK flip-flop is the SR flip-flop with its forbidden row put to good use. With $J = K = 1$ the output simply flips. That's why it's often called the universal flip-flop.

Excitation tables

When you design with flip-flops, for example a counter, you know the change you want, from $Q$ to $Q^+$, and need the inputs that cause it. That's the excitation table, where X means "don't care":

$Q \to Q^+$ D T J K S R --------------- 0 → 0 0 0 0 X 0 X 0 → 1 1 1 1 X 1 0 1 → 0 0 1 X 1 0 1 1 → 1 1 0 X 0 X 0

The don't cares in the JK column are why JK flip-flops often give the simplest counter circuits: more X's on the K-map mean bigger groups.

A T flip-flop halves the frequency

Tie $T = 1$ and the flip-flop toggles on every rising clock edge. Its output completes one full cycle for every two clock cycles, so it runs at half the clock frequency. Feed that output into a second T flip-flop and you halve it again:

$n$ flip-flops in a chain divide the clock frequency by $2^n$. This chain is also the start of a binary counter, which is where we'll go next.

Race-around: the JK flip-flop's weakness

Suppose a JK flip-flop is level-triggered and $J = K = 1$. While the clock stays high, the output toggles, and the new output feeds back and makes it toggle again, and again, as long as the clock is high. When the clock finally goes low, the output could be either value. This is the race-around condition. It happens when

that is, when the clock pulse width is longer than the flip-flop's propagation delay. There are three ways out:

Keep the pulse width shorter than the propagation delay, $t{pw} < t{pd} < T$. It works, but it's fragile. Use a master-slave JK flip-flop. The master responds while the clock is high and the slave copies it only when the clock goes low, so the output can't feed back within one pulse. Use an edge-triggered flip-flop, which is what almost every modern design does.

Setup time, hold time and the maximum clock frequency

An edge-triggered flip-flop needs its input to sit still for a short while around the clock edge:

Setup time $t{su}$: how long before the edge the input must be stable. Hold time $th$: how long after the edge it must stay stable. Propagation delay $t{pd}$: how long after the edge the output changes.

When one flip-flop feeds another through some combinational logic, the signal has to leave the first flip-flop, pass through the logic, and arrive before the next setup window. So the clock period must satisfy

That formula is behind nearly every timing question in GATE.

Converting one flip-flop into another

GATE often asks you to build one type from another. The method is always the same:

The common results are worth remembering:

JK to T: connect $J = K = T$. JK to D: connect $J = D$ and $K = \bar{D}$. D to T: connect $D = T \oplus Q$. D to JK: connect $D = J\bar{Q} + \bar{K}Q$, which is just the JK characteristic equation.

Common traps in GATE questions

These are the mistakes I see most often.

Mixing up NOR and NAND latches. A NOR latch is active-high and forbids $S = R = 1$. A NAND latch is active-low and forbids $S = R = 0$. Calling a latch a flip-flop. A latch is level-sensitive and transparent. A flip-flop changes only at an edge. Reading the edge wrong. A small triangle at the clock input means edge-triggered. A bubble in front of it means the falling edge. Forgetting the $SR = 0$ condition. The SR characteristic equation only holds when $S$ and $R$ aren't both 1. Getting the race-around condition backwards. It happens when the pulse width is longer than the propagation delay. Leaving out a delay in $f{\max}$. Add the flip-flop delay, the logic delay and the setup time. Hold time isn't part of the sum. Asynchronous inputs. Preset and clear act immediately, without waiting for the clock edge.

Practice questions

Give yourself about two minutes each.

In a NOR SR latch, what are $Q$ and $\bar{Q}$ when $S = R = 1$? A JK flip-flop with $J = K = 1$ is driven by a 1 MHz clock. What is the frequency of its output? A flip-flop has $t{pd} = 10$ ns and $t{su} = 5$ ns, and the logic between two flip-flops takes 15 ns. What is the maximum clock frequency? A JK flip-flop has $J = \bar{Q}$ and $K = 1$, and starts at $Q = 0$. What sequence does $Q$ follow? Three T flip-flops with $T = 1$ are chained, the first driven by an 8 MHz clock. What is the frequency at the last output? What must be connected to the D input to make a D flip-flop behave like a T flip-flop?

Answers

Both are 0, which is why this input is forbidden. 500 kHz. The output toggles once per clock cycle, so it completes one cycle every two clock cycles. $1 / (10 + 15 + 5)\ \text{ns} = 1 / 30\ \text{ns} \approx 33.3$ MHz. $Q^+ = J\bar{Q} + \bar{K}Q = \bar{Q}\,\bar{Q} + 0 = \bar{Q}$, so it toggles: 0, 1, 0, 1, … $8 / 2^3 = 1$ MHz. $D = T \oplus Q$.

If question 4 caught you out, write the characteristic equation first and substitute. It works for every flip-flop question of that kind. Next time we'll chain flip-flops into counters and shift registers. Tell me in the comments which question took you longest.