Finite State Machines
Finite State Machines
Combinational
x
v
1
+
v
0
+
v
0
v
1
w
Huffman Model
clock
Storage
elements
A combinational circuit and storage elements are interconnected to form
a sequencial circuit.
The information stored at any time defines the state of the circuit at
that time.
The next state of the storage elements is a function of the inputs and
the present state.
Synchronous sequential circuit can be defined from the knowledge of its
signals at discrete instants.
Sequential Circuits
Question for You
Logic blocks are classified as:
Combinational and
Sequential
Does sequential logic contain both
combinational logic and memory?
Yes
No
Combinational and Sequential Logic
Combinational logic does not have memory
It generates output solely according to the input and
does not care about history
Often, we need a different reaction on the same input
depending on the current state
E.g.
Current state is 7 and input is 1, the new state and
output are 8
Current state is 15 and input is 1, the new state
and output are
To make the new state depends on the previous
state, we need memory
Sequential Logic and FSM
Computers are made of sequential logic
blocks
Truth tables are used to design combinational
logic, but cant be used to design sequential
logic
Finite state machines (FSM) are used instead
FSM describes a sequential logic block in
terms of:
Set of states,
State transition function (defined on current state
and input), and
Output function (defined on current state and input,
or on current state only)
Why State Machines?
Goal: provide simple abstractions of complex
systems
All computer systems are state machines
registers and memory are state
changes are transitions between states
a program defines the way in which initial states are
transformed into final states
a programming language determines a set of
programs (and hence, a set of machines)
Primary challenge will be to represent these very
complex machines with simpler (more abstract)
machines that we can reason about
State Machines Are Often Used
When it is possible to abstract away irrelevant
details, leaving only a small number of states
When we want to examine every possibility
using exhaustive checking
For communication protocols and complex
distributed algorithms (e.g., cache coherency)
Informally ...
A state machine captures the idea that a system
progresses through a set of states by performing
(or responding to) a set of actions.
Thus there are two key concepts
States
Actions
A state machine definition must say
what the possible states are
what initial states the machine may start in
what the possible actions are
how the state changes when actions occur
A (Very) Simple State Machine
World's simplest (and most boring) state
machine
States: {stop}
Actions: {}
Initial state: {stop}
stop
Another Simple Example
States: {alarm}
Actions: {beep}
Initial state: {alarm}
alarm
beep
Moore vs. Mealy Machines
Definitions
Moore Machine
Outputs are function
solely of the current
state
Outputs change
synchronously with
state changes
Mealy Machine
Outputs depend on
state AND inputs
Input change causes
an immediate
(asynchronous)
output change
State
Register
Clock
State
Feedback
X
Inputs
Z
Outputs
Combinational
Logic for
Next State
(FF Inputs)
Comb.
Logic for
Outputs)
Mealy only; no connection for Moore
Moore
Moore machines are faster
Mealy machines are smaller
Any Moore machine can be turned into a
Mealy machine (and vice versa)
Instead of using algebraic equations for next state
and outputs of sequential network, it is more
convenient and useful to express the information in
tabular form.
Transition Tables :
The Transition Table or State Transition Table or State Table is the
tabular representation of the transition and output equations. This
table consist of Present State, Next State, external inputs and
output variables. If there are n state variables then 2
n
rows are
present in state table.
State machine notations :
Input Variables : External input variables to sequential machine
as inputs.
Output Variables : All variables that exit from the
sequential machine are output variables.
State : State of sequential machine is defined by the content of
memory, when memory is realized by using FFs.
Present State : The status of all state variable i.e. content of FF
for given instant of time t is called as present state.
Next State : The state of memory at t+1 is called as Next state.
State Diagram : State diagram is graphical representation of
state variables represented by circle. The connection between
two states represented by lives with arrows and also indicates
the excitation input and related outputs.
Sequential Circuit Analysis (cont.)
Generate State Diagram
Circles (nodes) represent current or present state values
Lines (arcs) represent how state and output values change
Given the current state and current inputs, the next state
and output values are indicated by the associated arc
State diagram can have different forms depending on the type of
sequential circuit output.
Present
State
Value
Next
State
Value
Inputs/outputs
Output Variables : All variables that exit from the
sequential machine are output variables.
B
1
A
0
Q0
11/10
Q1
x0
11/01
State diagram of J-K FF
0X
Application Table of FF
PS NS FF input
Q Q
+
J K
0 0 0 X
0 1 1 X
1 0 X 1
1 1 X 0
Application Table of FF
PS NS FF i/p
Q Q
+
S R
0 0 0 X
0 1 1 0
1 0 0 1
1 1 X 0
State diagram of SR FF
0 1
01
00
10
01
00
10
Application Table of FF
PS NS FF i/p
Q Q
+
D i/p
0 0 0
0 1 1
1 0 0
1 1 1
State diagram of D FF
0 1
0
1
0
1
Application Table of FF
State diagram of T FF
0 1
0
1
1
0
PS NS FF i/p
Q Q
+
T i/p
0 0 0
0 1 1
1 0 1
1 1 0
FLIP FLOPS AND THEIR APPLICATIONS
1.
Sequential analysis
x Q Q Q x Z
Q Q Q x D
Q Q Q x D
2 1 1
2 1 1 2
2 1 2 1
1 2 1 1 2
2 1 1
2 1 2 1 2 1
and y x x
and
and
Q y y x K Q Q J
y x Q K y J
Q Q Z Q Q Z
To convert excitation expression into next state
expression, it is necessary to use the characteristic
equations of flip-flops.
Transition Equations :
The characteristic equations of FF depends on types of FF used.
Ex : For D FF Q
+
= D
For JK FF
Q K Q J Q
For T FF
Q
+
= T Q
By substituting the excitation expressions for a FF into
characteristic equation, an algebraic description of next state of
FF is obtained.
The expression for next state in terms of FF inputs
are referred as transition equations.
Q
1
+
= D
1
and Q
2
+
= D
2
For Moore network
2 1 1 2
2 1 2 1
Q Q Q x Q
Q Q Q x Q
1 2 2 2 2
1 1 1 1 1
Q K Q J Q
Q K Q J Q