C726 of 57
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

C7 · Lesson 26 · Latches and flip-flops

Feedback that remembers

Connect two NOR gates so that each one's output feeds the other's input, and the pair can sit stably in either of two states. Pulse one input and it flips to 1; pulse the other and it flips to 0; release both and it remembers. That's a latch: one bit of memory, made from logic and feedback. Add a clock so that it only listens at one instant, and you have a flip-flop, the element from which every register, counter and processor state is built.

Play

  • An SR latch from two NOR gates. The timing diagram shows S and R being pulsed in turn. Before S is pulsed, what's Q? (Red means unknown.)
  • After S goes back to 0, does Q forget?
  • Below it, a D flip-flop: Q copies D only when the clock rises. Watch D change between edges.

Predict

A D flip-flop's clock rises at t = 10 and t = 20. D goes to 1 at t = 12 and back to 0 at t = 17. What does Q do?

Name it

Memory elements

SR latch (two cross-coupled NORs):

SRQ
00unchanged (memory)
101 (set)
010 (reset)
11both outputs 0; avoid

At power-up, with neither input asserted, its state is unknown.

D latch: a latch with an enable. While enabled it's transparent (Q follows D); when disabled it holds the last value.

D flip-flop (edge-triggered): two latches back to back, enabled on opposite clock phases, so Q takes D's value at the rising edge only and holds it for a full cycle. It's the basic storage element of synchronous design.

Timing rules. D must be stable for a setup time before the edge and a hold time after it. Q changes a clock-to-Q delay after the edge. Violate setup or hold and the flip-flop can go metastable: hover between 0 and 1 for an unpredictable time before falling one way. That's why signals arriving from outside a clock domain pass through two flip-flops in a row (a synchronizer).

Reset. Flip-flops usually have a reset that forces Q to 0: synchronous (at the next edge) or asynchronous (at once).

Worked example

A flip-flop has tsetup = 0.2 ns and thold = 0.1 ns, and its clock rises at 10 ns. When must D be stable?

Show the solution
  1. Setup, before the edge. 10−0.2=9.8ns
  2. Hold, after the edge. 10+0.1=10.1ns
  3. Outside the window. D can change freely.

Answer D must be stable from 9.8 ns to 10.1 ns.

Worked example

An SR latch (cross-coupled NORs) gets S = 1, R = 0, then S returns to 0. What is Q?

Show the solution
  1. Set. S = 1 sets Q to 1.
  2. Hold. With S = R = 0 the latch holds, so Q stays 1.
  3. Why it holds. The feedback loop remembers the last set or reset.

Answer Q = 1.

Worked example

A D latch's clock is high from 0 to 5 ns, and D pulses high from 2 to 3 ns. What does Q do? What would an edge-triggered flip-flop clocked at 0 ns do?

Show the solution
  1. The latch while the clock is high. The latch is transparent: Q follows D, going high at 2 ns and low at 3 ns (each a gate delay later).
  2. The latch when the clock falls. At 5 ns it holds the 0 it has then.
  3. The flip-flop. It samples D only at the rising edge, when D was 0, so Q stays 0 and the pulse is never seen.
  4. Why designs use flip-flops. That difference is why synchronous designs use flip-flops: their outputs change only at edges, whatever the inputs do in between.

Answer the latch's Q copies the pulse, high from about 2 to 3 ns, then holds 0; the flip-flop's Q stays 0.

Check

An SR latch has Q = 1. S and R are both 0. Then R is pulsed to 1 and back. What's Q now?

Check

A D flip-flop's D is 0 at one rising edge and 0 at the next. What is Q just after the second edge?

Check

A flip-flop has a setup time of 50 ps, a hold time of 20 ps and a clock-to-Q delay of 120 ps. For how long around the edge must D stay still?

Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.

Check

Match each element to how it behaves.

  1. Aset and reset inputs, holds when both are 0
  2. Bcopies D only at the clock's edge
  3. Cfollows D while enabled, holds when disabled
  4. Dtwo flip-flops in a row on an outside signal

Check

How many flip-flops does a register holding a 2-byte value need?

Check

A flip-flop with setup 0.05 ns and hold 0.02 ns has its clock rise at 20 ns.

(a)

From when must D be stable?

Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.

(b)

Until when?

Check

A chain of n toggle flip-flops, each clocked by the previous one's output, starts from a clock of frequency f.

Step 1

What frequency comes out of the first?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why do two cross-coupled NOR gates remember a bit?

Practice

Keep practicing

7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.