exercise q3.17

29
Exercise Q3.17 Design an FSM to keep track of the mood of four students working in the digital design lab. Each Student is either: 1. Happy (the circuit works) 2. Sad (the circuit blew up) 3. Busy (working on the circuit) 4. Clueless (confused about the circuit) 5. Asleep (face down on the circuit board) How many states does the FSM have ? What is the minimum number of bits necessary to represent these states ?

Upload: jagger

Post on 29-Jan-2016

75 views

Category:

Documents


0 download

DESCRIPTION

Exercise Q3.17. Design an FSM to keep track of the mood of four students working in the digital design lab. Each Student is either: 1. Happy (the circuit works) 2. Sad (the circuit blew up) 3. Busy (working on the circuit) 4. Clueless (confused about the circuit) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Exercise Q3.17

Exercise Q3.17• Design an FSM to keep track of the mood of four students working in the digital

design lab. Each Student is either:

1. Happy (the circuit works) 2. Sad (the circuit blew up) 3. Busy (working on the circuit) 4. Clueless (confused about the circuit) 5. Asleep (face down on the circuit board) • How many states does the FSM have ? What is the minimum number of bits

necessary to represent these states ?

Page 2: Exercise Q3.17

• Each Student can either be:

1. Happy (the circuit works). 2. Sad (the circuit blew up). 3. Busy (working on the circuit). 4. Clueless (confused about the circuit). 5. Asleep (face down on the circuit board). • So each student can be in five different states. Hence, we can say that overall

we have 625 distinct states (5 possible states for 4 students, 54 = 625). • For 625 distinct states, we need a minimum of ceiling(log2 625) = 10 bits.

Exercise Q3.17 Solution

Page 3: Exercise Q3.17

Exercise Q3.22

• Design an FSM that recognizes 1101 or 1110.– Draw state transition diagram (use as few states as possible).– Choose state encodings.– Write state transition and output table using the encodings.– Write next state equations and output equations.

Page 4: Exercise Q3.17

Exercise Q3.22 Solutuon

“ ”0

“1”0

“11”0

“110”0

“1101”1

“111”0

“1110”1

1 1 0 1

0

1

Reset

00 00 1

10

1

Page 5: Exercise Q3.17

“ ”0

“1”0

“11”0

“110”0

“1101”1

“111”0

“1110”1

1 1 0 1

0

1

0

Reset

1

0

0

00 1

1

State encoding:

A = 000 ; B = 001 ; C = 010 ; D = 011; E = 100 ; F = 101 ; G = 110

Page 6: Exercise Q3.17

State transition and output table:

Present StateS2 S1 S0

X = 0 X = 1FNS

S2+ S1+ S0+NS

S2+ S1+ S0+

0 0 0 0 0 0 0 0 1 0

0 0 1 0 0 0 0 1 0 0

0 1 0 0 1 1 1 0 1 0

0 1 1 0 0 0 1 0 0 0

1 0 0 0 0 0 0 1 0 1

1 0 1 1 1 0 1 0 1 0

1 1 0 0 0 0 1 0 0 1

Page 7: Exercise Q3.17

K-Maps:

0 1 0 0

1 1 0 0

0 0 X X

0 0 1 0

S0+ S0 XS2 S1 00 01 11 10

00

01

11

10

S0+ = S0’.S1.S2’ + X.S0’.S2’ + X.S0.S2

0 0 1 0

1 0 0 0

0 0 X X

0 1 0 1

S1+ S0 XS2 S1 00 01 11 10

00

01

11

10

S1+ = X.S0.S1’.S2’ + X’.S0’.S1.S2’ + X.S0’.S1’.S2 + X’.S0.S2

0 0 0 0

0 1 1 0

0 1 X X

0 0 1 1

S2+ S0 XS2 S1 00 01 11 10

00

01

11

10

S2+ = S0.S2 + X.S1

0 0

0 0

1 X

1 0

F S0 XS2 S1 00 01

00

01

11

10

F = S0’.S2

Page 8: Exercise Q3.17

Interview Q 3.1 (textbook)Design an FSM that recognizes 01010 when it is received serially.

“1”----0

“0”----0

“01”----0

“010”----0

“0101”----0

“01010-----

1

0 1 0 1

0

0

Reset

1

0

0

11 1

Page 9: Exercise Q3.17

Exercise Q3.27 (textbook)

• Design an FSM with one input, A, and two outputs, X and Y.

• X should be 1 if A has been 1 for at least three cycles altogether (not necessarily consecutively).

• Y should be 1 if A has been 1 for at least two consecutive cycles.

• Show your state transition diagram, encoded state transition table, next state and output equations, and schematic.

Page 10: Exercise Q3.17

Important : Understand the problem correctly

• X should be 1 if A has been 1 for at least three cycles altogether (not necessarily consecutively).• Y should be 1 if A has been 1 for at least two consecutive cycles.

Sample Pattern1 (assuming Moore Machine, output is 1 cycle delayed)Input A 0 1 1 0 1 1 1Output Y 0 0 0 1 1 1 1Output X 0 0 0 0 0 1 1

Sample Pattern2 A 0 1 1 1 0 0 1 Y 0 0 0 1 1 1 1

X 0 0 0 0 1 1 1

Sample Pattern3 A 1 0 1 0 1 1 0 Y 0 0 0 0 0 0 1

X 0 0 0 0 0 1 1

Sample Pattern4 A 1 0 1 1 1 1 0 Y 0 0 0 0 1 1 1

X 0 0 0 0 1 1 1

Page 11: Exercise Q3.17

0A----

X = 0Y = 0

0B----

X = 0Y = 0

0C-----

X = 0Y = 1

1

1 1A----

X = 0Y = 0

1B----

X = 0Y = 0

1C-----

X = 1Y = 1

1

1 2A----

X = 0Y = 0

2B----

X = 1Y = 0

2C-----

X = 1Y = 1

1

1

0

0

+3A----

X = 1Y = 0

+3B----

X = 1Y = 0

+3C-----

X = 1Y = 1

1

1―

0

0

10

0

0

0

0

Are there any equivalent states?

Redundant/Equivalent states are those which can not be observed/distinguished from the FSM I/O behavior

Page 12: Exercise Q3.17

0A----

X = 0Y = 0

0B----

X = 0Y = 0

0C-----

X = 0Y = 1

1

1 1A----

X = 0Y = 0

1B----

X = 0Y = 0

1C-----

X = 1Y = 1

1

1 2A----

X = 0Y = 0

2B----

X = 1Y = 0

2C-----

X = 1Y = 1

1

1

0

0

+3A----

X = 1Y = 0

+3B----

X = 1Y = 0

+3C-----

X = 1Y = 1

1

1―

0

0

10

0

0

0

0

Combining equivalent states 1c, 2c, 3c

Reason : once these states are reached, output is always X=1, Y=1 for any input sequence.

Page 13: Exercise Q3.17

0A----

X = 0Y = 0

0B----

X = 0Y = 0

0C-----

X = 0Y = 1

1

1

0

1A----

X = 0Y = 0

1B----

X = 0Y = 0

1C-----

X = 1Y = 1

1

1

2A----

X = 0Y = 0

2B----

X = 1Y = 0

1

1

0

0

1 +3A----

X = 1Y = 0

+3B----

X = 1Y = 0

1

1

0

0

0

0

0

0

Are there any more equivalent states?

Explicit Equivalence:Two states are equivalent if outputs, Next states areidentical for all input combinations.

Page 14: Exercise Q3.17

0A----

X = 0Y = 0

0B----

X = 0Y = 0

0C-----

X = 0Y = 1

1

1

0

1A----

X = 0Y = 0

1B----

X = 0Y = 0

1C-----

X = 1Y = 1

1

1

2A----

X = 0Y = 0

2B----

X = 1Y = 0

1

1

0

0

1 +3A----

X = 1Y = 0

+3B----

X = 1Y = 0

1

1

0

0

0

0

0

0

Combining equivalent states 2b, 3b

Reason : Next states, outputs areidentical for all input combinations.

Page 15: Exercise Q3.17

Common Mistake in Midterm2• Many got B = C = F, but didn’t get E = G• Their state table looked like this.

Present State

Next StateI=0 I=1

Output I = 0 I = 1

A A B 0 0B B E 1 1D B A 0 0E B D 1 0G B D 1 0

Explicit Equivalence E = G.

Page 16: Exercise Q3.17

0A----

X = 0Y = 0

0B----

X = 0Y = 0

0C-----

X = 0Y = 1

1

1

0

1A----

X = 0Y = 0

1B----

X = 0Y = 0

1C-----

X = 1Y = 1

1

1

2A----

X = 0Y = 0

2B----

X = 1Y = 0

1

1

0

0

1 +3A----

X = 1Y = 0

1

00

0

0

0

Page 17: Exercise Q3.17

• Another approach is to design an FSM for X (FSM-X) and a separate FSM for Y (FSM-Y)

• Then “simulate” the execution from the “initial states”

Page 18: Exercise Q3.17

VA

----X = 0

VB

----X = 0

1

1

VC

-----X = 0

VD

-----X = 1

1

1

SA

----Y = 0

SB

----Y = 0

SC

-----Y = 1

0

1

01

FSM-X

FSM-Y

0

0

0

――

Page 19: Exercise Q3.17

VBSA----

X = 0Y = 0

0

VASA----

X = 0Y = 0

VBSB----

X = 0Y = 0

VCSC-----

X = 0Y = 1

1

1

VDSC-----

X = 1Y = 1

10

0

VCSB----

X = 0Y = 0

1

1

0

VCSA----

X = 0Y = 0

VDSB----

X = 1Y = 0

