You are on page 1of 8

10/21/2016

A Finite State Machine (FSM) Models a System


University of Illinois at Urbana-Champaign
Dept. of Electrical and Computer Engineering A model of a system
◦ system moves among a finite set of states
ECE 120: Introduction to Computing ◦ motion based on external inputs
◦ produces external outputs
Examples include:
◦ coin/bill-operated machines,
Finite State Machines (FSMs) ◦ many vehicle control systems, and
◦ computers executing programs.

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 1 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 2

An FSM Consists of Five Parts A Digital FSM Must be Complete

1. a finite set of states (bits) We implement FSMs as clocked synchronous


sequential circuits. (So state ID bits are
2. a set of possible inputs (bits)
stored in flip-flops.)
3. a set of possible outputs (bits)
Given any state and any combination of
4. a set of transition rules (Boolean inputs, a transition rule from the given
expressions) state to a next state must be defined.
5. methods for calculating outputs (Bool. Self-loops–transitions from a state to itself–
expr’s) are acceptable.
When implemented as a digital system, all
parts of an FSM must be mapped to … bits!

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 3 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 4
10/21/2016

Use Keyless Entry as a Motivating Example A List of Abstract States Need Only List States

meaning state
driver’s other alarm In a list of abstract states,
door doors on? ◦ we can just list the states.
vehicle
locked
LOCKED locked locked no ◦ Adding human meanings is optional
(good to have if state names are generic).
driver door
DRIVER unlocked locked no
unlocked Including outputs
all doors
UNLOCKED unlocked unlocked no ◦ is also optional,
unlocked
◦ and implies that
alarm
ALARM locked locked yes outputs depend only on state.*
sounding
*An extra assumption that we will always make in our class.
Table is a list of abstract states.
ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 5 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 6

An Abstract Next-State Table Captures Expected Behavior Abstract Next-State Table Does Not Answer All Questions

To specify transitions, we use a next-state We wrote transitions for typical use cases, but
table, which maps combinations of states and the table can be incomplete, ambiguous,
inputs into next states. and even inconsistent.
This is an abstract next-state table. For example, what happens if the user pushes
“lock” and “unlock” at the same time?
state action/input next state state action/input next state
LOCKED push “unlock” DRIVER LOCKED push “unlock” DRIVER
DRIVER push “unlock” UNLOCKED DRIVER push “unlock” UNLOCKED
(any) push “lock” LOCKED (any) push “lock” LOCKED
(any) push “panic” ALARM (any) push “panic” ALARM

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 7 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 8
10/21/2016

Many Design Decisions are Usually Needed Abstract State Transition Diagram: the Same Information
push
All such design decision questions should “lock”
eventually be considered, and preferably push “unlock”
We can LOCKED DRIVER
answered. represent the push “lock”
Be aware: any digital logic same

push “panic”

push “unlock”
implementation will define answers. information

push “lock”
push
Only when any possible answer is acceptable as a graph “panic”
should you make use of “don’t cares.” called an
abstract state
Typically, you should review the final transition
push
implementation to determine how any “lock”
questions left open are answered. diagram. ALARM
UN-
push push “panic” LOCKED
“panic”

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 9 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 10

It’s Time to Make Our Design Complete and Concrete Let’s Start with the State Identifiers

The abstract next-state table and the abstract How many bits do we need
state transition diagram (can) contain to identify a state?
exactly the same information.
There are 4 states.
They answer the same questions. .
And neither is complete.

Call them S1S0.


So. It’s time for … bits!
“S” is for “S(tate).”

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 11 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 12
10/21/2016

All Outputs and Inputs Must Also Use Bits We Next Choose a Representation for States
What about outputs? Now we can choose a representation for states
D driver door; 1 means unlocked and rewrite our list of states.
R remaining doors; 1 means unlocked The order of states in the list doesn’t matter.
A alarm; 1 means alarm is sounding meaning state S1 S 0 D R A
And inputs? vehicle locked LOCKED 00 0 0 0
U unlock button; 1 means it’s been pressed driver door unlocked DRIVER 10 1 0 0
L lock button; 1 means it’s been pressed all doors unlocked UNLOCKED 11 1 1 0
P panic button; 1 means it’s been pressed
alarm sounding ALARM 01 0 0 1

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 13 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 14

Choice of Representation Affects Amount of Logic Needed Use to Denote the Next State (in Next Clock Cycle)

As you may realize The +’s in indicate that these are values
◦ from your experience with bit-sliced designs, in the next clock cycle.
◦ the representation does matter Let’s rewrite the next-state table with bits.
(for the amount of logic needed). ◦ The table gives us as a function of
We will talk more later about ways to choose. current state S1S0 and inputs ULP.
◦ Such tables typically use binary order for
states (vertical) and inputs (horizontal).
◦ We use Grey code order on both axes for
convenience (in copying to K-maps).

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 15 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 16
10/21/2016

How to Fill in the Next-State Table Completing the Design Requires Decisions

Where should we start? To fill in the next-state table


◦ starting with only the abstract design,
current ULP
state ◦ we need to make many design decisions,
S1S0 000 001 011 010 110 111 101 100 ◦ including some that we haven’t even
00 recognized yet.
What about
01 For example,
multiple buttons?
◦ What happens when the user presses more
11 than one button?
10 Let’s make ◦ What happens when the user presses
some design “unlock” in the UNLOCKED state?
decisions first…

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 17 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 18

Make Design Decisions Early When Possible Start by Deciding How to Handle Multiple Buttons

Let’s try to make decisions first. We’re going to start by


prioritizing the buttons.
Design decisions can shape the design,
and may conflict with one another. Our rules:
Making decisions early and writing them ◦ Panic has priority!
down ensures that ◦ Lock has second priority.
◦ any issues are raised early, and that ◦ Unlock only matters when
◦ known decisions are not overlooked neither of the others is pressed.
◦ (in which case the final design answers them
implicitly, with no human guidance).

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 19 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 20
10/21/2016

Start with the Panic Button (Highest Priority) Continue with the Lock Button (Second Priority)

The next-state table gives us . The next-state table gives us .


current ULP current ULP
state state
S1S0 000 001 011 010 110 111 101 100 S1S0 000 001 011 010 110 111 101 100
00 01 01 01 01 00 01 01 00 00 01 01
01 01 01 01 01 01 01 01 00 00 01 01
11 01 01 01 01 11 01 01 00 00 01 01
10 01 01 01 01 10 01 01 00 00 01 01

panic button pushed lock button pushed


ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 21 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 22

No Buttons? No Change. All Self-Loops Finally, Unlock … But are We Done?

What if the user pushes nothing? Two transitions were defined for Unlock.
current ULP current ULP from LOCKED
state state
S1S0 000 001 011 010 110 111 101 100 S1S0 000 001 011 010 110 111 101 100
00 00 01 01 00 00 01 01 00 00 01 01 00 00 01 01 10
01 01 01 01 00 00 01 01 01 01 01 01 00 00 What01
01 about
11 11 01 01 00 00 01 01 11 11 01 01 00 00 01 these?
01
10 10 01 01 00 00 01 01 10 10 01 01 00 00 01 01 11

no buttons pushed from DRIVER


ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 23 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 24
10/21/2016

We Have More Design Decisions to Make! Let’s Implement Our Decisions

What should happen if we press “unlock” Ignore Unlock in both other cases.
when the car is already fully unlocked current ULP from ALARM
(in the UNLOCKED state)? state
S1S0 000 001 011 010 110 111 101 100
Maybe just stay UNLOCKED.
00 00 01 01 00 00 01 01 10
What should happen if we press “unlock”
while the alarm is sounding? 01 01 01 01 00 00 01 01 01
◦ Continue to lock out an attacker / thief? 11 11 01 01 00 00 01 01 11
◦ Or open the doors so that the owner can 10 10 01 01 00 00 01 01 11
climb inside quickly?
from UNLOCKED

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 25 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 26

The Rest You Know How to Do One Last Tool: the Complete State Transition Diagram

The rest is K-maps, expressions, and logic. The complete state transition diagram
1. Express and in terms contains the information in both the
of S1, S0, U, L, and P. state list and the next-state table.
2. Express D, R, and A in terms of S1, S0.
inputs for this transition
3. Build the combinational logic.
state ID / outputs
4. Put the next state expressions and ULP = _ _ _
into the D inputs of two flip-flops.
You should do it as an exercise. Break up the STATE
truth tables or use 5-variable K-maps. S1S0/DRA

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 27 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 28
10/21/2016

Complete State Transition Diagram Be Careful with Input Abbreviations


ULP=100
ULP=000,x10
Input abbreviations can render
LOCKED DRIVER a state transition diagram
00/000 ULP=x10 10/100 ◦ incomplete (if labels fail to
ULP=000 cover all input combinations), or
abbreviate as ◦ inconsistent (if labels indicate

ULP=100
multiple next states).
ULP=xx1

ULP = x00
ULP=x10
ULP=xx1
For example,
◦ self-loop from ALARM labeled ULP=xx1,x0x:
ULP=
ULP=000 ◦ the patterns x01 match both labels!
x10
ALARM
UN- or 100 ◦ In this case, these two combinations go
01/001
LOCKED to the same next state, so it’s ok.
ULP=xx1 11/110
ULP=xx1,x0x

ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 29 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 30

You might also like