Custom

# What are Latches and Flip Flops and How do They Work?

March 16, 2019 by Daniel Hertz
Share

Learn how the basic types of latches and flip flops operate and how you can use them in your circuit.

A latch is a circuit that has two stable states which can be used to store one binary digit. Flip-flops and latches are fundamental building blocks used in many sequential circuits and larger storage devices, like shift registers. In this article, youâ€™ll learn how the basic types of latches and flip flops operate and how you can use them in your circuits.

### S/R Latches

Latches, sometimes referred to as S/R latches, are the smallest block of memory. They can be built using two NOR logic gates (S and R are active high) or two NAND gates (the inputs are active low) and theyâ€™re used to build the more complex latches and flip flops.

S/R Latch using two NOR logic gates.

The two inputs, S and R, can be used to set and reset the latch. Setting the latch is equivalent to storing a binary one. The output Q will become high and the inverted output Q will be pulled low. Resetting has the opposite effect. When both inputs are low, the current state is retained.

The simplicity of this circuit comes at a price: a few things can happen that will either cause indeterministic behavior (the next state of the circuit will be undefined) or a so-called critical race, where the latch will keep setting and resetting itself forever.

Adding two AND gates will convert the simple latch to a gated latch with an additional enable input. This method can be used to control when the data is latched. Without it, the data will (in theory) be present at the outputs as soon the latch is set or reset.

Adding two AND gates to a simple latch to make a gated latch.

### The D-Latch

This type of latch uses the R/S latch and adds an inverter to the circuit. Doing so prevents the critical race described above, making the latch easier to use.

D-Latch Circuit using two NOR gates and one NOT gate.

As you can see, this latch only has one input. The data, present at D, will be latched and stored. Note that the image above represents the core of the latch. This design will be useless in a real application because the output will change as soon as the input changes.

In reality, latches have inputs that enable them and the data will only be latched when they are enabled. I omitted the enable input for the sake of simplicity.

### The D Flip-Flop and the S/R Flip-Flop

While latches are enabled, they are transparent. This means that the output will have the same state as the input. However, there are situations when itâ€™s more useful to have the output change only at a rising or falling edge of a signal. For example, with a periodic clock signal.

Flips-flops achieve this output change by using two latches in series. The first stage is commonly referred to as the master (latch), the second one is the slave:

This is a positive logic, positive edge triggered D flip-flop.

S/R flip-flops can be constructed by replacing the D Latches with S/R latches. However, such a flip-flop, just like the latch from above, might enter an undefined state when both inputs are asserted. One way to solve this is to use a JK flip-flop.

### The JK Flip-Flop

The functionality of of the JK flip-flop is very similar to the one of a S/R flip-flop. It has a J input, which acts like the S input and a K input that resets the circuit. However, when both are asserted (high in positive logic, low in negative) at the same time, instead of entering an undefined state, the flip-flop toggles its state.

### Reviewing Latches and Flip-Flops

Latches are the smallest building blocks of memory. They are used in other circuits, like flip-flops and shift registers and theyâ€™ll apply the input(s) to their output as long as they are enabled. Flip-flops are edge-triggered and will only change their state when they are enabled and triggered. There are a few basic types of latches and flip-flops and each of them is useful in certain applications.