Professional Documents
Culture Documents
Introduction
S0 S1
reset 0/1
S0: No S1: “1”
Meaning elements observed
of states: of the
sequence
observed
Pseudo Code
always @ (posedge clk)
if (rst) cst <= s0;
else cst <= nst;
always @ *
case(cst)
so: if(inp == 1) { nst <= s1;}
out <= 0;
s1: if(inp == 0) {nst <= s0; out <= 1}
else out <= 0;
endcase
FSM Consists of….
• State Space: so,s1
• Inputs: Inp
• Output: out
• Next State Function:
case(cst)
so: if(inp == 1) { nst <= s1;}
s1: if(inp == 0) {nst <= s0;}
• Output Function:
case(cst)
so: out <= 0;
s1: out = !inp
• Reset State: so
• An FSM is defined in terms of:
1. S : Finite State Space
2. I : Input vectors
3. O : Output vectors
4. T : Transition function
5. F : Output Function
reset
current_state
clk
Definition of a State Machine
• A state machine represents a system as a
set of states, the transitions between
them, along with the associated inputs and
outputs.
• An FSM is a discrete dynamic system that
translates sequences of input vectors into
sequences of output vectors
Definition of a State Machine
(Contd.)
• So, a state machine is a particular
conceptualization of a particular sequential
circuit. State machines can be used for
many other things beyond logic design
and computer architecture.
• FSMs form the core sequential units of a
hardware design
Finite State Machines
• 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:
• Advanced EDA tools do this automatically. We’ll touch upon
some important optimizations and transformations in this
training
Implicit State Machines
-- Explicit FSM -- --Implicit FSM--
reset
current_state
clk
Example: FSM using enum variable
Choosing Sequential Encoding to
Original Design represent enum literals
State: enum (START = “001”, MIDDLE=“010”, State: enum (START = “001”, MIDDLE=“010”,
STOP=“100”); STOP=“100”);
Sequential
reset State IDLE One-Hot
…
State== State==
PAD
State Encoding Next next_state
Register
N
Table inputs
State
State[2:0]
Functionlog N log N
2 2 State[4:0]
clk bit wide Output
State Original One-Hot
Literal Literal
State[2:0]==IDLE State[0]==1
Output Function
IDLE 000 00001 Sequentially Enumerated FSM
WAIT 001 00010 N: Number of States
state
EVEN 010 00100
reset State
Register
N
ODD 011 01000 Next next_state
State
PAD 100 10000 inputs Function N N Output
clk bit wide
Output
Function
One-Hot Encoded FSM
One-Hot Encoding Contd.
• Result in reduced combinational area and
increased sequential logic.
• Good for large state machines.
• Other common encoding styles:
– Gray
– One-cold
– Two-Hot
FSM Re-encoding Heuristics
• Re-encoding may not always improve results
• Example:
– 64 states
– Sequentially encoded
– 6 bit wide state vector
– State space: {6’d0,6’d1, .... , 6’d63}
STATE2 NIL X
STATE3 NIL X
STATE4 STATE1, STATE2
STATE5 STATE4
STATE6 STATE3 X
STATE7 NIL X
Missing Choices Optimization
Removing Unreachable State(s)
State: enum (START = “00”, MIDDLE=“01”, State: enum (START = “00”, MIDDLE=“01”,
STOP=“10”); STOP=“10”);
State: enum (START = “00”, MIDDLE=“01”, State: enum (START = “00”, MIDDLE=“01”,
STOP=“10”); STOP=“10”);
reset reset
Next
next_state State Output Output
State
inputs Function Register Function Register outputs
clk clk
state
A
D
D
A
inputs D
T
R
A outputs
clk
ROM
reset
FSM in ROM: Example
• Block RAMs are used to implement ROMs
state
ADDR[8:5] DO[7:4]
• 16 states
inputs
ADDR[4:0]
• 4 outputs
Tied to GND
Tied to GND
WE
DO[3:0]
outputs
• 5 inputs
DI[7:0]