The SR Latch
Two circuits
CE2705 Digital Logic Design Lab · Arduino
A motor started by a momentary push button does not keep running because the button is held down. The
button closes for an instant, and the motor runs on until a separate stop button is pressed. The circuit that
holds the machine in one state between those two presses is a latch.
Every circuit built earlier in this course is combinational: its outputs depend only on the inputs present at that
instant. A latch is the first circuit whose output also depends on what happened before. Two versions are
built below, both as Arduino code.
1
Inputs and outputs
SW1 → pin 2
SW2 → pin 3
SW3 → pin 4
pin 8 → LED1
pin 9 → LED2
S
R
EN
Q
Q
Set
Reset
gated latch only
the stored value
the opposite of Q
A closed switch is 1 and an open switch is 0. A lit LED indicates an output of 1. The SR latch uses SW1 and SW2; the gated latch
adds SW3.
2
The SR latch
The latch is built from two NOR gates. Each gate takes one switch and the output of the other gate. This
second connection, the feedback path, is what separates the latch from every circuit built earlier.
R
Reset
NOR
Q
LED1 · pin 8
each output feeds the other gate
S
Set
NOR
Q
LED2 · pin 9
In the sketch the two outputs are held in variables. A variable keeps its value from one pass of loop() to the
next, in the same way that a wire holds its voltage. That stored value is the memory of the circuit.
3
Operation of the SR latch
The table below is the specification the code must satisfy. Two of the rows behave as an ordinary gate circuit
would. The remaining two do not.
S
R
Q
Q
Operation
0
0
Q0
Q0
Hold, the outputs keep the values they already had
0
1
0
1
Reset
1
0
1
0
Set
1
1
0
0
Not allowed, Q and Q are no longer opposites
Q0 denotes the value the output held before these inputs were applied.
4
Implementation
Each output must be written as a single NOR expression using only !, || and &&. The if statement is not
permitted. The circuit contains two gates, so the logic occupies two lines.
The complete sketch is required, including the pin definitions, setup() and loop(). The two variables
holding Q and Q must retain their values between successive passes of loop().
5
Test sequence
The steps are carried out in order, with none omitted. Each result depends on the steps before it, so the
sequence is valid only when followed from the top.
S
R
SW1
SW2
1
0
1
2
0
0
3
1
0
4
0
0
5
0
1
6
0
0
7
1
1
8
0
0
Step
LED1 (Q)
LED2 (Q)
Steps 2 and 4 apply the same switch positions, S = 0 and R = 0, and produce different outputs. The state
of the latch depends on the order in which its inputs were applied, and not on their present values
alone.
6
The gated SR latch
The gated latch is the same circuit with one further input. EN passes through an AND gate on each of S and
R, so an input reaches the latch only while EN is 1. Everything to the right of the two AND gates is the latch
above, unchanged.
R
Reset
AND
NOR
Q
LED1 · pin 8
EN
Enable
NOR
S
Set
AND
Q
LED2 · pin 9
7
Operation of the gated latch
Only the first row differs from the table above. While EN is 1 the gated latch behaves as the plain latch does.
EN
S
R
Q
Q
Operation
0
×
×
Q0
Q0
Hold, the switches have no effect
1
0
0
Q0
Q0
Hold
1
0
1
0
1
Reset
1
1
0
1
0
Set
1
1
1
0
0
Not allowed
× denotes an input whose value does not matter.
8
Implementation and test
The complete sketch is written again, modified so that S and R reach the latch only while EN is 1. The same
constraint applies: gate expressions only, no if. The two NOR lines themselves require no change.
EN
S
R
SW3
SW1
SW2
1
1
0
1
2
0
1
0
3
1
1
0
4
0
0
1
5
1
0
0
6
1
0
1
Step
LED1 (Q)
LED2 (Q)
In steps 2 and 4 the Set and Reset switches are moved to positions that changed the outputs in the
plain latch, and the outputs do not respond. The gated latch accepts new inputs only while EN is 1. An
input that determines when a circuit may change state is the basis of the clock.
Name: ______________________________ Student ID: ______________ Date: __________ Section: ______ Score: ______
The SR Latch · CE2705 Digital Logic Design Lab · Arduino