Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. LIBRARY ieee;
  2. USE ieee.std_logic_1164.all;
  3. USE ieee.std_logic_unsigned.all;
  4.  
  5. ENTITY count9 IS
  6. PORT (CLK_50MHZ, reset, key1: IN std_logic; -- reset, key1 and key2 are inputs
  7. clk : OUT std_logic); -- clk is final output signal, CLK_1HZ is referenced to it
  8. END count9;
  9.  
  10. ARCHITECTURE behav OF count9 IS
  11.  
  12. SIGNAL CLK_COUNT_1HZ: STD_LOGIC_VECTOR(24 DOWNTO 0); --needed space for binary of 500000000
  13. SIGNAL CLK_1HZ: STD_LOGIC; -- final result signal of 1 second
  14. SIGNAl counter: INTEGER:=0; -- counter neeeded to count desired number of cycles, initially Zero
  15.  
  16.  
  17. BEGIN
  18. PROCESS (CLK_50MHZ, reset)
  19. BEGIN
  20. IF reset = '1' THEN
  21. counter<=0;
  22. CLK_COUNT_1HZ <= "0000000000000000000000000"; --total 25 spaces for binary bit of 50M, zero as default
  23. CLK_1HZ <= '0'; --initially set to zero
  24. ELSIF rising_edge(CLK_50MHZ) THEN
  25.  
  26.  
  27.  
  28.  
  29. IF reset = '0' THEN
  30. IF CLK_COUNT_1HZ < X"17D7840" THEN --17D7840 is hex of 50M
  31. CLK_COUNT_1HZ <= CLK_COUNT_1HZ + 1; --checks 1 second counts up after each 1 second.
  32. ELSE
  33. CLK_COUNT_1HZ <= "0000000000000000000000000";
  34. IF counter < 9 THEN -- Condition to check is 9 seconds or 9 signals have passed
  35. counter<=counter+1;
  36. ELSE
  37. CLK_1HZ <= '1';
  38. END IF;
  39. END IF;
  40.  
  41. IF key1 = '0' THEN
  42. IF CLK_COUNT_1HZ < X"17D7840" THEN --17D7840 is hex of 50M
  43. CLK_COUNT_1HZ <= CLK_COUNT_1HZ + 1; --checks 1 second counts up after each 1 second.
  44. ELSE
  45. CLK_COUNT_1HZ <= "0000000000000000000000000";
  46. IF counter < 9 THEN -- Condition to check is 9 seconds or 9 signals have passed
  47. counter<=counter+1;
  48. ELSE
  49. CLK_1HZ <= '1';
  50. END IF;
  51. END IF;
  52.  
  53. END IF;
  54. clk<=CLK_1HZ; -- CLK_1HZ is now clk
  55. END PROCESS;
  56. END behav;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement