【问题标题】:VHDL Delay before lighting led点亮 LED 前的 VHDL 延迟
【发布时间】:2016-11-04 19:55:23
【问题描述】:

我想制作一个简单的 vhdl 代码,它会在 LED 亮起之前延迟 20 秒。我使用了一个信号计数器来延迟 20 秒,但是我注意到一个很奇怪的事情,如果我没有在延迟之前声明 LED 是关闭的,那么 LED 将永远开启。

看两个代码(时钟是50MHz):

在这段代码中,LED 总是亮着的。

library ieee;
use ieee.std_logic_1164.all;
entity check is
port(clk : in std_logic;
      led : out std_logic);
end check;

architecture arc of check is
signal counter : integer range 0 to 100e6;
begin
process(clk)
begin
if rising_edge(clk) then
    if counter<500e6 then
        counter<=counter+1;
    else
        led<='1';
    end if;
end if;
end process;
end arc;

在此代码中,LED 仅在 20 秒后亮起。

library ieee;
use ieee.std_logic_1164.all;
entity check is
port(clk : in std_logic;
      led : out std_logic);
end check;

architecture arc of check is
signal counter : integer range 0 to 100e6;
begin
process(clk)
begin
if rising_edge(clk) then
    if counter<500e6 then
        counter<=counter+1;
        led<='0';
    else
        led<='1';
    end if;
end if;
end process;
end arc;

【问题讨论】:

  • 如果该代码在模拟中工作,则模拟器已损坏。它永远无法打开 LED。

标签: vhdl delay clock led


【解决方案1】:

您应该同时初始化计数器和 LED。在模拟中,如果您不这样做,每个未初始化信号的值将是“U”,这意味着您根本无法确定它在实际系统中的值。可以为 0 或 1。 您可以在端口声明中使用 := '0'。

可能led一直亮着,因为根据这段代码,如果counter

【讨论】:

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