exercise q3 - university of california, san diego

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: others

Post on 17-Nov-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Exercise Q3 - University of California, San Diego

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 - University of California, San Diego

• 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 - University of California, San Diego

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 - University of California, San Diego

Exercise Q3.22 Solutuon

“ ” 0

“1” 0

“11” 0

“110” 0

“1101” 1

“111” 0

“1110” 1

1 1 0 1

0

1

Reset

0 0 0 0 1

1 0

1

Page 5: Exercise Q3 - University of California, San Diego

“ ” 0

“1” 0

“11” 0

“110” 0

“1101” 1

“111” 0

“1110” 1

1 1 0 1

0

1

0

Reset

1

0

0

0 0 1

1

State encoding:

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

Page 6: Exercise Q3 - University of California, San Diego

State transition and output table:

Present State S2 S1 S0

X = 0 X = 1

F NS 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 - University of California, San Diego

K-Maps:

0 1 0 0

1 1 0 0

0 0 X X

0 0 1 0

S0+ S0 X

S2 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 X

S2 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 X

S2 S1 00 01 11 10

00

01

11

10

S2+ = S0.S2 + X.S1

0 0

0 0

1 X

1 0

F S0 X

S2 S1 00 01

00

01

11

10

F = S0’.S2

Page 8: Exercise Q3 - University of California, San Diego

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

1 1 1

Page 9: Exercise Q3 - University of California, San Diego

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 - University of California, San Diego

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 1 Output Y 0 0 0 1 1 1 1 Output 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 - University of California, San Diego

0A ----

X = 0 Y = 0

0B ----

X = 0 Y = 0

0C -----

X = 0 Y = 1

1

1 1A ----

X = 0 Y = 0

1B ----

X = 0 Y = 0

1C -----

X = 1 Y = 1

1

1 2A ----

X = 0 Y = 0

2B ----

X = 1 Y = 0

2C -----

X = 1 Y = 1

1

1

0

0

+3A ----

X = 1 Y = 0

+3B ----

X = 1 Y = 0

+3C -----

X = 1 Y = 1

1

1 ―

0

0

1 0

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 - University of California, San Diego

0A ----

X = 0 Y = 0

0B ----

X = 0 Y = 0

0C -----

X = 0 Y = 1

1

1 1A ----

X = 0 Y = 0

1B ----

X = 0 Y = 0

1C -----

X = 1 Y = 1

1

1 2A ----

X = 0 Y = 0

2B ----

X = 1 Y = 0

2C -----

X = 1 Y = 1

1

1

0

0

+3A ----

X = 1 Y = 0

+3B ----

X = 1 Y = 0

+3C -----

X = 1 Y = 1

1

1 ―

0

0

1 0

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 - University of California, San Diego

0A ----

X = 0 Y = 0

0B ----

X = 0 Y = 0

0C -----

X = 0 Y = 1

1

1

0

1A ----

X = 0 Y = 0

1B ----

X = 0 Y = 0

1C -----

X = 1 Y = 1

1

1

2A ----

X = 0 Y = 0

2B ----

X = 1 Y = 0

1

1

0

0

1 +3A ----

X = 1 Y = 0

+3B ----

X = 1 Y = 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 are

identical for all input combinations.

Page 14: Exercise Q3 - University of California, San Diego

0A ----

X = 0 Y = 0

0B ----

X = 0 Y = 0

0C -----

X = 0 Y = 1

1

1

0

1A ----

X = 0 Y = 0

1B ----

X = 0 Y = 0

1C -----

X = 1 Y = 1

1

1

2A ----

X = 0 Y = 0

2B ----

X = 1 Y = 0

1

1

0

0

1 +3A ----

X = 1 Y = 0

+3B ----

X = 1 Y = 0

1

1

0

0

0

0

0

0

Combining equivalent states 2b, 3b

Reason : Next states, outputs are

identical for all input combinations.

Page 15: Exercise Q3 - University of California, San Diego

Common Mistake in Midterm2

• Many got B = C = F, but didn’t get E = G

• Their state table looked like this.

Present State

Next State

I=0 I=1

Output

I = 0 I = 1

A A B 0 0

B B E 1 1

D B A 0 0

E B D 1 0

G B D 1 0

