Professional Documents
Culture Documents
Teaching ESD Chap3
Teaching ESD Chap3
Nurul Hazlina 1
Electronic System Design Finite State Machine
Nurul Hazlina 2
Electronic System Design Finite State Machine
Nurul Hazlina 3
Electronic System Design Finite State Machine
Storage Elements
Nurul Hazlina 5
Electronic System Design Finite State Machine
Clock
Nurul Hazlina 6
Electronic System Design Finite State Machine
FSM Representations
1. States
– determined by possible values in sequential storage elements
2. Transitions
– change of state
3. Clock
– controls when state can change by controlling storage elements
4. Sequential logic
– sequences through a series of states
– based on sequence of values on input signals
– clock period defines elements of sequence
001 010 111
In = 1 In = 0
In = 0
100 110
In = 1
Nurul Hazlina 7
Electronic System Design Finite State Machine
0
0 0 1 0
001 011
0
Nurul Hazlina 8
Electronic System Design Finite State Machine
1- DESIGN A COUNTER
Nurul Hazlina 9
Electronic System Design Finite State Machine
Nurul Hazlina 10
Electronic System Design Finite State Machine
D Q D Q D Q
CLK
"1"
Nurul Hazlina 11
Electronic System Design Finite State Machine
Nurul Hazlina 12
Electronic System Design Finite State Machine
010 011
present state next state
001
0 000 001 1
1 001 010 2
000 3-bit up-counter 100 2 010 011 3
3 011 100 4
111 110 101 4 100 101 5
5 101 110 6
6 110 111 7
7 111 000 0
Nurul Hazlina 13
Electronic System Design Finite State Machine
Implementation
• D flip-flop for each state bit
Verilog notation to show
• Combinational logic based on encoding function represents an
input to D-FF
C3 C2 C1 N3 N2 N1
0 0 0 0 0 1
0 0 1 0 1 0 N1 <= C1’
0 1 0 0 1 1 N2 <= C1C2’ + C1’C2
0 1 1 1 0 0 <= C1 xor C2
N3 <= C1C2C3’ + C1’C3 + C2’C3
1 0 0 1 0 1 <= (C1C2)C3’ + (C1’ + C2’)C3
1 0 1 1 1 0 <= (C1C2)C3’ + (C1C2)’C3
1 1 0 1 1 1 <= (C1C2) xor C3
1 1 1 0 0 0
N3 C3 N2 C3 N1 C3
0 0 1 1 0 1 1 0 1 1 1 1
C1 0 1 0 1 C1 1 0 0 1 C1 0 0 0 0
C2 C2 C2
Nurul Hazlina 14
Electronic System Design Finite State Machine
In C1 C2 C3 N1 N2 N3
0 0 0 0 0 0 0 1
100 110
0 0 0 1 0 0 0
0 0 1 0 0 0 1 1 0 1 1
1
0 0 1 1 0 0 1
0 000 1 010 101 0 111 1
0 1 0 0 0 1 0
0 1 0 1 0 1 0 0 1 0
0 0
0 1 1 0 0 1 1
0 1 1 1 0 1 1 001 011
0
1 0 0 0 1 0 0
1 0 0 1 1 0 0 N1 <= In
1 0 1 0 1 0 1 N2 <= C1
1 0 1 1 1 0 1 N3 <= C2 OUT1 OUT2 OUT3
1 1 0 0 1 1 0
1 1 0 1 1 1 0
1 1 1 0 1 1 1 IN D Q D Q D Q
1 1 1 1 1 1 1
CLK
Nurul Hazlina 15
Electronic System Design Finite State Machine
note the don't care conditions that arise from the unused state codes
Nurul Hazlina 16
Electronic System Design Finite State Machine
C+ C B+ C A+ C
0 0 0 X 1 1 0 X 0 1 0 X
A X 1 X 1 A X 0 X 1 A X 1 X 0
B B B
C+ <= A
B+ <= B’ + A’C’
A+ <= BC’
Nurul Hazlina 17
Electronic System Design Finite State Machine
A 1 1 1 1 A 1 0 0 1 A 0 1 0 0
B B B
Nurul Hazlina 18
Electronic System Design Finite State Machine
Self-starting counters
• Start-up states
– at power-up, counter may be in an unused or invalid state
– designer must guarantee that it (eventually) enters a valid state
• Self-starting solution
– design counter so that invalid states eventually transition to a valid
state
– may limit exploitation of don't cares
111 111 implementation 001
001 on previous slide
011 011
Nurul Hazlina 19
Electronic System Design Finite State Machine
Activity
• 2-bit up-down counter (2 inputs)
– direction: D = 0 for up, D = 1 for down
– count: C = 0 for hold, C = 1 for count
S1 S0 C D N1 N0
0 0 0 0 0 0
C=0 C=0
0 0 0 1 0 0
D=X C=1 D=X 0 0 1 0 0 1
D=0 0 0 1 1 1 1
0 1 0 0 0 1
00 11 0 1 0 1 0 1
C=1 C=1 0 1 1 0 1 0
C=1 0 1 1 1 0 0
D=0 D=1 D=0 1 0 0 0 1 0
1 0 0 1 1 0
01 10 1 0 1 0 1 1
C=1 1 0 1 1 0 1
C=0 D=0 C=0 1 1 0 0 1 1
D=X D=X
1 1 0 1 1 1
1 1 1 0 0 0
1 1 1 1 1 0
Nurul Hazlina 20
Electronic System Design Finite State Machine
Activity (cont’d)
S1
0 0 1 1 N1 = C’S1
S1 S0 C D N1 N0 0 0 1 1 + CDS0’S1’ + CDS0S1
D + CD’S0S1’ + CD’S0’S1
0 0 0 0 0 0
C 1 0 1 0 = C’S1
0 0 0 1 0 0
0 0 1 0 0 1 0 1 0 1 + C(D’(S1 S0) + D(S1 S0))
0 0 1 1 1 1 S0
S1
0 1 0 0 0 1
0 1 0 1 0 1 0 1 1 0
N0 = CS0’ + C’S0
0 1 1 0 1 0 0 1 1 0
0 1 1 1 0 0 D
1 0 0 0 1 0 C 1 0 0 1
1 0 0 1 1 0 1 0 0 1
1 0 1 0 1 1 S0
1 0 1 1 0 1
1 1 0 0 1 1
1 1 0 1 1 1
1 1 1 0 0 0
1 1 1 1 1 0
Nurul Hazlina 21
Electronic System Design Finite State Machine
Counter/shift-register model
• Values stored in registers represent the state of the circuit
• Combinational logic computes:
– next state
• function of current state and inputs
– outputs
• values of flip-flops
next state
Inputs Next State
logic
Current State
Outputs
Nurul Hazlina 22
Electronic System Design Finite State Machine
output Outputs
logic
Inputs
next state Next State
logic
Current State
Nurul Hazlina 23
Electronic System Design Finite State Machine
Current State
Next State
State
Clock 0 1 2 3 4 5
Nurul Hazlina 24
Electronic System Design Finite State Machine
Nurul Hazlina 25
Electronic System Design Finite State Machine
Nurul Hazlina 26
Electronic System Design Finite State Machine
state feedback
• Mealy inputs
logic for
outputs
outputs
combinational
logic for reg
next state
state feedback
• Synchronous Mealy
logic for
inputs outputs
outputs
combinational
logic for reg
next state
state feedback
Nurul Hazlina 27
Electronic System Design Finite State Machine
Nurul Hazlina 28
Electronic System Design Finite State Machine
1/0
Nurul Hazlina 29
Electronic System Design Finite State Machine
output Outputs
logic
Inputs
next state
logic
Current State
Nurul Hazlina 30
Electronic System Design Finite State Machine
Activity
A 3-bit sequence detector will detect 111 and 001. All the input and
output will be reset after each sequence had been detected. An
example of input/output sequence that satisfies the conditions of the
network specifications is as follows;
x=011 111 010 100 001 011
z=000 001 000 000 001 000
Draw the state transition diagram of the system using Mealy machine
method.
Nurul Hazlina 31
Electronic System Design Finite State Machine
Nurul Hazlina 32
Electronic System Design Finite State Machine
Ant Behavior
A: Following wall, touching B: Following wall, not touching
Go forward, turning Go forward, turning right
left slightly slightly
Nurul Hazlina 33
Electronic System Design Finite State Machine
L+R L’ R
L’ R’ L’ R’ R
R
L’ R’
B C
R’
(TR, F) (TR, F)
R’
Nurul Hazlina 34
Electronic System Design Finite State Machine
Nurul Hazlina 35
Electronic System Design Finite State Machine
L’ R’ L’ R’ R
R
L’ R’
state L R next state outputs
LOST 0 0 LOST F B C
(TR, F) (TR, F) R’
LOST – 1 E/G F R’
LOST 1 – E/G F
A 0 0 B TL, F
A 0 1 A TL, F
A 1 – E/G TL, F
B – 0 C TR, F
B – 1 A TR, F
... ... ... ... ...
Nurul Hazlina 36
Electronic System Design Finite State Machine
Synthesis
• 5 states : at least 3 state variables required (X, Y, Z)
– State assignment (in this case, arbitrarily chosen)
LOST - 000
E/G - 001
A - 010
B - 011
state L R next state outputs C - 100
it now remains
X,Y,Z X', Y', Z' F TR TL to synthesize
000 0 0 000 1 0 0 these 6 functions
000 0 1 001 1 0 0
... ... ... ... ...
010 0 0 011 1 0 1
010 0 1 010 1 0 1
010 1 0 001 1 0 1
010 1 1 001 1 0 1
011 0 0 100 1 1 0
011 0 1 010 1 1 0
... ... ... ... ...
Nurul Hazlina 37
Electronic System Design Finite State Machine
Nurul Hazlina 38
Electronic System Design Finite State Machine
Circuit Implementation
• Outputs are a function of the current state only - Moore machine
output F
TR
logic
TL
L next state Next State
R logic
X+ Y+ Z+
Current State
X Y Z
Nurul Hazlina 39
Electronic System Design Finite State Machine
011 100
110 (TR, F) (TR, F) R’
R’
111
Ant is in deep trouble
if it gets in this state
Nurul Hazlina 40
Electronic System Design Finite State Machine
State Minimization
• Fewer states may mean fewer state variables
• High-level synthesis may generate many redundant states
• Two state are equivalent if they are impossible to distinguish from
the outputs of the FSM, i. e., for any input sequence the outputs are
the same
Nurul Hazlina 41
Electronic System Design Finite State Machine
L+R L’ R
L’ R’ L’ R’ R
R
L’ R’
B C
R’
(TR, F) (TR, F)
R’
Nurul Hazlina 42
Electronic System Design Finite State Machine
L+R L’ R
L’ R’ L’ R’ R
L’ R’
B/C
R’
(TR, F)
Nurul Hazlina 43
Electronic System Design Finite State Machine
Nurul Hazlina 44
Electronic System Design Finite State Machine
Reset
N
Vending Open
Coin Machine Release
Sensor FSM Mechanism
D
Clock
Nurul Hazlina 45
Electronic System Design Finite State Machine
• 3 nickels
• nickel, dime S0
• dime, nickel N D
• two dimes
– Draw state diagram: S1 S2
• Inputs: N, D, reset N D N D
• Output: open chute S4 S5 S6
S3
– Assumptions: [open] [open] [open]
Nurul Hazlina 46
Electronic System Design Finite State Machine
Nurul Hazlina 47
Electronic System Design Finite State Machine
Nurul Hazlina 48
Electronic System Design Finite State Machine
D1 = Q1 + D + Q0 N
D0 = Q0’ N + Q0 N’ + Q1 N + Q1 D
OPEN = Q1 Q0
Nurul Hazlina 49
Electronic System Design Finite State Machine
Nurul Hazlina 50
Electronic System Design Finite State Machine
0¢
N’ D’ 0¢ N’ D’/0
[0]
N N/0
D 5¢ D/0
N’ D’ 5¢ N’ D’/0
[0]
N N/0
10¢
D N’ D’ D/1 10¢ N’ D’/0
[0]
N+D N+D/1
15¢
Reset’ 15¢ Reset’/1
[1]
Nurul Hazlina 51
Electronic System Design Finite State Machine
Nurul Hazlina 52
Electronic System Design Finite State Machine
Nurul Hazlina 53
Electronic System Design Finite State Machine
farm road
car sensors
highway
Nurul Hazlina 54
Electronic System Design Finite State Machine
Nurul Hazlina 55
Electronic System Design Finite State Machine
S0
TL•C / ST TS / ST
S0: HG
S1: HY TS' S1 S3 TS'
S2: FG
S3: FY TS / ST TL+C' / ST
S2
(TL+C')'
Nurul Hazlina 56
Electronic System Design Finite State Machine
SA1: HG = 00 HY = 01 FG = 11 FY = 10
SA2: HG = 00 HY = 10 FG = 01 FY = 11
SA3: HG = 0001 HY = 0010 FG = 0100 FY = 1000 (one-hot)
Nurul Hazlina 57
Electronic System Design Finite State Machine
Nurul Hazlina 58
Electronic System Design Finite State Machine
Seq
N
Q1
DQ
Seq
D
Open
DQ
Com
Reset
Nurul Hazlina 59
Electronic System Design Finite State Machine
Nurul Hazlina 60
Electronic System Design Finite State Machine
Q0
DQ
Seq
N
Q1
DQ
Seq
D
OPEN Open
DQ
Seq
Reset
Nurul Hazlina 61
Electronic System Design Finite State Machine
STATE MINIMIZATION
Nurul Hazlina 62
Electronic System Design Finite State Machine
Nurul Hazlina 63
Electronic System Design Finite State Machine
Nurul Hazlina 64
Electronic System Design Finite State Machine
Nurul Hazlina 65
Electronic System Design Finite State Machine
State Minimization
2 Methods:
1. Row Matching
2. Implication Chart
NurulHazlina/BEE2243/FSM
Nurul Hazlina 66
Electronic System Design Finite State Machine
Reset S0 S1 S2 0 0
0 S1 S3 S4 0 0
1 S2 S5 S6 0 0
00 S3 S0 S0 0 0
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
11 S6 S0 S0 1 0
S0
0/0 1/0
S1 S2
0/0 1/0 0/0 1/0
S3 S4 S5 S6
1/0 1/0 1/0 1/0
0/0 0/1 0/0 0/1
NurulHazlina/BEE2243/FSM
Nurul Hazlina 67
Electronic System Design Finite State Machine
S0
S1
S2
S3
S4
S5
S6
S0 S1 S2 S3 S4 S5 S6
Figure 1 : Chart with entry of every pairs of states
Nurul Hazlina 68
Electronic System Design Finite State Machine
S0
S1
S2
S3
S4
S5
S6
S0 S1 S2 S3 S4 S5 S6
Nurul Hazlina 69
Electronic System Design Finite State Machine
S1 S1-S3
S2-S4
S1-S5 S3-S5
S2-S6 S4-S6
S2
S1-S0 S3-S0 S5-S0
S3 S2-S0 S4-S0 S6-S0
S4
X X X X
S5
S1-S0
S2-S0
S3-S0
S4-S0
S5-S0
S6-S0
S0-S0
S0-S0 X
S6
X X X X S0-S0
S0-S0
X
S0 S1 S2 S3 S4 S5 S6
S0, S1, S2, S3, S5sameNurulHazlina/BEE2243/FSM
output (group1)
S4, S6 same output (group2) any combination across g1 and g2 indicate by X
Nurul Hazlina 70
Electronic System Design Finite State Machine
S0 G2
S1
S4
S2
S6
S3
S5
Reset S0 S1 S2 0 0
0 S1 S3 S4 0 0
1 S2 S5 S6 0 0
00 S3 S0 S0 0 0
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
11 S6 S0 S0 1 0
Nurul Hazlina 72
Electronic System Design Finite State Machine
S1 X
X S3-S5
S2 S4-S6
S3 X X X
S4 X X X X
S5
X X X S0-S0
S0-S0
X
S6 X X X X S0-S0
S0-S0
X
S0 S1 S2 S3 S4 S5 S6
IF square Si and Sj contains the ISP Sm-Sn and square Sm,Sn contains an X, then
NurulHazlina/BEE2243/FSM
Mark
Nurul Si,Sj with an X as well.
Hazlina 73
Electronic System Design Finite State Machine
Simplified Table
S0
X/0
S1’
0/0 1/0
S3’ S4’
X/0 0/1 1/0
Nurul Hazlina 74
Electronic System Design Finite State Machine
Another Example
0
A B
0 1
[0] [0]
0
1 1
C
G 0 [0]
[0] 1
0 0
0
1 D
F [1]
E
[0] [0] 1
1
NurulHazlina/BEE2243/FSM
Nurul Hazlina 75
Electronic System Design Finite State Machine
Continue
Present Next state output
state 0 1
Divide into 2 groups;
A B C 0
A,B,C,E,F,G and D based on
Output value
B A C 0
C D C 0
D D E 1
E A F 0
F B G 0
G A E 0
NurulHazlina/BEE2243/FSM
Nurul Hazlina 76
Electronic System Design Finite State Machine
Reset S0 S1 S2 0 0
0 S1 S3 S4 0 0
1 S2 S5 S6 0 0
00 S3 S0 S0 0 0
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
11 S6 S0 S0 1 0
S0
0/0 1/0
S1 S2
0/0 1/0 0/0 1/0
S3 S4 S5 S6
1/0 1/0 1/0 1/0
0/0 0/1 0/0 0/1
Nurul Hazlina 77
Electronic System Design Finite State Machine
Reset S0 S1 S2 0 0
0 S1 S3 S4 0 0
1 S2 S5 S6 0 0
00 S3 S0 S0 0 0
01 S4 S0 S0 1 0
10 S5 S0 S0 0 0
11 S6 S0 S0 1 0
( S0 S1 S2 S3 S4 S5 S6 )
S1 is equivalent to S2
( S0 S1 S2 S3 S5 ) ( S4 S6 )
S3 is equivalent to S5
( S0 S3 S5 ) ( S1 S2 ) ( S4 S6 ) S4 is equivalent to S6
( S0 ) ( S3 S5 ) ( S1 S2 ) ( S4 S6 )
Nurul Hazlina 78
Electronic System Design Finite State Machine
Minimized FSM
• State minimized sequence detector for 010 or 110
Input Next State Output
Sequence Present State X=0 X=1 X=0 X=1
S0
X/0
S1’
0/0 1/0
S3’ S4’
X/0 0/1 1/0
Nurul Hazlina 79
Electronic System Design Finite State Machine
Implication Chart
Nurul Hazlina 80
Electronic System Design Finite State Machine
inputs here
00 10
S0 00 S1
[1] [0]
01 present next state output
10 11 state 00 01 10 11
11
00 01 S0 S0 S1 S2 S3 1
00 01 S1 S0 S3 S1 S4 0
S2 S3 S2 S1 S3 S2 S4 1
[1] 01 [0] S3 S1 S0 S4 S5 0
10
10 11 11 S4 S0 S1 S2 S5 1
01
S5 S1 S4 S0 S5 0
10 10
00 S4 11 S5 00
[1] [0]
symbolic state
01 transition table
11
Nurul Hazlina 81
Electronic System Design Finite State Machine
Minimized FSM
• Implication Chart Method
– Cross out incompatible states based on outputs
– Then cross out more cells if indexed chart entries are already crossed
out
Nurul Hazlina 83
Electronic System Design Finite State Machine
Nurul Hazlina 84
Electronic System Design Finite State Machine
X’
00
X’ [0] X
X
10 01
[0] [1]
X’
X’ 11 X
[0]
Nurul Hazlina 85
Electronic System Design Finite State Machine
Nurul Hazlina 87
Electronic System Design Finite State Machine
Nurul Hazlina 88
Electronic System Design Finite State Machine
X: 0 0 1 0 1 0 1 0 0 1 0 …
Z: 0 0 0 1 0 1 0 1 0 0 0 …
X: 1 1 0 1 1 0 1 0 0 1 0 …
Z: 0 0 0 0 0 0 0 1 0 0 0 …
Nurul Hazlina 89
Electronic System Design Finite State Machine
reset S0
[0]
0 1
S1 S4
[0] [0]
1 0
S2 S5
[0] [0]
0 0
S3 S6 0 or 1
[1] [0]
Nurul Hazlina 90
Electronic System Design Finite State Machine
reset S0
[0]
Exit conditions from S1: 0 1
recognizes strings of form …0 0 S1 S4 1
[0] ...0 ...1 [0]
(no 1 seen);
loop back to S1 if input is 0 1 0
S2 S5
Exit conditions from S4: ...01 [0] [0]
recognizes strings of form …1 0 1 0
(no 0 seen);
loop back to S4 if input is 1 S3 S6 0 or 1
...010 [1] ...100 [0]
Nurul Hazlina 91
Electronic System Design Finite State Machine
Nurul Hazlina 93
Electronic System Design Finite State Machine
Nurul Hazlina 94
Electronic System Design Finite State Machine
X
CLK
FSM 1 FSM 2
Y FSM1 A A B
Nurul Hazlina 95
Electronic System Design Finite State Machine
status control
info and state signal
inputs outputs
data-path
"puppet"
Nurul Hazlina 96
Electronic System Design Finite State Machine
Nurul Hazlina 97
Electronic System Design Finite State Machine
clock
open/closed
Nurul Hazlina 98
Electronic System Design Finite State Machine
C1!=value
C2!=value C3!=value
& new
& new & new
S1 S2 S3 OPEN
reset closed closed closed open
C1==value C2==value C3==value
& new & new & new
C1 C2 C3 new reset
4 4 4 mux
multiplexer
control
4 controller
value comparator
clock
4 equal
next
reset new equal state state mux open/closed
1 – – – S1 C1 closed
0 0 – S1 S1 C1 closed
0 1 0 S1 ERR – closed
0 1 1 S1 S2 C2 closed
...
0 1 1 S3 OPEN – open
...
mux
control
C1 C2 C3
4 4 4 mux
control
multiplexer
4
value comparator
4 equal
equal
Nurul Hazlina 103
Electronic System Design Finite State Machine
+ oc
C1 C2 C3
4 4 4 mux
control tri-state driver
multiplexer
4 (can disconnect
equal from output)
value comparator
4 equal open-collector connection
(zero whenever one connection is zero,
one otherwise – wired AND)
Nurul Hazlina 104
Electronic System Design Finite State Machine
C1 C2 C3
4 4 4 mux
multiplexer
control
4
value comparator
4 equal
CS 150 - Fall 2000 - Introduction - 105
Nurul Hazlina 105
Electronic System Design Finite State Machine
Section Summary
• FSM Design
– Understanding the problem
– Generating state diagram
– Implementation using synthesis tools
– Iteration on design/specification to improve qualities of mapping
– Communicating state machines
• Four case studies
– Understand I/O behavior
– Draw diagrams
– Enumerate states for the "goal"
– Expand with error conditions
– Reuse states whenever possible
Example: reduce-1-string-by-1
• Remove one 1 from every string of 1s on the input
Moore Mealy
zero
[0] 0/0
zero
1 0 [0]
0 one1 0/0 1/0
[0]
one1
0 1 [0]
1 1/1
two1s
[1]