Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.57 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3.  
  4. -- Uncomment the following library declaration if using
  5. -- arithmetic functions with Signed or Unsigned values
  6. --use IEEE.NUMERIC_STD.ALL;
  7.  
  8. -- Uncomment the following library declaration if instantiating
  9. -- any Xilinx leaf cells in this code.
  10. --library UNISIM;
  11. --use UNISIM.VComponents.all;
  12.  
  13. entity FSMexample is
  14.     Port ( CLK : in STD_LOGIC;
  15.            RST : in STD_LOGIC;
  16.            INPUTA : in STD_LOGIC;
  17.            INPUTB : in STD_LOGIC;
  18.            OUTPUTA : out STD_LOGIC;
  19.            OUTPUTB : out STD_LOGIC);
  20. end FSMexample;
  21.  
  22. architecture Behavioral of FSMexample is
  23.  
  24. -- signal to store the FSM state in. Start at 0 state
  25. signal state : std_logic_vector(1 downto 0) := "00";
  26.  
  27. begin
  28.  
  29. -- Logic to handle our outputs as a function of the current state.
  30. -- Note that these are not tied to the clock directly but are instead
  31. -- tied to the state variable that is synchronised to the clock for everything
  32. -- except an asynchronous reset
  33. OUTPUTA <= '1' when (state = "00" or state = "11") else '0';
  34. OUTPUTB <= '1' when (state = "00" or state = "01") else '0';
  35.  
  36. -- process to handle our state transitions that is sensitive to the clock and a reset
  37. process(CLK, RST)
  38.     begin
  39.         if RST = '1' then
  40.             -- This is the reset case, set the state back to 0
  41.             state <= "00";
  42.            
  43.         elsif rising_edge(CLK) then
  44.             -- This is where our state transition logic fits we'll handle the transition out of
  45.             -- each state with a case block
  46.            
  47.             case state is
  48.                 when "00" =>
  49.                     -- State transition logic for state 00
  50.                     if INPUTA = '0' AND INPUTB = '0' then
  51.                         state <= "10";
  52.                     end if;
  53.                    
  54.                 when "01" =>
  55.                     -- State transition logic for state 01
  56.                     if INPUTA = '1' AND INPUTB = '1' then
  57.                         state <= "11";
  58.                     end if;
  59.                    
  60.                    
  61.                 when "10" =>
  62.                     -- State transition logic for state 10
  63.                     if INPUTB = '1' then
  64.                         state <= "01";
  65.                     end if;
  66.                    
  67.                 when "11" =>
  68.                     -- State transition logic for state 11
  69.                     if INPUTA /= INPUTB then
  70.                         state <= "00";
  71.                     end if;
  72.                    
  73.             end case;
  74.         end if;
  75. end process;
  76.  
  77. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement