Top Banner
FSM Word Problems
12

FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

Feb 13, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

FSM Word Problems

Page 2: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

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)

Page 3: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

FSM Blackbox

• Inputs: CLK, TA, TB

• Outputs: LA, LB

Page 4: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

FSM State Transition Diagram

Page 5: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

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 …

Page 6: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

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

Traffic Light

Controller

TA

TB

LA

LB

CLK

Reset

+

2

2

4

MUX

4

4

“0001”

4 4

“0000”

0 1

CR

4

CT

CT CR

4-bit D-FFs

4-input AND

Page 7: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

FSM State Transition Diagram

S0 LA = G LB= R CR= 1

S1 LA = G LB= R CR= 0

S2 LA = Y LB= R CR= *

S3 LA = R LB= G CR= 1

S4 LA = R LB= G CR= 0

S5 LA = R LB= Y CR= *

Reset

CT

CT

CT

CT

TA TB

TA TB

TA TB

TA TB

TA

TB TA

TB

TA TB

TB TA

LA LB LA LB LA LB

LA LB LA LB LA LB

Page 8: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

String Recognition

• Simple case: recognize 1101

“ ” 0

“1” 0

“11” 0

Reset

1 “110”

0

1 0 1 “1101”

1

1

1

0 0

0

0

Page 9: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

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

Page 10: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

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

“ ” 0

“1” 0

“11” 0

Reset

1 “110”

0

1 0 1 “1101”

1

“10” 0

0

“101” 1

“1011” 1

1 1

Page 11: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

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

“11” 0

Reset

1 “111”

0

1 1 1 “1111”

1

“10” 0

0

“101” 1

“1011” 1

0 0

0

1 0

1 1

0

0

1

0

Page 12: FSM Word Problems - University of California, San Diego · FSM Word Problems . FSM Example •Traffic light controller –Traffic sensors: T A, T B (TRUE when there’s traffic) –Lights:

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

FF FF FF FF

S2 S1 S0

INPUT

OUTPUT