Finite State Machines Prof. Sirer COMP 303 Koç University.
-
Upload
derrick-payne -
Category
Documents
-
view
220 -
download
0
Transcript of Finite State Machines Prof. Sirer COMP 303 Koç University.
Finite State Machines
Prof. Sirer
COMP 303
Koç University
Finite State Machines
An electronic machine which has external inputs externally visible outputs internal state
Output and next state depend on inputs current state
Designing an FSM
Draw a state diagram
Write down state transition table
Assign numbers to states
Determine logic equations for all flip-flops and outputs
A Simple Example
Goal: flash hello on LEDsInputs: clockOutputs: Just one 7-segment LED
Flash “h” then “e” then “l” then “l” then “o” h = <0011101> e = <0111110> l = <0010110> o = <1110111>
o0
o1
o2
o3
o4
o5
o6
HELLObox: State Diagram
Determine the transitions label all edges (transitions) with the inputs that cause
them, unlabeled edges are unconditional transitions show start state
S0 S1 S2 S3 S4
<0011101>
H
<0111110>
E
<0010110>
L
< 0010110 >
L
<1110111>
O
HELLObox: State Table
CurrentState
NextState
Output
S0 S1 0011101
S1 S2 0111110
S2 S3 0010110
S3 S4 0010110
S4 S0 1110111
Build state table rote encoding of
the state diagram
HELLObox: State Assignment 1
Current
State
NextState
Output
000 001 0011101
001 010 0111110
010 011 0010110
011 100 0010110
100 000 1110111
Assign bit patterns to states that would make the resulting device simple One option is shown
Determine logic equations for every bit of output and next state, for every flip-flop and output
HELLObox #1
10 bits of information (7 outputs + 3 bits of next state) are computed by the combinatorial circuit
All 10 bits have non-trivial logic equations
flip-flops
com
bina
tiona
lci
rcui
t
o0o1o2o3o4o5
o6
HELLObox: State Assignment 2
Current
State
NextState
Output
00111010
01111100
0011101
01111100
00101100
0111110
00101100
00101101
0010110
00101101
11101110
0010110
11101110
00111010
1110111
Assign bit patterns to states that would make the resulting device simpleHere, we use far more bits than necessary to simplify the
combinatorial circuit
HELLObox #2
15 bits of information (7 outputs + 8 bits of next state) are computed by the combinatorial circuit
8 bits have non-trivial logic equations all 7 outputs are simple
pass-throughs
flip-flops
com
bina
tiona
lci
rcui
t
o0o1o2o3o4o5
o6
A Traffic Light
There is a large avenue and a Hospital ER on a side street
The avenue traffic light should be green at all times
Except when an ambulance is waiting on the side street
A sensor detects a waiting ambulance
Design the light controller
H
a
A Traffic Light
There is a large avenue and a Hospital ER on a side streetThe avenue traffic light should be green at all timesExcept when an ambulance is waiting on the side street
H
A Traffic Light
There is a large avenue and a Hospital ER on a side streetThe avenue traffic light should be green at all timesExcept when an ambulance is waiting on the side street
H
A Traffic Light
There is a large avenue and a Hospital ER on a side streetThe avenue traffic light should be green at all timesExcept when an ambulance is waiting on the side street
H
A Traffic Light
There is a large avenue and a Hospital ER on a side streetThe avenue traffic light should be green at all timesExcept when an ambulance is waiting on the side street
H
A Traffic Light
There is a large avenue and a Hospital ER on a side streetThe avenue traffic light should be green at all timesExcept when an ambulance is waiting on the side street
H
A Traffic Light
There is a large avenue and a Hospital ER on a side streetThe avenue traffic light should be green at all timesExcept when an ambulance is waiting on the side street
H
A Traffic Light
There is a large avenue and a Hospital ER on a side streetThe avenue traffic light should be green at all timesExcept when an ambulance is waiting on the side street
H
A Traffic Light
One input a
Six outputs (AR, AO, AG, HR, HO, HG)
001100 010100 100110 100001 100010 110100
0
1 0 & 1 0 & 1 0
1
0 & 1
0 & 1
S0 S1 S2 S3 S4 S5
FSM: Serial Adder
Add two input bit streams streams are sent with least-significant-bit
(lsb) first
…10110
…01111…00101
FSM: State Diagram
Two states: S0 (no carry), S1 (carry in hand)Inputs: a and bOutput: z Arcs labelled with input bits a and b, and output z
S0 S100/0
10/1 01/1 10/0 01/0
11/1
00/1
11/0
Serial Adder: State Table
Write down all input and state combinations
a b state
z next
state
0 0 S0 0 S0
0 1 S0 1 S0
1 0 S0 1 S0
1 1 S0 0 S1
0 0 S1 1 S0
0 1 S1 0 S1
1 0 S1 0 S1
1 1 S1 1 S1
Serial Adder: State Assignment
Two states, so 1-bit is sufficient A single flip-flop will
encode the state
a b s z s’
0 0 0 0 0
0 1 0 1 0
1 0 0 1 0
1 1 0 0 1
0 0 1 1 0
0 1 1 0 1
1 0 1 0 1
1 1 1 1 1
Serial Adder: Circuit
Equationsz = abs + abs + abs +
abs
s’ = abs + abs + abs + abs
clk
Q D
za
bcombinational
logic
s s’