Documente Academic
Documente Profesional
Documente Cultură
Chapter 3:
Sequential Logic Design -- Controllers
Slides to accompany the textbook Digital Design, First Edition,
by Frank Vahid, John Wiley and Sons Publishers, 2007.
http://www.ddvahid.com
3.1
Introduction
Sequential circuit
a
b
1
0
Combinational
digital circuit
1
a
Sequential
digital circuit
i
s
sa
i
n
Digital Design
Copyright 2006
Frank Vahid
Must know
sequence of
past inputs to
know output
2
Note: Slides with animation are denoted with a small red "a" near the animated items
3.2
Cancel
button
Call
Blue light
Bit
Storage
Blue light
Call
button
Bit
Storage
Cancel
button
Cancel
a
Call
button
Blue light
Bit
Storage
Cancel
button
1
0
1
0
1
0
0Q S 1
Digital Design
Copyright 2006
Frank Vahid
0
t
0Q
S 1
0
t
1Q
S 1
1
t
1Q
S 0
1Q
1
t
S (set)
Q
R (reset)
S=0
0
t
1
S=0
0
S=1
S=0
t
0
Recall
0
l
a
c
.e
0 Q
1
R=0
R=1
0 Q
0
Q
R=0
R=0
1
0
R1
0
t 1
0
1
Q
0
Digital Design
Copyright 2006
Frank Vahid
Blue light
Call
button
Bit
Storage
Cancel
button
Call=1 : sets Q to 1
Q stays 1 even after Call=0
Cancel=1 : resets Q to 0
Call
but t on
Blue light
Cancel
but t on
Digital Design
Copyright 2006
Frank Vahid
S=0
t
0
0 Q
R=1
S=0
1 Q
R=0
0
1
0
1
0 Q
0
1
R=0
Q
0
t
Q
1
0
1
0
Digital Design
Copyright 2006
Frank Vahid
SR latch
X
0
1
Y
0
Q
Y
1
S
0
SR= 11
1
Digital Design
Copyright 2006
Frank Vahid
R
0
Level-sensitive SR latch
S
C
Q
R
R1
S
Level-sensitive SR latch
S1
S1
1
R0
Clk
C
Q
R
Level-sensitive
SR latch symbol
a
1
0
1
S1
R1
0
1
R1 0
Digital Design
Copyright 2006
Frank Vahid
...S1R1 never = 11
Clk
C
Q
Level-sensitive SR latch
S
S1
R
Y
R1
10
Clocks
Period
100 GHz
10 GHz
1 GHz
100 MHz
10 MHz
0.01 ns
0.1 ns
1 ns
10 ns
100 ns
1 Hz = 1/s
Digital Design
Copyright 2006
Frank Vahid
11
Level-Sensitive D Latch
SR latch requires careful design to
ensure SR=11 never occurs
D latch relieves designer of that
burden
D latch
C
Q
1
0
1
0
1
D latch symbol
0
1
0
1
Q
0
Digital Design
Copyright 2006
Frank Vahid
12
D1
Q1
C1
D2
Q2
C2
D3
Q3
D4
C3
Q4
Clk
C4
Clk
Clk_A
Clk_B
Digital Design
Copyright 2006
Frank Vahid
13
D Flip-Flop
Flip-flop: Bit storage that stores on clock edge, not level
One design -- master-servant
Two latches, output of first goes to input of second, master
latch has inverted clock signal
So master loaded when C=0, then servant when C=1
When C changes from 0 to 1, master disabled, servant
loaded with value that was at D just before C changed -- i.e.,
value at D during rising edge of C
D flip-flop
D latch
D
Dm
Qm
Cm
master
Clk
Digital Design
Copyright 2006
Frank Vahid
D latch
Ds
Cs
Qs
Qs
servant
rising edges
Clk
Note:
Hundreds of
different flipflop designs
exist
Clk
D/Dm
Cm
Qm/Ds
Cs
Qs
14
D Flip-Flop
D
The triangle
means clock
input, edge
triggered
Q
Symbol for rising-edge
triggered D flip-flop
rising edges
falling edges
Clk
Clk
Digital Design
Copyright 2006
Frank Vahid
15
D Flip-Flop
Solves problem of not knowing through how many latches a signal
travels when C=1
In figure below, signal travels through exactly one flip-flop, for Clk_A or
Clk_B
Why? Because on rising edge of Clk, all four flip-flops are loaded
simultaneously -- then all four no longer pay attention to their input, until the
next rising edge. Doesnt matter how long Clk is 1.
T
n
d
i
s
h
c
a
e
D1
Q1
D2
Q2
D3
Q3
D4
Q4
ifl
l
o
o
-fl
p
s
e
h
c
Clk
Clk_A
Digital Design
Copyright 2006
Frank Vahid
Clk_B
16
Q (D flip-flop)
Digital Design
Copyright 2006
Frank Vahid
10
17
Call
Cancel
button
Preserve value: if
Q=0, make D=0; if
Q=1, make D=1
Cancel -- make
D=0
Cancel
but ton
Blue
light
Flight
attendant
call-button
system
button
Call
Cancel
Q
Clk
Blue
light
18
D flip-flop
D latch
Level-sensitive SR latch
S
S1
S (set)
S
D
C
Q
C
Q
D latch
Dm Qm
Ds Qs
Cm
master
Cs Qs
servant
Q
Q
Clk
R1
R (reset)
D latch
Feature: SR cant be 11 if
D is stable before and
while C=1, and will be 11
for only a brief glitch even
if D changes while C=1.
Problem: C=1 too long
propagates new values
through too many latches:
too short may not enable a
store.
19
Basic Register
Typically, we store multi-bit items
e.g., storing a 4-bit binary number
I2
I1
I0
4-bit register
D
Q
D
Q
I3 I2 I1 I0
reg(4)
D
Q
clk
Q3 Q2 Q1 Q0
Q3
Digital Design
Copyright 2006
Frank Vahid
Q2
Q1
Q0
20
10
x4
x3
x2
x1
x0
tu
r
o
n
se
p
m
e
timer
Present
1 hour ago
2 hours ago
Display
Display
Display
a4 a3 a2 a1 a0
b4 b3 b2 b1 b0
c4 c3 c2 c1 c0
TemperatureHistoryStorage
21
I4
I3
I2
I1
I0
Q4
Q3
Q2
Q1
Q0
b4 b3 b2 b1 b0
I4
I3
I2
I1
I0
Ra
Q4
Q3
Q2
Q1
Q0
c4 c3 c2 c1 c0
I4
I3
I2
I1
I0
Q4
Q3
Q2
Q1
Q0
Rb
Rc
TemperatureHistoryStorage
x4...x0
15 18 20 21 21 22 24 24 24 25 25 26 26 26 27 27 27 27
Digital Design
Copyright 2006
Frank Vahid
Ra
18
21
24
25
26
27
Rb
18
21
24
25
26
Rc
18
21
24
25
22
11
3.3
b Controller
laser
x
clk
patient
clk
x
Digital Design
Copyright 2006
Frank Vahid
23
Laser timer: What if press button again while x=1? x then stays one
another 3 cycles. Is that what we want?
24
12
clk^
x=0
Off
On
clk^
x=1
clk
On Off
On Off
Off
On Off
On
cycle 1
cycle 2
cycle 3
cycle 4
Off
On
Off
On
state
Outputs:
x
Digital Design
Copyright 2006
Frank Vahid
25
Outputs: x
x=0
Off
clk^
x=1
clk^
On2
On1
Four states
Transition on rising clock
edge to next state
x=1
clk^
x=1
On3
clk^
clk
State Off On1On2On3 Off On1On2 On3 Off
Outputs:
x
Digital Design
Copyright 2006
Frank Vahid
26
13
Four states
Wait in Off state while b is
0 (b)
When b is 1 (and rising
clock edge), transition to
On1
x=0
Off
Sets x=1
On next two clock edges,
transition to On2, then On3,
which also set x=1
clk^
b*clk^
b*clk^
x=1 clk^
x=1
On1
On2
clk^
x=1
On3
clk
Inputs:
b
State Off Off Off Off Off On1 On2 On3 Off
Outputs:
x
Digital Design
Copyright 2006
Frank Vahid
27
Inputs: b; Outputs: x
x=0
Off
Digital Design
Copyright 2006
Frank Vahid
clk^
b *clk^
b*clk ^
x=1 clk^
x=1
On1
On2
clk^
x=1
On3
Inputs: b; Outputs: x
x=0
Off
b
a
b
x=1
x=1
x=1
On1
On2
On3
28
14
FSM Definition
FSM consists of
Inputs: b; Outputs: x
x=0
Set of states
Off
Initial state
x=1
x=1
x=1
On1
On2
On3
Ex: Off
Set of transitions
Describes next states
Ex: Has 5 transitions
Set of actions
Sets outputs while in states
Ex: x=0, x=1, x=1, and x=1
Digital Design
Copyright 2006
Frank Vahid
29
Inputs: a; Outputs: r
FSM
Wait until computer requests
ID (a=1)
Transmit ID (in this case,
1101)
Digital Design
Copyright 2006
Frank Vahid
Wait
r=0
K1
K2
K3
K4
r=1
r=1
r=0
r=1
30
15
r=0
a
K1
K2
K3
K4
r=1
r=1
r=0
r=1
clk
Inputs
a
Inputs
a
State
Wait Wait
K1
K2
K3
K4 Wait Wait
State
Wait Wait
K1
K2
K4 Wait K1
K3
Output
Outputs
Digital Design
Copyright 2006
Frank Vahid
31
Start
u
r
g
b
a
Red
Green
Blue
Inputs: s,r,g,b,a;
Outputs: u
FSM
Wait
u=0 s
Digital Design
Copyright 2006
Frank Vahid
Start
u=0
Door
lock
Code
detector
ar
ab
ag
ar
ar
Red1
u=0
ab
a
Blue
u=0
ag
a
Green
u=0
ar
a
Red2
u=1
16
Wait
u=0 s
Start
u=0
ar ab ag
ar
ar
Red1
ab
Blue
u=0
Inputs: s,r,g,b,a;
Outputs: u
ag
a
u=0
ar
Green
Red2
u=0
u=1
33
Off
O
Combinational
logic
S
clk
Digital Design
Copyright 2006
Frank Vahid
x=1
x=1
On2
On3
s
tp
u
o
M
S
F
b
Combinational n1
logic
n0
s1
s0
clk
m-bit
state register
x=1
On1
FSM
outputs
FSM
inputs
Known as controller
FSM
inputs
FSM
outputs
State register
General version
34
17
3.4
Controller Design
Five step controller design process
Digital Design
Copyright 2006
Frank Vahid
35
Inputs: b; Outputs: x
x=0
00
b
Off
a
b
x=1
01 On1
x=1
10 On2
x=1
11 On3
M
S
F
b
Combinational n1
logic
n0
s1
s0
clk
Digital Design
Copyright 2006
Frank Vahid
FSM
outputs
FSM
inputs
s
tp
u
o
State register
36
18
Inputs: b; Outputs: x
x=0
00
b
Off
a
b
x=1
10 On2
b
Combinational n1
logic
n0
s1
s0
clk
x=1
11 On3
FSM
outputs
FSM
inputs
x=1
01 On1
State register
Digital Design
Copyright 2006
Frank Vahid
37
b
Combinational n1
logic
n0
s1
s0
clk
FSM
outputs
Step 5: Implement
combinational logic
State register
38
19
Combinational Logic
n
i
M
S
F
ts
u
p
FSM
inputs
x
x
b
Combinational n1
logic
n0
s1
s0
FSM
outputs
Step 5: Implement
combinational logic (cont)
n1
State register
clk
n0
s0
s1
clk
State register
x = s1 + s0
n1 = s1s0 + s1s0
n0 = s1s0b + s1s0
Digital Design
Copyright 2006
Frank Vahid
39
x=0
00
Off
b
b
x=1
x=1
x=1
01 On1
10 On2
11 On3
b
0
0
0
0
x
0
x=0
00
Off
x=1
x=1
x=1
01 On1
10 On2
11 On3
b
1
0
0
0
n1
0
clk
0
0
state=00
x=1
x=1
10 On2
11 On3
b
1
0
1
1
s1
0
0
s0
0
1
state=00
0
0
n0
0
0
clk
x
n1
1
n0
1
0
s0
x=1
01 On1
0
1
n0
0
s1
0
0
x
0
n1
0
0
0
clk
0
clk
s1
0
1
s0
1
0
state=01
Inputs:
b
Outputs:
x
Digital Design
Copyright 2006
Frank Vahid
40
20
Controller Example:
Button Press Synchronizer
clk
cycle1
cycle2
cycle3
cycle4
Inputs:
bi
bi
Button press
synchronizer
controller
bo
Outputs:
bo
41
Controller Example:
FSM inputs: bi; FSM outputs: bo
bi
A
bi
bo=0
bi
C bi
bi
bi
bo=1
bi
bo
Combinational
logic
s1
bo=0
clk
s0
FSM
outputs
FSM
inputs
n1
n0
n1 = s1s0bi + s1s0bi
n0 = s1s0bi
bo = s1s0bi + s1s0bi = s1s0
State register
Combinational logic
Step 1: FSM
s
tp
u
o
bo
M
S
F
bi
01
bi
bi
bo=1
bi
10 bi
bo=0
A
B
C
unused
Combinational logic
Inputs
Outputs
s1 s0 bi n1 n0 bo
0 0 0
0 0 0
0 0 1
0 1 0
0 1 0
0 0 1
0 1 1
1 0 1
1 0 0
0 0 0
1 0 1
1 0 0
1 1 0
0 0 0
1 1 1
0 0 0
bi
n1
n0
s1
clk
s0
State register
Step 5: Create
combinational circuit
42
21
wxyz=1000
Combinational
logic
s1
wxyz=0011
wxyz=1100
clk
wxyz=1000
n1
n0
s0
00
01
State register
10
wxyz=0011
wxyz=1100
w = s1
x = s1s0
y = s1s0
z = s1
n1 = s1 xor s0
n0 = s0
clk
s
tp
u
o
M
S
F
y
z
a
s1
Digital Design Step 4: Create state table
Copyright 2006
Frank Vahid
11
s0
State register
n0
n1
43
Inputs: a; Outputs: r
Wait
Step 1
r=0 a
K1
K2
K3
K4
r=1
r=1
r=0
r=1
s
tp
u
o
M
S
F
Step 2
M
S
F
n
tsi
u
p
Combinational
logic
n2
n1
n0
s2 s1 s0
clk
State register
Inputs: a; Outputs: r
000
Step 3
r=0
001
010
011
100
r=1
r=1
r=0
r=1
Digital Design
Copyright 2006
Frank Vahid
Step 4
44
22
s
tp
u
o
M
S
F
y=s1
z = s1s0
n1=(s1 xor s0)x
n0=(s1*s0)x
states
n
i
M
S
tsF
u
p
s1
clk
Outputs:y, z
A
n1
yz=10
yz=10
n0
yz=00
yz=01
states
with
outputs
s0
Inputs: x; Outputs:y, z
State register
x
x
yz=10 x
Work backwards
yz=10
x
C
yz=01
yz=00
x
states with
outputs and
transitions
45
b
ab=11
next state?
a
ab
what if
ab=00?
ab
ab
a
ab
Digital Design
Copyright 2006
Frank Vahid
46
23
a * ab
a
ab
47
ar * a
a * a(r+b+g)
= (a*a)r = 0*r
=0
=0
Digital Design
Copyright 2006
Frank Vahid
Red1
u=0
a
ab
a
Blue
u=0
ag
a
Green
u=0
ar
a
Red2
u=1
ar * a(r+b+g)
Intuitively: press red and blue
= (a*a)*(r+b+g) = 0*(r+b+g)
buttons at same time: conditions
= (a*a)*r*(r+b+g) = a*r*(r+b+g)
ar, and a(r+b+g) will both be
true. Which one should be
= arr+arb+arg
taken?
= 0 + arb+arg
a
Q: How to solve?
= arb + arg
= ar(b+g)
A: ar should be arbg
Fails! Means that two of Starts (likewise for ab, ag, ar)
transitions could be true
Note: As evidence the pitfall is common,
48
24
Simplifying Notations
FSMs
Assume unassigned output
implicitly assigned 0
a=0
b=1
c=0
a=0
b=0
c=1
clk
Sequential circuits
Assume unconnected clock
inputs connected to same
external clock
b=1
c=1
Digital Design
Copyright 2006
Frank Vahid
49
3.5
Digital Design
Copyright 2006
Frank Vahid
50
25
clk
D
setup time
clk
hold time
S
D
Q
S
2
C
u
Q
u
Q
Q
Leads to oscillation!
Digital Design
Copyright 2006
Frank Vahid
51
Metastability
clk
setup time
violation
Q
metastable
state
ai
Partial solution
Insert synchronizer flip-flop for
asynchronous input
Special flip-flop with very small setup/hold
time
ai
synchronizer
52
26
Metastability
One flip-flop doesnt completely solve problem
How about adding more synchronizer flip-flops?
Helps, but just decreases probability of metastability
low
very
low
very
very
low
incredibly
low
ai
synchronizers
Digital Design
Copyright 2006
Frank Vahid
53
cycle 1
AR
cycle 2
AR
AS
cycle 3
Q
Q
cycle 4
clk
D
AR
Digital Design
Copyright 2006
Frank Vahid
54
27
Inputs: x; Outputs: b
x=0
Off
b
x=1
x=1
x=1
On1
On2
On3
x
Combinational
logic
n1
n0
s1
State register
D
reset
Digital Design
Copyright 2006
Frank Vahid
s0
55
Glitching
Glitch: Temporary values on outputs that appear soon after
input changes, before stable new output values
Designer must determine whether glitching outputs may
pose a problem
If so, may consider adding flip-flops to outputs
Delays output by one clock cycle, but may be OK
Digital Design
Copyright 2006
Frank Vahid
56
28
Digital Design
Copyright 2006
Frank Vahid
57
Chapter Summary
Sequential circuits
Have state
58
29