Latches and Flip-Flops: 7.1 Bistable Element
Latches and Flip-Flops: 7.1 Bistable Element
Latches and Flip-Flops: 7.1 Bistable Element
stable
0
Q' 0 V in1 = V o u t 25
metastable
stable stable
7.2 SR Latch
The bistable element is able to remember or store one bit of information. However, because it does not have any
inputs, we cannot change the information bit that is stored in it. In order to change the information bit, we need to
add inputs to the circuit. The simplest way to add inputs is to replace the two inverters with two NAND gates as
shown in Figure 4(a). This circuit is called a SR latch. In addition to the two outputs Q and Q', there are two inputs S'
and R' for set and reset respectively. Following the convention, the prime in S and R denotes that these inputs are
active low. The SR latch can be in one of two states: a set state when Q = 1, or a reset state when Q = 0.
To make the SR latch go to the set state, we simply assert the S' input by setting it to 0. Remember that 0 NAND
anything gives a 1, hence Q = 1 and the latch is set. If R' is not asserted (R' = 1), then the output of the bottom NAND
gate will give a 0, and so Q' = 0. This situation is shown in Figure 4 (d) at time t0. If we de-assert S' so that S' = R' =
1, the latch will remain at the set state because Q', the second input to the top NAND gate, is 0 which will keep Q = 1
as shown at time t1. At time t2 we reset the latch by making R' = 0. Now, Q' goes to 1 and this will force Q to go to a
0. If we de-assert R' so that again we have S' = R' = 1, this time the latch will remain at the reset state as shown at
time t3. Notice the two times (at t1 and t3) when both S' and R' are de-asserted. At t1, Q is at a 1, whereas, at t3, Q is at
S'
Q
S R Q Qnext Qnext'
0 0 × 1 1
0 1 × 1 0
1 0 × 0 1
1 1 0 0 1
Q'
R' 1 1 1 1 0
(a) (b)
S'
R'
S' Q
Q Undefined
R' Q' Q' Undefined
t0 t1 t2 t3 t4 t5 t6
(c)
(d)
Figure 4. SR latch: (a) circuit using NAND gates; (b) truth table; (c) logic symbol; (d) timing diagram.
Chapter 7 – Latches and Flip-Flops Page 8 of 18
D D Q Qa
Clk E Q'
D Q Qb
Clk
Clk Q '
D
Qa
D Q Qc
Qb
Clk Q ' Qc
(a) (b)
Figure 12. Comparison of a gated latch, a positive-edge-triggered flip-flop, and a negative-edge-triggered flip-
flop: (a) circuit; (b) timing diagram.
Figure 12 compares the different operations between a latch and a flip-flop. In (a), we have a gated D latch, a
positive-edge-triggered D flip-flop and a negative-edge-triggered D flip-flop, all having the same D input and
controlled by the same clock signal. (b) shows a sample trace of the circuit’s operations. Notice that the gated D
latch Qa follows the D input as long as the clock is high. The positive-edge-triggered flip-flop Qb responds to the D
input only at the rising edge of the clock while the negative-edge-triggered flip-flop Qc responds to the D input only
at the falling edge of the clock.
D
EN Clk EN D Q Qnext Qnext'
D Q Q D Q
0 × × 0 0 1
0 × × 1 1 0 Clk
Clk Clk Q ' Q'
1 × × 0 0 1 EN Q'
1 × × 1 1 0
0 × 0 0 1
0 × 1 1 0
1 0 × 0 1 (c)
(a) 1 1 × 1 0
(b)
Figure 13. D flip-flop with enable: (a) circuit; (b) truth table; (c) logic symbol.
Chapter 7 – Latches and Flip-Flops Page 9 of 18
Preset'
S
D
Q
Preset'
E D Q
Q' E Q'
R Clear'
Clear'
(a) (b)
Preset'
Clk
Q' Preset'
D Q
D Clk Q '
Clear'
Clear'
(c) (d)
Figure 14. Storage elements with asynchronous inputs: (a) D latch with preset and clear; (b) logic symbol for (a);
(c) D edge-triggered flip-flop with preset and clear; (d) logic symbol for (c).
Another way to describe a flip-flop is to use the WAIT statement instead of the IF statement as shown in Figure
26. When execution reaches the WAIT statement, it stops until the condition in the statement is true before
proceeding. Note also that the process sensitivity list is omitted because the WAIT statement implies that the
sensitivity list contains only the clock signal.
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY D_flipflop IS
PORT(D, Clock : IN STD_LOGIC;
Q : OUT STD_LOGIC);
END D_flipflop;
Alternatively, we can write a structural VHDL description for the positive-edge-triggered D flip-flop as shown
in Figure 27. This VHDL code is based on the circuit for a positive-edge-triggered D flip-flop as given in Figure 11.
ENTITY NAND2 IS
PORT(I0, I1 : IN STD_LOGIC;
O : OUT STD_LOGIC);
END NAND2;
ENTITY NAND3 IS
PORT(I0, I1, I2 : IN STD_LOGIC;
O : OUT STD_LOGIC);
END NAND3;
ENTITY SRlatch IS
PORT(SN, RN : IN STD_LOGIC;
Q, QN : OUT STD_LOGIC);
END SRlatch;
ENTITY positive_edge_triggered_D_flipflop IS
PORT(D, Clock : IN STD_LOGIC;
Q, QN : OUT STD_LOGIC);
END positive_edge_triggered_D_flipflop;
BEGIN
U1: SRlatch PORT MAP (N4, Clock, N1, N2); -- set latch
U2: SRlatch PORT MAP (N2, N3, Q, QN); -- output latch
U3: NAND3 PORT MAP (N2, Clock, N4, N3); -- reset latch
U4: NAND2 PORT MAP (N3, D, N4);
END Structural;
Figure 27 (continue). Structural VHDL code for a positive-edge-triggered D flip-flop.
Chapter 7 – Latches and Flip-Flops Page 18 of 18
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY D_flipflop IS
PORT(D, Clock, Reset, Clear : IN STD_LOGIC;
Q : OUT STD_LOGIC);
END D_flipflop;