2016-06-13 42 views
2

我是VHDL,並且有簡單的錯誤。我正在嘗試使用whenelse構建來創建MUX。錯誤有兩種類型:VHDL when-else error

Error (10500): VHDL syntax error at lab13.vhd(21) near text "when"; expecting ";"

Error (10500): VHDL syntax error at lab13.vhd(21) near text "else"; expecting ":=", or "<="

而且這些錯誤與whenelse每個字符串。

這裏是代碼:

entity lab13 is 
port (SW : in STD_LOGIC_VECTOR (17 downto 0); 
LEDG : out STD_LOGIC_VECTOR (2 downto 0); 
LEDR : out STD_LOGIC_VECTOR (17 downto 0)); 
end lab13; 



architecture logicFunc of lab13 is 
begin 
    process 
variable a, b, c : STD_LOGIC_VECTOR (2 downto 0) :=0; 
begin 
    a(0) := SW(0) when (SW(15) = '0') else SW(3); 
    b(0) := SW(6) when (SW(15) = '0') else SW(9); 
    c(0) := a(0) when (SW(16) = '0') else b(0); 
    LEDG(0) <= c(0) when (SW(17) = '0') else SW(12); 

    a(1) := SW(1) when (SW(15) = '0') else SW(4); 
    b(1) := SW(7) when (SW(15) = '0') else SW(10); 
    c(1) := a(1) when (SW(16) = '0') else b(1); 
    LEDG(1) <= c(1) when (SW(17) = '0') else SW(13); 

    a(2) := SW(2) when (SW(15) = '0') else SW(5); 
    b(2) := SW(8) when (SW(15) = '0') else SW(11); 
    c(2) := a(2) when (SW(16) = '0') else b(2); 
    LEDG(2) <= c(2) when (SW(17) = '0') else SW(14); 
end process; 
    LEDR <= SW; 
end logicFunc; 

那麼,如何解決這些問題?

+0

什麼工具鏈您使用的? –

+0

@scary_jeff Quartus II 13.0 – levshkatov

+0

嗯,我並不那麼熟悉,但我認爲問題在於,您需要查看綜合或項目選項,並將VHDL模式設置爲VHDL-2008或VHDL-200x。看看你能找到那樣的東西。 –

回答

2

VHDL-2008中引入了用於條件變量或信號分配的順序語句中的when,Altera Quartus完全不支持該語句。

實現可以替代地與信號製成,並且沒有處理,如:

architecture logicFunc of lab13 is 
    signal a, b, c : STD_LOGIC_VECTOR (2 downto 0); 
begin 

    a(0) <= SW(0) when (SW(15) = '0') else SW(3); 
    b(0) <= SW(6) when (SW(15) = '0') else SW(9); 
    c(0) <= a(0) when (SW(16) = '0') else b(0); 
    LEDG(0) <= c(0) when (SW(17) = '0') else SW(12); 

    a(1) <= SW(1) when (SW(15) = '0') else SW(4); 
    b(1) <= SW(7) when (SW(15) = '0') else SW(10); 
    c(1) <= a(1) when (SW(16) = '0') else b(1); 
    LEDG(1) <= c(1) when (SW(17) = '0') else SW(13); 

    a(2) <= SW(2) when (SW(15) = '0') else SW(5); 
    b(2) <= SW(8) when (SW(15) = '0') else SW(11); 
    c(2) <= a(2) when (SW(16) = '0') else b(2); 
    LEDG(2) <= c(2) when (SW(17) = '0') else SW(14); 

    LEDR <= SW; 

end architecture; 

不需要的ab,和c的初始化值,否則它必須通過進行:

variable a, b, c : std_logic_vector (2 downto 0) := (others => '0'); 

如果像when是VHDL-在2008年之前得心應手,那麼tern函數可以寫爲:

function tern(cond : boolean; res_true, res_false : std_logic) return std_logic is 
begin 
    if cond then 
    return res_true; 
    else 
    return res_false; 
    end if; 
end function; 

,然後用作:

a(0) := tern(SW(15) = '0', SW(0), SW(3)); 
+0

或者您可以使用一個進程並切換到if語句而不是條件賦值語句。將數量過程從分配數量減少到一個的想法會更快地模擬。並行作業意味着單獨的過程。 – user1155120

+0

是的,看起來像代碼可以簡化。 –