CS 362: Computer DesignLecture 11: Finite State Machines
Mitchell TheysUniversity of Illinois at Chicago
October 2nd, 2018
Announcements
State Machines
• With state, can no longer represent digital functions with an equation alone
• Instead, we use a state machine
e f
b
b’
bb’
State Machines
• Set of states – circles in the picture• Set of transitions – arcs starting and ending at a state in
the picture• Start state – the arrow pointing to a state• Input – listed on the arcs• Output – can be in the states or on the arcs
e f
b
b’
bb’
y = 0 y = 1
Clocked FSMs
• In this class, we will assume FSMs change state on the rising edge of the clock
• On the rising edge, FSMs transition to the next state based on input
Assume input on b is 010011. What is the output?
A. 0010011B. 0100100
C. 100100D. None of the above
e f
g
b’
b b
b
b’
b’
y = 0
y = 0
y = 1
We want y to be the inverse of the input. Select the correct set of
transitions.
clicker w x y z
A b’ b’ b b
B b’ b b’ b
C b b b’ b’
D b b’ b b’
E None of the above
e gy = 0 y = 1
w
xyz
State Machines in Digital Logic
• Use flipflops to store state
• Use combinational logic to change state on inputs, produce output
Converting FSMs to Circuits
• Create a truth table from the FSM– Include current state as input, next state as output
• Create a set of equations for the truth table
• Convert equations into a circuit
Convert to Truth Table: Inputs
e f
g
b’
b b
b
b’
b’
y = 0
y = 0
y = 1
• Give each state an identifier
• The set of inputs for the truth table is each state, plus the input to the machine
Convert to Truth Table: Outputs
e00
f01
g10
b’
b b
b
b’
b’
y = 0
y = 0
y = 1
• The set of outputs is the identifier of the state we transition to, plus output
p1 p0 b
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Pick the Correct Truth Tablee0
g1
y = 0 y = 1
b’
b’bb
p b n y
0 0 1 0
0 1 0 0
1 0 1 1
1 1 0 1
p b n y
0 0 1 0
0 1 0 0
1 0 0 1
1 1 1 1
p b n y
0 0 1 1
0 1 0 0
1 0 0 0
1 1 1 1
p b n y
0 0 1 1
0 1 0 0
1 0 1 1
1 1 0 0
A B C D
p = previous stateb = inputn = next statey = output
E. None of the above
Building the circuit
• Register to hold the current state
• Combinational logic to decide state transitions and output
Building the Logic Circuit
e00
f01
g10
b’
b b
b
b’
b’
y = 0
y = 0
y = 1
• Find the equations for each output from the truth table– y =– n0 =– n1 =
p1 p0 b n1 n0 y
0 0 0 0 1 0
0 0 1 1 0 0
0 1 0 0 1 1
0 1 1 1 0 1
1 0 0 0 0 0
1 0 1 1 0 0
1 1 0 X X X
1 1 1 X X X
Building the Logic Circuit
e00
f01
g10
b’
b b
b
b’
b’
y = 0
y = 0
y = 1
• Create the circuit from the equations
y = p1’p0n0 = p1’b’n1 = b
Pick the Correct Equationse0
g1
y = 0 y = 1
b’
b’bb
p b n y
0 0 1 0
0 1 0 0
1 0 1 1
1 1 0 1
p = previous stateb = inputn = next statey = output A. y = p, n = b’
B. y = pb’ + pb, n = p’b’ + pb’
C. y = pb’n+pbn’, n = p’b’y’ + pb’y
D. y = pb’n+pbn’, n = b’
E. None of the above
Pick the correct circuite0
g1
y = 0 y = 1
b’
b’bb
y = p,n = b’
register
b
n
p
y
register
n
y
p
b
register
n
p
y
b
A B C
Converting Circuits to FSMs
• We can convert sequential circuits to FSMs– Must have a register and logic
• Write the logic as a truth table
• Give a state name to the register/bit combinations
• List output values for each state
• Draw transitions
Create Truth Table
p1
zb
p0
n0n1
p1 p0 b n1 n0 z
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Group Into States
p1
zb
p0
n0n1
p1 p0 b n1 n0 z
0 0 0 0 0 0
0 0 1 0 1 0
0 1 0 0 0 0
0 1 1 1 0 0
1 0 0 1 1 1
1 0 1 1 0 1
1 1 0 0 0 1
1 1 1 1 0 1
Write output for each state
p1 p0 b n1 n0 z
0 0 0 0 0 0
0 0 1 0 1 0
0 1 0 0 0 0
0 1 1 1 0 0
1 0 0 1 1 1
1 0 1 1 0 1
1 1 0 0 0 1
1 1 1 1 0 1
00 01
1011
Develop transitions from truth table
p1 p0 b n1 n0 z
0 0 0 0 0 0
0 0 1 0 1 0
0 1 0 0 0 0
0 1 1 1 0 0
1 0 0 1 1 1
1 0 1 1 0 1
1 1 0 0 0 1
1 1 1 1 0 1
00 01
1011
z = 0 z = 0
z = 1z = 1
Pick the correct column for z
p1
zb
p0
n0n1
p1 p0 b
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
z
0
0
0
0
1
1
1
1
z
0
0
0
0
1
1
0
0
z
0
0
1
1
0
0
0
0
z
0
1
0
0
0
1
0
0
A B C D
E. None of the above
Pick the correct column for n0
p1
zb
p0
n0n1
p1 p0 b
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
n0
1
1
0
0
1
1
0
0
n0
0
0
0
0
1
0
0
0
n0
0
1
0
0
1
0
0
0
n0
0
0
0
1
0
1
0
0
A B C D
E. None of the above
Pick the correct column for n1
p1
zb
p0
n0n1
p1 p0 b
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
n0
1
1
0
0
1
1
0
0
n0
0
0
0
0
1
0
0
0
n0
0
1
0
0
1
0
0
0
n0
0
0
0
1
0
1
0
0
A B C D
E. None of the above
The output will be 1 for which state?
p1 p0 b n1 n0 z
0 0 0 0 0 0
0 0 1 0 1 0
0 1 0 0 0 0
0 1 1 1 0 0
1 0 0 0 1 1
1 0 1 1 0 1
1 1 0 0 0 0
1 1 1 0 0 0
A. 00B. 01C. 10D. 11E. More than one of the above
Which state machine is correct?
p1 p0 b n1 n0 z
0 0 0 0 0 0
0 0 1 0 1 0
0 1 0 0 0 0
0 1 1 1 0 0
1 0 0 0 1 1
1 0 1 1 0 1
1 1 0 0 0 0
1 1 1 0 0 0
00 01
1011
b’b
b’
b’b
b
00 01
1011
b’b
b’b’
b
bb’
b
00 01
1011
b’b
b’
b’
b
b
A
B
C
00 01
1011
b
b’
b’
b
bD
E. None of the above
Reading
• Next lecture: Encoding Finite State Machines– Read 4.9 – 4.13