Professional Documents
Culture Documents
Chapter #8: Finite State Machine Design
Chapter #8: Finite State Machine Design
No. 8-1
Motivatio
n
No. 8-2
Chapter Overview
Concept of the State Machine
Word Problems
Case Studies
No. 8-3
Concept of the State
Machine
Example: Odd Parity Checker
Assert output whenever input bit stream has odd # of 1's
No. 8-5
Concept of the State
Machine
Example: Odd Parity Checker
Next State/Output Functions
NS = PS xor PI; OUT = PS
Input Output
NS T Q
Input CLK
D Q
PS/Output
CLK Q
Q R
R
\Reset \Reset
D FF Implementation T FF Implementation
Input 1 0 0 1 1 0 1 0 1 1 1 0
Clk
Output 1 1 1 0 1 1 0 0 1 0 1 1
No. 8-7
Concept of State
Machine
Example: Positive Edge Triggered Synchronous System
Delayed Outputs:
take effect on next clock edge
Outputs propagation delays must exceed hold times
No. 8-8
Concept of the State
Machine
Communicating State Machines
One machine's output is another machine's input
X
CLK
FSM 1 FSM 2
Y
FSM 1 A A B
X
Y=0 X=0
Y=0 X=0
A C FSM 2 C D D
[1] [0]
X=1 Y
Y=1
X=1
B D
Y=0,1 [0] X=0 [1]
No. 8-9
Basic Design Approach
Six Step Process
1. Understand the statement of the Specification
No. 8-10
Basic Design Approach
Example: Vending Machine FSM
General Machine Concept:
deliver package of gum after 15 cents deposited
no change
Block Diagram N
Coin
Vending Open Gum
Sensor D Machine Release
Reset FSM Mechanism
Clk
No. 8-11
Vending Machine
Example
Step 2. Map into more suitable abstract representation
Output: open N D
D N
S3 S4 S5 S6
[open] [open] [open]
N D
S7 S8
[open] [open]
No. 8-12
Vending Machine
Example
Step 3: State Minimization
Present Inputs Next Output
Reset
0¢
State D N State Open
0¢ 0 0 0¢ 0
N 0 1 5¢ 0
5¢
1 0 10¢ 0
D 1 1 X X
5¢ 0 0 5¢ 0
N 0 1 10¢ 0
10¢ 1 0 15¢ 0
D 1 1 X X
N, D 10¢ 0 0 10¢ 0
15¢
0 1 15¢ 0
1 0 15¢ 0
[open]
1 1 X X
15¢ X X 15¢ 1
reuse states
whenever Symbolic State Table
possible
No. 8-13
Vending Machine
Example
Step 4: State Encoding
Present State Inputs Next State Output
Q1 Q0 D N D 1 D0 Open
0 0 0 0 0 0 0
0 1 0 1 0
1 0 1 0 0
1 1 X X X
0 1 0 0 0 1 0
0 1 1 0 0
1 0 1 1 0
1 1 X X X
1 0 0 0 1 0 0
0 1 1 1 0
1 0 1 1 0
1 1 X X X
1 1 0 0 1 1 1
0 1 1 1 1
1 0 1 1 1
1 1 X X X
No. 8-14
Parity Checker Example
Step 5. Choose FFs for implementation
D FF easiest to use
D1 D0 Open
Q1
D D1 D Q Q1
Q0 CLK \ Q1
RQ
N
\reset
D1 = Q1 + D + Q0 N
N
\ Q0 OPEN
D0 = N Q0 + Q0 N + Q1 N + Q1 D
Q0
\N
D0 D Q0
Q1
Q OPEN = Q1 Q0
CLK \ Q0
N RQ
Q1 \reset
D
8 Gates
No. 8-15
Parity Checker Example
J1 = D + Q0 N
K1 = 0
J0 = Q0 N + Q1 D
K0 = Q1 N
N
Q0 J Q Q1
D \ Q1
CLK K Q
\ Q0 R
N
OPEN
Q1
D Q0
J Q
\ Q1 CLK
\ Q0
KR Q
N
\reset 7 Gates
No. 8-17
Alternative State Machine Representations
Why State Diagrams Are Not Enough
Not flexible enough for describing very complex finite state machines
No. 8-18
Alternative State Machine Representations
Algorithmic State Machine (ASM) Notation
Three Primitive Elements:
State Box
No. 8-19
Alternative State Machine Representations
ASM Notation
Condition Boxes:
Ordering has no effect on final outcome
A 010 A 010
F F
I0 I1
T T
F F
I1 I0
T T
B C B C
No. 8-20
Alternative State Machine Representations
Example: Parity Checker
Input X, Output Z
Even 0
Nothing in output list implies Z not asserted
No. 8-21
Alternative State Machine Representations
ASM Chart for Vending Machine
0¢ 00 10¢ 10
T T
D D
F F
F F
N N
T T
5¢ 01 15¢ 11
H.Open
T F
N Reset
F T
F T
D 0¢
No. 8-22
Moore and Mealy Machine Design
Procedure
Definitions
State
Register
Moore Machine
Xi Combinational
Comb. Outputs are function
Logic for
Inputs Logic for
Outputs
solely of the current
Next State state
(Flip-flop Zk
Inputs) Outputs
Outputs change
Clock synchronously with
state changes
state
feedback
Zk
Mealy Machine
Xi
Inputs Combinational Outputs
Logic for Outputs depend on
Outputs and state AND inputs
Next State
Input change causes
State
Feedback
an immediate output
State Register Clock change
Asynchronous outputs
No. 8-23
Moore and Mealy
Machines
State Diagram Equivalents
N D + Reset
Moore Reset Reset/0
(N D + Reset)/0
Mealy
Machine 0¢ 0¢ Machine
[0]
Reset Reset/0
N N/0
5¢ 5¢
ND D N D/0 D/0
[0]
N N/0
10¢ 10¢
D D/1
[0] ND N D/0
N+D N+D/1
15¢ 15¢
No. 8-24
Moore and Mealy
Machines
States vs. Transitions
Mealy Machine typically has fewer states than Moore Machine
for same output sequence
0
Asserts its output 0
0 0/0
1/1
[0]
Different # of states 1
2
[1] 1
S0 00 S0 0
IN
F F
IN
S1 T 01 S1
T 1
Equivalent
ASM Charts
IN F IN
F
S2 T 10 T
H.OUT H.OUT
T
IN
F
No. 8-25
Moore and Mealy
Machines
Timing Behavior of Moore Machines
Reverse engineer the following: why Moore ???
X J Q A Input X
C Output Z
X
KR Q \A State A, B (= Z)
\B
FFa
\Reset
Clk
X J Q Z
X C
KR Q \B
\A
FFb
\Reset
X
Clk
A
Z
\Reset
Reset X=1 X=0 X=1 X= 0 X=1 X= 0 X= 0
AB = 00 AB = 00 AB = 11 AB = 11 AB = 10 AB = 10 AB = 01 AB = 00
A B X A+ B+ Z
0 0 0 ? ? 0
1 1 1 0
0 1 0 0 0 1
Partially Derived
1 ? ? 1
State Transition 1 0 0 1 0 0
Table 1 0 1 0
1 1 0 1 1 1
1 1 0 1
No. 8-27
Moore and Mealy
Machines
Formal Reverse Engineering
Derive transition table from next state and output combinational
functions presented to the flipflops!
Ja = X Ka = X B Z=B
Jb = X Kb = X xor A
No. 8-28
Moore and Mealy
Machines
Complete ASM Chart for the Mystery Moore Machine
S0 00 S3 11
H.Z
0 1 0
X X
1
S1 01 S2 10
H.Z
0 1 1 0
X X
No. 8-29
Moore and Mealy
Machines
Reverse Engineering a Mealy Machine
Clk
\A
X
A B
D Q J Q
DA C
\A \B
C \X
R Q KR Q
\Reset \Reset
A
DA \X
X
B
B Z
\X X
A
X Note glitches
Clk
in Z!
A Outputs valid at
B following falling
clock edge
Z
\Reset
Reset X =1 X =0 X =1 X =0 X =1 X =1
AB =00 AB =00 AB =00 AB =01 AB =11 AB =10 AB =01
Z =0 Z =0 Z =0 Z =0 Z=1 Z =1 Z =0
A B X A+ B+ Z
0 0 0 0 1 0
Partially completed 1 0 0 0
state transition table 0 1 0 ? ? ?
based on the signal 1 1 1 0
trace 1 0 0 ? ? ?
1 0 1 1
1 1 0 1 0 1
1 ? ? ?
No. 8-31
Moore and Mealy
Machines
Formal Method
A+ = B (A + X) = A B + B X
B+ = Jb B + Kb B = (A xor X) B + X B
=ABX + ABX + BX
Z =AX + BX
Missing Transitions and Outputs:
State 01, Input 0 -> State 00, Output 1
State 10, Input 0 -> State 00, Output 0
A+ State 11, Input 1 -> State 11, Output 1
B+
No. 8-32
Moore and Mealy
Machines
ASM Chart for Mystery Mealy Machine
S0 = 00, S1 = 01, S2 = 10, S3 = 11
S0 00 S2 10
0
1 X
X
0 1
H. Z
H. Z S1 01 S3 11
H.Z
0 1 1
X X
0
No. 8-33
Moore and Mealy
Machines
Synchronous Mealy Machine
Clock
Xi Zk
Inputs Combinational
Outputs
Logic for
Outputs and
Next State
No. 8-34
Finite State Machine Word
Problems
Mapping English Language Description to Formal Specifications
No. 8-35
Finite State Machine Word
Problems
Finite String Pattern Recognizer
A finite string recognizer has one input (X) and one output (Z).
The output is asserted whenever the input sequence …010…
has been observed, as long as the sequence 100 has never been
seen.
X: 11011010010
Z: 00000001000
No. 8-36
Finite State Machine Word
Problems
Finite String Recognizer
Step 2. Draw State Diagrams/ASM Charts for the strings that must be
recognized. I.e., 010 and 100.
No. 8-37
Finite State Machine Word
Problems
Finite String Recognizer
Exit conditions from state S3:
if next input is 0 then have …0100 (state S6)
if next input is 1 then have …0101 (state S2)
No. 8-38
Finite State Machine Word
Problems
Finite String Recognizer
Exit conditions from S1: recognizes strings of form …0 (no 1 seen)
loop back to S1 if input is 0
No. 8-39
Finite State Machine Word
Problems
Finite String Recognizer
S2, S5 with incomplete transitions
No. 8-40
Finite State Machine Word
Problems
Finite String Recognizer
Review of Process:
No. 8-41
Finite State Machine Word
Problems
Complex Counter
A sync. 3 bit counter has a mode control M. When M = 0, the counter
counts up in the binary sequence. When M = 1, the counter advances
through the Gray code sequence.
No. 8-42
Finite State Machine Word
Problems
Complex Counter
One state for each output combination
Add appropriate arcs for the mode control
S0 000
S1 001
H.Z 0
0 1
M
S2 010 S3 011
H.Z 1 H.Z 1
H.Z 0
0
M
1
M
1
0
S6 110
H.Z 2 S4 100
H.Z 1 H.Z 2
1
S7 111 M
H.Z 2 0
H.Z 1
H.Z 0 S5 101
H.Z 2
0 1 H.Z 0
M
0 1
M
No. 8-43
Finite State Machine Word
Problems
Traffic Light Controller
Assume you have an interval timer that generates a short time pulse
(TS) and a long time pulse (TL) in response to a set (ST) signal. TS
is to be used for timing yellow lights and TL for green lights.
No. 8-44
Finite State Machine Word
Problems
Traffic Light Controller
Picture of Highway/Farmroad Intersection:
Farmroad
C
HL
FL
Highway
Highway
FL
HL C
Farmroad
No. 8-45
Finite State Machine Word
Problems
Traffic Light Controller
Tabulation of Inputs and Outputs:
Input Signal Description
reset place FSM in initial state
C detect vehicle on farmroad
TS short time interval expired
TL long time interval expired
No. 8-46
Finite State Machine Word
Problems
Traffic Light Controller
Refinement of ASM Chart:
Start with basic sequencing and outputs:
S0 S3
H.HG H.HR
H.FR H.FY
S1 S2
H.HY H.HR
H.FR H.FG
No. 8-47
Finite State Machine Word
Problems
Traffic Light Controller
Determine Exit Conditions for S0:
Car waiting and Long Time Interval Expired- C · TL
S0 S0
H.HG H.HG
H.FR H.FR
C · TL
0 0
TL TL • C
1 1
0
C H.ST
1
H.ST S1
H.HY
H.FR
S1
H.HY
H.FR
S1 S2
H.HY H.ST H.HR
H.FR H.FG
0 1
TS
No. 8-49
Finite State Machine Word
Problems
Traffic Light Controller
S2 Exit Condition: no car waiting OR long time interval expired
S0 S3
H.HG H.HR
H.FR H.ST H.FY
0 1 0
TL • C TS
H.ST H.ST
S1 S2
H.HY H.ST H.HR
H.FR H.FG
0 1 0
TS TL + C
1
TL • C
"3 bit serial lock controls entry to locked room. Inputs are RESET,
ENTER, 2 position switch for bit of key data. Locks generates an
UNLOCK signal when key matches internal combination. ERROR
light illuminated if key does not match combination. Sequence is:
(1) Press RESET, (2) enter key bit, (3) Press ENTER, (4) repeat (2) &
(3) two more times."
Inputs: Outputs:
Reset Unlock
Enter Error
Key-In
L0, L1, L2
No. 8-53
Finite State Machine Word
Problems
Digital Combination Lock
Enumeration of states:
START
START entered on RESET
0
Enter
0
1
COMP0
N
Continue on if Key-In matches L0
KI = L0
Y
No. 8-54
Finite State Machine Word
Problems
Digital Combination Lock
COMP0 IDLE1
Path to unlock:
N 0
KI = L 0 Enter
Y 1
IDLE0 COMP2
Wait for
Enter Key press
0 N
Enter KI = L2
1 Y
COMP1 DONE
H.Unlock
N 0
Compare Key-IN KI = L1 Reset
Y 1
START
No. 8-55
Finite State Machine Word
Problems
Digital Combination Lock
Now consider error paths
0 0
Enter 0 Reset
Enter
1 1 1
ERROR1 ERROR2
START
No. 8-56
Finite State Machine Word Reset + Enter
Problems
Digital Combination Lock Reset
Start
Reset • Enter
Comp0
KI = L0 KI ° L0
Enter Enter
Idle0 Idle0'
Enter Enter
Comp1 Error1
Equivalent State Diagram KI ° L1
KI = L1
Enter
Enter
Idle1 Idle1'
Enter Enter
Comp2 Error2
KI = L2 KI ° L2
Reset Reset
Done Error3
[Unlock] [Error]
Reset Reset
Start Start
No. 8-57
Chapter Review
Basic Timing Behavior an FSM
when are inputs sampled, next state/outputs transition and stabilize
Moore and Mealy (Async and Sync) machine organizations
outputs = F(state) vs. outputs = F(state, inputs)
First Two Steps of the Six Step Procedure for FSM Design
understanding the problem
abstract representation of the FSM
Word Problems
understand I/O behavior; draw diagrams
enumerate states for the "goal"; expand with error conditions
reuse states whenever possible
No. 8-58