Advertisement
Guest User

Untitled

a guest
Jan 6th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 7.48 KB | None | 0 0
  1. -- VHDL Test Bench Created by ISE for module: irrigatore
  2. --
  3. -- Dependencies:
  4. --
  5. -- Revision:
  6. -- Revision 0.01 - File Created
  7. -- Additional Comments:
  8. --
  9. -- Notes:
  10. -- This testbench has been automatically generated using types std_logic and
  11. -- std_logic_vector for the ports of the unit under test.  Xilinx recommends
  12. -- that these types always be used for the top-level I/O of a design in order
  13. -- to guarantee that the testbench will bind correctly to the post-implementation
  14. -- simulation model.
  15. --------------------------------------------------------------------------------
  16. LIBRARY ieee;
  17. USE ieee.std_logic_1164.ALL;
  18. USE ieee.std_logic_arith.ALL;
  19.  
  20. -- Uncomment the following library declaration if using
  21. -- arithmetic functions with Signed or Unsigned values
  22. --USE ieee.numeric_std.ALL;
  23.  
  24. ENTITY first_irrigator_test IS
  25. END first_irrigator_test;
  26.  
  27. ARCHITECTURE behavior OF first_irrigator_test IS
  28.  
  29.     -- Component Declaration for the Unit Under Test (UUT)
  30.  
  31.     COMPONENT irrigatore
  32.     PORT(
  33.          rst : IN  std_logic;
  34.          clk : IN  std_logic;
  35.          anomaly : IN  std_logic;
  36.          start_stop : IN  std_logic;
  37.          timer : IN  std_logic_vector(5 downto 0);
  38.          rot_frequency : IN  std_logic;
  39.          water : OUT  std_logic;
  40.          rotation : OUT  std_logic;
  41.          debug_time : OUT  std_logic_vector(5 downto 0);
  42.             debug_state : OUT std_logic_vector(2 downto 0)
  43.         );
  44.     END COMPONENT;
  45.    
  46.  
  47.    --Inputs
  48.    signal rst : std_logic := '0';
  49.    signal clk : std_logic := '0';
  50.    signal anomaly : std_logic := '0';
  51.    signal start_stop : std_logic := '0';
  52.    signal timer : std_logic_vector(5 downto 0) := (others => '0');
  53.    signal rot_frequency : std_logic := '0';
  54.  
  55.     --Outputs
  56.    signal water : std_logic;
  57.    signal rotation : std_logic;
  58.    signal debug_time : std_logic_vector(5 downto 0);
  59.     signal debug_state : std_logic_vector(2 downto 0);
  60.  
  61.    -- Clock period definitions
  62.    constant clk_period : time := 10 ns;
  63.  
  64. BEGIN
  65.  
  66.     -- Instantiate the Unit Under Test (UUT)
  67.    uut: irrigatore PORT MAP (
  68.           rst => rst,
  69.           clk => clk,
  70.           anomaly => anomaly,
  71.           start_stop => start_stop,
  72.           timer => timer,
  73.           rot_frequency => rot_frequency,
  74.           water => water,
  75.           rotation => rotation,
  76.           debug_time => debug_time,
  77.              debug_state => debug_state
  78.         );
  79.  
  80.    -- Clock process definitions
  81.    clk_process :process
  82.    begin
  83.         clk <= '0';
  84.         wait for clk_period/2;
  85.         clk <= '1';
  86.         wait for clk_period/2;
  87.    end process;
  88.  
  89.  
  90.    -- Stimulus process
  91.      stim_proc: process
  92.     variable vet,vet1 : std_logic_vector(2 downto 0):=(others =>'0');
  93.    begin       
  94.       -- hold reset state for 100 ns.
  95.         rst<='1';
  96.       wait for clk_period/2*10;
  97.         rst<='0';
  98.       wait for clk_period/2*10;
  99.  
  100.       -- insert stimulus here
  101.         timer <= "000011"; --fin quando rimango in spento il timer può essere cambiato
  102.         -- RIMANGO IN OFF
  103.         for i in 7 downto 4 loop
  104.             vet:=conv_std_logic_vector(i,3);     --mi permette di gestire tutti i casi in cui l'anomalia è 1
  105.             anomaly<=vet(2);
  106.             start_stop<=vet(1);
  107.             rot_frequency<=vet(0);
  108.             wait for clk_period/2*2;
  109.         end loop;
  110.         -- RIMANGO IN OFF
  111.         for i in 1 downto 0 loop
  112.             vet:=conv_std_logic_vector(i,3);      --mi permette di gestire i casi in cui l'anomalia e lo start_stop stanno a zero
  113.             anomaly<=vet(2);
  114.             start_stop<=vet(1);
  115.             rot_frequency<=vet(0);
  116.             wait for clk_period/2*2;
  117.         end loop;
  118.         -- VADO IN IRRIGAZIONE LENTA
  119.         anomaly<='0';
  120.         start_stop<='1';
  121.         timer<="000010"; --prima del passaggio al nuovo stato inserisco un altro tempo che quindi diventa il nuovo tempo di irrigazione
  122.         rot_frequency<='0';
  123.         wait for clk_period/2;
  124.        
  125.         -- RIMANGO IN IRRIGAZIONE LENTA
  126.         anomaly<='0';
  127.         start_stop<='0';
  128.         rot_frequency<='0';
  129.           timer <= "000111";--questo tempo non determina una variazione del tempo di irrigazione
  130.         wait for clk_period/2*3;
  131.  
  132. --VADO DA IRRIGAZIONE LENTA A SOSPENSIONE LENTA 2 VOLTE
  133.         for i in 3 downto 2 loop
  134.             --VADO
  135.             vet:=conv_std_logic_vector(i,3);
  136.             anomaly<=vet(2);
  137.             start_stop<=vet(1);
  138.             rot_frequency<=vet(0);
  139.             wait for clk_period/2;
  140.             -- RIMANGO IN SOSPENSIONE LENTA
  141.             for j in 0 to 1 loop
  142.                 vet1:=conv_std_logic_vector(j,3);
  143.                 anomaly<=vet1(2);
  144.                 start_stop<=vet1(1);
  145.                 rot_frequency<=vet1(0);
  146.                 wait for clk_period/2*2;
  147.             end loop;
  148.             -- RITORNO
  149.             anomaly<=vet(2);
  150.             start_stop<=vet(1);
  151.             rot_frequency<=vet(0);
  152.             wait for clk_period/2*3;
  153.         end loop;
  154.        
  155.         --RILEVO UN ANOMALIA IN IRRIGAZIONE LENTA(TUTTE LE COMBINAZIONI)
  156.         for i in 0 to 3 loop
  157.         -- SI SPEGNE LA MACCHINA
  158.             vet:=conv_std_logic_vector(i,3);
  159.             anomaly<='1';
  160.             start_stop<=vet(1);
  161.             rot_frequency<=vet(0);
  162.             wait for clk_period/2*2;
  163.         -- RITORNO AD IRRIGAZIONE LENTA
  164.            anomaly<='0';
  165.             start_stop<='1';
  166.             rot_frequency<='0';
  167.             wait for clk_period/2*2;
  168.         end loop;
  169.          
  170.         -- VADO DA IRRIGAZIONE LENTA A IRRIGAZIONE VELOCE
  171.         anomaly<='0';
  172.         start_stop<='0';
  173.         rot_frequency<='1';
  174.           timer <= "001111";
  175.         wait for clk_period/2*2;
  176.         -- RIMANGO IN IRRIGAZIONE VELOCE
  177.         anomaly<='0';
  178.         start_stop<='0';
  179.         timer<="000011";
  180.         rot_frequency<='1';
  181.         wait for clk_period/2*2;
  182.        
  183.         --VADO DA IRRIGAZIONE VELOCE A SOSPENSIONE VELOCE 2 VOLTE
  184.         for i in 2 to 3 loop
  185.             --VADO
  186.             vet:=conv_std_logic_vector(i,3);
  187.             anomaly<=vet(2);
  188.             start_stop<=vet(1);
  189.             rot_frequency<=vet(0);
  190.             wait for clk_period/2;
  191.             -- RIMANGO IN SOSPENSIONE VELOCE
  192.             for j in 0 to 1 loop
  193.                 vet1:=conv_std_logic_vector(j,3);
  194.                 anomaly<=vet1(2);
  195.                 start_stop<=vet1(1);
  196.                 rot_frequency<=vet1(0);
  197.                 wait for clk_period/2*2;
  198.             end loop;
  199.             -- RITORNO
  200.             anomaly<=vet(2);
  201.             start_stop<=vet(1);
  202.             rot_frequency<=vet(0);
  203.             wait for clk_period/2*3;
  204.         end loop;
  205.          
  206.          
  207.         --RILEVO UN ANOMALIA IN IRRIGAZIONE VELOCE(TUTTE LE COMBINAZIONI)
  208.         for i in 0 to 3 loop
  209.         -- SI SPEGNE LA MACCHINA  
  210.             anomaly<='1';
  211.             start_stop<=vet(1);
  212.             rot_frequency<=vet(0);
  213.             wait for clk_period/2*2;
  214.         -- RITORNO AD IRRIGAZIONE VELOCE
  215.            anomaly<='0';
  216.             start_stop<='1';
  217.             rot_frequency<='1';
  218.             wait for clk_period/2*2;
  219.         end loop;
  220.         -- VADO DA IRRIGAZIONE VELOCE A IRRIGAZIONE LENTA DOVE FINISCO DI IRRIGARE
  221.          anomaly<='0';
  222.          start_stop<='0';
  223.          rot_frequency<='0';
  224.        
  225.        
  226.     ---- All'inizio abbiamo utilizzato clk_period/2*n, in quanto avendo implementato la macchina con un'automa di Mealy e
  227.     ---- avendo utilizzato un pulsante impulsivo, volevamo cercare di sincronizzare ogni singola variazione di ingresso
  228.     ---- con la sua rispettiva uscita.
  229.  
  230.  
  231.        
  232.        
  233.    
  234.        
  235.  
  236.       wait;
  237.    end process;
  238.    
  239.        
  240. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement