Latches and Flip-Flops in Transistors

Build a latch from two transmission gates and two inverters, then a flip-flop from two latches. Measure where its setup and hold times come from.

You Will Be Able To

  • Draw a transmission-gate latch and say which gate is on in each clock phase.
  • Build a master-slave flip-flop from two latches of opposite phase.
  • Read setup time from a sweep of clock-to-Q against data arrival.
  • Explain how clock overlap lets data race through a flip-flop.
Lesson
G9.13
Time
35 min
Runs on
ngspice
Check
5 questions

A flip-flop from the lab captured D within 68.1 ps of the clock edge when D arrived early. When D arrived 50 ps before the edge it took 135.1 ps. At 45 ps it missed the new value altogether.

Measured sweepClock-to-Q Against How Early D ArrivesA transmission-gate master-slave flip-flop. Each point is one flop of the lab, with D rising ts before the clock edge.
60 ps70 ps80 ps90 ps100 ps110 ps120 ps130 ps140 psClock-to-Q50 ps100 ps150 ps200 ps250 ps300 psD before the clock edge (ts)setup ≈ 63 ps60 ps80 ps100 ps120 ps140 psClock-to-Q100 ps200 ps300 psD before the clock edge (ts)setup ≈ 63 ps
Read the plot as a table
D before the clock edge (ts)clock-to-Q, D rising
50 ps135.1 ps
100 ps68.36 ps
150 ps68.08 ps
200 ps68.08 ps
250 ps68.07 ps
300 ps68.07 ps

Measured with ngspice 42 on SKY130, 1.8 V. Flops that missed (D at 45, 40, 30, 0 ps) are not plotted.

A Latch from Two Transmission Gates

A latch is a loop of two inverters with a door. The input transmission gate lets D in while the latch is open. The feedback gate closes the loop while it is shut, so the two inverters hold the value.

The two gates take opposite phases of the clock. If both were on together, D and the loop would fight. If both were off, the inner node would float.

Two Latches Make a Flip-Flop

The master latch is open while clk = 0. The slave latch, after it, is open while clk = 1. At the rising edge the master closes on the value of D and the slave opens and passes it to q.

TransientOne Rising Clock Edge, D Arriving 100 Ps EarlyD, the master's input node, the clock and q.
  • v(d)
  • v(fm1), master node
  • v(clk)
  • v(q)
-0.5 V00.5 V1.0 V1.5 V2.0 VVoltage00.5 ns1.0 ns1.5 ns2.0 ns2.5 ns3.0 nsTimehalf of the supply-0.5 V00.5 V1.0 V1.5 V2.0 VVoltage01 ns2 ns3 nsTimehalf of the supply
  1. Time 2.4 nsv(d) = 900 mV · v(fm1), master node = 563.5 mV · v(clk) = 0 V · v(q) = -2.469 µV

    D rises while clk is 0. The master is open.

  2. Time 2.422 nsv(d) = 1.686 V · v(fm1), master node = 906.4 mV · v(clk) = 0 V · v(q) = 4.913 µV

    The master node follows 21.8 ps later, through the input gate.

  3. Time 2.5 nsv(d) = 1.8 V · v(fm1), master node = 1.789 V · v(clk) = 900 mV · v(q) = -2.037 mV

    The clock rises. The master closes on the new value, and the slave opens.

  4. Time 2.568 nsv(d) = 1.8 V · v(fm1), master node = 1.763 V · v(clk) = 1.8 V · v(q) = 899.8 mV

    q follows 68.4 ps after the clock edge: the clock-to-Q delay.

Read the plot as a table
Timev(d)v(fm1), master nodev(clk)v(q)
0 s0 V4.046 nV0 V872.2 mV
500 ps0 V-11.33 mV900 mV876.8 mV
1 ns0 V379.5 nV1.8 V358.2 nV
1.5 ns0 V-26.67 mV900 mV-461.1 µV
2 ns0 V4.065 nV0 V346.2 nV
2.4 ns900 mV563.5 mV0 V-2.469 µV
2.422 ns1.686 V906.4 mV0 V4.913 µV
2.5 ns1.8 V1.789 V900 mV-2.037 mV
2.568 ns1.8 V1.763 V1.8 V899.8 mV
3 ns1.8 V1.8 V1.8 V1.8 V

Measured with ngspice 42 on SKY130, 1.8 V, ideal clk and clkb.

Where Setup, Hold and Clock-to-Q Come From

D before the edgeClock-to-Q, D risingClock-to-Q, D falling
300 ps68.1 ps86.5 ps
150 ps68.1 ps86.5 ps
100 ps68.4 ps86.6 ps
80 ps69.4 ps87.2 ps
70 ps71.1 ps88.0 ps
60 ps76.4 ps89.7 ps
55 ps86.7 ps91.4 ps
50 ps135.1 ps94.2 ps
45 psmissed101.8 ps
40 psmissedmissed
30 psmissedmissed
0 psmissedmissed

Measured: the lab (D rising) and the same sweep with D falling. "missed" means q kept the old value.

When D arrives early, clock-to-Q is constant: the time for the slave gate and the output inverter. When D arrives late, the master has not settled when it closes, and clock-to-Q grows. Then the flop misses. The usual rule puts the setup time where clock-to-Q has grown by 10 %. That is about 63 ps for a rising D and 49 ps for a falling one.

D falls (after the edge; negative = before)q at the end
-60 ps0.00 V
-45 ps0.00 V
-40 ps0.00 V
-35 ps1.80 V
-30 ps1.80 V
-20 ps1.80 V
0 ps1.80 V
20 ps1.80 V

Measured: D is 1 before the edge, then falls. The flop should keep the 1.

The hold time is the earliest D may change after the edge. Here D could fall even 35 ps before the edge. A change of D needs time to pass the input gate and the master inverter. A change that late is simply not captured. A negative hold time is common in flops of this kind.

Clock Overlap and the C2MOS Latch

clkb lags clk byq after D fell 30 ps after the edge
0 ps1.80 V
50 ps1.80 V
100 ps0.00 V
200 ps0.00 V

Measured. q should stay at 1.8 V: D changed after the edge.

If clkb arrives late, both the master input gate and the slave gate are partly on just after the edge. A D change can then race through both latches in the same cycle.

A C2MOS LatchA clocked inverter: an inverter with a clocked transistor inside each half.
  • Device
  • I/O
  • Datapath
  • Data
A C2MOS latchA clocked inverter: an inverter with a clocked transistor inside each half. device PMOS of D, thenPMOS of clkb pull-up path io Node x not D while open device NMOS of clk,then NMOS of D pull-down path datapath Output inverter q clk = 1clk = 1
  1. device PMOS of D, then PMOS of clkbpull-up path
    • clk = 1 → Node x
  2. device NMOS of clk, then NMOS of Dpull-down path
    • clk = 1 → Node x
  3. io Node xnot D while open
    • Output inverter
  4. datapath Output inverterq
  1. Open: clk = 1

    Both clocked transistors are on, and the stage is an inverter of D. Here q followed D in 73.5 ps.

  2. Closed: clk = 0

    Both clocked transistors are off. x keeps its charge and ignores D: q still read 1.80 V after D had fallen.

  3. Size and speed

    The C2MOS form saves contacts, so it is a little smaller. The transmission-gate form is a little faster, since its output is driven through NMOS and PMOS in parallel.

Read the diagram as text
  • PMOS of D, then PMOS of clkb: pull-up path
  • Node x: not D while open
  • NMOS of clk, then NMOS of D: pull-down path
  • Output inverter: q
  • PMOS of D, then PMOS of clkb → Node x: clk = 1
  • NMOS of clk, then NMOS of D → Node x: clk = 1
  • Node x → Output inverter

This version holds its value as charge. A full C2MOS flip-flop adds a feedback path for long holds.

Asked in interviews
  1. How is a flip-flop built from latches?

    Two latches of opposite phase in series. The master is open while the clock is low and the slave while it is high. At the rising edge the master closes and the slave shows its value.

  2. Where does setup time come from?

    The master must settle on the new D before its input gate closes at the edge. If D arrives too late, clock-to-Q grows and then the flop misses the value.

  3. What is clock overlap?

    A moment when both phases of a two-phase clock enable latches together, for example when clkb lags clk. Data can race through master and slave in one cycle.

Try It

cq0 is clock-to-Q with D 300 ps early: 68.1 ps. cq7 is with D 50 ps early: 135.1 ps.

