DDCArv Ch3
DDCArv Ch3
DDCArv Ch3
Computer Architecture
Sarah Harris & David Harris
Chapter 3:
Sequential Logic
Design
Chapter 3 :: Topics
• State Elements
– Bistable Circuit
– SR Latch
– D Latch
– D Flip-Flop
– Variations
• Synchronous Sequential Logic
• Finite State Machines
– Moore
– Mealy
– Factored
• Timing of Sequential Logic
– Clock Skew
– Synchronization
• Parallelism
Digital Design & Computer Architecture Sequential Logic Design 2
Chapter 3: Sequential Logic
State Elements
Introduction
• Outputs of sequential logic depend on
current and prior input values – it has
memory.
• Some definitions:
– State: all the information about a circuit
necessary to explain its future behavior
– Latches and flip-flops: state elements that store
one bit of state
– Synchronous sequential circuits: Sequential
circuits using flip-flops sharing a common clock
Bistable Circuit
Bistable Circuit
• Fundamental building block of other state
elements
• Two outputs: Q, Q
• No inputs Same circuit!
I1 Q
Q Q
I2 I1
I2 Q
then Q = 1, Q = 0 (consistent)
0 1
I2 Q
– Q = 1: I1
1
Q
0
then Q = 0, Q = 1 (consistent)
1 0
I2 Q
SR Latch
SR (Set/Reset) Latch
• SR Latch R
N1 Q
N2 Q
S
– S = 0, R = 1: 1
R 0
then Q = 0 and Q = 1 1
N1 Q
then Q = Qprev R
0
N1
0
Q
R
0
N1
1
Q
1 0
Memory!
0 1
1 0
0 N2 Q N2 Q
S S 0
– S = 1, R = 1: R
1
N1
0
Q
0
then Q = 0, Q = 0
0
Invalid State S
1 N2
0
Q
Q ≠ NOT Q
Digital Design & Computer Architecture Sequential Logic Design 13
SR Latch
• SR stands for Set/Reset Latch
– Stores one bit of state (Q)
• Control what value is being stored with S, R inputs
– Set: Make the output 1
S = 1, R = 0, Q = 1 SR Latch
Symbol
– Reset: Make the output 0
S = 0, R = 1, Q = 0 R Q
– Memory: Retain value
S = 0, R = 0, Q = Qprev S Q
D Latch
D Latch
• Two inputs: CLK, D
– CLK: controls when the output changes
– D (the data input): controls what the output changes to
• Function
D Latch
– When CLK = 1,
Symbol
D passes through to Q (transparent) CLK
– When CLK = 0, D Q
Q holds its previous value (opaque) Q
• Avoids invalid case when
Q ≠ NOT Q
16
Digital Design & Computer Architecture Sequential Logic Design
D Latch Internal Circuit
CLK R CLK
D R Q Q
D Q
S S Q Q
D Q
CLK D D S R Q Q
0 X X 0 0 Qprev Qprev
1 0 1 0 1 0 1
1 1 0 1 0 1 0
D Flip-Flop
D Flip-Flop
• Inputs: CLK, D
D Flip-Flop
• Function: Symbols
• When CLK = 1 L1 Q L2 Q Q
– L2 is transparent
– L1 is opaque
– N1 passes through to Q
• Thus, on the edge of the clock (when CLK rises from 0 1)
– D passes through to Q
CLK
Q (latch)
Q (flop)
Variations on a Flop
Registers: One or More Flip-flops
CLK
Easier to draw!
D3 D Q Q3
CLK
D2 D Q Q2
4 4
D3:0 Q3:0
D1 D Q Q1
4-bit Register
D0 D Q Q0
Two ways to draw a register
4-bit Register 23
0
D Q Q D Q
D 1
EN
Symbols
D Q
r
Reset
D
D Q Q
Reset
Symbols
D Q
s
Set
Synchronous
Sequential Logic
Sequential Logic
• Sequential circuits: all circuits that aren’t
combinational
• A problematic circuit:
X
X Y Z Y
Z
0 1 2 3 4 5 6 7 8 time (ns)
FSMs:
Finite State Machines
Finite State Machine (FSM)
• Consists of:
– State register CLK
– Combinational logic
• Computes the next state
• Computes the outputs
Next State Output
Logic Logic
CL Next
State
CL Outputs
CLK
M next k
next
k N
inputs state
state state output
outputs
logic
logic
Mealy FSM
CLK
M next k
next
k state N
inputs state
state output
outputs
logic
logic
CLK
M next k
next
k N
inputs state
state state output
outputs
logic
logic
Mealy FSM
CLK
M next k
next
k state N
inputs state
state output
outputs
logic
logic
Bravado
Dining
Hall
LB
LA TB
LA
Academic TA TA Ave.
Labs TB LB Dorms
Blvd.
Fields
TA Traffic LA
Light
TB Controller LB
Reset
S0 T S1 A
S3 S2
LA: red LA: red
LB: yellow LB: green
TB
TB
S : Current State
LA: green LA: yellow
LB: red LB: red
State Encoding
S'1 = S1S0 + S1S0TB + S1S0TB = S1S0 + S1S0 = S1 ⊕ S0 S0 00
S'0 = S1S0TA + S1S0TB S1 01
S2 10
S3 11
Digital Design & Computer Architecture Sequential Logic Design 43
FSM Output Table
Current State Outputs
S1 S0 LA1 LA0 LB1 LB0
0 S0 0 0 green 0 1 red 0
0 S1 1 0 yellow 1 1 red 0
1 S2 0 1 red 0 0 green 0
1 S3 1 1 red 0 0 yellow 1
Reset
TA
Output Encoding
LA1 = S1S0 + S1S0 = S1
S0 TA S1
LA: green LA: yellow
green 00
LB: red LB: red
LA0 = S1S0
S3
LA: red
LB: yellow
LB1 = S1S0 + S1S0 = S1
S2
LA: red
LB: green
yellow 01
TB
LB0 = S1S0
TB
red 10
Digital Design & Computer Architecture Sequential Logic Design 44
FSM Schematic
Next State Current State
CLK LA1
S'1 S1
LA0
TA S'0 S0
LB1
r
TB Reset
S1 S0 LB0
CLK
Reset
TA
TB
0 5 10 15 20 25 30 35 40 45 t (sec)
TA
Reset
S0 TA S1
LA: green LA: yellow
LB: red LB: red
S3 S2
LA: red LA: red
LB: yellow LB: green
TB
TB
CLK
Reset
TA
TB
0 5 10 15 20 25 30 35 40 45 t (sec)
TA
Reset
S0 TA S1
LA: green LA: yellow
LB: red LB: red
S3 S2
LA: red LA: red
LB: yellow LB: green
TB
TB
S0 S1 S2
0 0 1
1 0 0
1
Mealy FSM
Reset
0/0
S0 S1
1/0 0/0
1/1
S0 S1 S2
0 0 1
1 0 0
1
Current Next
State Input State Output
State Encoding
S0 A S'0 Y
0 0 1 0 S0 0
0 1 0 0
S1 1
1 0 1 0
1 1 0 1
Mealy FSM S0’ = A
Reset
0/0
Y = S0 A
S0 S1
1/0 0/0
1/1
r
Reset
CLK
Output Equation
S'0 S0 Y
Y = S0A
r
Reset
CLK
Reset
A 0 1 0 1 1 0 1 1 1
Moore Machine
S ?? S0 S1 S2 S1 S2 S0 S1 S2 S0
Y
Mealy Machine
S ?? S0 S1 S0 S1 S0 S1 S0
S0 S1 S2 S0 S1
1
0
0
0
0
1
1/0 0/0 Moore FSM: asserts Y one cycle after
input pattern 01 is detected
1
1/1
Factored FSMs
Factoring FSMs
• Break complex FSMs into smaller interacting
FSMs
• Example: Modify traffic light controller to
have Parade Mode.
– Two more inputs: P, R
– When P = 1, enter Parade Mode & Bravado Blvd
light stays green
– When R = 1, leave Parade Mode
P
Factored FSM
Mode
R FSM
TA Lights LA
TB FSM LB
Controller
FSM
P
Reset
S3 S2 P
S0 S1
LA: red LA: red
M: 0 M: 1
LB: yellow LB: green R
MTB
M + TB R
Lights FSM Mode FSM
Timing
Timing
• Flip-flop samples D at clock edge
• D must be stable when sampled
• Similar to a photograph, D must be stable
around clock edge
CLK
D Q D
tsetup thold
ta
CLK
Q
D Q
tccq
tpcq
R1 R2
Tc
CLK
Q1
D2
R1 R2
Tc ≥ tpcq + tpd + tsetup
Tc tpd ≤ Tc – (tpcq + tsetup)
CLK
Q1
(tpcq + tsetup):
D2 sequencing overhead
tpcq tpd tsetup
D2
tccq tcd
thold
Flip-Flops
B
tpcq = 50 ps
tsetup = 60 ps
X' X
C thold = 70 ps
Y' Y
D
Logic delays:
per gate
tpd = 35 ps
tcd = 25 ps
tpd = 3 x 35 ps = 105 ps
tcd = 25 ps
Flip-Flops
B
tpcq = 50 ps
tsetup = 60 ps
X' X
C thold = 70 ps
Y' Y
D
Logic delays:
per gate
tpd = 35 ps
tcd = 25 ps
tpd = 3 x 35 ps = 105 ps
tcd = 2 x 25 ps = 50 ps
Clock Skew
Clock Skew
• The clock doesn’t arrive at all registers at same time
• Skew: difference between two clock edges
• Perform worst case analysis to guarantee dynamic
discipline is not violated for any register – many
registers in a system!
delay CLK
CLK1 CLK2
Q1 C D2
L
R1 R2
t skew
CLK1
CLK2
CLK
D2
R1 R2
CLK1
tskew thold
Synchronization
Violating the Dynamic Discipline
Asynchronous (for example, user) tsetup thold
CLK
button
D
Case I
D
Q Q
Case II
Q
Case III
???
Q
metastable
stable stable
N2 Q
S
CLK
SYNC
D Q
CLK
D2 metastable
CLK
D2 metastable
CLK
D2 metastable
= 5.6 × 10-6
MTBF = 1/[P(failure)/second]
P(failure)/second = 10 × (5.6 × 10-6 )
= 5.6 × 10-5 / second
MTBF = 1/[P(failure)/second] ≈ 5 hours
Parallelism
Parallelism
• Two types of parallelism:
– Spatial parallelism
• duplicate hardware performs multiple tasks at once
– Temporal parallelism
• task is broken into multiple stages
• also called pipelining
• for example, an assembly line
Time
Tray 1 Ben 1 Ben 1
Roll
Parallelism
Bake
Tray 3 Ben 2 Ben 2
Legend
Tray 4 Alyssa 2 Alyssa 2
Time
Tray 1 Ben 1 Ben 1
Parallelism
Temporal