2016-01-15 88 views
0

我一直在努力製作一個解碼器,我可以在多個實例中使用,只需更改輸入/輸出矢量大小的通用值即可。解碼器將「輸入」一位,基於輸入整數轉換的多個位置。解碼器本身工作正常。當我製作測試臺並編譯時,問題就會出現。 「n」 被使用的對象,但不聲明VHDL - 測試平臺 - 泛型

我已經添加下面的模型和試驗檯:導致:

錯誤(10482):在DECODER.vhd VHDL錯誤(41):

LIBRARY IEEE; 
USE IEEE.std_logic_1164.ALL; 
USE IEEE.numeric_std.ALL; 

ENTITY DECODER IS 
    --GENERIC (delay : delay_length := 0 ns); 
    GENERIC (n  : POSITIVE := 2); 
    PORT (a : IN  std_logic_vector(n-1 DOWNTO 0); 
      x : OUT std_logic_vector(2**n-1 DOWNTO 0)); 
END ENTITY DECODER; 

ARCHITECTURE dflow OF DECODER IS 
    CONSTANT x_out : BIT_VECTOR (2**n-1 DOWNTO 0) := 
          (0 => '1', OTHERS => '0'); 
BEGIN 
    x <= to_stdlogicvector(x_out sll to_integer(unsigned(a))); 
END ARCHITECTURE dflow; 

--test bench---------------------------------------- 
LIBRARY IEEE; 
USE IEEE.std_logic_1164.ALL; 
USE IEEE.numeric_std.ALL; 

ENTITY TN2 IS 
END ENTITY TN2; 

ARCHITECTURE IO_TN2 OF TN2 IS 
    COMPONENT DECODER IS 
     --GENERIC (delay : delay_length := 0 ns); 
     GENERIC (n  : POSITIVE := 2); 
    PORT (a : IN  std_logic_vector(n-1 DOWNTO 0); 
      x : OUT std_logic_vector(2**n-1 DOWNTO 0)); 
END COMPONENT DECODER; 
SIGNAL a  : std_logic_vector (n-1 DOWNTO 0); --<-- USED BUT NOT DECLARED 
SIGNAL x : std_logic_vector (2**n-1 DOWNTO 0); 
BEGIN 
G1 : DECODER 
    GENERIC MAP (n => 2) 
    PORT MAP (a,x); 

    a <= "00", "01" AFTER 1 NS, "10" AFTER 2 NS, "11" AFTER 3 NS, 
      "00" AFTER 4 NS, "0Z" AFTER 5 NS; 
END ARCHITECTURE IO_TN2; 

CONFIGURATION CFG_DECODER OF TN2 IS 
    FOR IO_TN2 
     FOR G1 : DECODER 
        USE ENTITY work.DECODER(dflow) 
        GENERIC MAP (n => 2) 
        PORT MAP (a,x); 
     END FOR; 
    END FOR; 
END CONFIGURATION CFG_DECODER; 

編譯器告訴我,我沒有聲明n,我認爲我在組件聲明中做過。我應該在哪裏申報? 第二個問題是我如何聲明多種泛型,例如 1通用於delay_length 1通用for n 我試着在模型實體中放置2個通用語句,但編譯器不認爲這是正確的。

一如既往非常感謝您的幫助。 d

回答

2

你的組件聲明指出,有一個名爲decoder成分,它(連同該組件的其它屬性)有一個通用名爲n,與2的默認值。在分析文件的這一點上,你沒有提到你想要分配給n的實際值。

我的方法是定義一個常數,宣告部件之前:

constant DECODER_WIDTH : integer := 2; 

然後,您可以用它來聲明信號:當你實例化decoder

SIGNAL a : std_logic_vector (DECODER_WIDTH-1 downto 0); 

,你再還綁定n通用於此常數:

G1 : DECODER 
GENERIC MAP (n => DECODER_WIDTH) 
PORT MAP (a,x); 

如果你真的需要有配置改變的n的價值,你將不得不宣佈DECODER_WIDTH常數的包內,此文件將隨後use,無論是TN2實體聲明之前,和之前的配置語句。如果您不需要配置來更改解碼器大小,那麼您可以從配置語句中省略generic map

0

感謝您的意見,我跟你建議的修改更新,下面的代碼和它的工作原理以及

--test bench for 2/4 decoder---------------------------------------- 
LIBRARY IEEE; 
USE IEEE.std_logic_1164.ALL; 
USE IEEE.numeric_std.ALL; 

ENTITY TN2 IS 
END ENTITY TN2; 

ARCHITECTURE IO_TN2 OF TN2 IS 
COMPONENT DECODER IS 
    --GENERIC (delay : delay_length := 0 ns); 
    GENERIC (n  : POSITIVE := 2); 
    PORT (a : IN  std_logic_vector(n-1 DOWNTO 0); 
      x : OUT std_logic_vector(2**n-1 DOWNTO 0)); 
END COMPONENT DECODER; 
CONSTANT DECODER_WIDTH : integer := 2; ---<-- ADDED constant changing this value will alter decoder vector size 
SIGNAL a : std_logic_vector (DECODER_WIDTH-1 downto 0); --< changed n to decoder_width 
SIGNAL x : std_logic_vector (2**DECODER_WIDTH-1 DOWNTO 0); --< changed n to decoder_width 
BEGIN 
G1 : DECODER 
    GENERIC MAP (n => DECODER_WIDTH) --< pass decoder_width to n 
    PORT MAP (a,x); 
    a <= "00", "01" AFTER 1 NS, "10" AFTER 2 NS, "11" AFTER 3 NS, 
      "00" AFTER 4 NS, "0Z" AFTER 5 NS; 
END ARCHITECTURE IO_TN2; 

CONFIGURATION CFG_DECODER OF TN2 IS 
FOR IO_TN2 
    FOR G1 : DECODER 
        USE ENTITY work.DECODER(dflow) 
        GENERIC MAP (n => decoder_width) 
        PORT MAP (a,x); 
    END FOR; 
END FOR; 
END CONFIGURATION CFG_DECODER;