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 there’s 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 1’s)
• Datapath: 4-bit counter “0000”
4 4

0 1
CLK MUX CR

2 4
TA LA
Traffic 2 4-bit D-FFs “0001”
TB Light LB 4 4
Controller CR
CT
+
4-input AND
4
Reset CT
FSM State Transition Diagram
TA TB
TA TB CT
TA TB
S0 TA TB S1 CT S2
LA = G LA = G LA = Y
Reset LB= R LA LB LB= R LA LB LB= R LA LB
CR= 1 CR= 0 CR= *

TA TB
S5 S4 TA TB S3 TA TB
LA = R CT LA = R LA = R
LB= Y LA LB LB= G LA LB LB= G LA LB
CR= * CR= 0 CR= 1

CT
TA TB
String Recognition
• Simple case: recognize 1101

1 1 0 1
“” “1” “11” “110” “1101”
Reset 0 0 0 0 1

0 1
0
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

1 1 0 1
“” “1” “11” “110” “1101”
Reset 0 0 0 0 1

“10” 1 “101” 1 “1011”


0 1 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
0 1

1 1 1 1
“” “1” “11” “111” “1111”
Reset 0 0 0 0 1
0
0 0 0
1
“10” 1 “101” 1 “1011”
0 0 1 1

0
String Recognition using Shift Registers
• Example: 1111, 1011, 101
1. Use N bit shift register if longest pattern has N bits
2. Create an AND gate for pattern
3. OR together AND gates
4. Caveat: result is invalid for the first N cycles
S3 S2 S1 S0

FF FF FF FF INPUT

OUTPUT

You might also like