Electrical Engineering › Section U · Sequential logic › Topic U.1

Latches and flip-flops

Feed a gate's output back to the input of another and the circuit starts to remember. Latches and flip-flops are the one-bit memories that every register, counter and processor is built from.

Memory from feedback

Cross-couple two gates, each output feeding one input of the other, and the pair has two stable states. It stays in one after the inputs that put it there are gone: one bit of memory. The outputs are named \(Q\) and \(\overline{Q}\), and they are normally complements. \(Q = 1\) is called the SET state and \(Q = 0\) the RESET state. A latch is the simplest circuit of this kind; a flip-flop adds a clock so that it changes only at chosen instants.

The S-R latch

Two cross-coupled NOR gates form an S-R latch with active-HIGH inputs. \(S = 1\) sets it (\(Q = 1\)), \(R = 1\) resets it (\(Q = 0\)), and with both inputs 0 it holds its last state. \(S = R = 1\) is invalid: both outputs go to 0, breaking the rule that they are complements, and when both inputs return to 0 together the final state is unpredictable. Two cross-coupled NAND gates make the active-LOW version, with inputs \(\overline{S}\) and \(\overline{R}\). It holds when both are 1, and \(\overline{S} = \overline{R} = 0\) is the invalid case, forcing both outputs to 1.

Worked example: tracing a NOR latch

A NOR S-R latch starts reset, \(Q = 0\), and receives the input pairs (S, R) = (1, 0), (0, 0), (0, 1), (0, 0), (1, 0) in turn. 1. (1, 0) sets it: \(Q = 1\). 2. (0, 0) holds: \(Q = 1\), though S has gone back to 0. 3. (0, 1) resets it: \(Q = 0\). 4. (0, 0) holds: \(Q = 0\). 5. (1, 0) sets it again: \(Q = 1\). Steps 2 and 4 show memory: the same inputs, (0, 0), give different outputs depending on what came before, something no combinational circuit can do. A classic use is switch debouncing: a mechanical switch bounces for a few milliseconds, but the first contact sets the latch and later bounces leave it set.

Gated latches and the D latch

A gated latch adds an enable input EN: the S and R inputs only reach the latch while EN is HIGH. The gated D latch removes the invalid state altogether by deriving both inputs from one data line D, with \(S = D\) and \(R = \overline{D}\). While EN is HIGH, Q follows D, so the latch is called transparent. When EN goes LOW, Q holds whatever D was at that moment. The 74HC75 contains four D latches. Transparency is a weakness in synchronous systems: any change on D during the enable time passes straight through.

Edge-triggered flip-flops

A flip-flop changes state only at a clock edge: the rising edge for a positive-edge-triggered device, the falling edge for a negative-edge one. The clock input is marked with a small triangle, plus a bubble for falling-edge triggering. Between edges the inputs can change freely without affecting Q. The D flip-flop simply copies D at each active edge: \(Q_{next} = D\). The 74HC74 holds two positive-edge D flip-flops. Because each flip-flop samples once per cycle, a whole system of them can update together: synchronous design.

The J-K flip-flop

The J-K flip-flop behaves like an S-R device, J setting and K resetting, but turns the former invalid case into a useful one: with \(J = K = 1\) it toggles, changing to the opposite state at each active edge. Its characteristic equation and table are:

Q_{next} = J\overline{Q} + \overline{K}Q
\begin{array}{cc|l} J & K & Q_{next} \\ \hline 0&0& Q \text{ (hold)} \\ 0&1& 0 \text{ (reset)} \\ 1&0& 1 \text{ (set)} \\ 1&1& \overline{Q} \text{ (toggle)} \end{array}

The 74HC112 holds two negative-edge J-K flip-flops.

Worked example: a J-K sequence

A positive-edge J-K flip-flop starts with \(Q = 0\). At six successive rising edges the inputs (J, K) are (1, 0), (0, 0), (1, 1), (1, 1), (0, 1) and (1, 1). 1. (1, 0) sets: \(Q = 1\). 2. (0, 0) holds: \(Q = 1\). 3. (1, 1) toggles: \(Q = 0\). 4. (1, 1) toggles again: \(Q = 1\). 5. (0, 1) resets: \(Q = 0\). 6. (1, 1) toggles: \(Q = 1\). Check with the equation at step 3: \(Q = 1\), so \(J\overline{Q} + \overline{K}Q = 1 \cdot 0 + 0 \cdot 1 = 0\). Inputs that change between edges have no effect.

Preset, clear, and timing limits

Most flip-flops also have asynchronous inputs, usually active-LOW preset \(\overline{PRE}\) and clear \(\overline{CLR}\), which force Q to 1 or 0 at once, ignoring the clock; they set a known state at power-up. Datasheets give propagation delays from clock edge to output (\(t_{PLH}\) for a LOW-to-HIGH output change, \(t_{PHL}\) for HIGH-to-LOW). Setup time \(t_s\) is how long D must be steady before the edge, and hold time \(t_h\) how long after it. Violate either and the output may be wrong or briefly undecided. There are also minimum clock pulse widths and a maximum clock frequency \(f_{max}\). Power is \(P = V_{CC}I_{CC}\): 5 V and 2 mA give 10 mW.

Worked example: how fast can the clock run?

One flip-flop's output passes through combinational logic to another flip-flop's D input. Assume a clock-to-Q delay of 5 ns, a logic delay of 12 ns on the critical path and a setup time of 3 ns. 1. After a clock edge, the new Q appears at 5 ns. 2. The logic output settles at \(5 + 12 = 17\) ns. 3. It must then be steady for 3 ns before the next edge, so the period must be at least 20 ns. 4. So \(f_{max} = 1/(20\,\text{ns}) = 50\,\text{MHz}\). The same reasoning scales up: a processor clocked at 3 GHz has a period of about 333 ps, and every path between its registers must fit inside it.

Flip-flop applications

Flip-flops store data: four D flip-flops sharing a clock form a 4-bit register that captures a whole number at one edge. They divide frequency: a J-K flip-flop with \(J = K = 1\) toggles at every active edge, so its output is a square wave at half the clock frequency. Two in series divide by 4, turning 16 kHz into 4 kHz, and n in series divide by \(2^n\). Chained like this, the outputs also step through binary numbers, which makes a counter, developed in "Finite state machines and asynchronous and synchronous counters".

Common mistakes to avoid

First, treating S = R = 1 on a NOR latch, or both inputs LOW on a NAND latch, as a normal state; it is invalid. Second, confusing a latch with a flip-flop: a D latch is transparent for the whole enable time, while a D flip-flop samples only at the edge. Third, applying J and K changes at the wrong time: only the values at the active edge count. Fourth, forgetting that preset and clear override the clock. Fifth, ignoring setup and hold times when choosing a clock frequency.

Key takeaways

Cross-coupled gates store a bit. An S-R latch sets, resets or holds, with one invalid input combination; NOR versions are active-HIGH and NAND versions active-LOW. A gated D latch is transparent while enabled. Edge-triggered flip-flops change only at a clock edge: D copies its input, and J-K adds toggle. Preset and clear act asynchronously. Setup time, hold time and propagation delay set the maximum clock frequency. Flip-flops store data, divide frequency by 2 per stage, and form counters.

Flashcards

Flashcard

Latch

Cross-coupled gates storing one bit

Two stable states, SET and RESET.

Test your understanding

Question 1 of 5

A NOR S-R latch holds Q = 1. Its inputs go from S = 0, R = 0 to S = 0, R = 1 and then back to S = 0, R = 0. What is Q at the end?

Question 2 of 5

How does a gated D latch differ from a positive-edge D flip-flop?

Question 3 of 5

A J-K flip-flop has Q = 0. At the next active clock edge J = 1 and K = 1. What is Q after the edge?

Question 4 of 5

A path has a clock-to-Q delay of 4 ns, logic delay of 14 ns and setup time of 2 ns. What is the maximum clock frequency?

Question 5 of 5

Three toggling flip-flops are connected in series, each clocked by the output of the one before. The first is clocked at 24 kHz. What is the output frequency of the third?

← Previous topicNext topic →