【问题标题】:VHDL Testbench : Output not changingVHDL 测试台:输出不变
【发布时间】:2017-06-06 16:07:07
【问题描述】:

我目前正在学习如何为我的 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;

【问题讨论】:

  • 你还没有给出dff的代码。
  • 嗯,不知道怎么弄。它是 Quartus 中的标准组件。我知道组件可以工作,我让它在物理设计中运行,它只是我无法弄清楚的测试平台。
  • 也许尝试以标准方式之一生成时钟:clk &lt;= not clk after 10 ns;? INPUT 也一样。
  • IEEE Std 1076-2008 15.3 词法元素、分隔符和定界符,第 2 段 - 在某些情况下,需要显式分隔符来分隔相邻的词法元素(即,在没有分隔的情况下,解释为单个词法元素是可能的)。 ...,第 4 段 - ...在标识符或抽象文字与相邻标识符或抽象文字之间至少需要一个分隔符。 5ns 必须是 @ 987654326@ 或可以识别为包含非基本字符的抽象文字。一个有利于供应商锁定而忽略的可移植性问题。

标签: vhdl fpga


【解决方案1】:

问题是您还没有编译实体以绑定到dff 组件。请参阅this example on EDA Playground,您会在其中看到以下警告:

ELAB1 WARNING 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;

(谷歌“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 上做了一些更明智的事情。 (我还没有检查它是否在做正确的事情。)

顺便说一句:你为​​什么要初始化这个输出?这样做似乎很奇怪:

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

【讨论】:

  • IEEE Std 1076-2008 7.3.3 默认绑定指示,第 2 段“...可见实体声明是以下列表中的第一个实体声明(如果有) :...c) 由 L.C 表示的实体声明,其中 L 是目标库,C 是实例化组件的简单名称。目标库是包含库的库逻辑名称声明组件 C 的设计单元。”避免配置规范的机制,您的dff 实体与testbench 在同一个工作库中找到。有关识别架构,请参见第 4 段。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-05
  • 1970-01-01
  • 2019-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多