延迟信号导致 VHDL 中的意外行为
delayed signal cause unexpected behavior in VHDL
当信号不正确时,我的程序将停止。但是,输入信号需要时间来重新生成,并且该过程会重新使用旧信号。导致代码停止,无法恢复运行。
例如
process(A,B,startRun)
begin
if (A = 1) then
case (B) is
when 0 =>
-- do something
when others =>
if(startRun = '1')then
halt <= '1';
end if;
end case;
else
-- do something else
end if;
end process;
我的问题是当A = 1,但是B是旧值,比如说1。当B变成新值后,halt总是设置为1。程序最终会停止。我该如何解决这个问题?
我同意 "Jonathan Drolet"。我看不到你在哪里将信号 halt
重置为零。设置 halt
后,它总是 1
并且没有重置语句。
当不需要停止时,您可以使用 else
语句将 halt
重置为零:
process(A,B,startRun)
begin
if (A = 1) then
case (B) is
when 0 =>
halt <= '0';
-- do something
when others =>
if(startRun = '1')then
halt <= '1';
else
halt <= '0';
end if;
end case;
else
halt <= '0';
-- do something else
end if;
end process;
您也可以在流程开始时将 halt
重置为 0
,但是如果 (A = 1
and B /= 0
and startRun = '1'
) 确定将 hlat
设置为 1
已应用,因为在过程结束时应用了信号或端口分配:
process(A,B,startRun)
begin
halt <= '0';
if (A = 1) then
case (B) is
when 0 =>
-- do something
when others =>
if(startRun = '1')then
halt <= '1';
end if;
end case;
else
-- do something else
end if;
end process;
当信号不正确时,我的程序将停止。但是,输入信号需要时间来重新生成,并且该过程会重新使用旧信号。导致代码停止,无法恢复运行。
例如
process(A,B,startRun)
begin
if (A = 1) then
case (B) is
when 0 =>
-- do something
when others =>
if(startRun = '1')then
halt <= '1';
end if;
end case;
else
-- do something else
end if;
end process;
我的问题是当A = 1,但是B是旧值,比如说1。当B变成新值后,halt总是设置为1。程序最终会停止。我该如何解决这个问题?
我同意 "Jonathan Drolet"。我看不到你在哪里将信号 halt
重置为零。设置 halt
后,它总是 1
并且没有重置语句。
当不需要停止时,您可以使用 else
语句将 halt
重置为零:
process(A,B,startRun)
begin
if (A = 1) then
case (B) is
when 0 =>
halt <= '0';
-- do something
when others =>
if(startRun = '1')then
halt <= '1';
else
halt <= '0';
end if;
end case;
else
halt <= '0';
-- do something else
end if;
end process;
您也可以在流程开始时将 halt
重置为 0
,但是如果 (A = 1
and B /= 0
and startRun = '1'
) 确定将 hlat
设置为 1
已应用,因为在过程结束时应用了信号或端口分配:
process(A,B,startRun)
begin
halt <= '0';
if (A = 1) then
case (B) is
when 0 =>
-- do something
when others =>
if(startRun = '1')then
halt <= '1';
end if;
end case;
else
-- do something else
end if;
end process;