VDSC-----

X = 1Y = 1

1

1

0

VDSA----

X = 1Y = 0

VDSB----

X = 1Y = 0

VDSC-----

X = 1Y = 1

1

1

0

0

0

0

Page 20: Exercise Q3.17

VBSA----

X = 0Y = 0

0

VASA----

X = 0Y = 0

VBSB----

X = 0Y = 0

VCSC-----

X = 0Y = 1

1

1

VDSC-----

X = 1Y = 1

10

0

VCSB----

X = 0Y = 0

1

1

0

VCSA----

X = 0Y = 0

VDSB----

X = 1Y = 0

VDSC-----

X = 1Y = 1

1

1

0

VDSA----

X = 1Y = 0

VDSB----

X = 1Y = 0

VDSC-----

X = 1Y = 1

1

1

0

0

0

0

Page 21: Exercise Q3.17

VBSA----

X = 0Y = 0

0

VASA----

X = 0Y = 0

VBSB----

X = 0Y = 0

VCSC-----

X = 0Y = 1

1

1

VDSC-----

X = 1Y = 1

10

0

VCSB----

X = 0Y = 0

1

1

0

VCSA----

X = 0Y = 0

VDSB----

X = 1Y = 0

1

0

VDSA----

X = 1Y = 0

1

0

0

0

1

Page 22: Exercise Q3.17

• Can also synthesize an FSM for X (FSM-X) and an FSM for Y (FSM-Y) separately (although this is different than what’s asked in this question)

Page 23: Exercise Q3.17

VA

----X = 0

VB

----X = 0

1

1

VC

-----X = 0

VD

-----X = 1

1

1

SA

----Y = 0

SB

----Y = 0

SC

-----Y = 1

0

1

01

FSM-X

FSM-Y

0

0

0

――

Page 24: Exercise Q3.17

State transition and output table, K-Maps for X, V1+, V0+ (for FSM-X)

0 0

0 1

1 1

1 1

V1+ AV1 V0 0 1

00

01

11

10

V1+ = V1 + V0.A

0 1

1 0

1 1

0 1

V0+ AV1 V0 0 1

00

01

11

10

V0+ = V0.A’ + V1V0 + V0’.A

0 0

0 1

Y V0 V1 0 1

0

1

Y = V1.V0

Present StateV1 V0

A = 0 A = 1X

NSV1+ V0+

NSV1+ V0+

VA = 0 0 0 0 0 1 0

VB = 0 1 0 1 1 0 0

VC = 1 0 1 0 1 1 0

VD = 1 1 1 1 1 1 1

Page 25: Exercise Q3.17

Schematic for X, V1, V0

DFF

DFF

V1

X

V0V0+

V1+A

Page 26: Exercise Q3.17

State transition and output table, K-Maps for Y, S1+, S0+ (for FSM-Y)

0 0

0 1

X X

1 1

S1+ AS1 S0 0 1

00

01

11

10

S1+ = S1 + S0.A

0 1

0 0

X X

0 0

S0+ AS1 S0 0 1

00

01

11

10

S0+ = A.S0’.S1’

0 0

1 X

Y S0 S1 0 1

0

1

Y = S1

Present StateS1 S0

A = 0 A = 1YNS

S1+ S0+NS

S1+ S0+

SA = 0 0 0 0 0 1 0

SB = 0 1 0 0 1 0 0

SC = 1 0 1 0 1 0 1

Page 27: Exercise Q3.17

Schematic for Y, S1, S0

DFF

DFF

S1 Y

S0S0+

S1+A

Page 28: Exercise Q3.17

State transition and output table, K-Maps for Y, S1+, S0+ (for FSM-Y) : Using a different State Assignment for Sc. (Using 11 instead of 10)This helps in reducing the number of literals required to compute S0+. (requires 2 literals instead of 3)Efficient State Assignment problem is sometimes taken care of by EDA tools.

0 0

0 1

1 1

X X

S1+ AS1 S0 0 1

00

01

11

10

S1+ = S1 + S0.A

0 1

0 1

1 1

X X

S0+ AS1 S0 0 1

00

01

11

10

S0+ = S1 + A

0 0

X 1

Y S0 S1 0 1

0

1

Y = S1

Present StateS1 S0

A = 0 A = 1YNS

S1+ S0+NS

S1+ S0+

SA = 0 0 0 0 0 1 0

SB = 0 1 0 0 1 1 0

SC = 1 1 1 1 1 1 1

Page 29: Exercise Q3.17

• Can also directly implement using datapath (e.g. counters and shift registers) – all FF’s initialize to “0”.

• One possible way is as given here. Other methods of implementations also exist.

+

2

MUX

2

1

“01”

2 2

1 0

2

2-bit D-FFs

2-inputAND

X

(counts to 3 and remains at 3)

A

(shifts to “11” and remains at “11”)

FF

MUX

FF

MUX

Y

1 0 1 0