VHDL - 测试平台 - 泛型
VHDL - test bench - generics
我一直致力于制作一个解码器,我只需更改 input/output 向量大小的通用值即可在多个实例中使用它。解码器将 'sll' 单个位,基于输入的整数位置的数字转换。解码器本身工作正常。当我制作测试台并编译时出现问题。结果:
Error (10482): VHDL error at DECODER.vhd(41): object "n" is used but not declared
我在下面添加了模型和测试台:
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,我以为我在组件声明中声明了。我应该在哪里申报?
第二个问题是我如何声明多个泛型,即
delay_length 的 1 个通用
1 通用的 n
我尝试将 2 个通用语句放入模型实体中,但编译器认为这样做不正确。
一如既往地感谢您的帮助。
D
您的组件声明声明有一个名为 decoder
的组件,它(连同该组件的其他属性)有一个名为 n
的泛型,默认值为 [=15] =].在文件分析的这一点上,您没有说明要分配给 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
。
感谢您的评论,我已经根据您建议的修改更新了下面的代码并且运行良好
--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;
我一直致力于制作一个解码器,我只需更改 input/output 向量大小的通用值即可在多个实例中使用它。解码器将 'sll' 单个位,基于输入的整数位置的数字转换。解码器本身工作正常。当我制作测试台并编译时出现问题。结果:
Error (10482): VHDL error at DECODER.vhd(41): object "n" is used but not declared
我在下面添加了模型和测试台:
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,我以为我在组件声明中声明了。我应该在哪里申报? 第二个问题是我如何声明多个泛型,即 delay_length 的 1 个通用 1 通用的 n 我尝试将 2 个通用语句放入模型实体中,但编译器认为这样做不正确。
一如既往地感谢您的帮助。 D
您的组件声明声明有一个名为 decoder
的组件,它(连同该组件的其他属性)有一个名为 n
的泛型,默认值为 [=15] =].在文件分析的这一点上,您没有说明要分配给 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
。
感谢您的评论,我已经根据您建议的修改更新了下面的代码并且运行良好
--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;