From Feedback to Control

In our previous lesson, we learned that connecting an output back to an input creates a feedback loop. This loop allows a circuit to "remember" a state. However, a simple loop isn't very useful if we can't change the value it is holding. To build a real computer, we need a way to "write" a new value into memory and "erase" it when we are done.

The SR Latch is one of the most basic types of digital memory. The S stands for Set (making the value 1), and the R stands for Reset (making the value 0). By using two logic gates together, we can create a circuit that stays in a specific state until we tell it to change.

Brief Recall: The NOR Gate

Before we look at the whole circuit, let's quickly remember how a NOR gate works. A NOR gate is essentially an OR gate with an inverter at the end.

The rule for a NOR gate is simple: it outputs a 1 only if both inputs are 0. If even one input is a 1, the output immediately becomes 0.

Input AInput BOutput
001
010
1
The Cross-Coupled Design

To make an SR Latch, we connect two NOR gates in a cross-coupled pattern. This means the output of the top gate is wired to one of the inputs of the bottom gate. Similarly, the output of the bottom gate is wired back to one of the inputs of the top gate.

This creates a criss-cross shape in the middle of the circuit. In a standard setup:

  • The top gate provides the main output, which we call Q.
  • The bottom gate provides the opposite output, called Not-Q.
  • In a healthy circuit, these two outputs should always be opposites. If is , should be .
Set and Reset Actions

The "magic" happens when we use the two remaining inputs to control the circuit. Let's look at how we change the stored bit.

The Reset Action (R=1, S=0) When you turn the Reset input to 1, the top NOR gate sees a 1. Because of how NOR gates work, any 1 input forces the output to 0. Therefore, Q becomes 0. This 0 travels down to the bottom gate. Since the Set input is 0 and the feedback from Q is now 0, the bottom sees two s and outputs a . So, becomes .

The Hold State

The most important feature of the SR Latch is the Hold State. This happens when both the Set and Reset inputs are 0.

Imagine you just used the Set input to make Q=1Q = 1. If you now turn the Set input back to 0, what happens?

  1. The bottom gate still receives a 1 from the top gate (Q).
  2. Because it sees a 1, the bottom gate keeps outputting a 0.
The Forbidden State and Race Conditions

There is one combination of inputs that we must avoid: turning both Set and Reset to 1 at the same time (S=1,R=1S=1, R=1).

In this state, both NOR gates see a 1. This forces both Q and Not-Q to become 0. This is called an Invalid State because Q and are supposed to be opposites.

Summary and Practice

You have now learned how to build a basic memory cell using two NOR gates. Here is a summary of the SR Latch behavior:

S (Set)R (Reset)Q (Output)State Description
00No ChangeHold: Remembers the last value.
101Set: Stores a 1.
010Reset: Stores a 0.
110
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal