Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.57 KB | None | 0 0
  1. //binary_counter
  2.  
  3. library IEEE;
  4. use IEEE.STD_LOGIC_1164.ALL;
  5. use IEEE.STD_LOGIC_1164.ALL;
  6. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  7.  
  8. entity binary_counter_test is
  9.     Port ( clk_in : in  STD_LOGIC;
  10.            count_out : out  STD_LOGIC_VECTOR (1 downto 0));
  11. end binary_counter_test;
  12.  
  13. architecture Behavioral of binary_counter_test is
  14.     signal clk_1hz : std_logic;                                                                         --TO DO 1 -> deklarirati signal clk_1Hz koji je tipa std_logic
  15.     signal count_temp   :   std_logic_vector(1 downto 0);
  16. begin
  17.  
  18.     divider_1Hz :   entity work.generic_divider generic map (100_000_000) port map (clk_in, clk_1hz);       --TO DO 2 -> instancirati generički djelitelj frekvencije tako da ulazni signal takta pretvori u signal takta frekvencije 1Hz
  19.     counter :   entity work.binary_counter port map(clk_1hz, count_out);                            --TO DO 3 -> instancirati binarni brojač tako da broji frekvencijom od 1Hz i da povratnu vrijednost spremi u signal count_temp
  20.  
  21. end Behavioral;
  22.  
  23. // COUNTER
  24.  
  25. library IEEE;
  26. use IEEE.STD_LOGIC_1164.ALL;
  27. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  28.  
  29. entity binary_counter is
  30.     Port ( clk_in : in  STD_LOGIC;
  31.            count_out : out  STD_LOGIC_VECTOR (1 downto 0));
  32. end binary_counter;
  33.  
  34. architecture Behavioral of binary_counter is
  35. signal count_temp : std_logic_vector(1 downto 0);                                                                   --TO DO 1 -> deklarirati signal count_temp koji je tipa std_logic i veličine je 2 bita
  36. begin
  37.  
  38.     PROCESS(clk_in)
  39.    
  40.     BEGIN
  41.         IF(clk_in'event and clk_in='1') THEN                                                        --TO DO 2 -> detektirati rastući brid signala takta clk_in
  42.             count_temp<=count_temp+1;                                                           --TO DO 3 -> uvećati signal count_temp za 1
  43.         END IF;
  44.     END PROCESS;
  45.  
  46.                                                                         --TO DO 4 -> izlaznom signalu count_out pridružiti vrijednost signala count_temp
  47. count_out<=count_temp;
  48. end Behavioral;
  49.  
  50. // divider
  51.  
  52. library IEEE;
  53. use IEEE.STD_LOGIC_1164.ALL;
  54.  
  55. entity generic_divider is
  56. GENERIC
  57. (
  58.     N   :   INTEGER :=  50_000_000
  59. );
  60. PORT
  61. (
  62.     clk_in  :   IN  STD_LOGIC;
  63.     clk_out :   OUT STD_LOGIC
  64. );
  65. end generic_divider;
  66.  
  67. architecture Behavioral of generic_divider is
  68.     signal clk_t    :   STD_LOGIC;
  69. begin
  70.  
  71. PROCESS(clk_in)
  72.     variable temp   :   INTEGER RANGE 0 TO N;
  73. BEGIN
  74.    
  75.     IF(clk_in'event and clk_in='1') THEN                                --TO DO 1   -> detektirati rastući brid signala takta clk_in
  76.         temp:=temp+1;                                   --TO DO 2   -> varijablu temp uvećati za 1
  77.         IF(temp >= N) THEN
  78.             clk_t<=not clk_t;                               --TO DO 3   -> invertirati signal clk_t
  79.             temp := 0;
  80.         END IF;
  81.     END IF;
  82.    
  83. END PROCESS;
  84.  
  85. clk_out <= clk_t;                                           --TO DO 4   ->  izlaznom signalu clk_out pridružiti vrijednost signala clk_t
  86.  
  87. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement