fsm word problems - university of california, san diego · fsm word problems . fsm example...

12
FSM Word Problems

Upload: others

Post on 13-Feb-2020

24 views

Category:

Documents


1 download

TRANSCRIPT

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

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

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

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

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

“ ” 0

“1” 0

“11” 0

Reset

1 “110”

0

1 0 1 “1101”

1

“10” 0

0

“101” 1

“1011” 1

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

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