无符号数组的 VHDL 怪异行为
VHDL weird behavoir of an array of unsigneds
基本上我有一个无符号数组和一个将数组中的第一个值递增一个的过程。在我实现异步重置之前,它工作正常,它将数组的元素设置为 0。奇怪的是,即使从未达到异步重置的代码,它也会使我的其余代码不再工作。这是我的代码:
use work.datentyp.all;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity vektoruhr is
port (
clk, reset : in std_logic ;
);
end vektoruhr;
architecture v1 of vektoruhr is
signal internal_stamp : vektor := (others => (others => '0'));
begin
process(clk)
begin
if(rising_edge(clk)) then
internal_stamp(0) <= internal_stamp(0) + 1;
end if;
end process;
process(reset)
begin
if(rising_edge(reset)) then
report "reset triggered";
-- internal_stamp <= (others => (others => '0'));
alarm <= '0';
end if;
end process;
end v1;
如您所见,行
-- internal_stamp <= (others => (others => '0'));
被注释掉了。像这样,一切正常。但是如果我删除 --,第一个元素的值首先是 00,然后在第一次递增后变为 0x,在第二次递增后变为 xx。之后它留在xx。复位输入从一开始就设置为“0”,并且永远不会改变。
VHDL是一种硬件描述语言。每个进程代表一个硬件。您正在从两个进程驱动信号 internal_stamp
。你短路了。当你注释掉行
internal_stamp <= (others => (others => '0'));
这导致 internal_stamp
仅由一个进程驱动。因此没有短路,也没有 'X' 值。
如果您要编写时序逻辑代码,则应坚持使用模板。这是一个带有异步复位的时序逻辑模板,所有综合工具都应该理解它:
process(clock, async_reset) -- nothing else should go in the sensitivity list
begin
-- never put anything here
if async_reset ='1' then -- or '0' for an active low reset
-- set/reset the flip-flops here
-- ie drive the signals to their initial values
elsif rising_edge(clock) then -- or falling_edge(clock)
-- put the synchronous stuff here
-- ie the stuff that happens on the rising or falling edge of the clock
end if;
-- never put anything here
end process;
这是没有异步复位的时序逻辑模板:
process(clock) -- nothing else should go in the sensitivity list
begin
if rising_edge(clock) then -- or falling_edge(clock)
-- put the synchronous stuff here (including the reset)
-- ie the stuff that happens on the rising or falling edge of the clock
end if;
-- never put anything here
end process;
因此,您应该使用一个进程而不是两个进程来编写逻辑代码。假设您想要 异步重置 :
process(clk, reset)
begin
if reset = '1' then
report "reset triggered";
internal_stamp <= (others => (others => '0'));
alarm <= '0';
elsif(rising_edge(clk)) then
internal_stamp(0) <= internal_stamp(0) + 1;
end if;
end process;
但是,如果您想要同步重置:
process(clk)
begin
if(rising_edge(clk)) then
if reset = '1' then
report "reset triggered";
internal_stamp <= (others => (others => '0'));
alarm <= '0';
else
internal_stamp(0) <= internal_stamp(0) + 1;
end if;
end process;
基本上我有一个无符号数组和一个将数组中的第一个值递增一个的过程。在我实现异步重置之前,它工作正常,它将数组的元素设置为 0。奇怪的是,即使从未达到异步重置的代码,它也会使我的其余代码不再工作。这是我的代码:
use work.datentyp.all;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity vektoruhr is
port (
clk, reset : in std_logic ;
);
end vektoruhr;
architecture v1 of vektoruhr is
signal internal_stamp : vektor := (others => (others => '0'));
begin
process(clk)
begin
if(rising_edge(clk)) then
internal_stamp(0) <= internal_stamp(0) + 1;
end if;
end process;
process(reset)
begin
if(rising_edge(reset)) then
report "reset triggered";
-- internal_stamp <= (others => (others => '0'));
alarm <= '0';
end if;
end process;
end v1;
如您所见,行
-- internal_stamp <= (others => (others => '0'));
被注释掉了。像这样,一切正常。但是如果我删除 --,第一个元素的值首先是 00,然后在第一次递增后变为 0x,在第二次递增后变为 xx。之后它留在xx。复位输入从一开始就设置为“0”,并且永远不会改变。
VHDL是一种硬件描述语言。每个进程代表一个硬件。您正在从两个进程驱动信号 internal_stamp
。你短路了。当你注释掉行
internal_stamp <= (others => (others => '0'));
这导致 internal_stamp
仅由一个进程驱动。因此没有短路,也没有 'X' 值。
如果您要编写时序逻辑代码,则应坚持使用模板。这是一个带有异步复位的时序逻辑模板,所有综合工具都应该理解它:
process(clock, async_reset) -- nothing else should go in the sensitivity list
begin
-- never put anything here
if async_reset ='1' then -- or '0' for an active low reset
-- set/reset the flip-flops here
-- ie drive the signals to their initial values
elsif rising_edge(clock) then -- or falling_edge(clock)
-- put the synchronous stuff here
-- ie the stuff that happens on the rising or falling edge of the clock
end if;
-- never put anything here
end process;
这是没有异步复位的时序逻辑模板:
process(clock) -- nothing else should go in the sensitivity list
begin
if rising_edge(clock) then -- or falling_edge(clock)
-- put the synchronous stuff here (including the reset)
-- ie the stuff that happens on the rising or falling edge of the clock
end if;
-- never put anything here
end process;
因此,您应该使用一个进程而不是两个进程来编写逻辑代码。假设您想要 异步重置 :
process(clk, reset)
begin
if reset = '1' then
report "reset triggered";
internal_stamp <= (others => (others => '0'));
alarm <= '0';
elsif(rising_edge(clk)) then
internal_stamp(0) <= internal_stamp(0) + 1;
end if;
end process;
但是,如果您想要同步重置:
process(clk)
begin
if(rising_edge(clk)) then
if reset = '1' then
report "reset triggered";
internal_stamp <= (others => (others => '0'));
alarm <= '0';
else
internal_stamp(0) <= internal_stamp(0) + 1;
end if;
end process;