【问题标题】:Clock divider in vhdl from 100MHz to 1Hz codevhdl 中的时钟分频器从 100MHz 到 1Hz 代码
【发布时间】:2020-09-04 18:07:36
【问题描述】:

我编写了这个代码来划分时钟一个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;

【问题讨论】:

  • 一般情况下,FPGA 不推荐使用逻辑来创建分频时钟。它应该生成时钟使能。

标签: vhdl fpga clock


【解决方案1】:

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

    if(count = 50000000) then

...到:

    if(count = 50000000-1) then

【讨论】:

  • 技术上是正确的,但我敢打赌,误差远低于 OP 板上振荡器的容差。如果他的板子有 50ppm 的时钟,那就幸运了。
【解决方案2】:

程序看起来是正确的,但您应该将内部信号(计数)声明为整数。然后你的代码应该编译成功。但是您会收到一些警告,并且会在 testbech 模拟中发现一些问题。为避免这种情况,您需要将内部信号 ( count ) 声明为: signal count : std_logic_vector (25 downto 0);因为 100MHz 编码为 26 位。我更喜欢将 50000000 转换为十六进制格式,它应该可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多