2010-11-02 84 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;