0% found this document useful (0 votes)
62 views2 pages

Lec 4

This document describes state machines and how to design them. A state machine specifies the states a controller can be in, the outputs for each state, and the input conditions that cause transitions between states. To design a state machine, you define the outputs, inputs, states, and state transition rules. State machines are represented using state diagrams or tables. They allow modeling a controller's logical behavior without implementation details. Exercises are provided to help understand state machines.

Uploaded by

jkmaro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views2 pages

Lec 4

This document describes state machines and how to design them. A state machine specifies the states a controller can be in, the outputs for each state, and the input conditions that cause transitions between states. To design a state machine, you define the outputs, inputs, states, and state transition rules. State machines are represented using state diagrams or tables. They allow modeling a controller's logical behavior without implementation details. Exercises are provided to help understand state machines.

Uploaded by

jkmaro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

APSC 380 : I NTRODUCTION TO M ICROCOMPUTERS

1997/98 W INTER S ESSION T ERM 2

State Machines
This lecture describes state machines and explains how state machines are designed and specified.
After this lecture you should be able to design a state machine from a description of its behaviour. You should be able
to describe the state machine using state transition diagrams and tables.
State Machines Inputs and Outputs

A state machine is an abstract way of describing the A controller’s inputs are typically signals from
behaviour of a controller. The state machine descrip- sensors such as switches, thermometers, pressure
tion reduces the description of any controller to just gauges, and so on. The outputs are signals that drive
four things: inputs, outputs, states, and state transi- actuators such as motors or valves, displays, etc.
tion rules. We will restrict ourselves to inputs and outputs
The state machine description contains no de- that are binary values (represented as 0/1, false/true,
tails about the implementation of the controller (no or low/high).
flowcharts, programs, schematics, mechanical dia- To simplify the state machine description, each
grams, etc.). Instead, a state machine only describes input and output is given an abbreviation, usually
the different states that the controller can be in, the mnemonic. For example an input that indicates that a
outputs in each state, and what input conditions will tank is full might be given the label full, an output
cause transitions between states. that turns a drill motor on might be given the label
A state machine description can be used to de- drill.
scribe and analyze existing systems and to aid in the
design of new systems. The simplified description States
represented by a state machine allows us to verify
proper operation and document the logical operation A state machines (also called a Finite State Machine
of a controller before proceeding with detailed de- or FSM) is a controller that can be in a finite number
sign (e.g. writing a program or designing hardware). of different conditions. Each of these conditions is
called a state.
For example, a simple controller for a motor may
Design of State Machines have two states: motor turned on and motor turned
off. A more complicated controller may have more
There are four steps to designing a state machine:
states. For example, a controller for an overhead pro-
jector cooling fan motor (which must continue to run
define the outputs – these are the signals that
until it the bulb has cooled down, even if the projec-
control those things that the controller needs to
tor is turned off) may have three states: motor run-
control
ning, motor cooling down, and motor off.
define the inputs – the signals that provide the The number of states required to describe the state
controller with information about things that it machine and the definitions of each of these states
needs to monitor in order to operate properly will be determined by the application.
Each state is given a mnemonic symbol (ON,
define all of the possible states that the con- COOLING, OFF, etc).
troller will need to be in and what values the In this course we will only consider state machines
outputs will take for each of these states whose output is a function of the current state1. Be-
cause of this there must be at least one state for each
define the exact input conditions that will cause
the state machine to switch from one state to 1 It is also possible to have state machines whose output is a
another function of the inputs as well as the state

lec4.tex 1
desired combination of output values. In some cases state run
there may actually be more states than there are out- ON 1
COOLING 1
put conditions. For example, the second motor con-
OFF 0
troller described above might have only one binary
output (to control the motor) but might have three The second table has one row for each possible
states (ON, OFF, and COOLING). combination of current state and input conditions. It
has three columns: the current state, the input condi-
State Transition Diagram tions and the state to switch to if that particular com-
bination of state and input conditions happens.
The rules describing the transitions between states For example, for the motor controller described
are commonly given as a diagram called a state tran- above, the tabular form of the state transition dia-
sition diagram (or simply “state diagram”). gram shown above is:
In the state diagram each state is represented by
a circle. Each circle is labeled with its state name. current input next
Lines are drawn to show the possible transitions be- state conditions state
tween the states and each such line is labelled with on hot
a logical expression describing the input conditions ON 0 0 COOLING
required for that transition to happen. If none of the ON 0 1 COOLING
ON 1 0 ON
transition conditions is met, the controller remains in
ON 1 1 ON
its current state. COOLING 0 0 OFF
For example, the 3-state motor controller de- COOLING 0 1 COOLING
scribed above might have a switch input (on) and COOLING 1 0 ON
an input from a temperature sensor (hot). The state COOLING 1 1 ON
transition diagram might look as follows: OFF 0 0 OFF
on==1 OFF 0 1 OFF
OFF 1 0 ON
hot==0 && on==0
OFF 1 1 OFF
on==0
ON COOLING OFF
Exercise:
A simple burglar alarm has two inputs: an on/off switch (arm)
and an open-window detector (open). It has one output that
sounds a siren (siren). If the alarm is armed and the window
on==1
is opened then the siren is turned on. The siren remains on until
There are many different conventions for drawing the alarm is shut off even if the window is closed again.
state diagrams. For example, it’s common to also List the inputs and outputs. How many unique combinations
of outputs are there? How many states will be required? Give a
show the values of the outputs on the state diagram.
table showing the outputs for each state. Draw the state transition
In the examples in this course we will describe the diagram. Give the state transition table in the format described
output values for each state separately. above.

Tabular Representation Deadlock and Unreachable States


The operation of a state machine can also be de-
The state machine diagram allows us to easily detect
scribed by using two tables: one to list the output
certain errors. One of these is a state that can never
values for each state and one to give the input condi-
be reached. This indicates an incomplete specifica-
tions which cause the state machine to switch from
tion. Another problem is a state that can be reached
one state to another. The first table has one row for
but can’t be exited. This is called deadlock and is
each state. Each column gives the value of the out-
usually undesired.
puts for that state. For example, the motor controller
has only one output, say run, and the table might
look like:

You might also like