VHDL:意外IF的问题

时间:2011-09-12 11:07:12

标签: vhdl

您好我正在尝试在xilinx ISE环境中学习VHDL,但我无法使用此代码,我不知道为什么。我尝试使用/不使用ands的单引号,但没有任何作用。有人可以帮助我吗?

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity teh_3 is
    Port ( thermo_input : in  STD_LOGIC_VECTOR(3 DOWNTO 0);
           too_hot : out  STD_LOGIC;
           too_cold : out  STD_LOGIC;
           just_right : out  STD_LOGIC);
end teh_3;

architecture Behavioral of teh_3 is

begin

IF thermo_input < "1000" THEN
  too_cold <='1' and
  too_hot <='0' and
  just_right <='0';
ELSIF thermo_input > "1011" THEN 
    too_hot <='1' and
    too_cold <='0' and
    just_right <='0';
ELSIF thermo_input > "0111" THEN 
  just_right <='1' and
  too_hot <='0' and
  too_cold <='0';
ELSE
  just_right <='0' and
  too_hot <='0' and
  too_cold <='0';
END IF;

结束行为;

ERROR:HDLParsers:164 - "/home/student/kokeilu/kokeil.vhd" Line 40. parse error, unexpected IF

谢谢!

3 个答案:

答案 0 :(得分:5)

从根本上说,如果不在流程之外,则不能使用。

此外,请勿使用std_logic_arith,请使用numeric_std - http://parallelpoints.com/node/3


修复,制作流程或使用patrick建议的正确组合语法。

目前它的方式必须是组合过程,所以要小心在敏感列表中获取所有输入或使用新的VHDL- 2008 process(all)语法。取决于您使用的ISE版本是否支持。

或者使它成为一个同步过程 - 这就是大多数FPGA编写代码的方式。

向您的实体添加clk输入,然后将if/elsif/else代码放入同步过程中:

process (clk)
begin
  if thermo_input < "1000" then
   .... etc
end process;

最后,你不要使用AND一次发生几件事情:

IF thermo_input < "1000" THEN
  too_cold <='1'; -- semicolons here, not ANDs!
  too_hot <='0';
  just_right <='0';

是正确的方法!

答案 1 :(得分:2)

if只能在流程中使用。您可以使用WHEN代替,也可以创建流程。我应该去看看这个看起来像这样的时候。

实施例

too_cold   <= '1' WHEN (thermo_input < "1000") ELSE '0';
too_hot    <= '1' WHEN (thermo_input > "1011") ELSE '0';
just_right <= '1' WHEN (thermo_input > "0111" AND thermo_input < "1011") ELSE '0';

我没有测试它,但这是为了给你一个想法。

答案 2 :(得分:1)

您还应该对thermo_input > "0111"

小心

确保你对“0111”所代表的内容三思而后行。它是带符号或无符号的4位整数吗? 我建议明确这一点。库'numeric_std'包含许多有用的方法。