2013-07-28 38 views
3

如何實現具有「不關心」輸入並具有「無所謂」直接表示的VHDL功能?的Free Range VHDL具有無關輸入功能

練習4.8-2a問我:

...編寫實現用...選擇的信號分配這些功能的VHDL模型。

一個)F(A,B,C,d)= A'CD '+ B'C + BCD'

此代碼的工作:

library ieee; 
use ieee.std_logic_1164.all; 

entity funca_selected is 
    port (
    a: in std_ulogic; 
    b: in std_ulogic; 
    c: in std_ulogic; 
    d: in std_ulogic; 
    x: out std_ulogic); 
end entity; 

architecture rtl of funca_selected is 
    signal s: std_ulogic_vector(3 downto 0); 
begin 
    s <= a & b & c & d; 
    with s select x <= 
    '1' when "0010" | "0110" | "0011" | "1010" | "1011" | "1110", 
    '0' when others; 
end architecture; 

它是,但是,函數定義的表示很差。我想使用「不關心」輸入對其進行編碼,以便代碼更接近地匹配定義。這會減少工作,並且更容易得到正確的結果。我嘗試這樣做:

with s select x <= 
    '1' when "0-10" | "-01-" | "-110", 
    '0' when others; 

這不起作用:當我的試驗檯行使此項功能,結果始終是「0」。

我使用GHDL版本0.29 + gcc4.3.i386。

VHDL函數如何表示「不關心」輸入?

回答

3

隨着劃線表示法(如A ̅)的從練習4.8-2a函數是:

F(A,B,C,d)= A ̅ CD ̅ + B ̅ C + BCD ̅

GHDL最多隻支持VHDL-2000(根據GHDL features),所以沒有關於(' - ')檢查的VHDL-2008比較操作。對於GHDL另一種表達是表達:?

x <= ((not a) and c and (not d)) or 
    ((not b) and c) or 
    (b and c and (not d)); 

但是,如果VHDL-2008是工具,那麼=運算符,檢查不在乎用,可作爲:

x <= (s ?= "0-10") or (s ?= "-01-") or (s ?= "-110"); 

請注意,此表達式也適用於VHDL-2008 implicit布爾型到std_logic轉換。

或者?的情況下,也將對其進行不在乎,可作爲:

process (s) is 
begin 
    case? s is 
    when "0010" | "0110" | "0011" | "1010" | "1011" | "1110" => x <= '1'; 
    when others => x <= '0'; 
    end case?; 
end process; 

沒有與? VHDL-2008中的運算符用於併發類似分配。

有關VHDL-2008功能的更多信息,請點擊這裏VHDL-2008: Why It Matters

1

VHDL中的比較是按元素精確匹配的非常純粹的元素。這是VHDLs daftnesses其中有一個擴展來解決它的VHDL-2008一個,用case?聲明和=?操作

http://www.doulos.com/knowhow/vhdl_designers_guide/vhdl_2008/vhdl_200x_small/#matchcase

不幸的是,VHDL-2008不支持GHDL,所以你必須使用std_match函數,我認爲這也排除了使用with..select

+0

其實修復是允許使用重載的預定義的操作符。 IEEE Std 1076-2008,9.2.3關係運算符第3和第4節告訴我們,除了需要與某些軟件包相反的匹配元素之外,進行平等是非法的。爲了元匹配平等,需要新的運營商。平等不能被重新定義。 – user1155120

+0

@DavidKoontz - 我不確定我說我有什麼不同嗎?如果您可以建議改寫我的答案,請修改它。 –

1

是的,ghdl只能算作符合IEEE Std 1076-1993標準,而且還有一兩個孔。

當我們意識到不需要第一項(A̅CD̅)時,該函數可能會更簡單,而不依賴於結果。輸出中從未發現第一個產品術語。

無論選定信號分配的評估目標是表達式。您可以使用表情從MortenZdk的並行信號賦值語句:

library ieee; 
use ieee.std_logic_1164.all; 

entity f_test is 
end; 
architecture test of f_test is 

    subtype vector is std_logic_vector (3 downto 0); 
    type vectorstream is array (0 to 15) of vector; 

    constant stimulous: vectorstream :=(
    x"0",x"1",x"2",x"3",x"4",X"5",x"6",x"7", 
    x"8",x"9",x"A",x"B",x"C",x"D",x"E",X"F" 
    ); 

    signal index: integer range 0 to 15; 

    signal a,b,c,d: std_logic; 

    signal x: std_logic; 

begin 
Test_Vectors: 
    process 
     variable TV: std_logic_vector(3 downto 0); 
    begin 
     -- first term is valid 
     for i in vectorstream'range loop 

       index <= (i); -- make vector index visible in waveform 
       TV := vector(stimulous(i)); 
       a <= TV(3); b <= TV(2); c <= TV(1); d <= TV(0); 
       wait for 10 ns;      
      end loop; 

      wait; -- ends simulation 

    end process; 
EVALUATE: -- "the code more closely matches the definition" 

    with TO_X01(
       (not a   and c and not d) or -- b is don't care 
       (   not b and c   ) or -- a, d are don't care 
       (    b and c and not d)  -- a is don't care 
       ) select x <= '1' when '1', 
          '0' when '0', 
          'X' when 'X'; -- equivalent of 'else 'X' in 
              -- concurrent signal assignment 

end; 

TO_X01被稱爲強度剝離,是從包裝std_logic_1164和計算結果爲「X」的「0」或「1」。

選定的信號分配具有等價的條件信號分配,並且都可以表示爲過程,這就是它們如何被仿真。

ghdl -a f_test.vhdl 
ghdl -r f_test --wave=f_test.ghw 
open f_test.ghw 

gtkwave simulation result

你可以添加到stimulous允許傳播其他元素值的示範如stdlogic_table for「和」和指定「或」在std_Logic_1164包映射到鍵入X01減少所選信號分配語句中的選項數量。

還請注意在選擇x時< ='1'時,第一個'1'表示std_logic值,而第二個'1'表示類型X01的值。

您可以註釋掉A̅CD̅的第一個產品條款行,以證明它對結果x沒有任何影響。

1

我在Xilinx ISE 14.6版本中嘗試了兩種版本的邏輯,兩種版本都可以工作,但是有一些注意事項。首先,當我將「無所謂」版本的RTL原理圖與顯式版本進行比較時,「無所謂」版本更簡單且更優化。 「不關心」版本有四個邏輯門,每個門的最大輸入線是三條線。顯式版本有七個邏輯門,每個門的最大輸入線是六條線。

當我測試臺上的兩個版本時,我有四種不同的模擬選項:行爲模式,翻譯後模式,後貼圖模式和後路模式。在行爲模型中,「不關心」版本輸出與您所說的一樣是一條扁平線,而且似乎「不關心」版本不起作用,但是,在所有其他三種仿真選項中,兩種版本均可完美工作並輸出是相同的。所以看起來行爲模型並不知道如何處理VHDL代碼中的「不關心」部分,但代碼是可合成的,並且在VHDL代碼中使用「不關心」是非常有價值的。

+0

歡迎來到SO,並感謝您的測試結果。 –