
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































Outline
Resources
components and interconnects
VHDL Design Styles
“concurrent” statements (^) • Sequential Logic
“sequential” statements
Template for Moore Machines
architecture behavioral of fsm_example is type state is (S0, S1, S2, S3); -- define the state type signal pr_state, nx_state: state; -- declare present state and next state begin -- section 1: fsm register process (resetn,clock) begin if (resetn='0') then pr_state <= S0; -- choose reset state elsif (clock'event and clock='1') then pr_state <= nx_state; end if; end process;
Template for Moore Machines cont'd
-- section 2: next state function process (input, pr_state) begin case pr_state is when S0 => if (input =... ) then nx_state <= S1; else nx_state <= S2; end if;
... end case; end process; -- section 3: output function process (pr_state) –- or can use concurrent statements begin output <=... ... end end behavioral;
library IEEE; use IEEE.STD_LOGIC_1164.all; entity moore_fsm is port(w : in STD_LOGIC; clock : in STD_LOGIC; resetn : in STD_LOGIC; z : out STD_LOGIC); end moore_fsm; architecture behavioral of moore_fsm is type state is (S0, S1, S2); signal pr_state, nx_state: state; begin -- section 1: fsm register process (resetn,clock) begin if (resetn='0') then pr_state <= S0; -- reset state elsif (clock'event and clock='1') then pr_state <= nx_state; end if; end process;
-- section 2: next state function process (w, pr_state) -- sensitive to both input and present state begin case pr_state is when S0 => if (w = '0') then nx_state <= S0; else nx_state <= S1; end if; when S1 => if (w = '0') then nx_state <= S0; else nx_state <= S2; end if;
when S2 => if (w = '0') then nx_state <= S0; else nx_state <= S2; end if; end case; end process;
-- section 3: output function z <= '1' when pr_state = S2 else '0'; -- or can use process statement: -- process(pr_state) -- sensitive to present state only -- begin -- if pr_state = S2 then z <='1'; else z<='0'; end if; -- end process; end behavioral;
Testbench
library ieee; use ieee.std_logic_1164.all; entity moore_fsm_tb is end moore_fsm_tb; architecture TB_ARCHITECTURE of moore_fsm_tb is component moore_fsm port(w : in std_logic; clock : in std_logic; resetn : in std_logic; z : out std_logic ); end component; signal w : std_logic := '0'; signal clock : std_logic := '0'; constant clockperiod : time := 20 ns; signal resetn : std_logic; signal z : std_logic; begin
Coding Alternative: Merging sections 2 & 3
library IEEE; use IEEE.STD_LOGIC_1164.all; entity moore_fsm is port(w : in STD_LOGIC; clock : in STD_LOGIC; resetn : in STD_LOGIC; z : out STD_LOGIC); end moore_fsm; architecture behavioral of moore_fsm is type state is (S0, S1, S2); signal pr_state, nx_state: state; begin -- section 1: fsm register process (resetn,clock) begin if (resetn='0') then pr_state <= S0; elsif (clock'event and clock='1') then pr_state <= nx_state; end if; end process;
-- section 2 & 3: next state function, output function process (w, pr_state) begin case pr_state is when S0 => z <= '0'; if (w = '0') then nx_state <= S0; else nx_state <= S1; end if; when S1 => z <= '0'; if (w = '0') then nx_state <= S0; else nx_state <= S2; end if;
when S2 => z <= '1'; if (w = '0') then nx_state <= S0; else nx_state <= S2; end if; end case; end process; end behavioral;
Template for Mealy Machines
architecture behavioral of fsm_example is type state is (S0, S1, S2, S3); signal pr_state, nx_state: state; begin -- section 1: fsm register process (resetn,clock) begin if (resetn='0') then pr_state <= S0; -- reset state elsif (clock'event and clock='1') then pr_state <= nx_state; end if; end process;
Template for Mealy Machines cont'd
-- section 2: next state function process (input, pr_state) begin case pr_state is when S0 => if (input =... ) then nx_state <= S1; else
... end case; end process; -- section 3: output function process (input, pr_state) -- or can use concurrent statements begin case pr_state is when S0 => if (input =... ) then ... end case; end process; end behavioral;
S
w = 0 ⁄ z = 0
w = 0 ⁄ z = 0 S1 w = 1 ⁄ z = 1
resetn w = 1 ⁄ z = 0
Mealy Example FSM
Present Next state^ Output^ z state (^) w = 0 w = 1 w = 0 w = 1
A A B 0 0 B A B 0 1
Mealy Example FSM – State Table
-- section 3: output function process(w, pr_state) -- sensitive to both input and present state begin case pr_state is when S0 => z <= '0'; when S1 => if (w = '0') then z <= '0'; else z <= '1'; end if; end case; end process; -- or can use concurrent code: -- z <= '1' when (pr_state = S1 and w = '1') else '0'; end behavioral;
Testbench
Waveform
Coding Alternative: Merging sections 2 & 3
State Encoding Problem
are known to produce optimal circuit
Types of State Encoding