简体   繁体   English

整数比较在if语句(vhdl)中不起作用

[英]integer comparison doesn't work in if statement (vhdl)

What is the error in the following code? 以下代码中的错误是什么?

In the testbench x is set to "00001111" , yet the else branch is executed (in the simulation all of y 's bits are set to high impedance state, but y should equal x ). 在测试平台中, x设置为"00001111" ,但是执行else分支(在仿真中, y的所有位都设置为高阻抗状态,但是y应该等于x )。 I'm using XILNX ISE Design Suite and ISim as simulation environment. 我正在使用XILNX ISE Design SuiteISim作为仿真环境。 Thanks in advance. 提前致谢。

entity test is
    Port ( x : in  STD_LOGIC_VECTOR (7 downto 0);
           y : out  STD_LOGIC_VECTOR (7 downto 0));
end test;

architecture Behavioral of test is

signal tmp : integer;

begin

process(x)
begin
tmp <= to_integer(unsigned(x(3 downto 0)));
if tmp = 15 then
    y <= std_logic_vector(to_unsigned(tmp, 8));
else
    y <= "ZZZZZZZZ";
end if;
end process;

end Behavioral;

The tmp is a signal, thus it takes a delta delay before it reveals the value assigned by (pkg_sig_1'range) <= z(pkg_sig_1'range); tmp是一个信号,因此在显示(pkg_sig_1'range) <= z(pkg_sig_1'range);分配的值之前要经过一个增量延迟(pkg_sig_1'range) <= z(pkg_sig_1'range); . So when the process is triggered at the change of x , the tmp will have the previous value in the if tmp = 15 then ... , and the new value of tmp is not assigned until after the process is completed. 因此,当在x的变化处触发过程时, if tmp = 15 then ... ,则tmp将具有先前的值,并且直到过程完成后才分配tmp的新值。

Add tmp to the sensitivity list, or change tmp to a variable in the process, like: tmp添加到敏感度列表,或在此过程中将tmp更改为变量,例如:

process(x)
  variable tmp : integer;
begin
  tmp := to_integer(unsigned(x(3 downto 0)));
  if tmp = 15 then
    y <= std_logic_vector(to_unsigned(tmp, 8));
  else
    y <= "ZZZZZZZZ";
  end if;
end process;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM