Facebook
From sugier, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 207
  1. --------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:   14:40:59 12/17/2018
  6. -- Design Name:  
  7. -- Module Name:   C:/Users/lab/lab500/lab5test.vhd
  8. -- Project Name:  lab500
  9. -- Target Device:  
  10. -- Tool versions:  
  11. -- Description:  
  12. --
  13. -- VHDL Test Bench Created by ISE for module: lab55
  14. --
  15. -- Dependencies:
  16. --
  17. -- Revision:
  18. -- Revision 0.01 - File Created
  19. -- Additional Comments:
  20. --
  21. -- Notes:
  22. -- This testbench has been automatically generated using types std_logic and
  23. -- std_logic_vector for the ports of the unit under test.  Xilinx recommends
  24. -- that these types always be used for the top-level I/O of a design in order
  25. -- to guarantee that the testbench will bind correctly to the post-implementation
  26. -- simulation model.
  27. --------------------------------------------------------------------------------
  28. LIBRARY ieee;
  29. USE ieee.std_logic_1164.ALL;
  30.  
  31. -- Uncomment the following library declaration if using
  32. -- arithmetic functions with Signed or Unsigned values
  33. --USE ieee.numeric_std.ALL;
  34.  
  35. ENTITY lab5test IS
  36. END lab5test;
  37.  
  38. ARCHITECTURE behavior OF lab5test IS
  39.  
  40.     -- Component Declaration for the Unit Under Test (UUT)
  41.  
  42.     COMPONENT lab55
  43.     PORT(
  44.          DI : IN  std_logic_vector(7 downto 0);
  45.          RDY : IN  std_logic;
  46.          RST : IN  std_logic;
  47.          CLK : IN  std_logic;
  48.          CE : IN  std_logic;
  49.          Y : OUT  std_logic
  50.         );
  51.     END COMPONENT;
  52.    
  53.  
  54.    --Inputs
  55.    signal DI : std_logic_vector(7 downto 0) := (others => '0');
  56.    signal RDY : std_logic := '0';
  57.    signal RST : std_logic := '0';
  58.    signal CLK : std_logic := '0';
  59.    signal CE : std_logic := '1';
  60.    
  61.         --Outputs
  62.    signal Y : std_logic;
  63.    type data_type is array (0 to 18) of std_logic_vector(7 downto 0);
  64.  
  65.    -- Clock period definitions
  66.    constant CLK_period : time := 10 ns;
  67.    
  68.    signal data : data_type :=(
  69.       X"15",
  70.       X"15",
  71.       X"15",
  72.       X"3B",
  73.       X"42",
  74.       X"42",
  75.       X"42",
  76.       X"15",
  77.       X"15",
  78.       X"15",
  79.       X"3B",
  80.       X"42",
  81.       X"42",
  82.       X"3B",
  83.       X"42",
  84.       X"42",
  85.       X"42",
  86.       X"15",
  87.       X"15"
  88.    );
  89.  
  90. BEGIN
  91.  
  92.         -- Instantiate the Unit Under Test (UUT)
  93.    uut: lab55 PORT MAP (
  94.           DI => DI,
  95.           RDY => RDY,
  96.           RST => RST,
  97.           CLK => CLK,
  98.           CE => CE,
  99.           Y => Y
  100.         );
  101.  
  102.    -- Clock process definitions
  103.    CLK_process :process
  104.    begin
  105.                 CLK <= '0';
  106.                 wait for CLK_period/2;
  107.                 CLK <= '1';
  108.                 wait for CLK_period/2;
  109.    end process;
  110.  
  111.    -- Stimulus process
  112.    stim_proc: process
  113.    begin               
  114.       -- hold reset state for 100 ns.
  115.       wait until falling_edge (clk);
  116.          wait for CLK_period;
  117.          for i in 0 to 18 loop
  118.             wait until falling_edge(Clk);
  119.             RDY <= '1';
  120.             DI <= data(i);
  121.             wait for CLK_period;
  122.             RDY <= '0';
  123.             wait for CLK_period;
  124.             wait until falling_edge(Clk);
  125.             RDY <= '1';
  126.             -- DI <= X"F0";
  127.             wait for CLK_period;
  128.             RDY <= '0';
  129.             wait for CLK_period;
  130.             wait until falling_edge(Clk);
  131.             RDY <= '1';
  132.             DI <= data(i);
  133.             wait for CLK_period;
  134.             RDY <= '0';
  135.             wait for CLK_period;
  136.  
  137.          END loop;
  138.  
  139.       wait;
  140.    end process;
  141.  
  142. END;
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159. ----------------------------------------------------------------------------------
  160. -- Company:
  161. -- Engineer:
  162. --
  163. -- Create Date:    14:16:45 12/17/2018
  164. -- Design Name:
  165. -- Module Name:    lab55 - Behavioral
  166. -- Project Name:
  167. -- Target Devices:
  168. -- Tool versions:
  169. -- Description:
  170. --
  171. -- Dependencies:
  172. --
  173. -- Revision:
  174. -- Revision 0.01 - File Created
  175. -- Additional Comments:
  176. --
  177. ----------------------------------------------------------------------------------
  178. library IEEE;
  179. use IEEE.STD_LOGIC_1164.ALL;
  180.  
  181. -- Uncomment the following library declaration if using
  182. -- arithmetic functions with Signed or Unsigned values
  183. --use IEEE.NUMERIC_STD.ALL;
  184.  
  185. -- Uncomment the following library declaration if instantiating
  186. -- any Xilinx primitives in this code.
  187. --library UNISIM;
  188. --use UNISIM.VComponents.all;
  189.  
  190. entity lab55 is
  191.     Port ( DI : in  STD_LOGIC_VECTOR (7 downto 0);
  192.            RDY : in  STD_LOGIC;
  193.            RST : in  STD_LOGIC;
  194.            CLK : in  STD_LOGIC;
  195.            CE : in  STD_LOGIC;
  196.            Y : out  STD_LOGIC);
  197. end lab55;
  198.  
  199. architecture Behavioral of lab55 is
  200. type state_type is (q0,q1,q2,q3,q4);
  201.         signal state, next_state : state_type;
  202.  
  203. begin
  204. process1 : process (CLK)
  205. begin
  206.         if CE = '1' then
  207.                 if rising_edge(CLK) then
  208.                         if RST = '1' then
  209.                                 state <= q0;
  210.                         elsif RDY = '1' then
  211.                                 state <= next_state;
  212.                         end if;
  213.                 end if;
  214.         end if;
  215. end process process1;
  216.  
  217. process2 : process (state, RDY)
  218. begin
  219.         next_state <= state;
  220.  
  221.         case state is
  222.                 when q0 =>
  223.                         if DI = X"3B" then
  224.                                 next_state <=q1;
  225.                         else
  226.                                 next_state <=q0;
  227.                         end if;
  228.                 when q1 =>
  229.                         if DI = X"42" then
  230.                                 next_state <= q2;
  231.                         else
  232.                                 next_state <= q0;
  233.                         end if;
  234.                 when q2 =>
  235.                         if DI = X"42" then
  236.                                 next_state <= q3;
  237.                         else
  238.                                 next_state <= q0;
  239.                         end if;
  240.                 when q3 =>
  241.                         if DI = X"42" then
  242.                                 next_state <= q4;
  243.                         else
  244.             next_state <=q0;
  245.                         end if;
  246.                 when q4 =>
  247.                         if DI = X"3B" then
  248.                                 next_state <= q1;
  249.                         else
  250.                                 next_state <= q0;
  251.                         end if;
  252.                
  253.         end case;
  254.         end process process2;
  255.         Y<='1' when state = q4 else '0';
  256. end Behavioral;
  257.  
  258.  
  259.  
  260.  
  261.