Lecture 3 FSM
Lecture 3 FSM
1
10/18/2023
Step Description
Step 1: Create a truth table or equations, whichever is
Capture the
Capture most natural for the given problem, to describe
function
behavior the desired behavior of each output of the
Like we had for combinational logic.
2
10/18/2023
Inputs: b; Outputs: x
Three Cycle High Laser Timer
x=0
Turn on laser for three cycles whenever clk^
button is pressed Off b’*clk ^
State Off Off Off Off Off On1 On2 On3 Off
Outputs:
x
Inputs: b; Outputs: x
Showing rising clock on every transition:
x=0
cluttered clk ^
Make implicit -- assume every edge has Off b’ *clk ^
rising clock, even if not shown
b*clk ^
What if we wanted a transition without a clk ^ clk ^
x=1 x=1 x=1
rising edge
We don’t consider such asynchronous FSMs -- On1 On2 On3
less common, and advanced topic
Only consider synchronous FSMs -- rising
edge on every transition
Inputs: b; Outputs: x
x=0
Off b’
a
b
x=1 x=1 x=1
3
10/18/2023
K1 K2 K3 K4
4
10/18/2023
clk clk
Inputs Inputs
a
a
State Wait Wait K1 K2 K3 K4 Wait Wait State Wait Wait K1 K2 K3 K4 Wait K1
Outputs Output a
r r
Inputs: a; Outputs: r
Wait
r=0 a’
a
K1 K2 K3 K4 clk
r=1 r=1 r=0 r=1 Inputs
a
State ?? ?? ?? ?? ?? ?? ?? K1
10
5
10/18/2023
11
List states
Give meaningful names, show initial state
Optionally add some transitions if they help
Create transitions
For each state, define all possible transitions leaving that state.
Refine the FSM
Execute the FSM mentally and make any needed improvements.
12
6
10/18/2023
u=0
ar (a = 1 & r = 1)
ab ag ar
Red1 Blue Green Red2
Capture as FSM s 1
Start u
List states r Door
Red Code
Create transitions Green
g detector lock
Blue b
a
Inputs: s, r, g, b, a
Outputs: u
Wait ar'
u=0 s'
s
a
Start
u=0 a'
ar
ab ag ar
Red1 Blue Green Red2
7
10/18/2023
Capture as FSM s 1
Start
u
List states r Door
Red Code
Create transitions Green
g detector lock
Repeat for remaining Blue b
states a
Refine FSM a
Mentally execute
Works for normal
sequence
Inputs: s, r, g, b, a
Check unusual cases
Outputs: u
Wait
u=0 s'
s
ar' ab' ag' ar'
Start
u=0 a'
ar
ab ag ar
Red1 Blue Green Red2
a' a' a'
u=0 u=0 u=0 u=1
15
Inputs: s, r, g, b, a
Outputs: u
Wait
u=0 s'
s
ar' ab' ag' ar'
Start
u=0 a'
ar
ab ag ar
Red1 Blue Green Red2
a' a' a'
u=0 u=0 u=0 u=1
16
8
10/18/2023
Inputs: s,r,g,b,a;
Outputs: u
Wait
u=0 s s’ ar’ ab’ ag’ ar’
Start
a’
u=0
ar
ab ag ar
Red1 Blue Green Red2
a’ a’ a’
u=0 u=0 u=0 u=1
outputs
O
FSM
I
FSM
Combinational
Use standard architecture logic
State register -- to store the present state
S
Combinational logic -- to compute outputs, and a m
next state m-bit m
clk
state register
For laser timer FSM
2-bit state register, can represent four states N
Known as controller
Inputs: b; Outputs: x
inputs
outputs
b x
FSM
FSM
x=0 Combinational n1
logic
Off b’ n0
s1 s0
b
clk State register
x=1 x=1 x=1
18
9
10/18/2023
Step Description
Step 1:
Capture the FSM Create an FSM that describes the desired behavior of the
Capture
behavior controller.
Step 2: 2A: Set up Use state register of appropriate width and combinational logic. The
Convert architecture logic’s inputs are the state register bits and the FSM inputs; outputs
to circuit are next state bits and the FSM outputs.
2B: Encode Assign unique binary number (encoding) to each state. Usually use
the states fewest bits, assign encoding to each state by counting up in binary.
2C: Fill in Translate FSM to truth table for combinational logic such that the logic
the truth table will generate the outputs and next state signals for the given FSM.
Ordering the inputs with state bits first makes the correspondence
between the table and the FSM clear.
19
b x
FSM
FSM
20
10
10/18/2023
outputs
inputs
FSM
b x
FSM
Combinational n1
logic
n0
s1 s0
clk State register
21
b x
FSM
Combinational n1
logic
n0
s1 s0
clk State register
22
11
10/18/2023
outputs
inputs
FSM
b x
FSM
Combinational n1
FSM inputs logic n1 a
n0
s1 s0
clk State register
n0
s1 s0
x = s1 + s0
n1 = s1’s0 + s1s0’
n0 = s1’s0’b + s1s0’
23
b x b x b x
0 0 0
0 0 1 0 1 1
0 0 1
0 0 1
n1 n1 n1
0 0 1
0 0 0 a
0 1 0
n0 n0 n0
0 1 0
0 0 0
s1 s0 s1 s0 s1 s0
clk clk clk
0 0 0 0 0 1
0 0 0 1 1 0
Input (b):
Output (x):
24
12
10/18/2023
b x b x b x
0 0 0
0 0 1 0 1 1
0 0 1
0 0 1
n1 n1 n1
0 0 1
0 0 0
0 1 0
n0 n0 n0
0 1 0
0 0 0
s1 s0 s1 s0 s1 s0
clk clk clk
0 0 0 0 0 1
0 0 0 1 1 0
Input (b):
Output (x):
25
Want simple sequential circuit that converts button press to single cycle
duration, regardless of length of time that button was actually pressed
We assumed such an ideal button press signal in earlier example,
like the button in the laser timer controller
26
13
10/18/2023
Check Yourself –
Controller Example: Sequence Generator
Want generate sequence 0001, 0011, 1100, 1000, (repeat)
Each value for one clock cycle
Common, e.g., to create pattern in 4 lights, or control magnets of a “stepper motor”
27
14