Advertisement
Guest User

Untitled

a guest
Jan 7th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 11.24 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:   11:47:43 12/27/2018
  6. -- Design Name:  
  7. -- Module Name:   /home/ise/Desktop/New Folder/Progetto_Traccia4/Tb_Controllo_lezioni_TECD.vhd
  8. -- Project Name:  Progetto_Traccia4
  9. -- Target Device:  
  10. -- Tool versions:  
  11. -- Description:  
  12. --
  13. -- VHDL Test Bench Created by ISE for module: Controllo_lezioni_TECD
  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. use ieee.std_logic_arith.all;
  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 Tb_Controllo_lezioni_TECD IS
  36. END Tb_Controllo_lezioni_TECD;
  37.  
  38. ARCHITECTURE behavior OF Tb_Controllo_lezioni_TECD IS
  39.  
  40.     -- Component Declaration for the Unit Under Test (UUT)
  41.  
  42.     COMPONENT Controllo_lezioni_TECD
  43.     PORT(
  44.          clk : IN  std_logic;
  45.          rst : IN  std_logic;
  46.          badge : IN  std_logic;
  47.          col : IN  std_logic_vector(3 downto 1);
  48.          row : IN  std_logic_vector(4 downto 1);
  49.             state_debug: out std_logic_vector(3 downto 0);
  50.          output : OUT  std_logic_vector(2 downto 1)
  51.         );
  52.     END COMPONENT;
  53.    
  54.  
  55.    --Inputs
  56.    signal clk : std_logic := '0';
  57.    signal rst : std_logic := '0';
  58.    signal badge : std_logic := '0';
  59.    signal col : std_logic_vector(3 downto 1) := (others => '0');
  60.    signal row : std_logic_vector(4 downto 1) := (others => '0');
  61.  
  62.     --Outputs
  63.    signal output : std_logic_vector(2 downto 1);
  64.    signal state_debug: std_logic_vector(3 downto 0);
  65.    
  66.     signal vector: std_logic_vector(7 downto 0):= (others =>'0');
  67.    -- Clock period definitions
  68.    constant clk_period : time := 10 ns;
  69.  
  70. BEGIN
  71.  
  72.     -- Instantiate the Unit Under Test (UUT)
  73.    uut: Controllo_lezioni_TECD PORT MAP (
  74.           clk => clk,
  75.           rst => rst,
  76.           badge => badge,
  77.           col => col,
  78.           row => row,
  79.              state_debug => state_debug,
  80.           output => output
  81.         );
  82.    
  83.     -- Clock process definitions
  84.    clk_process :process
  85.    begin
  86.         clk <= '0';
  87.         wait for clk_period/2;
  88.         clk <= '1';
  89.         wait for clk_period/2;
  90.    end process;
  91.  
  92.    
  93.    -- Stimulus process
  94.    stim_proc: process
  95.    
  96.    begin       
  97.       -- hold reset state for 100 ns.
  98.         rst<= '1';
  99.       wait for 10 ns;  
  100.         rst<= '0';
  101.       wait for clk_period*10;
  102.  
  103.       -- insert stimulus here
  104.       --testiamo tutte le combinazioni in s0
  105.         badge<='0';
  106.         wait for 10 ns;
  107.         for i in 1 to 8 loop
  108.             col<= conv_std_logic_vector(i, 3);
  109.              for j in 1 to 16 loop
  110.                 row<= conv_std_logic_vector(j,4);
  111.                 wait for clk_period;
  112.           end loop;
  113.         end loop;
  114.        --input che mi fa transitare di stato(s0->s1)
  115.         badge<= '1';
  116.         wait for 10 ns;
  117.        
  118.         col<= "000";
  119.         row<= "0000";
  120.         wait for 10 ns;
  121.         --inserimento cancelletto
  122.         col<= "001";
  123.         row<= "0001";      
  124.         wait for 10 ns;
  125.         --testiamo tutte le combinazioni errate su s1(tutte escluse cancelletto e 0)
  126.        
  127.         for i in 1 to 8 loop
  128.             col<= conv_std_logic_vector(i, 3);
  129.              for j in 1 to 16 loop
  130.                 row<= conv_std_logic_vector(j,4);
  131.                 wait for clk_period*10;
  132.           end loop;
  133.         end loop;
  134.         --inserimento cancelletto per andare in s1
  135.         col<= "001";
  136.         row<= "0001";      
  137.         wait for 10 ns;
  138.         --inserimento 0 per andare in s3
  139.         col<= "010";
  140.         row<= "0001";      
  141.         wait for 10 ns;
  142.        
  143.         --testiamo tutte le combinazioni errate su s3 che ci portano in s4(tranne #, 0 e 1)
  144.         for i in 1 to 8 loop
  145.             col<= conv_std_logic_vector(i, 3);
  146.              for j in 1 to 16 loop
  147.                 row<= conv_std_logic_vector(j,4);
  148.                 wait for clk_period;
  149.           end loop;
  150.         end loop;
  151.         --inserimento cancelletto per andare in s3
  152.         col<= "001";
  153.         row<= "0001";      
  154.         wait for 10 ns;
  155.         --inserimento lezione di teoria
  156.         col<= "100";
  157.         row<= "1000";
  158.         wait for 10 ns;
  159.         --testiamo tutte le combinazioni errate su s5 che ci portano in s6(tranne #, 1 e 2)
  160.         for i in 1 to 8 loop
  161.             col<= conv_std_logic_vector(i, 3);
  162.              for j in 1 to 16 loop
  163.                 row<= conv_std_logic_vector(j,4);
  164.                 wait for clk_period;
  165.           end loop;
  166.         end loop;
  167.         --inserimento cancelletto per ritornare in s5
  168.         col<= "001";
  169.         row<= "0001";      
  170.         wait for 10 ns;
  171.         --inserimento 2 per andare in s7(ore di lezione)
  172.         col<= "010";
  173.         row<= "1000";
  174.         wait for 10 ns;
  175.         --testiamo tutte le combinazioni errate su s7 che ci portano in s8(tranne # e *)
  176.         for i in 1 to 8 loop
  177.             col<= conv_std_logic_vector(i, 3);
  178.              for j in 1 to 16 loop
  179.                 row<= conv_std_logic_vector(j,4);
  180.                 wait for clk_period;
  181.           end loop;
  182.         end loop;
  183.         --inserimento cancelletto per ritornare in s7
  184.         col<= "001";
  185.         row<= "0001";      
  186.         wait for 10 ns;
  187.         --inserimento * per andare in s9
  188.         col<= "100";
  189.         row<= "0001";      
  190.         wait for 100 ns;
  191.        
  192.         badge<='0';
  193.         wait for 10 ns;
  194.         wait;
  195.     end process;
  196.    
  197. debug: process(state_debug, clk, rst)
  198. variable state_col: std_logic_vector(3 downto 1);
  199. variable state_row: std_logic_vector(4 downto 1);
  200. begin
  201. state_col:= col;
  202. state_row:= row;
  203.        
  204. if rising_edge(clk) then
  205.  
  206. --macchina spenta
  207. if(rst = '1') then
  208.     report "Macchina spenta" severity note;
  209.  
  210. --macchina in attesa di badge in s0
  211. elsif(state_debug="0000" and badge='0') then
  212.    report "Sono in s0 in attesa del badge" severity note;
  213.  
  214. --in s0 ricevo badge=1
  215. elsif(state_debug="0000" and badge='1') then   
  216.     report "Badge letto. Vado in s1" severity note;
  217.    
  218. --testiamo lo stato s1
  219.    
  220. elsif(state_debug="0001") then
  221.    if(badge='1') then
  222. --siamo in s1 e non inseriamo nessun input 
  223.         if(state_col="000" and state_row="0000") then
  224.             report "Sono in attesa di input in s1" severity note;
  225. --inserimento cancelletto in s1
  226.        elsif((state_col="001" and state_row="0001")) then
  227.             report "# letto in s1. Resto in s1" severity note;
  228. --inserimento 0 in s1
  229.        elsif(state_col="010" and state_row="0001") then
  230.             report "0 letto in s1. Vado in s3" severity note;
  231. --inserimento sequenze errate
  232.       else
  233.            report "Combinazione errata, vado in s2" severity note;
  234.         end if;
  235.    else
  236.         report "Badge=0 quindi torno in s0" severity note;
  237.     end if;
  238.    
  239. --testiamo lo stato s2
  240.  
  241. elsif(state_debug="0010") then
  242.    if(badge='1') then
  243. --nessun input inserito
  244.         if(state_col="000" and state_row="0000") then
  245.             report "Sono in attesa di input in s2" severity note;
  246. --inserimento cancelletto in s2
  247.        elsif((state_col="001" and state_row="0001")) then
  248.             report "# letto in s2. Vado in s1" severity note;
  249. --inserimento sequenze errate
  250.       else
  251.            report "Combinazione errata, resto in s2" severity note;
  252.         end if;
  253.    else
  254.         report "Badge=0 quindi torno in s0" severity note;
  255.     end if;
  256.  
  257. -- testiamo lo stato s3
  258.  
  259. elsif(state_debug="0011") then
  260.    if(badge='1') then
  261. --nessun input inserito
  262.         if(state_col="000" and state_row="0000") then
  263.             report "Sono in attesa di input in s3" severity note;
  264. --inserimento cancelletto in s3
  265.        elsif((state_col="001" and state_row="0001")) then
  266.             report "# letto in s3. Resto in s3" severity note;
  267. --inserimento 0 o 1
  268.         elsif((state_col="010" and state_row="0001") or(state_col="100" and state_row="1000")) then
  269.             if(state_col="010" and state_row="0001") then
  270.               report "0 inserito. Lezione di teoria" severity note;
  271.             else
  272.               report "1 inserito. Lezione di pratica" severity note;
  273.             end if;
  274. --inserimento sequenze errate
  275.       else
  276.            report "Combinazione errata, vado in s4" severity note;
  277.         end if;
  278.    else
  279.         report "Badge=0 quindi torno in s0" severity note;
  280.     end if;
  281.    
  282. --testiamo lo stato s4 
  283.    
  284. elsif(state_debug="0100") then
  285.    if(badge='1') then
  286. --nessun input inserito
  287.         if(state_col="000" and state_row="0000") then
  288.             report "Sono in attesa di input in s4" severity note;
  289. --inserimento cancelletto in s4
  290.        elsif((state_col="001" and state_row="0001")) then
  291.             report "# letto in s4. Vado in s3" severity note;
  292. --inserimento sequenze errate
  293.       else
  294.            report "Combinazione errata, resto in s4" severity note;
  295.         end if;
  296.    else
  297.         report "Badge=0 quindi torno in s0" severity note;
  298.     end if;
  299.  
  300. --testiamo lo stato s5
  301.  
  302. elsif(state_debug="0101") then
  303.    if(badge='1') then
  304. --nessun input inserito
  305.         if(state_col="000" and state_row="0000") then
  306.             report "Sono in attesa di input in s5" severity note;
  307. --inserimento cancelletto in s5
  308.        elsif((state_col="001" and state_row="0001")) then
  309.             report "# letto in s5. Resto in s5" severity note;
  310. --inserimento 0 o 1
  311.         elsif((state_col="010" and state_row="1000") or(state_col="100" and state_row="1000")) then
  312.             if(state_col="010" and state_row="1000") then
  313.               report "2 inserito. Due ore di lezione" severity note;
  314.             else
  315.               report "1 inserito. Un'ora di lezione" severity note;
  316.             end if;
  317. --inserimento sequenze errate
  318.       else
  319.            report "Combinazione errata, vado in s6" severity note;
  320.         end if;
  321.    else
  322.         report "Badge=0 quindi torno in s0" severity note;
  323.     end if;
  324.  
  325. --testiamo lo stato s6
  326.  
  327. elsif(state_debug="0110") then
  328.    if(badge='1') then
  329. --nessun input inserito
  330.         if(state_col="000" and state_row="0000") then
  331.             report "Sono in attesa di input in s6" severity note;
  332. --inserimento cancelletto in s6
  333.        elsif((state_col="001" and state_row="0001")) then
  334.             report "# letto in s6. Vado in s5" severity note;
  335. --inserimento sequenze errate
  336.       else
  337.            report "Combinazione errata, resto in s6" severity note;
  338.         end if;
  339.    else
  340.         report "Badge=0 quindi torno in s0" severity note;
  341.     end if;
  342.  
  343. --testiamo lo stato s7
  344.  
  345. elsif(state_debug="0111") then
  346.    if(badge='1') then
  347. --nessun input inserito
  348.         if(state_col="000" and state_row="0000") then
  349.             report "Sono in attesa di input in s7" severity note;
  350. --inserimento cancelletto in s7
  351.        elsif((state_col="001" and state_row="0001")) then
  352.             report "# letto in s7. Resto in s7" severity note;
  353. --inserimento *
  354.         elsif(state_col="100" and state_row="0001") then
  355.             report "* letto in s7. Vado in s9" severity note;
  356. --inserimento sequenze errate
  357.       else
  358.            report "Combinazione errata, vado in s8" severity note;
  359.         end if;
  360.    else
  361.         report "Badge=0 quindi torno in s0" severity note;
  362.     end if;
  363.  
  364. --testiamo s8
  365.  
  366. elsif(state_debug="1000") then
  367.    if(badge='1') then
  368. --nessun input inserito
  369.         if(state_col="000" and state_row="0000") then
  370.             report "Sono in attesa di input in s8" severity note;
  371. --inserimento cancelletto in s8
  372.        elsif((state_col="001" and state_row="0001")) then
  373.             report "# letto in s8. Vado in s7" severity note;
  374. --inserimento sequenze errate
  375.       else
  376.            report "Combinazione errata, resto in s8" severity note;
  377.         end if;
  378.    else
  379.         report "Badge=0 quindi torno in s0" severity note;
  380.     end if;
  381. -- testiamo s9
  382. elsif(state_debug ="1001") then
  383.     if(badge='1') then
  384.      report "Sessione aperta" severity note;
  385.     else
  386.      report "Sessione chiusa, ritorno in s0" severity note;
  387.     end if;
  388.    
  389. end if;
  390. end if;
  391. end process debug;
  392. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement