Advertisement
Guest User

Untitled

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