Advertisement
K1SR

2. domaci

Nov 18th, 2022
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1.  
  2. library ieee;
  3. use ieee.std_logic_1164.all;
  4.  
  5. library work;
  6.  
  7. entity lprs1_homework2_tb is
  8. end entity;
  9.  
  10. architecture arch of lprs1_homework2_tb is
  11.  
  12. constant i_clk_period : time := 25 ns; -- 40 MHz
  13.  
  14. signal i_clk : std_logic;
  15. signal i_rst : std_logic;
  16. signal i_run : std_logic;
  17. signal i_pause : std_logic;
  18.  
  19. signal o_digit0 : std_logic_vector(3 downto 0);
  20. signal o_digit1 : std_logic_vector(3 downto 0);
  21. signal o_digit2 : std_logic_vector(3 downto 0);
  22. signal o_digit3 : std_logic_vector(3 downto 0);
  23.  
  24. begin
  25.  
  26. uut: entity work.lprs1_homework2
  27. port map(
  28. i_clk => i_clk,
  29. i_rst => i_rst,
  30. i_run => i_run,
  31. i_pause => i_pause,
  32. o_digit0 => o_digit0,
  33. o_digit1 => o_digit1,
  34. o_digit2 => o_digit2,
  35. o_digit3 => o_digit3
  36. );
  37.  
  38. clk_p: process
  39. begin
  40. i_clk <= '1';
  41. wait for i_clk_period/2;
  42. i_clk <= '0';
  43. wait for i_clk_period/2;
  44. end process;
  45.  
  46. stim_p: process
  47. begin
  48. -- Test cases:
  49. i_run <= '0';
  50. i_pause <= '0';
  51. i_rst <= '1';
  52. wait for 1000ns-i_clk_period;
  53. i_rst <= '0';
  54. wait for i_clk_period;
  55. i_run <= '1';
  56. wait for i_clk_period;
  57. i_run <= '0';
  58. --1025ns
  59. -------------------------------------
  60. wait for 3000ns-i_clk_period-i_clk_period-i_clk_period;
  61. i_pause <= '1';
  62. --3950ns
  63. wait for i_clk_period;
  64. i_pause <= '0';
  65. i_run <= '1';
  66. wait for i_clk_period;
  67. i_run <= '0';
  68.  
  69. wait for i_clk_period;
  70. i_run <= '1';
  71. --4025ns
  72. wait for 1000ns;
  73. i_rst <= '1';
  74. wait for 1000ns-i_clk_period;
  75. --6000ns s_en_1us=1
  76. i_rst <= '0';
  77.  
  78. wait for 33000ns+i_clk_period;
  79. i_rst <= '1';
  80. --39025ns
  81. wait for i_clk_period;
  82. i_rst <= '0';
  83. --39050ns
  84. wait for 24000ns+i_clk_period;
  85. i_rst <= '1';
  86. wait for i_clk_period;
  87. i_rst <= '0';
  88. wait for i_clk_period;
  89. i_rst<='1';
  90. wait for i_clk_period;
  91. i_rst <= '0';
  92. wait;
  93. end process;
  94.  
  95.  
  96. end architecture;
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. library ieee;
  106. use ieee.std_logic_1164.all;
  107. use ieee.std_logic_unsigned.all;
  108. -- Libraries.
  109.  
  110. entity lprs1_homework2 is
  111. port(
  112. i_clk : in std_logic;
  113. i_rst : in std_logic;
  114. i_run : in std_logic;
  115. i_pause : in std_logic;
  116. o_digit0 : out std_logic_vector(3 downto 0);
  117. o_digit1 : out std_logic_vector(3 downto 0);
  118. o_digit2 : out std_logic_vector(3 downto 0);
  119. o_digit3 : out std_logic_vector(3 downto 0)
  120. );
  121. end entity;
  122.  
  123.  
  124. architecture arch of lprs1_homework2 is
  125. -- Signals.
  126. signal s_en_1us: std_logic;
  127. signal s_tc_1us : std_logic;
  128. signal s_cnt_1us: std_logic_vector (7 downto 0);
  129. signal s_en0 : std_logic;
  130. signal s_tc0 : std_logic;
  131. signal s_cnt0 : std_logic_vector (3 downto 0);
  132. signal s_en1 : std_logic;
  133. signal s_cnt1 : std_logic_vector (3 downto 0);
  134. signal s_tc1 : std_logic;
  135. begin
  136. -- Body.
  137. --Stoperica
  138. process (i_clk, i_rst) begin
  139. if(i_rst = '1') then
  140. s_en_1us <='0';
  141. elsif(rising_edge(i_clk)) then
  142. if(i_run = '1') then
  143. s_en_1us <= '1';
  144. elsif(i_pause = '1') then
  145. s_en_1us <= '0';
  146. end if;
  147. end if;
  148. end process;
  149.  
  150. --Brojac mikrosekunde-moduo 40
  151. process (i_clk, i_rst) begin
  152. if(i_rst = '1') then
  153. s_cnt_1us <= "00000000";
  154. elsif(rising_edge(i_clk)) then
  155. if(s_en_1us = '1') then
  156. if(s_cnt_1us = 39) then
  157. s_cnt_1us <="00000000";
  158. else
  159. s_cnt_1us <= s_cnt_1us + 1;
  160. end if;
  161. end if;
  162. end if;
  163. end process;
  164.  
  165. s_tc_1us <= '1' when s_cnt_1us = 39 else
  166. '0';
  167.  
  168. s_en0 <= '1' when s_en_1us = '1' and s_tc_1us = '1' else
  169. '0';
  170.  
  171.  
  172. --Brojac jedne nulte cifre
  173. process (i_clk, i_rst) begin
  174. if(i_rst = '1') then
  175. s_cnt0 <= "0000";
  176. elsif(rising_edge(i_clk)) then
  177. if(s_en0 = '1') then
  178. if(s_cnt0 = "1001") then
  179. s_cnt0 <= "0000";
  180. else
  181. s_cnt0 <= s_cnt0 + 1;
  182. end if;
  183. end if;
  184. end if;
  185. end process;
  186.  
  187. s_tc0 <= '1' when s_cnt0 ="1001" else
  188. '0';
  189.  
  190. s_en1 <= '1' when s_tc0 = '1' and s_en0 = '1' else
  191. '0';
  192.  
  193. o_digit0 <= s_cnt0;
  194.  
  195. --Brojac jedne prve cifre
  196. process (i_clk, i_rst) begin
  197. if(i_rst = '1') then
  198. s_cnt1 <= "0000";
  199. elsif(rising_edge(i_clk)) then
  200. if(s_en1 = '1') then
  201. if(s_cnt1 = "0110") then
  202. s_cnt1 <= "0000";
  203. else
  204. s_cnt1 <= s_cnt1 + 1;
  205. end if;
  206. end if;
  207. end if;
  208. end process;
  209.  
  210. s_tc1 <= '1' when s_cnt1 = "0110" else
  211. '0';
  212.  
  213. o_digit1 <= s_cnt1;
  214.  
  215. o_digit2 <= "0001";
  216. o_digit3 <= "1100";
  217. end architecture;
  218.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement