The SR latch

The SR latch is a sequential circuit that is used in digital logic and electronics. The SR latch has two stable states and can store a single bit of information; the two stable states are known as set and reset, hence the name SR. The latch also provides two outputs, namely Q and Q-bar (the inverse of Q).

The circuit diagram

Below, we can see the circuit diagram for the SR latch.

SR latch circuit diagram
SR latch circuit diagram

As we see in the diagram, the SR latch comprises two cross-coupled NAND gates, where the output of one gate is connected to the input of the other and vice versa. The latch takes two binary inputs, S and R, and produces two binary outputs, Q and Q-bar.

Formation of the truth table

Now that we have looked at the circuit diagram for the SR latch, we will not look at how the truth table is formed by looking at the different input values of S and R.

Case 1: When S = 1 and R = 0 (SET)

The set state
The set state

The NAND gates provide an output of 1 whenever there is an 0 in the input to the logic gate. In the case of S = 1 and R = 0, the logic gate connected to the reset input receives a 1, so it will output a 0. That 0 will then propagate to the NAND gate connected to the set input, providing an output of 0 as 1 NAND with 1 is 0.

So the Q values will be 1, and the value of Q-bar will be 0 showing that we set the value of the output Q as 1.

Case 2: When S = 0 and R = 1 (RESET)

The reset state
The reset state

This is the reverse of Case 1 we went through above; over here, we have reversed the inputs S and R to be 1 and 0; hence our output for Q would then be 0, and Q-bar would be 1 showing that we have reset the output bit Q.

Case 3: When S = 0 and R = 0 (INVALID)

The invalid state
The invalid state

In this case, we see that one of the inputs to both NAND gates is 0; this means that the output of both gates will always be 1 regardless of the 2nd input to the NAND gates. Since the value of Q and Q-bar is the same, we call this SR latch state invalid.

Case 4: When S = 1 and R = 1 (HOLD)

The hold state
The hold state

This case is a bit tricky to solve as none of the inputs is 0, which means that the output depends on the 2nd input to the NAND gates. We will try to solve this using boolean algebra, as seen in the diagram. We see that there will be no change in already stored bits for Q and Q-bar upon solving the equation; hence we call this state the hold state since none of the values of the output change.

Truth table

Now that we have gone through all the different states of an SR latch, we can see the final truth table below that shows the values of Q and Q-bar against the input bits S and R.

Truth table for the SR latch
Truth table for the SR latch

Code implementation

Let's explore how the SR latch, a fundamental building block in electronics, can be coded in C++.

#include <iostream>
bool s = false;
bool r = false;
bool q = true;
bool qBar = false;
void evaluateOutputs(bool s, bool r) {
if (s && !r) { // When s=1 and r=0, executes this block
q = true;
qBar = false;
std::cout << "q=" << q << std::endl;
std::cout << "qbar=" << qBar << std::endl;
} else if (!s && r) { // When s=0 and r=1, executes this block
q = false;
qBar = true;
std::cout << "q=" << q << std::endl;
std::cout << "qbar=" << qBar << std::endl;
} else if (!s && !r) { // When s=0 and r=0, executes this block
q = true;
qBar = true;
std::cout << "q=" << q << std::endl;
std::cout << "qbar=" << qBar << std::endl;
} else if (s && r) { // When s=1 and r=1, executes this block
q = q;
qBar = qBar;
std::cout << "q=" << q << std::endl;
std::cout << "qbar=" << qBar << std::endl;
}
}
int main() {
// Set inputs
bool s_input = true; // You can change the S input here
bool r_input = false; // You can change the R input here
// Evaluate outputs
evaluateOutputs(s_input, r_input);
return 0;
}

Applications of an SR latch

Now that we have gone through what is an SR latch and its internal working, now let's look at some of the applications of an SR latch below.

  • Memory circuits: As the SR latch can store a single bit of data, it can be used to create large memory circuits for temporary memory storage.

  • Control signals: As the SR latches can hold states, they can be used in control signals to hold some bits till a certain condition is met.

  • Flip flops and counters: The SR latch is a basic building block for various types of flip flops and counter circuits.

  • Debouncing circuits: In circuits with various buttons and switches, we can use an SR latch to stabilize the signals and prevent false readings arising from mechanical bouncingWhen a mechanical switch is pressed they do not form a clear connection instead they make and break contacts numerous times resulting in mechanical bouncing..

Conclusion

The SR latch is a fundamental part of digital electronics. Its significance lies in its use as a foundational component for intricate flip-flops, registers, and sequential logic circuits. Thanks to its capacity to hold bits of data, it can be used as a cornerstone for memory components, control systems, synchronization circuits, and more.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved