首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VHDL测试平台:输出不变

VHDL测试平台:输出不变
EN

Stack Overflow用户
提问于 2017-06-06 16:07:07
回答 1查看 1.6K关注 0票数 0

我目前正在学习如何为我的VHDL组件编写测试基准。我正在试着测试一个时钟同步器,只是由两个级联D型触发器组成.我已经写了一个测试台,提供了一个时钟和适当的输入信号刺激,但我看到输出没有变化,当我模拟,它只是停留在"00“。

如果有任何帮助,我将不胜感激!

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

下面是组件VHDL:

代码语言:javascript
复制
    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;

下面是测试台:

代码语言:javascript
复制
   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;
EN

回答 1

Stack Overflow用户

发布于 2017-06-06 16:59:33

问题是,您还没有编译一个实体来绑定到dff组件。请参见EDA游乐场上的示例,在此您可以看到以下警告:

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

如果您没有配置,则需要调用dff,并且必须具有与dff组件完全相同的端口,即:

代码语言:javascript
复制
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触发器的功能进行建模。我假设了以下功能:

代码语言:javascript
复制
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游乐场上做了一些更明智的事情。(我没有检查它是否做了正确的事情。)

顺便问一句:你为什么要初始化这个输出?这似乎是一件奇怪的事情:

代码语言:javascript
复制
OUTPUT      : out std_logic_vector(Nbits-1 downto 0) := (others=>'0')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44394921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档