Finite State Machines This work is licensed under the Creative Commons...

15
Finite State Machines This work is licensed under the Creative Commons Attribution- NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Transcript of Finite State Machines This work is licensed under the Creative Commons...

Page 1: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Finite State Machines

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Page 2: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Outline and Objectives

Outline• Motivation• Example: Door

Controller• Formal Definition• Example/Activity:

Vending Machine

Learning Objectives• Describe finite state

machine (FSM).• Give an example of a

task or action that can be modelled by a FSM.

• Convert a simple FSM to an implementation in sequential logic.

Page 3: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Motivation

Observation: When we act, we • look at our current situation (take into account

our current “state” and environment/inputs)• respond (“act”) and enter a new situation

This same behavior can be modelled by simple “machines”.

Page 4: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Example: Door Controller

Consider a controller that opens an automatic door…

We would like to regulate when the door should open and close…

Back Sensor Front Sensor

open closefrontbackboth

bothback

neither

neither

front

State Diagram

Page 5: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Example: Door Controller

Now we need to convert this diagram into something we can implement with a circuit…• encode the states in Boolean variables• represent the sensors as Boolean variables

s=1 s=0f=1 orb=1

(f=1 and b=1), or (b=1 and f=0), or (f=0 and b=0)

f=0 and b=0

f=1 and b=0

frontbackboth

bothbackneither

neither

front

Page 6: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Example: Door ControllerCreate a truth table taking three inputs (f, b, and s) and one output (s+) f b s s+(f,b,s)

0 0 0 00 0 1 00 1 0 00 1 1 11 0 0 11 0 1 11 1 0 01 1 1 1

Page 7: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Example: Door Controller

We will use a Kmap to simply the formula for s+

s+ (f, b, s) = s b + f b

fb/s 00 01 11 10

0 0 0 0 1

1 0 1 1 1

f b s s+(f,b,s)0 0 0 00 0 1 00 1 0 00 1 1 11 0 0 11 0 1 11 1 0 01 1 1 1

Page 8: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Example: Door Controller

s+ (f, b, s) = s b + f b

Note how the output (next state) depends on the current state.

This means we will need what type of logic to implement the controller?

Page 9: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Example: Door Controller

Page 10: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Formal Definition

A FSM can be fully specified byo Finite set of states So A start state q

0 ε S

o A set of accept states Fo A finite set of valid inputs X (i.e., domain of

input)o A transition function, f, that maps current

state and input to the next state(Sipser, 35)

Page 11: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Example: Vending Machine

We need to construct a simple machine that will determine if a combination of nickels and dimes should dispense a gumball.

We should dispense the gumball when we’ve received 15¢ (i.e., accept when we have the $$).

(Katz, 389)

Page 12: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Example: Vending Machine

We create a state diagram to see how we could arrive at an accept state.

0¢ 5¢ 10¢ 15¢

N N N,D

D D

Page 13: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Example: Vending Machine

o S = {0¢, 5¢, 10¢, 15¢}o q

0 = 0¢

o F = {15¢}o X = {N, D}

Curr. State Coin Rcvd. Next State

0¢ N 5¢

0¢ D 10¢

5¢ N 10¢

5¢ D 15¢

10¢ N 15¢

10¢ D 15¢

f(X,S)Formalizing a FSM

Page 14: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

Example: Vending Machine

Activity: Convert this FSM to a circuit.

First: Determine an encoding for the states and create Boolean expressions for the transition function

Then: Convert the Boolean expression to a logic diagram and implement in HDL.

Page 15: Finite State Machines This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.

References

Sipser M: Introduction to the theory of computation. 2nd ed. Boston: Thomson Course Technology; 2006.

Katz RH: Contemporary logic design. Redwood City, Calif: Benjamin/Cummings; 1994.