2010-11-02 86 views
1

我想写一个VHDL模块,但我有一个if语句的问题。很可能这是一个愚蠢的错误,但由于我对VHDL非常陌生,我无法弄清楚这个问题。这里是我的代码:意外的TICK错误

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use ieee.std_logic_arith.all; 
use ieee.std_logic_unsigned.all; 


entity binary_add is 
    port(n1 : in std_logic_vector(3 downto 0); 
    n2 : in std_logic_vector(3 downto 0); 
    segments : out std_logic_vector(7 downto 0); 
    bool : out bit; 
    o : out std_logic_vector(3 downto 0); 
    DNout : out std_logic_vector(3 downto 0)); 

end binary_add; 

architecture Behavioral of binary_add is 
begin 

process(n1, n2) 
begin 

o <= n1 + n2; 

if(o = '1010') then 
bool <= '1'; 
else 
bool <= '0'; 
end if; 

end process; 

end Behavioral; 

我从if语句的第一行得到如下答案:

ERROR:HDLParsers:## - "C:/Xilinx/12.3/ISE_DS/ISE/.../binary_add.vhd" Line ##. parse error, unexpected TICK 

我在做什么错?

+0

嗨。如果答案帮助你,请注册。接受最有用的! – Marty 2010-11-03 13:56:06

回答

2

'1010'应该是“1010”(双引号)。单引号用于字符文字(单个字符)。

+0

然后我得到这个错误;模式输出的参数o不能与模式中的形式参数相关联。 – makyol 2010-11-02 17:19:29

+0

这是因为我没有在process()中使用参数o吗?另外,我可以把o内部过程,因为它是一个输出? – makyol 2010-11-02 17:23:10

2

因此,您已经根据Mark的回答修正了第一个错误。

第二个错误是您无法使用输出的值。

if output = "0101"; -- illegal 

some_signal <= output; -- illegal 

为了解决这个问题,你需要创建一个内部信号(比如总和)。然后使用内部信号,并将其分配给外部信号。

architecture Behavioral of binary_add is 

signal sum : std_logic_vector(3 downto 0); 

begin 

process(n1, n2, sum) 
begin 

sum <= n1 + n2; 

if(sum = '1010') then 
bool <= '1'; 
else 
bool <= '0'; 
end if; 

end process; 

o <= sum; 

end Behavioral;