State Machines

Finite State Machines
Mealy machine
current state
inputs
next state
function
clock
Outputs
output
function
next state function:
output function:
1
Fnext state ( I, S(i) )  S(i+1)
Foutput ( I, S(i) )  O(i)
Example -- Traffic Lights Controller

The controller operates the traffic lights at one intersection.
Detectors in both directions provide input signals to controllers: car
approaching NS / car approaching EW.
Outputs control the traffic light: set to green / set to red.
When cars approach in both directions, toggle the light.

The controller



needs two states, green/red.
A state/output
table is used to
construct the
controller
2
state(i)
carNS
carEW
state(i+1)
NSgo
no
no
NSgo
NSgo
no
yes
EWgo
NSgo
yes
no
NSgo
NSgo
yes
yes
EWgo
EWgo
no
no
EWgo
EWgo
no
yes
EWgo
EWgo
yes
no
NSgo
EWgo
yes
yes
NSgo
State Diagram
carEW or both directions
NSgo
carNS or both directions
EWgo
carNS or nothing
carEW or nothing
Calculate next state transitions using the table and Boolean identities
This example is a Moore machine  the outputs are a function only of the state.
In this case the output function is trivial: In state NSgo we want a signal for a NS
green light. In state EWgo we want a signal for an EW green light.
3
Moore and Mealy Machines



4
Both these machine types follow the basic
characteristics of state machines, but differ in
the way that outputs (not next state) are
produced.
Moore Machine:
– Outputs are independent of the inputs, i. e.
outputs are effectively produced from
within only the state of the state machine.
Mealy Machine:
– Outputs can be determined by the present
state alone, or by the present state and the
present inputs, i. e. outputs are produced
as the machine makes a transition from
one state to another.
Machine Models
Inputs
Inputs
Combinatorial
Logic to
Determine State
Combinatorial
Logic to
Determine State
Present State
Register Bank
Present State
Register Bank
Combinatorial
Logic to
Determine
Output Based on:
Present State 
Combinatorial
Logic to
Determine
Output Based on:
Present State 
Present Inputs
Moore Machine
Output
5
Mealy Machine
Output
Advantages of Mealy FSM


Moore and Mealy FSMs Can Be Functionally
Equivalent.
Mealy FSM Has a Richer Description and
Usually Requires Smaller Number of States
– Smaller circuit area.

Mealy FSM Computes Outputs as soon as
Inputs Change
– Mealy FSM responds one clock cycle sooner than
equivalent Moore FSM.
6
Advantages of Moore FSM

Moore FSM Has No Combinational
Path Between Inputs and Outputs.
– output changes only when clock ends  short
inputs that temporarily generated during the
clock cycles will be ignored.
7
Moore FSM that Recognizes
Sequence 10
0
1
0
1
S0 / 0
reset
Meaning
of states:
8
S1 / 0
1
S2 / 1
0
S0: No
elements
of the
sequence
observed
S1: “1”
observed
S1: “10”
observed
Mealy FSM that Recognizes
Sequence 10
0/0
1/0
S0
reset
Meaning
of states:
9
1/0
S1
0/1
S0: No
elements
of the
sequence
observed
S1: “1”
observed
Moore & Mealy Time Line
clock
input
Moore
Mealy
10
0
1
0
0
0
S0
S1
S2
S0
S0
S0
S1
S0
S0
S0
Finite State Machine

Any circuit with memory is a Finite State
Machine
– Even computers can be viewed as huge FSMs

Design of FSMs Involves
– Defining states
– Defining transitions between states
– Optimization / minimization
11
Implementation
Finite state machine with a state variable
Outputs
Combinational Logic
State Register
inputs
12
General Digital System
Control
Combinational Logic
control
lines
Architecture
State Register
CLOCK
Opcode
13
Finite State Machine: Conclusion
State Diagram
– Illustrates the form and function of a state machine.
Usually drawn as a bubble-and-arrow diagram.
State
– A uniquely identifiable set of values measured at
various points in a digital system.
Next State
– The state to which the state machine makes the
next transition, determined by the inputs present
when the device is clocked.
Mealy Machine
– A state machine that determines its outputs from
the present state and from the inputs.
Moore Machine
– A state machine that determines its outputs from
the present state only.

14