分频器的设计
下面的程序是将50Mhz的信号频率分成5hz 的频率信号,其具体设计如下:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_arith.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
entity div_freq5 is
port(clk:in std_logic;
freq_out :out std_logic);
end div_freq5;
architecture a of div_freq5 is
signal rst:std_logic;
signal qn:std_logic_vector(23 downto 0);
begin
process(clk,rst)
begin
if rst='1' then
qn<="000000000000000000000000";
elsif clk'event and clk='1' then
qn<=qn+1;
end if;
end process;
rst<='1' when qn=10000000 else '0';
freq_out<=qn(23);
end a;