The Bistable and the SR Latch

See how two gates in a loop store a bit, how to set and reset it, and why one release is forbidden.

You Will Be Able To

  • Explain why two cross-coupled inverters have two stable states and one metastable point.
  • Set, reset and hold an SR latch built from NOR gates.
  • Use the active-low S'R' latch built from NAND gates.
  • Debounce a two-contact switch with an S'R' latch.
Lesson
G5.4
Time
30 min
Runs on
Your browser
Check
5 questions

A test fixture pressed set and reset of an SR latch together, then let both go in the same instant. In simulation the output never came to rest. In the lab it settled, but nobody could say to which value.

Both Inputs Released at t = 25One column per gate delay, from t = 24 to t = 31. Unit delays, equal for both gates.
01234567srqqnrelease
Scroll horizontally ↔
  1. Cycle 0

    With s = r = 1 both NOR gates give 0: q = qn = 0.

  2. Cycle 2

    Both inputs fall at t = 25. Each gate now sees 0 and 0, so both outputs rise.

  3. Cycle 3

    Now each gate sees a 1 from the other, so both fall again.

  4. Cycle 7

    In this ideal model the race never ends. The lab counts 19 changes of q in 20 ns.

Measured on the sr-latch circuit model; the lab below shows the same oscillation on Icarus.

Two Inverters in a Loop

Connect the output of one inverter to the input of another, and the second output back to the first input. The loop has no input, yet it holds a value. It is a bistable: it has two stable states.

To see why, cut the loop open. Drive the first input with a voltage x, and look at the second output. Wherever that output equals x, the loop can be closed and stay put.

DC sweepTwo SKY130 Inverters in Series Against the Line v(back) = v(x)Each inverter: W = 1 µm, L = 0.15 µm, SKY130 tt, 1.8 V. v(x) is the solid line, so the curves cross where the loop could rest.
  • v(back)
  • v(x)
00.5 V1.0 V1.5 V2.0 VVoltage00.2 V0.4 V0.6 V0.8 V1.0 V1.2 V1.4 V1.6 V1.8 VLoop input v(x)stable: 0metastable: 0.837 Vstable: 1.8 V00.5 V1.0 V1.5 V2.0 VVoltage00.5 V1.0 V1.5 VLoop input v(x)stable: 0metastable: 0.837 Vstable: 1.8 V
  1. Loop input v(x) 200 mVv(back) = 260.6 nV · v(x) = 200 mV

    Near 0 V the curve is flat: a small push on x barely moves the output. The loop pulls itself back to 0.

  2. Loop input v(x) 837 mVv(back) = 844.8 mV · v(x) = 837 mV

    At 0.837 V the curve crosses the line steeply. The loop gain here is about 163: the smallest push grows until the loop falls to one side.

  3. Loop input v(x) 1.6 Vv(back) = 1.8 V · v(x) = 1.6 V

    Near 1.8 V the curve is flat again: the second stable state.

Read the plot as a table
Loop input v(x)v(back)v(x)
0 V260.6 nV0 V
200 mV260.6 nV200 mV
400 mV260.8 nV400 mV
600 mV286.2 nV600 mV
800 mV557.6 µV800 mV
837 mV844.8 mV837 mV
1 V1.8 V1 V
1.2 V1.8 V1.2 V
1.4 V1.8 V1.4 V
1.6 V1.8 V1.6 V
1.8 V1.8 V1.8 V

Measured with ngspice 42 on SKY130 (400 of 1801 points).

The middle point is a metastable state: balanced, but like a ball on a hilltop. Real noise tips it to 0 or 1, and nobody can say which, or exactly when. Lesson G5.11 returns to it.

The SR Latch from NOR Gates

Replace each inverter with a two-input NOR gate. The spare inputs, S (set) and R (reset), can now push the loop to a side.

Two NOR Gates That Remember
Two NOR Gates That Rememberg0 · NORq=1g1 · NORqn=1s=0r=0
s=0 r=0
g0 · NORr=0, qn=1 → q=1
g1 · NORs=0, q=1 → qn=1
Read the connections
GateKindInputsOutput
g0NORr, qnq
g1NORs, qqn

Outputs: q, qn. MUX inputs: d0, d1, select. Latch/flip-flop inputs: data, enable/clock. Unknown values are marked x; high impedance is folded into x in this model.

Gate delay 64. This circuit oscillates or has not settled within 64 gate delays.

Output values at each gate delay012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364qxx111111111000000000000000101010101010101010101010101010101010101qnx0000000000011111111100000101010101010101010101010101010101010101
Scroll horizontally ↔
Every computed frame
Timeqqn
0xx
1x0
210
310
410
510
610
710
810
910
1010
1100
1201
1301
1401
1501
1601
1701
1801
1901
2001
2100
2200
2300
2400
2500
2611
2700
2811
2900
3011
3100
3211
3300
3411
3500
3611
3700
3811
3900
4011
4100
4211
4300
4411
4500
4611
4700
4811
4900
5011
5100
5211
5300
5411
5500
5611
5700
5811
5900
6011
6100
6211
6300
6411

  1. Step 2 · Set. `s` = 1 forces `qn` to 0, and then `q` to 1.
  2. Step 9 · Hold. `s` went back to 0 at 5. Nothing drives the latch now, but the loop keeps `q` = 1.
  3. Step 12 · Reset. `r` = 1 at 10 forces `q` to 0, and then `qn` to 1.
  4. Step 21 · Both inputs 1. At 20 both inputs are 1. Both outputs are 0: `q` and `qn` are no longer opposites.
  5. Step 30 · Released together. At 25 both inputs drop. Each gate sees 0 and 0 and turns on, then both turn off, again and again.

The sr-latch preset, unit delays. The model stops after 64 gate delays: "This circuit oscillates."

SRQ nextName
00Qhold
101set
010reset
110 (and Q' = 0)forbidden

A 1 on either input of a NOR gate forces its output to 0. That is how S and R take control.

Held S = R = 1 is steady, but both outputs are 0, so Q' is no longer the complement of Q. The real danger is releasing both at once: the gates race, as the hook showed.

The NAND Latch with Active-Low Inputs

The same loop built from NAND gates acts on 0s. Its inputs are active-low: S' = 0 sets, R' = 0 resets, and 1 on both holds. Here S' = R' = 0 is the forbidden pair.

Debouncing a Switch

A mechanical switch bounces: its contact closes and opens several times before it settles. A counter fed from it would count every bounce.

A two-contact switch has a blade that rests on contact A and moves to contact B. Each contact pulls its line to 0 when touched. Feed the two lines into an S'R' latch.

A Bouncing Switch, a Clean Output
A Bouncing Switch, a Clean Outputg1 · NANDclean=0g2 · NANDclean_n=1a_n=0b_n=1
a_n=0 b_n=1
g1 · NANDb_n=1, clean_n=1 → clean=0
g2 · NANDa_n=0, clean=0 → clean_n=1
Read the connections
GateKindInputsOutput
g1NANDb_n, clean_nclean
g2NANDa_n, cleanclean_n

Outputs: clean. MUX inputs: d0, d1, select. Latch/flip-flop inputs: data, enable/clock. Unknown values are marked x; high impedance is folded into x in this model.

Gate delay 43. Settled after 43 gate delays from t = 0.

Output values at each gate delay012345678910111213141516171819202122232425262728293031323334353637383940414243cleanxx000000000001111111111111111111111111110000
Scroll horizontally ↔
Every computed frame
Timeclean
0x
1x
20
30
40
50
60
70
80
90
100
110
120
131
141
151
161
171
181
191
201
211
221
231
241
251
261
271
281
291
301
311
321
331
341
351
361
371
381
391
400
410
420
430

  1. Step 6 · Leaving A. The blade leaves contact A. Both contact lines are now 1: the latch holds `clean` = 0.
  2. Step 13 · First touch of B. `b_n` falls at 12 and `clean` rises at 13.
  3. Step 22 · Bounces. The blade bounces off B twice. Each time `b_n` returns to 1, the latch holds. `clean` stays 1.
  4. Step 40 · Back to A. `a_n` falls at 38 and `clean` falls at 40. The bounce at 41 changes nothing.

Two NAND gates as an S'R' latch on a two-contact switch. Active-low lines: 0 means the blade touches.

From a Bouncing Blade to One Clean EdgeArrows show the signal path. The contacts pull their lines to 0 when the blade touches them.
  • Device
  • Storage
  • Structure
  • Reset
  • Control
From a bouncing blade to one clean edgeArrows show the signal path. The contacts pull their lines to 0 when the blade touches them. device Switch blade moves from A to B device Contact A a_n = 0 when touched device Contact B b_n = 0 when touched storage S'R' latch two NAND gates storage Counter one count per press resetsetclean
  1. device Switch blademoves from A to B
    • Contact A
    • Contact B
  2. device Contact Bb_n = 0 when touched
    • set → S'R' latch
  3. storage S'R' latchtwo NAND gates
    • clean → Counter
  4. storage Counterone count per press
  5. device Contact Aa_n = 0 when touched
    • reset → S'R' latch
  1. First touch

    The blade reaches B: b_n = 0 sets the latch, and clean rises.

  2. Bounce

    The blade lifts off B but never reaches A. Both lines are 1: hold.

  3. One edge

    The counter sees a single rising edge per press.

Read the diagram as text
  • Switch blade: moves from A to B
  • Contact A: a_n = 0 when touched
  • Contact B: b_n = 0 when touched
  • S'R' latch: two NAND gates
  • Counter: one count per press
  • Switch blade → Contact A
  • Switch blade → Contact B
  • Contact A → S'R' latch: reset
  • Contact B → S'R' latch: set
  • S'R' latch → Counter: clean

The latch needs two contacts: a single-contact switch is debounced by timing instead.

The first touch of B sets the latch. During a bounce the blade touches nothing, both lines are 1, and the latch holds. The blade never reaches A during a bounce, so it cannot reset the latch by mistake.

Asked in interviews
  1. Why is S = R = 1 forbidden in a NOR SR latch?

    While held, both outputs are 0, so they are not complements. When both are released together the two gates race; the latch may oscillate or settle to an unknown side. The NAND latch has the same problem with S' = R' = 0.

  2. What is a bistable, and what is its metastable point?

    Two inverters in a loop with two stable states, 0 and 1. Between them is a balance point with a high loop gain. Any noise pushes it to one side after an unknown time.

  3. How do you debounce a switch?

    For a two-contact switch, an S'R' latch: the first touch sets or resets it and the bounces are hold. For a single contact, sample it slowly or require a stable count, as in the RTL debouncer of lesson R2.5.

Try It

Before any input, q is x: the loop has no known value. The set pulse gives it one.

Hold keeps the value with both inputs at 0. Reset clears it. S = R = 1 gives 0 on both outputs, which is legal but not a stored bit.

The release makes both gates switch together, again and again: 19 changes of q in 20 ns. Give one gate #2 and run again: the race now ends on one side.

The RTL track builds a counter-based debouncer for a single contact in lesson R2.5.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: start q=x qn=x s=1 r=0 set q=1 qn=0 (q changed 1 times) s=0 r=0 hold q=1 qn=0 (q changed 0 times) s=0 r=1 reset q=0 qn=1 (q changed 1 times) s=0 r=0 hold q=0 qn=1 (q changed 0 times) s=1 r=1 both q=0 qn=0 (q changed 0 times) s=0 r=0 release q=1 qn=1 (q changed 19 times)
Read included file: tb.sv
// tb.sv: each input pair is held for 20 ns; the bench counts the changes of q (read-only).
`timescale 1ns/1ns
module tb;
  logic s = 0, r = 0;
  wire  q, qn;
  int   toggles;
  sr_nor dut (.s(s), .r(r), .q(q), .qn(qn));
  always @(q) toggles++;
  task automatic apply(input logic s_in, r_in, input string what);
    s = s_in; r = r_in; toggles = 0;
    #20 $display("s=%b r=%b  %-10s q=%b qn=%b  (q changed %0d times)", s, r, what, q, qn, toggles);
  endtask
  initial begin
    $display("start         q=%b qn=%b", q, qn);
    apply(1, 0, "set");
    apply(0, 0, "hold");
    apply(0, 1, "reset");
    apply(0, 0, "hold");
    apply(1, 1, "both");
    apply(0, 0, "release");
    $finish;
  end
endmodule

Check Yourself

ConceptA NOR SR latch holds q = 1. Then S = 0 and R = 1 for a while, and then R goes back to 0. What is q?
ConceptWhich input pair is forbidden for the NAND latch with inputs S' and R'?
Read the waveformThe trace shows the contact line b_n of a switch being pressed, and the latch output clean. How many times does a counter clocked by clean count?
One press with bounces
01234567b_na_nclean
Scroll horizontally ↔

Contact A stays open (a_n = 1) for the whole trace.

ConceptAt the middle crossing of the two-inverter loop, the measured loop gain is about 163. What does that mean?
Predict the outputIn the lab latch, g1 now has #2 and g2 keeps #1. Both inputs are 1, then both fall at the same time. Predict the exact line.
`timescale 1ns/1ns
module tb;
  logic s = 1, r = 1;
  wire  q, qn;
  int   toggles = 0;
  nor #2 g1 (q,  r, qn);
  nor #1 g2 (qn, s, q);
  always @(q) if ($time > 5) toggles++;
  initial begin
    #10 s = 0; r = 0;
    #20 $display("q=%b qn=%b after %0d change(s) of q", q, qn, toggles);
  end
endmodule

Common Mistakes

Wrong Think S = R = 1 damages the latch.

While both are 1 the NOR latch is steady, with both outputs at 0. The trouble is the release: both gates then race.

Fix Never release both inputs together. Better, never assert both.

Wrong Use the active-high table for the NAND latch.

The NAND latch acts on 0s. A 1 on both of its inputs is hold, and 0 on both is the forbidden pair.

Fix Name its inputs s_n and r_n, and read 0 as "asserted".

Wrong Expect the release oscillation of the simulator in silicon.

Two real gates are never exactly equal, so the loop settles to one side after a while. Which side, and when, is unknown.

Fix Treat a released S = R = 1 as an unknown state, the same risk as metastability (G5.11).

Wrong Debounce a two-contact switch with a plain inverter or buffer.

A gate has no memory, so every bounce of the contact reaches the output.

Fix Use an S'R' latch: the first touch sets it, and the bounces only bring both inputs back to "hold".

Remember

  • Two inverters in a loop have two stable states and one metastable balance point (0.837 V for the SKY130 pair here).
  • The NOR SR latch sets on S = 1, resets on R = 1 and holds on 0, 0. The NAND latch does the same on 0s.
  • Holding both inputs active is steady but not a stored bit; releasing them together is a race with an unknown outcome.
  • An S'R' latch on a two-contact switch removes the bounces: the first touch sets it, the bounces are hold.

Practice

Report a problem with this page