VHDL - 测试台 - 泛型

时间:2016-01-15 15:35:36

标签: vhdl

我一直致力于制作一个可以在多个实例中使用的解码器,只需更改输入/输出向量大小的通用值即可。解码器将“输出”单个位,基于输入的整数转换的多个位置。解码器本身工作正常。当我做一个测试工作台并编译时,问题就出现了。导致:

  

错误(10482):DECODER.vhd(41)处的VHDL错误:使用了对象“n”但未声明

我在下面添加了模型和测试平台:

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个通用的n 我尝试在模型实体中放入2个泛型语句,但编译器并不认为这是正确的做法。

总是非常感谢你的帮助。 d

2 个答案:

答案 0 :(得分:2)

您的组件声明声明存在名为decoder的组件,该组件(以及此组件的其他属性)具有名为n的通用组件,默认值为2 。此时,在分析文件时,您没有说明要分配给n的实际值。

我的方法是在声明组件之前定义一个常量:

constant DECODER_WIDTH : integer := 2;

然后使用它来声明您的信号:

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

当您实例化decoder时,您还将n泛型绑定到此常量:

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

如果您确实需要更改n的值,则必须在包中声明DECODER_WIDTH常量,然后此文件将use TN2实体声明,以及配置语句之前。如果您不需要配置来更改解码器大小,那么您可以从配置语句中省略generic map

答案 1 :(得分: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;