【问题标题】:Realizing Top Level Entity in Testbench using VHDL使用 VHDL 在 Testbench 中实现顶层实体
【发布时间】:2016-04-10 12:59:34
【问题描述】:

我是 VHDL 和硬件领域的新手。 我正在尝试使用 Top Level Hierarchy 制作一个 Count&Compare 示例,并使用 testbench 对其进行测试,并在 ISIM 上查看结果。

这是我的框图草图:

所以我最终得到了这 3 个 vhd 源文件:

Counter.vhd

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Count_src is
    Port ( CLK   : in  STD_LOGIC;
           Reset : in  STD_LOGIC;
           S     : out  STD_LOGIC_VECTOR (3 downto 0));
end Count_src;

architecture Behavioral of Count_src is
signal count : STD_LOGIC_VECTOR (3 downto 0);

begin
process (Reset, CLK)
    begin
        if Reset = '1' then                             -- Active high reset
            count <= "0000";                            -- Clear count to 0
        elsif (rising_edge(CLK)) then                   -- Positive edge
            count <= count + "0001";                    -- increment count
        end if;
    end process;
S <= count;                                             -- Export count
end Behavioral;

比较

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;


entity Compare_src is
    Port ( A : in  STD_LOGIC_VECTOR (3 downto 0);
           B : in  STD_LOGIC_VECTOR (3 downto 0);
           S : out  STD_LOGIC);
end Compare_src;

architecture Behavioral of Compare_src is

begin

    S <= '1' when (A = B) else          -- Test if A and B are same
         '0';                           -- Set when S is different

end Behavioral;

CountCompare(顶级)

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity CountCompare_src is
    Port ( Clock : in  STD_LOGIC;
           Reset : in  STD_LOGIC;
           Value : in  STD_LOGIC_VECTOR (3 downto 0);
           Flag : out  STD_LOGIC);
end CountCompare_src;

architecture Behavioral of CountCompare_src is

-- COMPONENT DECLERATIONS
component counter is
    port ( CLK   : in std_logic;
           Reset : in std_logic;
           S     : out std_logic_vector(3 downto 0)
         );
end component;

component compare is
    port (A : in std_logic_vector(3 downto 0);
          B : in std_logic_vector(3 downto 0);
          S : out std_logic
         );
end component;

-- Component Spesification and Binding
for all : counter use entity work.Count_src(behavioral);
for all : compare use entity work.Compare_src(behavioral);

-- Internal Wires
signal count_out : std_logic_vector(3 downto 0);

begin

-- Component instantiation

C1: counter PORT MAP ( Reset => Reset,
                       CLK => Clock,
                       S => count_out
                     );

C2: compare PORT MAP ( A => count_out,
                       B => Value,
                       S => Flag
                     );

end Behavioral;

为了测试设计,我编写了一个测试平台,如下所示:

测试台

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;

ENTITY TopLevelTester_tb IS
END TopLevelTester_tb;

ARCHITECTURE behavior OF TopLevelTester_tb IS 

   --Input and Output definitions.
   signal Clock : std_logic := '0';
    signal Reset : std_logic := '0';
   signal Value : std_logic_vector(3 downto 0) := "1000";
    signal Flag  : std_logic;

   -- Clock period definitions
   constant clk_period : time := 1 ns;

BEGIN

   -- Instantiate the Unit Under Test (UUT)
   uut: entity work.CountCompare_src PORT MAP 
    (
        Clock => Clock,
        Reset => Reset,
        Value => Value
    );

   proc: process
   begin
       Clock <= '0';
       wait for clk_period/2;
       Clock <= '1';
       wait for clk_period/2;   
   end process;

END;

当我模拟行为模型时,ISIM 会弹出,但我在比较标志上看不到任何变化。这是ISIM的ss:

我在这里缺少什么?为什么Flag没有变化?

我最诚挚的问候。

【问题讨论】:

  • 您永远不会通过在测试台中断言 reset = '1' 然后回到 '0' 来初始化计数器。如果您在波形显示中显示 count 或 count_out,这将很明显。
  • 您好,感谢您的回复。我添加了另一个刺激,可以看到标志正在改变。但是,我猜它只有在值等于 0 时才会出现。我猜我的计数器不起作用。如何确定我的计数值是否在变化?
  • 将其添加到您的波形中? (并向您的测试平台添加一个重置刺激)。另请参阅答案。

标签: vhdl simulation test-bench


【解决方案1】:

你有两个问题,都在你的测试平台中。

第一个是你永远不会重置计数器中的计数,它总是'U'或'X'(在你增加它之后)。

第二个是测试台中的直接实体实例化缺少正式标志输出与实际标志信号的关联:

begin

uut: 
    entity work.countcompare_src 
        port map (
            clock => clock,
            reset => reset,
            value => value,
            flag => flag
        );

proc: 
    process
    begin
        clock <= '0';
        wait for clk_period/2;
        clock <= '1';
        wait for clk_period/2;  
        if now > 20 ns then
            wait;
        end if; 
    end process;

stimulus:
    process
    begin
        wait for 1 ns;
        reset <= '1';
        wait for 1 ns;
        reset <= '0';
        wait;
    end process;

解决这两个问题,你会得到:

【讨论】:

  • 我现在看到了。谢谢你:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多