FSM Word Problems PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

FSM Word Problems

FSM Example
Traffic light controller
Traffic sensors: TA, TB (TRUE when theres traffic)
Lights: LA, LB
If LA = GREEN, then LA remains GREEN as
long as A has cars (i.e. TA = 1)
If LB = GREEN, then LB remains
GREEN as long as B has cars
(i.e. TB = 1)
Light colors change
(GREEN, RED)
(YELLOW, RED)
(RED, GREEN)

FSM Blackbox
Inputs: CLK, TA, TB
Outputs: LA, LB

FSM State Transition Diagram

Modified FSM Example


If LA is GREEN: Case

No cars on either A or B: change light after 16 cycles


Cars waiting on both A and B: change light after 16 cycles
Cars waiting only on A: LA stays GREEN
Cars waiting only on B: change light
Light colors change (GREEN, RED) (YELLOW, RED)
(RED, GREEN)

If LB is GREEN: Case

FSM Blackbox
FSM Inputs: CLK, TA, TB, CR (to reset counter)
FSM Outputs: LA, LB, CT (TRUE if count is 15, all 1s)
0000
Datapath: 4-bit counter
4

CLK

TB
CT

Traffic
Light
Controller

Reset

CR

TA

MUX

LA

4-bit D-FFs

LB
CR
4-input AND
CT

0001

+
4

FSM State Transition Diagram


TA TB

TA TB

CT
S0

Reset

LA = G
LB= R
CR= 1

S5
LA = R
LB= Y
CR= *

TA TB
TA TB

S1
LA = G
LB= R
CR= 0

LA LB

S4

CT

LA = R
LB= G
CR= 0

LA LB

CT

S2

CT

LA = Y
LB= R
CR= *

LA LB

TA TB
TA TB
LA LB

TA TB

S3
LA = R
LB= G
CR= 1

LA LB

TA TB
LA LB

String Recognition
Simple case: recognize 1101

0
0

Reset
0

1
0

11
0

110
0

1101
1

String Recognition
General rules:
1. Create string matching tree
2. State output = 1 if a pattern is contained along the path
3. Add failure edges: find longest suffix of string seen so
far and transition to the corresponding prefix state

String Recognition
Example: 1101, 1011, 101
1. Create string matching tree
2. State output = 1 if a pattern is contained along the path
3. Add failure edges: find longest suffix of string seen so
far and transition to the corresponding prefix state

Reset

1
0

11
0

110
0

1101
1

10
0

101
1

1011
1

String Recognition
Example: 1111, 1011, 101
1. Create string matching tree
2. State output = 1 if a pattern is contained along the path
3. Add failure edges: find longest suffix of string seen so
far and transition to the corresponding prefix state
1

Reset

1
0

11
0
0
10
0

111
0

1
0

1111
1

0
1

101
1

0
0

1
1011
1

String Recognition using Shift Registers


Example: 1111, 1011, 101
1.
2.
3.
4.

Use N bit shift register if longest pattern has N bits


Create an AND gate for pattern
OR together AND gates
Caveat: result is invalid for the first N cycles
S3

S2

S1

S0

FF

FF

FF

FF

OUTPUT

INPUT

You might also like