Explicit Equivalence

E = G.

Page 16: Exercise Q3 - University of California, San Diego

0A ----

X = 0 Y = 0

0B ----

X = 0 Y = 0

0C -----

X = 0 Y = 1

1

1

0

1A ----

X = 0 Y = 0

1B ----

X = 0 Y = 0

1C -----

X = 1 Y = 1

1

1

2A ----

X = 0 Y = 0

2B ----

X = 1 Y = 0

1

1

0

0

1 +3A ----

X = 1 Y = 0

1

0

0

0

0

0

Page 17: Exercise Q3 - University of California, San Diego

• 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 - University of California, San Diego

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

0 1

FSM-X

FSM-Y

0

0

0

― ―

Page 19: Exercise Q3 - University of California, San Diego

VBSA ----

X = 0 Y = 0

0

VASA ----

X = 0 Y = 0

VBSB ----

X = 0 Y = 0

VCSC -----

X = 0 Y = 1

1

1

VDSC -----

X = 1 Y = 1

1 0

0

VCSB ----

X = 0 Y = 0

1

1

0

VCSA ----

X = 0 Y = 0

VDSB ----

X = 1 Y = 0

VDSC -----

X = 1 Y = 1

1

1

0

VDSA ----

X = 1 Y = 0

VDSB ----

X = 1 Y = 0

VDSC -----

X = 1 Y = 1

1

1

0

0

0

0

Page 20: Exercise Q3 - University of California, San Diego

VBSA ----

X = 0 Y = 0

0

VASA ----

X = 0 Y = 0

VBSB ----

X = 0 Y = 0

VCSC -----

X = 0 Y = 1

1

1

VDSC -----

X = 1 Y = 1

1 0

0

VCSB ----

X = 0 Y = 0

1

1

0

VCSA ----

X = 0 Y = 0

VDSB ----

X = 1 Y = 0

VDSC -----

X = 1 Y = 1

1

1

0

VDSA ----

X = 1 Y = 0

VDSB ----

X = 1 Y = 0

VDSC -----

X = 1 Y = 1

1

1

0

0

0

0

Page 21: Exercise Q3 - University of California, San Diego

VBSA ----

X = 0 Y = 0

0

VASA ----

X = 0 Y = 0

VBSB ----

X = 0 Y = 0

VCSC -----

X = 0 Y = 1

1

1

VDSC -----

X = 1 Y = 1

1 0

0

VCSB ----

X = 0 Y = 0

1

1

0

VCSA ----

X = 0 Y = 0

VDSB ----

X = 1 Y = 0

1

0

VDSA ----

X = 1 Y = 0

1

0

0

0

1

Page 22: Exercise Q3 - University of California, San Diego

• 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 - University of California, San Diego

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

0 1

FSM-X

FSM-Y

0

0

0

― ―

Page 24: Exercise Q3 - University of California, San Diego

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

0 0

0 1

1 1

1 1

V1+ A

V1 V0 0 1

00

01

11

10

V1+ = V1 + V0.A

0 1

1 0

1 1

0 1

V0+ A

V1 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 State V1 V0

A = 0 A = 1

X NS

V1+ V0+ NS

V1+ 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 - University of California, San Diego

Schematic for X, V1, V0

DFF

DFF

V1

X

V0 V0+

V1+ A

Page 26: Exercise Q3 - University of California, San Diego

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

0 0

0 1

X X

1 1

S1+ A

S1 S0 0 1

00

01

11

10

S1+ = S1 + S0.A

0 1

0 0

X X

0 0

S0+ A

S1 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 State S1 S0

A = 0 A = 1

Y NS 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 - University of California, San Diego

Schematic for Y, S1, S0

DFF

DFF

S1 Y

S0

S0+

S1+ A

Page 28: Exercise Q3 - University of California, San Diego

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+ A

S1 S0 0 1

00

01

11

10

S1+ = S1 + S0.A

0 1

0 1

1 1

X X

S0+ A

S1 S0 0 1

00

01

11

10

S0+ = S1 + A

0 0

X 1

Y S0

S1 0 1

0

1

Y = S1

Present State S1 S0

A = 0 A = 1

Y NS 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 - University of California, San Diego

• 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-input AND

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