qend11 is q at the end with D arriving at the edge: 0.00 V. The flop kept the old 0.

Change W=2 to W=4 in the master inverter PMOS lines Xf5i1P to Xf9i1P, the flops whose D arrives 60 to 40 ps early. Run and compare cq5 to cq9 with the table.

SPICEngspice 42 · simulator service
Edit the netlist, then run it
Expected measurements: cq0 = 6.806694e-11 targ= 2.568067e-09 trig= 2.500000e-09 qend0 = 1.800000e+00 cq1 = 6.808156e-11 targ= 2.568082e-09 trig= 2.500000e-09 qend1 = 1.800000e+00 cq2 = 6.836014e-11 targ= 2.568360e-09 trig= 2.500000e-09 qend2 = 1.800000e+00 cq3 = 6.937262e-11 targ= 2.569373e-09 trig= 2.500000e-09 qend3 = 1.800000e+00 cq4 = 7.108208e-11 targ= 2.571082e-09 trig= 2.500000e-09 qend4 = 1.800000e+00 cq5 = 7.635096e-11 targ= 2.576351e-09 trig= 2.500000e-09 qend5 = 1.800000e+00 cq6 = 8.674046e-11 targ= 2.586740e-09 trig= 2.500000e-09 qend6 = 1.800000e+00 cq7 = 1.351097e-10 targ= 2.635110e-09 trig= 2.500000e-09 qend7 = 1.800000e+00 qend8 = 3.462366e-07 qend9 = 3.462366e-07 qend10 = 3.462366e-07 qend11 = 3.462366e-07

Check Yourself

Predict the outputThe same latch with another sequence of clk and d. Predict the exact line.
module tb;
  reg clk = 1, d = 0;
  wire clkb = ~clk;
  wire x, xb, q;
  // input gate: on while clk = 1
  nmos ti_n (x, d, clk);   pmos ti_p (x, d, clkb);
  // forward and feedback inverters
  not i1 (xb, x);          not i2 (q, xb);
  // feedback gate: on while clk = 0
  nmos tf_n (x, q, clkb);  pmos tf_p (x, q, clk);
  initial begin
    #1 $write("%b", q);              // open, d = 0
    clk = 0;   #1 d = 1;
    #1 $write("%b", q);              // closed while d rose
    clk = 1;   #1 $write("%b", q);   // open
    d = 0;     #1 $display("%b", q); // still open
  end
endmodule
ConceptHow was the setup time read from the sweep?
Conceptclkb is made by a slow inverter, so it lags clk by 200 ps. What did the run show?
ConceptWhat does a negative hold time mean?
ConceptA C2MOS latch is closed. What holds its inner node?

Common Mistakes

Wrong Leave out the feedback gate of a latch to save two transistors.

While the input gate is off, nothing drives the inner node. It holds its value only as charge, which leaks and picks up noise.

Fix Keep the feedback loop, or accept a dynamic latch only where the clock never stops.

Wrong Assume data may change right up to the clock edge.

The master must settle before it closes. With D rising 50 ps before the edge, clock-to-Q grew to 135.1 ps. At 45 ps the flop missed the new value.

Fix Respect the setup time. By the 10 % rule it is about 63 ps here for a rising D and 49 ps for a falling one.

Wrong Generate clkb with a slow inverter and ignore the overlap.

If clkb lags clk, both latches are open together for a moment. With a 100 ps lag, D fell 30 ps after the edge and raced through. q ended at 0.00 V instead of 1.8 V.

Fix Generate both phases locally with matched delays, or clock the two latches with two non-overlapping phases.

Wrong Read the hold time of a flop as a delay that must pass after the edge.

In this flop D could fall up to 35 ps before the edge and q still captured the old 1. The hold time is negative.

Fix Read setup and hold from the flop's own sweep or its library table; either can be negative.

Remember

  • A TG latch: an input gate, two inverters in a loop and a feedback gate, on opposite clock phases.
  • A master-slave flip-flop is two latches of opposite phase. The master closes at the edge.
  • Setup time: how early D must settle in the master. Read it where clock-to-Q grows by 10 %.
  • Hold time can be negative. Read both from the flop's own measurement.
  • Clock overlap lets data race through both latches of a TG flop. Non-overlapping phases prevent it.

Practice

Report a problem with this page