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.
Read the plot as a table
| D before the clock edge (ts) | clock-to-Q, D rising |
|---|---|
| 50 ps | 135.1 ps |
| 100 ps | 68.36 ps |
| 150 ps | 68.08 ps |
| 200 ps | 68.08 ps |
| 250 ps | 68.07 ps |
| 300 ps | 68.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.
- v(d)
- v(fm1), master node
- v(clk)
- v(q)
- 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.
- 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.
- 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.
- 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
| Time | v(d) | v(fm1), master node | v(clk) | v(q) |
|---|---|---|---|---|
| 0 s | 0 V | 4.046 nV | 0 V | 872.2 mV |
| 500 ps | 0 V | -11.33 mV | 900 mV | 876.8 mV |
| 1 ns | 0 V | 379.5 nV | 1.8 V | 358.2 nV |
| 1.5 ns | 0 V | -26.67 mV | 900 mV | -461.1 µV |
| 2 ns | 0 V | 4.065 nV | 0 V | 346.2 nV |
| 2.4 ns | 900 mV | 563.5 mV | 0 V | -2.469 µV |
| 2.422 ns | 1.686 V | 906.4 mV | 0 V | 4.913 µV |
| 2.5 ns | 1.8 V | 1.789 V | 900 mV | -2.037 mV |
| 2.568 ns | 1.8 V | 1.763 V | 1.8 V | 899.8 mV |
| 3 ns | 1.8 V | 1.8 V | 1.8 V | 1.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 edge | Clock-to-Q, D rising | Clock-to-Q, D falling |
|---|---|---|
| 300 ps | 68.1 ps | 86.5 ps |
| 150 ps | 68.1 ps | 86.5 ps |
| 100 ps | 68.4 ps | 86.6 ps |
| 80 ps | 69.4 ps | 87.2 ps |
| 70 ps | 71.1 ps | 88.0 ps |
| 60 ps | 76.4 ps | 89.7 ps |
| 55 ps | 86.7 ps | 91.4 ps |
| 50 ps | 135.1 ps | 94.2 ps |
| 45 ps | missed | 101.8 ps |
| 40 ps | missed | missed |
| 30 ps | missed | missed |
| 0 ps | missed | missed |
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 ps | 0.00 V |
| -45 ps | 0.00 V |
| -40 ps | 0.00 V |
| -35 ps | 1.80 V |
| -30 ps | 1.80 V |
| -20 ps | 1.80 V |
| 0 ps | 1.80 V |
| 20 ps | 1.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 by | q after D fell 30 ps after the edge |
|---|---|
| 0 ps | 1.80 V |
| 50 ps | 1.80 V |
| 100 ps | 0.00 V |
| 200 ps | 0.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.
- Device
- I/O
- Datapath
- Data
- Open: clk = 1
Both clocked transistors are on, and the stage is an inverter of D. Here q followed D in 73.5 ps.
- 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.
- 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
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.
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.
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.
Run the netlist to draw its plots here.
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-07Check Yourself
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.