VHDL Testbench:输出不变

时间:2017-06-06 16:07:08

标签: vhdl fpga

我目前正在学习为我的VHDL组件编写测试平台。我正在尝试测试一个时钟同步器,它只是由两个级联的D型触发器组成。我编写了一个测试平台,提供了一个时钟和适当的输入信号激励,但是当我模拟时,我看到没有输出变化,它只是保持在“00”。

如果有任何帮助,我将非常感激!

编辑:dff组件是标准的Quartus组件,不太确定如何获取内部代码。

这是组件VHDL:

    library ieee;
use ieee.numeric_std.all;
use ieee.std_logic_1164.all;


--This device is to synchronize external signals that are asynchronous to the 
--system by use of two cascaded D-Type flip flops, in order to avoid metastability issues.

--Set the generic term Nbits as required for the number of asynchronous inputs to
--be synchronized to the system clock OUTPUT(0) corresponds to INPUT(0), ect.

entity CLOCK_SYNCHRONIZER is

    generic(Nbits : positive := 2);

    port
    (
        --Define inputs
        SYS_CLOCK   : in std_logic;
        RESET       : in std_logic;
        INPUT       : in std_logic_vector(Nbits-1 downto 0);

        --Define output
        OUTPUT      : out std_logic_vector(Nbits-1 downto 0) := (others=>'0')
    );
end entity;



architecture v1 of CLOCK_SYNCHRONIZER is

    --Declare signal for structural VHDL component wiring 
    signal A : std_logic_vector(Nbits-1 downto 0);

    --Declare D-Type Flip-Flop
    component dff
        port(D : in std_logic; CLK : in std_logic; CLRN : in std_logic; Q : out std_logic);
    end component;

begin

    --Generate and wire number of synchronizers required
    g1 : for n in Nbits-1 downto 0 generate 
        c1 : dff port map(D=>input(n), CLK=>sys_clock, Q=>A(n), CLRN=>reset);
        c2 : dff port map(D=>A(n), CLK=>sys_clock, Q=>output(n), CLRN=>reset);
    end generate;


end architecture v1;

这是测试平台:

   library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;


entity testbench is
end entity;


architecture v1 of testbench is 

    component CLOCK_SYNCHRONIZER

        generic(Nbits : positive := 2);

        port
        (
            --Define inputs
            SYS_CLOCK   : in std_logic;
            RESET       : in std_logic;
            INPUT       : in std_logic_vector(Nbits-1 downto 0);

            --Define output
            OUTPUT      : out std_logic_vector(Nbits-1 downto 0)
        );
    end component;

    constant Bus_width      : integer := 2;
    signal SYS_CLOCK        : std_logic := '0';
    signal RESET            : std_logic := '1';
    signal INPUT        : std_logic_vector(Bus_width-1 downto 0) := (others=>'0');
    signal OUTPUT       : std_logic_vector(Bus_width-1 downto 0) := (others=>'0');

begin

    C1 : CLOCK_SYNCHRONIZER
    generic map(Nbits=>Bus_width)
    port map(SYS_CLOCK=>SYS_CLOCK, RESET=>RESET, INPUT=>INPUT, OUTPUT=>OUTPUT);


    always : process
    begin
        for i in 0 to 50 loop
            INPUT <= "11";
            wait for 24ns;
            INPUT <= "00";
            wait for 24ns;
        end loop;
    WAIT;
    end process;

    clk : process
    begin

        for i in 0 to 50 loop
            SYS_CLOCK <= '1';
            wait for 5ns;
            SYS_CLOCK <= '0';
            wait for 5ns;
        end loop;
    WAIT;
    end process;






end architecture v1;

1 个答案:

答案 0 :(得分:1)

问题是您尚未编译实体以绑定到dff组件。请参阅this example on EDA Playground,您会看到以下警告:

  

ELAB1警告ELAB1_0026:“组件没有默认绑定   “DFF”。 (没有找到名为“dff”的实体)。“”design.vhd“45 0 ...   ELBREAD:警告:ELBREAD_0037组件/ testbench / C1 / g1__1 / c1:dff未绑定。   ELBREAD:警告:ELBREAD_0037组件/ testbench / C1 / g1__1 / c2:dff未绑定。   ELBREAD:警告:ELBREAD_0037组件/ testbench / C1 / g1__0 / c1:dff未绑定。   ELBREAD:警告:ELBREAD_0037组件/ testbench / C1 / g1__0 / c2:dff没有绑定。

鉴于您没有配置,这需要被称为dff,并且必须与dff组件具有完全相同的端口,即:

entity dff is
        port(D : in std_logic; CLK : in std_logic; CLRN : in std_logic; Q : out std_logic);
end entity;

(Google“VHDL默认绑定规则”)

这需要模拟dff触发器的功能。我假定以下功能:

architecture v1 of dff is
begin

  process (CLK, CLRN)
  begin
    if CLRN = '0' then
      Q <= '0';
    elsif rising_edge(CLK) then
      Q <= D;
    end if;
  end process;

end architecture v1;

你现在可以看到这在EDA Playground做了更明智的事情。 (我没有检查是否正在执行正确的事情。)

BTW:你为什么要初始化这个输出?这似乎很奇怪:

OUTPUT      : out std_logic_vector(Nbits-1 downto 0) := (others=>'0')