Testbench For Entitiy with package - VHDL

时间:2015-07-23 16:35:31

标签: package vhdl

我在为使用包的测试模块创建测试平台时遇到问题。 该软件包只包含一个数组块,可以在不同的进程中访问。

-------------------- Package ---------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
package my_array_pkg is
 type my_array is array ( 0 to 9) of std_logic_vector(3 downto 0);
 end my_array_pkg;

顶级实体。

----------------- TOP ENTITY -------------------------
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use work.my_array_pkg.all;
    use IEEE.NUMERIC_STD.ALL;

entity pkt_top is
Port ( sys_clk  : IN STD_LOGIC;
        RESET : IN STD_LOGIC;
        AN_EN   : OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
        Seg_Cathodes    : out Std_logic_Vector(6 downto 0)
);      
end pkt_top;

architecture Behavioral of pkt_top is

SIGNAL CLK1HZ, CLK256HZ : STD_LOGIC;
signal my_digit : my_array;

COMPONENT Clock_1Hz is
    Port ( Sys_clk  : in  STD_LOGIC;
                Reset       : in std_logic;
                C_256Hz : out std_logic;
                C_1Hz       : out std_logic
                );
end COMPONENT;

COMPONENT Array_Count is
Port ( C_1Hz    : in std_logic;
        reset   : in std_logic;
        digit   : out my_array
        );
end COMPONENT;

COMPONENT Display_Driver is
Port ( Reset            : in std_logic;
        c256Hz          : in std_logic;
        C_1Hz           : in std_logic;
        digit_in        : in my_array;
        Seg_Cathodes    : out Std_logic_vector(6 downto 0);
        An_En           : out std_logic_vector(3 downto 0)
    );
end COMPONENT;

begin

C1 : Clock_1Hz -- Gives two clock divisions.
    PORT MAP ( SYS_CLK, RESET,CLK256HZ,  CLK1HZ);

C2 : Array_Count -- Initialize array with some numbers on every 1Hz edge
    PORT MAP ( CLK1HZ, RESET, my_digit);

C3 : Display_Driver -- Dispaly the numbers on seven segments with 256Hz switching time between segments.
    PORT MAP (RESET , CLK256HZ, CLK1HZ, my_digit, SEG_CATHODES, AN_EN);

end Behavioral;

代码是可综合的,可以在BASYS2板上运行,但我不能通过测试平台进行模拟。

--------------------My TestBench -------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
use work.my_array_pkg.all;

ENTITY pkg_tb IS
END pkg_tb;

ARCHITECTURE behavior OF pkg_tb IS 

    -- Component Declaration for the Unit Under Test (UUT)

    COMPONENT pkt_top
    PORT(
         sys_clk : IN  std_logic;
         RESET : IN  std_logic;
         AN_EN : OUT  std_logic_vector(3 downto 0);
         array_test : INOUT  my_array;
         Seg_Cathodes : OUT  std_logic_vector(6 downto 0)
        );
    END COMPONENT;


   --Inputs
   signal sys_clk : std_logic := '0';
   signal RESET : std_logic := '0';
    signal my_digit : my_array;

    --Outputs
   signal AN_EN : std_logic_vector(3 downto 0);
   signal Seg_Cathodes : std_logic_vector(6 downto 0);

   -- Clock period definitions
   constant sys_clk_period : time := 20 ns;

BEGIN

    -- Instantiate the Unit Under Test (UUT)
   uut: pkt_top PORT MAP (
          sys_clk => sys_clk,
          RESET => RESET,
          AN_EN => AN_EN,
          array_test => my_digit,
          Seg_Cathodes => Seg_Cathodes
        );

   -- Clock process definitions
   sys_clk_process :process
   begin
        sys_clk <= '0';
        wait for sys_clk_period/2;
        sys_clk <= '1';
        wait for sys_clk_period/2;
   end process;


   -- Stimulus process
   stim_proc: process
   begin        
      -- hold reset state for 100 ns.
        reset <= '1';
      wait for 100 ns;
        reset <= '0';

      -- insert stimulus here 

      wait;
   end process;

END;
---------------------------------------------------------------

当模拟ISIM时,会给出关于&#39; array_test&#39;的错误。不在Top实体中可用,如果删除它,则模拟仍为空白。

请关于测试平台的任何帮助。

2 个答案:

答案 0 :(得分:3)

我在实体pkt_top的描述中看不到名为“array_test”的端口。您必须在pkt_top中将其声明为输出端口。

答案 1 :(得分:0)

避免测试平台错误的另一种方法是删除testbench的.vhd文件,并为要模拟的实体创建一个新文件。

此外,每次编辑顶层实体的端口时,都可以删除旧版本并创建新的测试平台或编辑测试平台中同一实体的组件。