--------------------------------------------------------------------------- -- (c) 2013 mark watson -- I am happy for anyone to use this for non-commercial use. -- If my vhdl files are used commercially or otherwise sold, -- please contact me for explicit permission at scrameta (gmail). -- This applies for source and binary form and derived works. --------------------------------------------------------------------------- LIBRARY ieee; USE ieee.std_logic_1164.all; use ieee.numeric_std.all; ENTITY enable_divider IS generic(COUNT : natural := 1); PORT ( CLK : IN STD_LOGIC; RESET_N : IN STD_LOGIC; ENABLE_IN : IN STD_LOGIC; ENABLE_OUT : OUT STD_LOGIC ); END enable_divider; ARCHITECTURE vhdl OF enable_divider IS function log2c(n : integer) return integer is variable m,p : integer; begin m := 0; p := 1; while p 64KHz -> /28 process(count_reg,enable_in,enabled_out_reg) begin count_next <= count_reg; enabled_out_next <= enabled_out_reg; if (enable_in = '1') then count_next <= std_logic_vector(unsigned(count_reg) + 1); enabled_out_next <= '0'; if (unsigned(count_reg) = to_unsigned(COUNT-1,WIDTH)) then count_next <= std_logic_vector(to_unsigned(0,WIDTH)); enabled_out_next <= '1'; end if; end if; end process; -- output enable_out <= enabled_out_reg and enable_in; END vhdl;