【发布时间】: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 <= not clk after 10 ns;? INPUT 也一样。 -
IEEE Std 1076-2008 15.3 词法元素、分隔符和定界符,第 2 段 - 在某些情况下,需要显式分隔符来分隔相邻的词法元素(即,在没有分隔的情况下,解释为单个词法元素是可能的)。 ...,第 4 段 - ...在标识符或抽象文字与相邻标识符或抽象文字之间至少需要一个分隔符。
5ns必须是 @ 987654326@ 或可以识别为包含非基本字符的抽象文字。一个有利于供应商锁定而忽略的可移植性问题。