Advertisement
Guest User

Untitled

a guest
May 25th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 0.80 KB | None | 0 0
  1. entity divider is
  2.     port ( clk_i : in std_logic;
  3.            rst_i : in std_logic;
  4.            clk_o : out std_logic);
  5. end divider;
  6.  
  7. architecture behavioral of divider is
  8. constant n : integer := 4; -- for 1khz == 50000 -- for simulation == 4
  9. signal cnt_n : integer range 0 to n - 1 := 0;
  10. signal clk : std_logic := '0';
  11. begin
  12.     process (clk_i, rst_i)
  13.         begin
  14.         if (rst_i = '1') then
  15.             cnt_n <= 0;
  16.             clk <= '0';
  17.         elsif (rising_edge(clk_i)) then
  18.             cnt_n <= cnt_n + 1;
  19.             if (cnt_n = (n / 2) - (1 - (n mod 2))) then
  20.                 clk <= '1';
  21.             end if;
  22.             if cnt_n = n - 1 then
  23.                 clk <= '0';
  24.                 cnt_n <= 0;
  25.             end if;
  26.         end if;
  27.     end process;
  28. clk_o <= clk;
  29. end behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement