gpt4 book ai didi

创建模 16 计数器时的 VHDL 时钟问题

转载 作者:行者123 更新时间:2023-12-02 20:15:37 25 4
gpt4 key购买 nike

我使用 basys3 板创建了这个简单的 mod16 计数器,但我的时钟有些不对劲。代码本身确实有效,但是一次计数(从“1”变为“2”等)持续了 40 秒,而不是 1 秒!我尝试将“clk_vector”if 条件降低为 1,但也没有帮助。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity mod_16_k is
Port ( switch : in STD_LOGIC_VECTOR (3 downto 0);
CLK1 : in STD_LOGIC;
reset : in STD_LOGIC;
led : out STD_LOGIC_VECTOR (15 downto 0));
end mod_16_k;
architecture Behavioral of mod_16_k is

signal clk_vector :integer;
signal clk_vec2 :std_logic_vector(15 downto 0);

begin
zegar_wew : process(CLK1)
begin

if(CLK1'event and CLK1 = '1') then
clk_vector <= clk_vector + 1;
if(clk_vector = 100000000) then
clk_vec2 <= std_logic_vector(unsigned(clk_vec2) + 1);
end if;
end if;
end process;
led <= clk_vec2;
end Behavioral;

时钟的 .XDC 线是: enter image description here

如果我们检查basys3数据表,时钟连接到“W5”端口。 enter image description here

您知道这里可能存在什么问题吗?它可能与检测 clk 的上升沿有关,但所有变化(从 1 到 2 等)都会持续约 40 秒。

最佳答案

这是因为您忘记在达到 1 秒后重置 clk_vector。因为它是一个整数,它是 32 位,因此会计数 2^32 而不是 100000000。

这应该有效:

If(CLK1'event and CLK1 = '1')  then
if(clk_vector = 100000000-1) then
clk_vector <= 0;
clk_vec2 <= std_logic_vector(unsigned(clk_vec2) + 1);
else
clk_vector <= clk_vector + 1;
end if;
end if;

另外,请注意,要计算 1 秒,您需要数到 100000000-1,我们从零开始计数!

关于创建模 16 计数器时的 VHDL 时钟问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52468509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com