首页 > 解决方案 > vhdl 中的时钟分频器从 100MHz 到 1Hz 代码

问题描述

我写了这个代码来划分时钟一个nexys4 fpga,默认情况下它的集成时钟频率为100Mhz,我需要将它划分为1hz。有人可以告诉我它是否正确或者是否需要更改?

LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;


entity digi_clk is
port (clk1 : in std_logic;
       clk : out std_logic
     );
end digi_clk;

architecture Behavioral of digi_clk is

signal count : integer :=0;
signal b : std_logic :='0';
begin

 --clk generation.For 100 MHz clock this generates 1 Hz clock.
process(clk1) 
begin
if(rising_edge(clk1)) then
count <=count+1;
if(count = 50000000) then
b <= not b;
count <=0;

end if;
end if;
clk<=b;
end process;
end;

标签: vhdlfpgaclock

解决方案


代码看起来不错。然而,现有代码将产生一个略低于 1 Hz 的输出频率。要获得精确的 100000000:1 比率,您需要将条件语句从以下位置更改:

    if(count = 50000000) then

... 至:

    if(count = 50000000-1) then

推荐阅读