Professional Documents
Culture Documents
08a VHDL FSM
08a VHDL FSM
08a VHDL FSM
Confucius
2020
Finite State Machines
2
Summary
A FSM is used to model a system that transits among a finite
number of internal states.
The transitions depend on the current state and external
input.
◦ Unlike a regular sequential circuit, the state transitions of an FSM
do not exhibit a simple, repetitive pattern.
◦ Its next-state logic is usually constructed from scratch and is
sometimes known as “random” logic.
3
Summary
In practice, the main application of an FSM is
◦ to act as the controller of a large digital system,
◦ which examines the external commands and status and activates proper
control signals to control operation of a data path, which is usually
composed of regular sequential components.
4
FSM – general architecture (Mealy
machine)
(State
excitation Memory) pr_state outputs
inputs Next-state Output Logic
Next-state
Logic (F) (G)
Logic (F)
Clk
clocked synchronous state machine - general structure
5
Moore Machine
(State
excitation Memory) pr_state outputs
inputs Next-state Output Logic
Next-state
Logic (F) (G)
Logic (F)
Clk
6
Mealy and Moore outputs
(State
excitation Memory) pr_state Mealy
inputs Next-state Output Logic
Next-state
Logic (F) (G1) outputs
Logic (F)
Clk
7
Pipelined Outputs
inputs (State
Output
excitation Memory) pr_state Pipelined
Next-state Output Logic Pipeline
Next-state
Logic (F) (G) Memory outputs
Logic (F)
Clk
8
FSM representation
An FSM is usually specified by
◦ an abstract state diagram or
◦ ASM chart (algorithmic state machine chart)
9
State diagram – single node
Mo – Moore Output
Me – Mealy Output
state_name
Mo<=value
10
ASM chart
11
Finite State Machines
Finite state machines (FSM) constitute a special modeling
technique for sequential logic circuits.
Such a model can be very helpful in the design of certain
types of systems, particularly those whose tasks form a
well-defined sequence (digital controllers, for example).
12
Single-phase state machine
Upper section (gates)
Input Output
Combinational
logic
pr_state next_state
Clk Sequential
logic
Reset
13
Upper section (gates)
logic
pr_state next_state
Clk Sequential
process (reset, clock) Reset logic
begin
Lower section (flip-flops)
if (reset = '1') then
pr_state <= initial_state;
elsif (clock'event and clock = '1') then
pr_state <= next_state;
end if;
end process;
14
Upper section (gates)
Combinational Logic al
logic
process (input, pr_state) pr_state next_state
begin
Clk Sequential
case pr_state is
Reset logic
when state0 =>
15
Design Styles
a. Style #1 b. Style #2
16
Design Style #1
library ieee;
use ieee.std_logic_1164.all;
entity <entity_name> is
end <entity_name>;
begin
17
Design Style #1
---------- lower section: ------------------------
process (reset, clock)
begin
if (reset = '1') then
pr_state <= state0;
elsif (clock'event and clock = '1') then
pr_state <= next_state;
end if;
end process;
18
Design Style #1
---------- upper section: ------------------------
process (input, pr_state)
begin
case pr_state is
when state0 =>
if (input = ...) then
output <= <value>;
next_state <= state1;
else ...
end if;
19
Design Style #1
when state1 =>
else ...
end if;
else ...
end if;
...
end case;
end process;
end <arch_name>;
20
a. Style #1 b. Style #2
21
Design Style #2 (Stored/pipelined
Output)
library ieee;
use ieee.std_logic_1164.all;
entity <ent_name> is
end <ent_name>;
begin
22
Design Style #2 (Stored Output)
---------- lower section: --------------------------
process (reset, clock)
begin
if (reset='1') then
pr_state <= state0;
elsif (clock'event and clock = '1') then
output <= temp;
pr_state <= next_state;
end if;
end process;
23
Design Style #2 (Stored Output)
---------- upper section: --------------------------
process (pr_state)
begin
case pr_state is
...
end if;
...
end if;
24
Design Style #2 (Stored Output)
when state2 =>
temp <= <value>;
if (condition) then next_state <= state3;
...
end if;
...
end case;
end process;
end <arch_name>;
25