Altera_Forum
Honored Contributor
15 years agofrequency divider
i want ot create frequency divider which devide the frequency by 50 000 000 (so with 50 MHz clock i want ot reach 1 HZ (T=1s))
can i use this code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity counter is
port (CLK, RST :in std_logic;
devided_clk : out std_logic;
Q :out std_logic_vector(16 downto 0)
) ;
end counter;
architecture beh of counter is
signal QL : std_logic_vector (16 downto 0);
begin
process(CLK, RST )
begin
if (CLK'event and CLK = '1')
then if RST='1'
then QL <= "00000000000000000"; devided_clk<= '0';
else if (QL = "11101110011010110010100000000") then QL <= "00000000000000000"; devided_clk <= '1'; else
devided_clk <= '0';
QL <= QL+1;
end if;
end if;
end if;
end process;
Q <= QL;
end beh;