Ch8b Finite State Machine
Ch8b Finite State Machine
1
Timing w
diagram 0
1
z
0
Understanding the problem (Step 0)
The output z=1 if w=1 during two immediately preceding
clock cycles; otherwise z=0
Next State
Present State Output
w=0 w=1
Initial State (no 1’s) Initial State Got 1 1’s 0
Got 1 1’s Initial State Got 2 1’s 0
Got 2 1’s Initial State Got 2 1’s 1
Understanding the problem (Step 0)
The output z=1 if w=1 during two immediately preceding
clock cycles; otherwise z=0
Next State
Present State Output
w=0 w=1
Initial State (no 1’s) Initial State Got 1 1’s 0
Got 1 1’s Initial State Got 2 1’s 0
Got 2 1’s Initial State Got 2 1’s 1
w = 1
w = 0 Az= 0 Bz= 0
w = 0
w = 0 w = 1
Present Next State
Output
State w=0 w=1
A A B 0 Cz = 1
B A C 0
C A C 1
w = 1
State Assignment (Step 2 and 4, we skip step 3)
We need at least two FF’s
State transition/output table
for three states
Next State
Let’s pick two FF’s, call Present
Output
State w=0 w=1
them y1 and y2
y2 y1 Y2 Y1 Y2 Y1 z
Assign states to 0 0 0 0 0 1 0
combinations of (y1,y2): 0 1 0 0 1 0 0
A: (0,0) 1 0 0 0 1 0 1
B: (0,1) 1 1 d d d d d
C: (1,0)
y2,y1 = present state
(note - we will never need
the combination 1,1) Y2,Y1 = next state
Excitation Table (Step 5 and 6)
Using D flip-flops: Excitation/output table
Characteristic Equation Q*=D Next State
Present
If we want next state to be Y State
Output
then w=0 w=1
Y must be the input to the FF’s y2 y1 D2 D1 D2 D1 z
Now derive logic functions 0 0 0 0 0 1 0
for 0 1 0 0 1 0 0
Y1(y2,y1,w) 1 0 0 0 1 0 1
Y2(y2,y1,w)
1 1 d d d d d
z(y2,y1)
for D flip-flops, excitation table is the
same as state transition table
Q* = D so Y = D
Excitation/Output Equations (Step 7)
y 2 y1
w 00 01 11 10 Present Next State
Output
0 0 0 d 0 State w=0 w=1
1 1 0 d 0 y2 y1 D2 D1 D2 D1 z
0 0 0 0 0 1 0
D1 wy1 y2
0 1 0 0 1 0 0
y2y1 1 0 0 0 1 0 1
w 00 01 11 10
1 1 d d d d d
0 0 0 d 0
1 0 1 d 1
y1
D2 wy1 wy2 y2 0 1
0 0 0
1 1 d
z y2
Implementation (Step 8)
D2 wy1 wy2 Y2
D Q
y2
z z y2
D2 w( y1 y2 )
Q
D1 wy1 y2
Y1 y1
w D Q
Clock
Resetn
Present Next State
Output
State w=0 w=1
Timing Diagram y2 y1 Y2 Y1 Y2 Y1 z
A 0 0 0 0 0 1 0
B 0 1 0 0 1 0 0
C 1 0 0 0 1 0 1
D 1 1 d d d d d
CLK
y1
y2
z
A A A B A B C A
Same Problem different implementation
This time use JK FF Present Next State
Output
State w=0 w=1
From Step 5
y2 y1 Y2 Y1 Y2 Y1 z
Select JK FF 0 0 0 0 0 1 0
Q* = JQ’ + K’Q 0 1 0 0 1 0 0
So 1 0 0 0 1 0 1
Y2 = J2y’2 + K’2y2 1 1 d d d d d
Y1 = J1y’1 + K’1y1
What JK input we
must apply to
produce transition
from Q → Q*?
State table
Excitation Table (Step 6)
Present Next State
Output
JK transitions (y → Y) State w=0 w=1
0 → 0 : JK = 0d y2 y1 Y2 Y1 Y2 Y1 z
0 0 0 0 0 1 0
0 → 1 : JK = 1d
0 1 0 0 1 0 0
1 → 0 : JK = d1
1 0 0 0 1 0 1
1 → 1 : JK = d0
1 1 d d d d d
Excitation table
y2 y 1 y2 y1
w 00 01 11 10 w 00 01 11 10
0 0 d d 0 0 0 0 d d
y1
1 1 d d 0 1 0 1 d d y2 0 1
0 0 0
J1 wy2 J 2 wy1
y2y1 y2y1 1 1 d
w 00 01 11 10 w 00 01 11 10
0 d 1 d d 0 d d d 1 z y2
1 d 1 d d 1 d d d 0
K1 1 K2 w
Dram Circuit (Step 8)
J1 wy2
w Y1 y1
K1 1 J
SET
Q
J 2 wy1
vcc
K2 w
K CLR Q
z y2
Y2 SET
y2 z
J Q
K CLR Q
Example of Sequence Generator
Secure Car Key
Many new car keys
include tiny computer
chip
When car starts, car’s Present Next State Output
computer (under engine State a=0 a=1 r
hood) requests identifier Wait Wait First 0
from key by sending a First Second Second 1
signal to the key (Input a) Second Third Third 1
Key transmits identifier Third Fourth Fourth 0
Identifier a sequence of 4 Fourth Wait Wait 1
bits 1101 (Output r)
If not, computer shuts off
car
Example of Sequence Generator
Secure Car Key
FSM
Wait until computer Present Next State Output
requests ID (a=1) State a=0 a=1 r
Inputs: a; Outputs: r
Wait/0
1 0
First/1 Second/1 Third/0 Fourth/1
Example of Sequence Generator
Secure Car Key
Present Next State Output
FSM State a=0 a=1 r
5 states : 3 FF’s Wait Wait First 0
Assign States First Second Second 1
D2 y2 y1 y2 y1 D1 ay3 y2 y1 y2 y1
Example: Button Press Synchronizer
Button press
bi synchronizer
bo
controller
Button press
bi synchronizer
bo
controller
clk clk
clk clk