有人可以解释为什么这有效:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Switches_LEDs is
Port ( switches : in STD_LOGIC_VECTOR(5 downto 0);
LEDs : out STD_LOGIC_VECTOR(7 downto 0);
CLK_100MHz : in STD_LOGIC
);
end Switches_LEDs;
architecture Behavioral of Switches_LEDs is
signal counter : STD_LOGIC_VECTOR(29 downto 0) := (others => '0');
begin
clk_proc: process(CLK_100MHz)
begin
LEDs <= counter(29 downto 22);
if (switches(0) = '0') then
counter <= (others => '0');
elsif rising_edge(CLK_100MHz) then
counter <= counter+1;
end if;
end process;
end Behavioral;
而不是这个:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Switches_LEDs is
Port ( switches : in STD_LOGIC_VECTOR(5 downto 0);
LEDs : out STD_LOGIC_VECTOR(7 downto 0);
CLK_100MHz : in STD_LOGIC
);
end Switches_LEDs;
architecture Behavioral of Switches_LEDs is
signal counter : STD_LOGIC_VECTOR(29 downto 0) := (others => '0');
begin
clk_proc: process(CLK_100MHz)
begin
LEDs <= counter(29 downto 22);
if (switches(0) = '0') then
counter <= (others => '0');
end if;
if rising_edge(CLK_100MHz) then
counter <= counter+1;
end if;
end process;
end Behavioral;
另外,为什么我不需要“声明”clk_proc中的开关?对于有很多代码的问题有一个警告...所以...添加单词。
在一个过程中,最后的任务获胜在你的代码中,计数器和开关都不在灵敏度列表中,所以我会期待一些意想不到的行为
如果您需要异步重置,那么您应该使用如下模板:
process(clk, reset)
begin
if reset condition then
elsif clock event then
end if;
end process;
如果您需要同步重置,那么:
process(clk)
begin
if clock event then
if reset condition then
else
end if;
end if;
end process;
你应该移动LED <= counter(29 downto 22);可能也在过程中。