Professional Documents
Culture Documents
8 - Latches and Flip-Flops
8 - Latches and Flip-Flops
Outline
Storage Elements
Flip-Flops
Gated SR Latch
Gated D Latch
Edge-Triggered D Flip-Flop
In combinational circuits, the value of each When the inputs change values, the new
output depends solely on the present inputs either leave the circuit in the same
values of signals applied to the inputs state or cause the circuit to change to a
In sequential circuits, the values of outputs new state
depend not only on the present values of Over time, a circuit with storage elements
the inputs but also on the past behavior moves through a sequence of states in
of the circuit (past inputs and outputs) response to the changes in the inputs:
Sequential circuits include storage sequential circuits (state machines)
elements that store the values of logic
signals: the contents of storage elements
represent the state of the circuit
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Simple Memory Element
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Outline
Storage Elements Consists of a loop with two inverters (cross-coupled
inverter pair)
Basic Latch Circuit will maintain its state as long as the power
supply is applied
Gated SR Latch The circuit has two states (AB = 0b01 or AB = 0b10)
The simple memory element does not provide the
Gated D Latch means to control these two states: circuit needs to
be expanded to provide the capability to change
Edge-Triggered D Flip-Flop state
A B
T Flip-Flop
JK Flip-Flop
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
A memory element built with two NOR gates: inputs When Set and Reset are both 0, the latch
Set and Reset provide the means to change state maintains its state
Reset Reset
0
Set Qa Set Qa
0
Qb QQab’
R S R Qa Qb R S R Qa Qb
Qa Qa
When Set = 0 and Reset = 1, the latch is reset (Qa When Set = 1 and Reset = 0, the latch is set (Qa =
= 0) 1)
Reset Reset
1 0
0 1
Set Qa Set Qa
0 1
Qb Q=b 1 Qb Q=b 0
R S R Qa Qb R S R Qa Qb
Qa Qa
Basic Latch
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Basic Latch Oscillation and Uncertainty
After Set and Reset are both 1 and both outputs are
When Set and Reset are both 1, both outputs are
zero: Qa = Qb = 0, what if both Set and Reset
zero: Qa = Qb = 0
transition to 0 at the same time?
Reset
1 Reset 0→1→0
1→0
0 →1…
Set Qa Set Qa
1 1→0
Qb Q=b 0 Qbb
Q Qa and
Qb
0→1→0→1… oscillate
S R Qa Qb
R
Qa R
S R Qa Qb between
Qa
0 0 0/1 1/0 Q a = Qb
Both 0 0 0/1 1/0
0 1 0 1 = 1 and
0 1 0 1
Qb 1 0 1 0 outputs Q a = Qb
S Qb 1 0 1 0
A more common way to draw the basic latch 1 1 0 0 are 0 S =0
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design 1 1 0 0 VOLKAN KURSUN
Basic Latch Timing Diagram
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Basic Latch Oscillation and Uncertainty
Qa and Qb oscillate between Qa = Qb = 1 and Qa = Qb = R S R Qa Qb
Qa
0 0 0 0/1 1/0 (no change)
0 1 0 1 Qa and Qb
If the delays through the two NOR gates are identical, 1 0 1 0 oscillate between
the oscillation will continue indefinitely Qb 1 1 0 0
Qa = Qb = 1 and
S Q a = Qb = 0
In a real circuit, the delays of the two NOR gates will be t1 t2 t3 t4 t5 t6 t7 t8 t9 t 10
different and the latch will eventually settle down to one 1
of its two stable states: however, the final state would R
0
be unknown (uncertain)
Reset 0→1→0 1
1→0
S
0
→1… 1
Set Qa Qa ?
1→0 0
Qbb
Q Qb
1
?
0→1→0→1… 0
Time
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Gated SR Latch
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Outline
Storage Elements In the basic SR latch, the state changes occur
anytime that the set and reset inputs change
Basic Latch Add an enable signal that would allow controlling
when the latch would respond to the changes in its
Gated SR Latch set and reset inputs: when disabled, the changes in
the set and reset signals would be ignored by the
Gated D Latch latch and the existing state would be maintained
Rint
Edge-Triggered D Flip-Flop
T Flip-Flop
JK Flip-Flop Sint
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Gated SR Latch Gated SR Latch: Level-Sensitive
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
When clk = 0, the latch is disabled: the changes in When clk = 1, the latch is enabled: Rint = R and Sint =
the set and reset signals would be ignored by the S and the latch behaves like the basic SR latch
latch and the existing state would be maintained If S = R = 0, the latch maintains its state
Rint 0 0
Rint 0
(no
change (no
0 of 1
change
state) of
state)
Sint 0 0 Sint 0
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
When clk = 1, the latch is enabled: Rint = R and Sint = When clk = 1, the latch is enabled: Rint = R and Sint =
S and the latch behaves like the basic SR latch S and the latch behaves like the basic SR latch
If S = 0 and R = 1, the latch is reset If S = 1 and R = 0, the latch is set
1
Rint 1 0
Rint 0
0 1
1 1
reset
1 0 set
0 Sint 0 1 Sint 1
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Gated SR Latch: Level-Sensitive
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
SR Latch Oscillation and Uncertainty
When clk = 1, the latch is enabled: Rint = R and Sint = If S = R = 1, Q = Q’ = 0. If S and R transition from 1 to 0
at the same time, Q and Q’ oscillate between Q = Q’ = 0
S and the latch behaves like the basic SR latch
and Q = Q’ = 1
If S = 1 and R = 1, both outputs are 0 1→0
Rint 0→1→0
1
Rint 1 →1…
0 1→0
1 1
Undefined Undefined
if both R if both R
and S and S
0 transition to transition to
1→0 0→1→0
1 Sint 1
0 afterwards 1→0
Sint →1…
0 afterwards
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Clk
Q
R
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Gated D Latch
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Outline
Storage Elements Stores the value of single data input (bit storage)
Data is stored under the control of a clock signal:
Since S = D and R = D’, the troublesome situation where As long as Clk = 1, the Q output follows the D input
S = R = 1 cannot occur in a D latch: no output When Clk = 0, the Q output cannot change: maintains
uncertainty in a D latch state
The output Q tracks the input D as long as Clk = 1 (latch
is transparent when Clk = 1): level-sensitive behavior
D latch stores the value of D shortly before the Clk
transitions from 1 to 0
When Clk = 0, the latch is opaque and maintains state
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Positive latch
CLK
t
tsetup thold D Q
D DATA CLK
STABLE t
td to q
Q OUTPUT
STABLE t
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Gated D Latch VHDL
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Consists of two gated (level sensitive) D When Clock = 1: the master stage tracks the value of
latches: master and slave the D input while the slave stage does not change
When Clock transitions from 1 to 0: master stage stops
Master stage: changes its state while Clock = 1
following the changes in the D input while the slave
Slave stage: changes it state while Clock = 0 stage stores the value of the signal Qm
M S Since Qm does not change while Clock = 0, the slave
Qm stage can undergo only one change of state (output
D D Q D Q Q switching) during a clock cycle: the slave stage changes
state only at the negative edge of the clock signal
Clock Clk Q Clk Q Q Regardless of the number of changes in the D input to
the master stage during one clock cycle, there may be
only one change at the Q output that corresponds to
the D input stored at the negative edge of the clock
signal: negative edge triggered
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Master-Slave D Flip-Flop
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Q Qb
D
Qb
Qm D Q Qc
Negative edge-
triggered D flip-
flop
Q Qc Q Qc
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
D Flip-Flop Timing
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Clock
P2 6 Q
3
D Q
4 P4 Clock
Q
D
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
change (Data is
1 P1
of state) 1→D’
P1
stored)
2 2
5 Q 5 Q
0→1 D
Clock
0 Clock
P2 6 Q P2 6 D’ Q
3 3
1 1→D
4 P4 4 P4
D
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
D
EEE 102 Introduction to Digital Circuit Design D’ VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
clock edge
arrives
stored) stored)
2
1→D’
P1
5
D Q
2
1→D’
P1
5
D Q
0→1
Clock
0→1
Clock
3
P2 6
D’ Q
3
P2 6
D’ Q
0→1
Clock
0→1
Clock
3
P2 6
1 Q
3
P2 6
0 Q
0→1 4 P4
is transferred onto P2. Once D
is transferred onto P2, changes 1→0 4 P4
is transferred onto P2. Once D
is transferred onto P2, changes
D
EEE 102 Introduction to Digital Circuit Design 1 in D do not matter. VOLKAN KURSUN D
EEE 102 Introduction to Digital Circuit Design 0→1 in D do not matter. VOLKAN KURSUN
Edge-Triggered D VHDL Edge-Triggered D VHDL Code -2
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
D Flip-Flop with Clear and Preset D Flip-Flop with Clear and Preset
Typically, it is necessary to be able to initialize sequential Preset_n = 0, Clear_n = 1: Preset the Q output to 1
circuits to a specific state Preset_n Clear_n Q Q’ Asynchronous preset: Preset_n signal is used to preset the
0 1 1 0 flip-flop regardless of the clock signal
Clear = 0: Clear the Q output to 0
Preset = 0: Set the Q output to 1
1
1
0
1
0
Normal op.
1
0
Example: master-slave flip-flop based on NAND gates
with active-low asynchronous clear and preset 1 1
0
1 0 1 0
1
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
D Flip-Flop with Clear and Preset D Flip-Flop with Clear and Preset
Preset_n = 0, Clear_n = 1: Preset the Q output to 1 Clear_n = 0, Preset_n = 1: Clear the Q output to 0
Asynchronous preset: Preset_n signal is used to preset the Asynchronous clear: Clear_n signal is used to clear the flip-
flip-flop regardless of the clock signal flop regardless of the clock signal
0 1
1 1 1 0 1 0
1 0
0 1 0 1
D
D’ 1
0
1 0 0
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
D Flip-Flop with Clear and Preset D Flip-Flop with Clear and Preset
Clear_n = 0, Preset_n = 1: Clear the Q output to 0 Clear_n = 1, Preset_n = 1: clear and preset signals have no
Asynchronous clear: Clear_n signal is used to clear the flip- effect on the circuit operation, normal negative edge-
flop regardless of the clock signal triggered master-slave flip-flop operation
1 1
D 1 1 1
D’ 0
1 0
1 1
D’ 0 1
0 0 1 1
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Alternative D Flip-Flop with Clear and Preset Alternative D Flip-Flop with Clear and Preset
Preset_n = 0, Clear_n = 1: Preset the Q output to 1 Preset_n = 0, Clear_n = 1: Preset the Q output to 1
Asynchronous preset: Preset_n signal is used to preset the Asynchronous preset: Preset_n signal is used to preset the
flip-flop regardless of the clock signal flip-flop regardless of the clock signal
0 0
1 1
0 1 1 0 0 1
0 1
1 0 1
0 0
1 1
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Alternative D Flip-Flop with Clear and Preset Alternative D Flip-Flop with Clear and Preset
Clear_n = 0, Preset_n = 1: Clear the Q output to 0 Clear_n = 0, Preset_n = 1: Clear the Q output to 0
Asynchronous clear: Clear_n signal is used to clear the flip- Asynchronous clear: Clear_n signal is used to clear the flip-
flop regardless of the clock signal flop regardless of the clock signal
1 1
1 1 0 1 1 0
0 0 1 0
1 1
0 0 0 0
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
1 D’
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
1
D
Clear_n Clear_n
1
Clock
1
Clock
Preset_n’ Q Preset_n’ Q
0 0
When Clear_n = 0, Preset_n = 0, the flip-flop operates When Clear_n = 1, Preset_n = 0, the flip-flop is set with
normally the positive edge of the clock (synchronous preset)
Clear_n’
1 1 0 1
Preset_n D’ Clear_n’
D’
0 D D Preset_n
0 D 1
0
D Q Q
1
D
Clear_n Clear_n
1
Clock
0
Clock
Preset_n’ Q
Preset_n’ Q
EEE 102 Introduction to Digital Circuit Design 1 VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design 1 VOLKAN KURSUN
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
ENTITY flipflop IS
PORT ( D, Resetn, Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC) ;
END flipflop ;
Whenever the process is
ARCHITECTURE Behavior OF flipflop IS
triggered, check Resetn
BEGIN
PROCESS ( Resetn, Clock ) first (without checking the
BEGIN clock signal):
IF Resetn = '0' THEN asynchronous reset
Q <= '0' ;
ELSIF Clock'EVENT AND Clock = '1' THEN
Q <= D ;
END IF ;
END PROCESS ;
END Behavior ;
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
ENTITY flipflop IS
PORT ( D, Resetn, Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC) ;
END flipflop ;
If T = 0, D = Q and the flip-flop will maintain its state If t = 1, D = Q’ and the flip-flop will toggle state
Clock Clock
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
Toggle (T) Flip-Flop Timing
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Outline
T Q t + 1 Storage Elements
D=T 0 Q t Basic Latch
D Q Q 1 Q t
T
Q Q T Q
Gated SR Latch
Clock Q Gated D Latch
1 2 3 4
Clock Edge-Triggered D Flip-Flop
T T Flip-Flop
Q
JK Flip-Flop
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
JK Flip-Flop JK Flip-Flop
VOLKAN KURSUN Bilkent University VOLKAN KURSUN Bilkent University
Behaves as an SR flip-flop where J = S and K = R for all When J = K = 0, JK flip-flop maintains state
input values except J = K = 1
When J = K = 1, JK flip-flop toggles like a T flip-flop
0 0
J
Q(t) D Q
J Q
D Q Q
K 0 1
K Q Q
Q(t) Q Q
When JK = 0b01, JK flip-flop clears the output When JK = 0b10, JK flip-flop sets the output
0 0 1 Q(t)’
J J
0 D Q 0 Q
1 D Q Q(t)→1
Q
K 1 0 K 0 1
0 Q Q Q(t) Q Q
1 Q(t)’ Q(t)→
Describes the
combinational
J circuit that
Q(t)’ D Q
Q(t)’ produces the
D input of the
Q D flip-flop
K 1 0 Q
0 Q
Clock
J K Q t + 1 J K Q t + 1
J Q J Q
0 0 Q t 0 0 Q t
0 1 0 0 1 0
1 0 1 1 0 1
1 1 Q t
K Q 1 1 Q t
K Q
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN
JK Flip-Flop
VOLKAN KURSUN Bilkent University
J
D Q Q
K Q Q
Clock
J K Q t + 1
J Q
0 0 Q t
0 1 0
1 0 1
1 1 Q t
K Q
EEE 102 Introduction to Digital Circuit Design VOLKAN KURSUN