Draft preview. Lessons are being written and reviewed.

Digital Design / Module 4: Sequential logic

20. SR and D latches

See how feedback stores one bit.

Lecture coming soon

See it move

The idea

Everything so far has had no memory. Feed a gate's output back to its input, however, and the circuit can hold a value by itself. This is how a bit gets stored.

The SR latch

Cross-couple two NOR gates. Each gate's output feeds the other's input.

SRResult
00Hold the value
10Set: Q = 1
01Reset: Q = 0
11Forbidden

With S = R = 0, the loop reinforces whichever value it already has. With S = R = 1, both outputs go low. They are no longer opposites, and if both inputs are released at once, the final value is unpredictable.

The D latch

A D latch removes the forbidden case. It has a data input D and an enable. While enabled it is transparent: Q follows D. While disabled, it holds. It is level-sensitive, so any change on D during the enabled phase passes through.

always_latch begin
  if (en) q = d;
end

Latches or flops

Most logic uses flops, because they change at one instant, which makes timing easy to reason about. Latches do appear on purpose: in cells, in some memories, and in high-speed designs that use time borrowing. There, a slow path may take a little time from the next stage, as long as the data arrives while the latch is open.

Common mistake

Confusing "latch" and "flop" in an interview. A latch is sensitive to a level, and a flop to an edge. Use the second animation to compare them with the same inputs: the latch output follows every wiggle during the enabled phase, whereas the flop ignores them.

One more to try

Key ideas

  • Cross-coupled gates hold state.
  • A D latch is transparent while enabled.
  • Latches allow time borrowing but complicate timing.

Your exercise

Trace an SR latch through set, hold, and reset.

Interview questions

coreLatch or flop: level or edge sensitive?

basicFor an SR latch built from two cross-coupled NOR gates, what happens for each combination of S and R?

basicWhat does a D latch do while its enable is high, and while it is low?

coreIn a NOR SR latch, S and R are both 1. What are Q and Q-bar, and what happens if both inputs drop to 0 at exactly the same time?

coreAn SR latch is built from two cross-coupled NAND gates instead of NOR. How do its inputs behave, and which input combination is forbidden?

coreA D latch and a rising-edge flop receive the same D and the same clock, and D wiggles several times while the clock is high. How do the two outputs differ?

coreThis code is meant to model a D latch. In simulation, with en held high, D changes from 0 to 1 but q stays 0. Why?

always @(en)
  if (en) q = d;

advancedA design runs on a 10 ns clock with a 50% duty cycle. Stage 1 logic needs 12 ns and stage 2 needs 7 ns. Ignoring setup and latch delays, can it work with flops between the stages? Can it work if the middle element is a latch that is open during the high phase?

advancedA latch's enable is driven by combinational logic that can glitch high for a moment while it is meant to stay low. Why is this a real problem for a latch, when a glitch of the same kind on a flop's D input usually is not?

Practise these 9 questions with animations