2017-04-02 24 views
1

以下代碼是一個4:1多路複用器。如果dis信號爲'1',則所有輸出引腳的輸出應爲0。有沒有一個簡明的方式來表明,如果dis是高的,那麼輸出應該是0,無論sel,沒有 必須通過sel的每個組合排列?VHDL:條件信號分配的簡明表述

我知道,在某些情況下,如果條件分配模糊不清,則可能會出現無意識的鎖存器生成以及其他不良的副作用。

architecture dataflow of mux8_4 is 
begin 
    q <=d0 when sel = "00" and dis = '0' else 
     d1 when sel = "01" and dis = '0' else 
     d2 when sel = "10" and dis = '0' else 
     d3 when sel = "11" and dis = '0' else 
     "00000000" when sel = "00" and dis = '1' else 
     "00000000" when sel = "01" and dis = '1' else 
     "00000000" when sel = "10" and dis = '1' else 
     "00000000" when sel = "11" and dis = '1'; 
end architecture dataflow; 

我嘗試(我瞭解所有可能的語句的遺漏是壞 ,但實際上)

architecture dataflow of mux8_4 is 
begin 
    q <= "00000000" when dis = '1' else 
     d0 when sel = "00" and dis = '0' else 
     d1 when sel = "01" and dis = '0' else 
     d2 when sel = "10" and dis = '0' else 
     d3 when sel = "11" and dis = '0'; 
end architecture dataflow; 

回答

6

另外,您還可選擇信號分配:

architecture foo of mux8_4 is 
    subtype choice_type is std_logic_vector (2 downto 0); 
begin 
    with choice_type'(dis & sel) select 
     q <= d0   when "000", 
      d1   when "001", 
      d2   when "010", 
      d3   when "011", 
      "00000000" when others; 
end architecture; 

凡CASE表達式可能是具有本地靜態子類型的類型標記的限定表達式。

參見IEEE Std 1076-1993 9.5.2選擇的信號分配8.8案例語句或IEEE Std 1076-2008 11.6併發信號分配語句10.5.4選擇的信號分配語句10.9事件語句。

此(和您的)併發信號分配語句具有等效的包含等效順序信號分配語句的過程。條件和選定的信號賦值語句在-2008年被允許作爲順序語句。對於選定的信號分配有一個等效的情況說明。

只有在弱值'H'和'L'分別映射到強值'1'和'0'時,纔可以爲dis和select提供二進制值。對於模擬,您可以使用轉換函數來確保dis和sel表示二進制值(如果它們的值可能較弱)。

如果你的四個複用數據輸入可以表達你描述一個多路複用器多一點的緊湊陣列值:

architecture fum of mux8_4 is 
    type mux4 is array (0 to 3) of std_logic_vector(7 downto 0); 
    use ieee.numeric_std.all; 
    signal mux:  mux4; 
begin 
    mux <= (d0, d1, d2, d3); 
    q <= mux(to_integer(unsigned(sel))) when dis = '0' else (others => '0'); 

end architecture; 

索引名需要與本地靜態名稱的數組對象,這樣一個類型聲明用於聲明分配了類型爲mux4的聚合值的數組對象(mux)。

之後,我們可以在條件信號分配中dis ='0'時使用從sel轉換爲自然的索引作爲索引,其他值全部爲0。

這兩種架構都可以分析。如果您提供了一個Minimal, Complete and Veriable example實體聲明和一個測試平臺,它們可能已被詳細闡述和模擬,演示功能。 (他們都用一個附加的實體聲明進行分析)。

如果您的sel信號是受約束的整數子類型,索引名稱索引會更加緊湊和可讀。包數字__dd中找到的to_integer轉換函數將表示二進制值的弱級別映射爲強壯,並且如果sel包含元值(將被映射爲'0'),則會生成警告。