--* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * --* * * * * * * * * * * * * * * * VHDL Source Code * * * * * * * * * * * * * * --* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * --* Title : TEST_STATE --* Filename & Ext : test_state.vhdl --* Author : David W. Bishop --* Created : Apr 19, 1996 --* Version : 1.2 --* Revision Date : 97/02/17 --* SCCSid : 1.2 2/17/97 test_state.vhdl --* WORK Library : chiptest --* MOD History : --* Description : This IS an example state machine FOR VHDL. --* Known Bugs : --* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * library ieee; use ieee.std_logic_1164.all; entity test_state IS port ( clk : in std_ulogic; RESET : in std_ulogic; con1, con2, con3 : in std_ulogic; out1, out2 : OUT std_ulogic ); END test_state; ------------------------------------------------------------------------------- -- Example of a MOORE machine (outputs come from CASE statment) -- Note that with this TYPE of state machine you must specify the state -- of ALL of the outputs of your state machine. Otherwise, you GET -- latches. ------------------------------------------------------------------------------- architecture rtl of test_state IS TYPE state_type IS (s0, s1, s2, s3); SIGNAL state, next_state : state_type; begin -- rtl state_encode : process ( state, con1, con2, con3 ) begin next_state <= s1; -- Note: This LINE will optomize your state machine -- in synthesis. It does nothing in simulation. CASE state IS when s0 => next_state <= s1; when s1 => IF ( con1 = '1' ) then next_state <= s2; ELSE next_state <= s1; END IF; when s2 => next_state <= s3; when s3 => IF ( con2 = '0' ) then next_state <= s3; elsif ( con3 = '0' ) then next_state <= s2; ELSE next_state <= s0; END IF; END CASE; END process state_encode; state_register : process ( RESET, clk ) begin IF ( RESET = '0' ) then state <= s0; elsif ( clk'event and clk = '1' ) then state <= next_state; END IF; END process state_register; state_decode : process ( state, con1, con2, con3 ) begin CASE state IS when s0 => out1 <= '0'; out2 <= '0'; when s1 => out1 <= '1'; out2 <= '0'; when s2 => out1 <= '0'; out2 <= '1'; when s3 => IF ( con2 = '0' ) then out1 <= '0'; out2 <= '0'; elsif ( con3 = '0' ) then out1 <= '0'; out2 <= '1'; ELSE out1 <= '1'; out2 <= '1'; END IF; END CASE; END process state_decode; END rtl;