In Class - Finite State Machine Examples
In Class - Finite State Machine Examples
ENGN3213/6213
Digital Systems and Microprocessors
Whats on today
Three complete examples of finite state
machine designs
An alarm system
A pedestrian traffic controller
A vending machine
ENGN3213/6213 - Week 5
Resources
Wakerly Ch. 7.7 for yet another example
of FSM design
Wakerly Ch. 7.13 describes standards for
Verilog coding of state machines
ENGN3213/6213 - Week 5
ENGN3213/6213 - Week 5
States:
Quiet (Armed)
Sound alarm (Sound)
Outputs:
Alarm bell (on/off)
ENGN3213/6213 - Week 5
Alarm
Reset
Trigger
S0
Armed
0
Trigger
S1
Sound
1
Reset AND
NOT(Trigger)
ENGN3213/6213 - Week 5
A=Armed
S=Sound
T=Trigger signal
R=Reset signal
ENGN3213/6213 - Week 5
State
Input
Next
state
Output
TR
OFF
TR
OFF
TR
OFF
TR
OFF
TR
ON
TR
ON
TR
ON
TR
ON
8
T
inputs
TR
00 01
11
10
state
S
RS
T
9
S*
T
clk
ENGN3213/6213 - Week 5
CK Q
10
ENGN3213/6213 - Week 5
11
ENGN3213/6213 - Week 5
12
Outputs
The 5 lights: R,O,G, WALK, HALT
States
13
Request
Request
s0
00
G, HALT
s1
01
O, HALT
Timer
Timer
s2
11
R,WALK
s3
10
R,HALT
Timer
14
ENGN3213/6213 - Week 5
State
S[1:0]
Input
Next
state
Output
00
Req
01
G,H
01
Req
11
O,H
11
Req
10
R,W
10
Req
00
R,H
00
Req
00
G,H
01
Req
11
O,H
11
Req
10
R,W
10
Req
00
R,H
15
input
Req
00 01
11
00 01
11
10
input
Req
state
S
10
0
S[1]* =S[0]
0
S[0]* = S[1](Req+S[0])
16
S[1]
CK
Req
S*[0]
S[0]
CK C
CK
ENGN3213/6213 - Week 5
17
Output
00
G,H
01
O,H
11
R,W
10
R,H
S[0]
R
O
W
H
ENGN3213/6213 - Week 5
18
Q
CK
19
20
21
22
abbreviation
output
abbreviation
coin
return
CN
RTN
sum<75
sum=75
sum>75
change-available
SM0
SM1
SM2
CA
release-candy
return-change
return-all-coins
RC
RCH
RAC
ENGN3213/6213 - Week 5
23
Description
Next state
Release
candy
Return
all coins
Return
change
s0
idle
s0 if CN=0, RTN=0
s1 if CN=1, RTN=0
s5 if CN=0, RTN=1
s1
s0 if SM0=1
s2 if SM1=1
s3 if SM2=1
s2
release candy
s0
s3
s5 if CA=0
s4 if CA=1
s4
return change
s2
s5
s0
ENGN3213/6213 - Week 5
24
State code
(ABCDEF)
Description
s0
000001
idle
s1
000010
s2
000100
release candy
s3
001000
s4
010000
return change
s5
100000
ENGN3213/6213 - Week 5
25
CNRTN
CNRTN
s5
return all coins
100000 (A)
s0 idle
000001 (F)
Reset
SM0
CN
s2
return candy
000100 (D)
s4
return change
010000 (B)
SM1
s1 coin in
000010 (E)
ENGN3213/6213 - Week 5
SM2
CA
CA
s3
check change
001000 (C)
26
CN
RTN
DA
D Q
CK
QA
DB
D Q
CK
QB
DC
D Q
CK
QC
DD
D Q
CK
QD
DE
D Q
CK
QE
DF
D Q
CK
QF
SM0
SM1
Next state
logic
SM2
CA
Reset
ENGN3213/6213 - Week 5
RC
Output
logic
RCH
RAC
clk
27
Next-state logic:
DA = (QF CN RTN) + (QC CA)
(the next state will be A (s5) if the current state is C (s3) and CA=0 or if the current state
is F(s0) and RTN=1 with CN=0)
DB = QC CA
DC = QE SM2
DD = QE SM1 + QB
DE = QF CN
DF = (QF CN RTN) + (QE SM0) + QD + QA
ENGN3213/6213 - Week 5
28
ENGN3213/6213 - Week 5
29
Summing up
3 examples of state machine design
The main state machine design workflow ideas:
ENGN3213/6213 - Week 5
30