28
CS 362: Computer Design Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018

CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

CS 362: Computer DesignLecture 11: Finite State Machines

Mitchell TheysUniversity of Illinois at Chicago

October 2nd, 2018

Page 2: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Announcements

Page 3: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

State Machines

• With state, can no longer represent digital functions with an equation alone

• Instead, we use a state machine

e f

b

b’

bb’

Page 4: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

State Machines

• Set of states – circles in the picture• Set of transitions – arcs starting and ending at a state in 

the picture• Start state – the arrow pointing to a state• Input – listed on the arcs• Output – can be in the states or on the arcs

e f

b

b’

bb’

y = 0 y = 1

Page 5: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Clocked FSMs

• In this class, we will assume FSMs change state on the rising edge of the clock

• On the rising edge, FSMs transition to the next state based on input

Page 6: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Assume input on b is 010011.  What is the output?

A. 0010011B. 0100100

C. 100100D. None of the above

e f

g

b’

b b

b

b’

b’

y = 0

y = 0

y = 1

Page 7: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

We want y to be the inverse of the input.  Select the correct set of 

transitions.

clicker w x y z

A b’ b’ b b

B b’ b b’ b

C b b b’ b’

D b b’ b b’

E None of the  above

e gy = 0 y = 1

w

xyz

Page 8: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

State Machines in Digital Logic

• Use flipflops to store state

• Use combinational logic to change state on inputs, produce output

Page 9: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Converting FSMs to Circuits

• Create a truth table from the FSM– Include current state as input, next state as output

• Create a set of equations for the truth table

• Convert equations into a circuit

Page 10: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Convert to Truth Table: Inputs

e f

g

b’

b b

b

b’

b’

y = 0

y = 0

y = 1

• Give each state an identifier

• The set of inputs for the truth table is each state, plus the input to the machine

Page 11: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Convert to Truth Table: Outputs

e00

f01

g10

b’

b b

b

b’

b’

y = 0

y = 0

y = 1

• The set of outputs is the identifier of the state we transition to, plus output

p1 p0 b

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

Page 12: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Pick the Correct Truth Tablee0

g1

y = 0 y = 1

b’

b’bb

p b n y

0 0 1 0

0 1 0 0

1 0 1 1

1 1 0 1

p b n y

0 0 1 0

0 1 0 0

1 0 0 1

1 1 1 1

p b n y

0 0 1 1

0 1 0 0

1 0 0 0

1 1 1 1

p b n y

0 0 1 1

0 1 0 0

1 0 1 1

1 1 0 0

A B C D

p = previous stateb = inputn = next statey = output

E. None of the above

Page 13: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Building the circuit

• Register to hold the current state

• Combinational logic to decide state transitions and output

Page 14: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Building the Logic Circuit

e00

f01

g10

b’

b b

b

b’

b’

y = 0

y = 0

y = 1

• Find the equations for each output from the truth table– y =– n0 =– n1 = 

p1 p0 b n1 n0 y

0 0 0 0 1 0

0 0 1 1 0 0

0 1 0 0 1 1

0 1 1 1 0 1

1 0 0 0 0 0

1 0 1 1 0 0

1 1 0 X X X

1 1 1 X X X

Page 15: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Building the Logic Circuit

e00

f01

g10

b’

b b

b

b’

b’

y = 0

y = 0

y = 1

• Create the circuit from the equations

y = p1’p0n0 = p1’b’n1 = b 

Page 16: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Pick the Correct Equationse0

g1

y = 0 y = 1

b’

b’bb

p b n y

0 0 1 0

0 1 0 0

1 0 1 1

1 1 0 1

p = previous stateb = inputn = next statey = output A. y = p, n = b’

B. y = pb’ + pb, n = p’b’ + pb’

C. y = pb’n+pbn’, n = p’b’y’ + pb’y

D. y = pb’n+pbn’, n = b’

E. None of the above

Page 17: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Pick the correct circuite0

g1

y = 0 y = 1

b’

b’bb

y = p,n = b’

register

b

n

p

y

register

n

y

p

b

register

n

p

y

b

A B C

Page 18: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Converting Circuits to FSMs

• We can convert sequential circuits to FSMs– Must have a register and logic

• Write the logic as a truth table

• Give a state name to the register/bit combinations

• List output values for each state

• Draw transitions

Page 19: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Create Truth Table

p1

zb

p0

n0n1

p1 p0 b n1 n0 z

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

Page 20: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Group Into States

p1

zb

p0

n0n1

p1 p0 b n1 n0 z

0 0 0 0 0 0

0 0 1 0 1 0

0 1 0 0 0 0

0 1 1 1 0 0

1 0 0 1 1 1

1 0 1 1 0 1

1 1 0 0 0 1

1 1 1 1 0 1

Page 21: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Write output for each state

p1 p0 b n1 n0 z

0 0 0 0 0 0

0 0 1 0 1 0

0 1 0 0 0 0

0 1 1 1 0 0

1 0 0 1 1 1

1 0 1 1 0 1

1 1 0 0 0 1

1 1 1 1 0 1

00 01

1011

Page 22: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Develop transitions from truth table

p1 p0 b n1 n0 z

0 0 0 0 0 0

0 0 1 0 1 0

0 1 0 0 0 0

0 1 1 1 0 0

1 0 0 1 1 1

1 0 1 1 0 1

1 1 0 0 0 1

1 1 1 1 0 1

00 01

1011

z = 0 z = 0

z = 1z = 1

Page 23: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Pick the correct column for z

p1

zb

p0

n0n1

p1 p0 b

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

z

0

0

0

0

1

1

1

1

z

0

0

0

0

1

1

0

0

z

0

0

1

1

0

0

0

0

z

0

1

0

0

0

1

0

0

A B C D

E. None of the above

Page 24: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Pick the correct column for n0

p1

zb

p0

n0n1

p1 p0 b

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

n0

1

1

0

0

1

1

0

0

n0

0

0

0

0

1

0

0

0

n0

0

1

0

0

1

0

0

0

n0

0

0

0

1

0

1

0

0

A B C D

E. None of the above

Page 25: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Pick the correct column for n1

p1

zb

p0

n0n1

p1 p0 b

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

n0

1

1

0

0

1

1

0

0

n0

0

0

0

0

1

0

0

0

n0

0

1

0

0

1

0

0

0

n0

0

0

0

1

0

1

0

0

A B C D

E. None of the above

Page 26: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

The output will be 1 for which state?

p1 p0 b n1 n0 z

0 0 0 0 0 0

0 0 1 0 1 0

0 1 0 0 0 0

0 1 1 1 0 0

1 0 0 0 1 1

1 0 1 1 0 1

1 1 0 0 0 0

1 1 1 0 0 0

A. 00B. 01C. 10D. 11E. More than one of the above

Page 27: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Which state machine is correct?

p1 p0 b n1 n0 z

0 0 0 0 0 0

0 0 1 0 1 0

0 1 0 0 0 0

0 1 1 1 0 0

1 0 0 0 1 1

1 0 1 1 0 1

1 1 0 0 0 0

1 1 1 0 0 0

00 01

1011

b’b

b’

b’b

b

00 01

1011

b’b

b’b’

b

bb’

b

00 01

1011

b’b

b’

b’

b

b

A

B

C

00 01

1011

b

b’

b’

b

bD

E. None of the above

Page 28: CS 362: Computer Design Lecture 11: Finite State …...Lecture 11: Finite State Machines Mitchell Theys University of Illinois at Chicago October 2nd, 2018 Announcements State Machines

Reading

• Next lecture:  Encoding Finite State Machines– Read 4.9 – 4.13