Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_unsigned.all;
  4. use IEEE.numeric_std.to_unsigned;
  5.  
  6. entity Timer is
  7. port( S, U : in std_logic;
  8. LT, LS, LD, LJ : out std_logic_vector(3 downto 0) );
  9. end Timer;
  10.  
  11. library IEEE;
  12. use IEEE.std_logic_1164.all;
  13. use IEEE.std_logic_unsigned.all;
  14. use IEEE.numeric_std.to_unsigned;
  15.  
  16. entity Licznik is
  17. port( Clk, Sh : in std_logic;
  18. LT, LS, LD, LJ : out std_logic_vector(3 downto 0);
  19. R : out std_logic);
  20. end Licznik;
  21.  
  22. library IEEE;
  23. use IEEE.std_logic_1164.all;
  24. use IEEE.std_logic_unsigned.all;
  25.  
  26. entity Detektor is
  27. port( U : in std_logic;
  28. U10 : out std_logic);
  29. end Detektor;
  30.  
  31. library IEEE;
  32. use IEEE.std_logic_1164.all;
  33. use IEEE.std_logic_unsigned.all;
  34.  
  35. entity Sygnaly is
  36. port( S, U, U10 : in std_logic;
  37. R : inout std_logic;
  38. Clk, Sh : buffer std_logic);
  39. end Sygnaly;
  40.  
  41.  
  42.  
  43. architecture struktura of Timer is
  44. component Sygnaly
  45. port( S, U, U10 : in std_logic;
  46. R : inout std_logic;
  47. Clk, Sh : buffer std_logic);
  48. end component;
  49.  
  50. component Detektor is
  51. port( U : in std_logic;
  52. U10 : out std_logic);
  53. end component;
  54.  
  55. component Licznik is
  56. port( Clk, Sh : in std_logic;
  57. LT, LS, LD, LJ : out std_logic_vector(3 downto 0);
  58. R : out std_logic);
  59. end component;
  60.  
  61. signal Clk, R, U10, Sh : std_logic;
  62.  
  63. begin
  64. Struct1: Sygnaly port map(S, U, U10, R, Clk, Sh);
  65. Struct2: Detektor port map(U, U10);
  66. Struct3: Licznik port map(Clk, Sh, LT, LS, LD, LJ, R);
  67. end struktura;
  68.  
  69. architecture tablicowa of Licznik is
  70. type liczba is array(0 to 3) of integer range 0 to 9;
  71. begin
  72. process(Clk)
  73. variable tablica : liczba := (0,0,0,0);
  74. begin
  75. if Clk'event and Clk = '1' then
  76. if Sh = '0' then -- tutaj lecimy w gore
  77. for i in 3 downto 0 loop
  78. if not (tablica(i) = 9) then
  79. tablica(i) := tablica(i) + 1;
  80. exit;
  81. else tablica(i) := 0;
  82. end if;
  83. end loop;
  84. -- if tablica(0) = 9 and tablica(1) = 9 and tablica(2) = 9 and tablica(3) = 9 then ;
  85. LT <= std_logic_vector(to_unsigned(tablica(0), LT'length));
  86. LS <= std_logic_vector(to_unsigned(tablica(1), LS'length));
  87. LD <= std_logic_vector(to_unsigned(tablica(2), LD'length));
  88. LJ <= std_logic_vector(to_unsigned(tablica(3), LJ'length));
  89.  
  90. else
  91. if not (tablica(0) = 0 and tablica(1) = 0 and tablica(2) = 0 and tablica(3) = 0) then
  92. for i in 3 downto 0 loop
  93. if not (tablica(i) = 0) then
  94. tablica(i) := tablica(i) - 1;
  95. exit;
  96. else tablica(i) := 9;
  97. -- wpisac cos na 9 9 9 9
  98. end if;
  99. end loop;
  100. LT <= std_logic_vector(to_unsigned(tablica(0), LT'length));
  101. LS <= std_logic_vector(to_unsigned(tablica(1), LS'length));
  102. LD <= std_logic_vector(to_unsigned(tablica(2), LD'length));
  103. LJ <= std_logic_vector(to_unsigned(tablica(3), LJ'length));
  104. else R <= '1';
  105. end if;
  106. end if;
  107. end if;
  108. end process;
  109. end tablicowa;
  110.  
  111. architecture Detektor10Hz of Detektor is
  112. begin
  113. process
  114. variable flaga : boolean;
  115. begin
  116. if U = '0' then
  117. flaga := true;
  118. for i in 0 to 30 loop
  119. if U = '0' then
  120. wait for 10 ms;
  121. else
  122. flaga := false;
  123. exit;
  124. end if;
  125. end loop;
  126.  
  127. if flaga = true then
  128. U10 <= '1';
  129. wait until U = '1';
  130. U10 <= '0';
  131. wait for 5 ms;
  132. end if;
  133. end if;
  134. end process;
  135. end Detektor10Hz;
  136.  
  137. architecture sygnaly of Sygnaly is
  138. begin
  139. process
  140. begin
  141. if S = '0' then
  142. Sh <= '1';
  143. end if;
  144.  
  145. if R = '1' then
  146. Sh <= '0';
  147. R <= '0';
  148. end if;
  149.  
  150. if Sh = '1' then
  151. Clk <= '1';
  152. wait for 500 ms;
  153. Clk <= '0';
  154. wait for 500 ms;
  155. end if;
  156.  
  157. if U'event and U = '0' then
  158. Clk <= '1';
  159. Clk <= '0';
  160. wait for 5 ms;
  161. end if;
  162.  
  163. if U10 = '1' then
  164. Clk <= '1';
  165. wait for 50 ms;
  166. Clk <= '0';
  167. wait for 50 ms;
  168. end if;
  169. end process;
  170. end sygnaly;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement