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.
- Cycle 0
With s = r = 1 both NOR gates give 0:
q=qn= 0. - Cycle 2
Both inputs fall at t = 25. Each gate now sees 0 and 0, so both outputs rise.
- Cycle 3
Now each gate sees a 1 from the other, so both fall again.
- 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.
- v(back)
- v(x)
- 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.
- 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.
- 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 V | 260.6 nV | 0 V |
| 200 mV | 260.6 nV | 200 mV |
| 400 mV | 260.8 nV | 400 mV |
| 600 mV | 286.2 nV | 600 mV |
| 800 mV | 557.6 µV | 800 mV |
| 837 mV | 844.8 mV | 837 mV |
| 1 V | 1.8 V | 1 V |
| 1.2 V | 1.8 V | 1.2 V |
| 1.4 V | 1.8 V | 1.4 V |
| 1.6 V | 1.8 V | 1.6 V |
| 1.8 V | 1.8 V | 1.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.
| S | R | Q next | Name |
|---|---|---|---|
| 0 | 0 | Q | hold |
| 1 | 0 | 1 | set |
| 0 | 1 | 0 | reset |
| 1 | 1 | 0 (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.
- Device
- Storage
- Structure
- Reset
- Control
- First touch
The blade reaches B:
b_n= 0 sets the latch, andcleanrises. - Bounce
The blade lifts off B but never reaches A. Both lines are 1: hold.
- 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
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.
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.
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.
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
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.