07 FSM - VHDL

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Finite State Machines

Mixed Style RTL Modeling


Finite State Machines (FSMs)
Finite State Machines, or automata, originated in computational theory and mathematical models in
support of various fields of bioscience. However, their popularity today in the computer science and
engineering fields can be attributed to the pioneering efforts of George H. Mealy and Edward F.
Moore

• Tow FSM approachs

• Moore FSM (George H. Mealy - Bell Labs )

• Mealy FSM (Edward F. Moore - IBM)

2
Finite State Machines (FSMs)

• 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

• Above Approach Is Practical for Small FSMs Only

3
Moore FSM
• Output Is a Function of Present State Only
Inputs
Next State
function

Next State
Present State
Transition condition 1

clock
Present State
reset Register state 1 /output 1 state 2 /output 2

Transition condition 2

Outputs
Output
function

4
Mealy FSM
• Output Is a Function of a Present State and Inputs

Inputs Next State


function

Next State Present State


transition condition 1 / output 1

clock Present State


state 1 state 2
reset Register
transition condition 2 / output 2

Output Outputs
function

5
Moore FSM with asynchronous reset
comb_logic: process(current_state, a)
begin
a=0
a=0 a=0
a=0 case current_state is
a=1 a=1 a=1
S0 /x= 0 S1 / x=0 S2 /x= 0 S3 /x= 1 when S0 => x <= '0';
if a='0' then
a=1 next_state <= S0;
reset elsif a ='1' then
next_state <= S1;
end if;

library ieee ; when S1 => x <= '0';


use ieee.std_logic_1164.all; if a='0' then
next_state <= S1;
----------------------------------------------------- elsif a='1' then
next_state <= S2;
entity seq_design is end if;
port( a: in std_logic;
clock: in std_logic; when S2 => x <= '0';
reset: in std_logic; if a='0' then
x: out std_logic); next_state <= S2;
end seq_design; elsif a='1' then
next_state <= S3;
----------------------------------------------------- end if;

when S3 => x <= '1';


architecture FSM of seq_design is if a='0' then
next_state <= S3;
type state_type is (S0, S1, S2, S3); elsif a='1' then
signal next_state, current_state: state_type; next_state <= S0;
end if;
begin
when others =>
state_reg: process(clock, reset) x <= '0';
begin next_state <= S0;
if (reset='1') then
current_state <= S0; end case;
elsif (clock'event and clock='1') then end process;
current_state <= next_state; end FSM;
end if;
end process;
Mealy FSM - Example 1

• Mealy FSM that Recognizes Sequence “10”

0/0 1/0 1/0

S0 S1

reset 0/1

7
Mealy FSM in VHDL
TYPE state IS (S0, S1);
SIGNAL Mealy_state: state;

U_Mealy: PROCESS(clock, reset)


BEGIN
IF(reset = ‘1’) THEN 1/0
0/0 1/0
Mealy_state <= S0;
ELSIF (clock = ‘1’ AND clock’event) THEN
CASE Mealy_state IS S0 S1
WHEN S0 =>
IF input = ‘1’ THEN reset
Mealy_state <= S1;
ELSE 0/1
Mealy_state <= S0;
END IF;

WHEN S1 =>
IF input = ‘0’ THEN
Mealy_state <= S0;
ELSE
Mealy_state <= S1;
END IF;
END CASE;
END IF;
END PROCESS;

Output <= ‘1’ WHEN (Mealy_state = S1 AND input = ‘0’) ELSE ‘0’;
8

You might also like