【发布时间】: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。