求高手帮忙用vhdl编一个2,4,8,16分频程序

2024-12-16 12:36:58
推荐回答(1个)
回答1:

这是对时钟进行10分频的VHDL代码,2,4,8,16分频原理与其相同。

entity clk_div is
port (clk_in :in std_logic;
clk_out:out std_logic);
end clk_div;

architecture Behavioral of clk_div is
signal cnt:integer range 1 to 10;
signal clk_temp:std_logic:='0';
begin
process (clk_in,cnt)
begin
if clk_in'event and clk_in='1' then
if cnt=10 then cnt<=1;
else cnt<=cnt+1;
end if;
if cnt>5 then clk_temp<='1';
else clk_temp<='0';
end if;
end if;
end process;
clk_out<=clk_temp;
end Behavioral;