【问题标题】:Testbench for T Flip Flop using D Flip Flop in VHDL在 VHDL 中使用 D 触发器的 T 触发器测试台
【发布时间】:2014-12-07 18:24:11
【问题描述】:

我有一个 D 触发器的 VHDL 代码,以及一个在结构上使用它的 T 触发器:它由一个 DFF 组成,其中 D 输入与 Q 相异或,一个时钟。但是我的模拟给了我一个只有红色直线“U”输出的波形。我认为是因为 Q 对 D 的反馈,并且一开始是未初始化的。但我不知道怎么写。这是代码:

--这是DFF:

    library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity d_flip_flop is
     port(
         clk : in STD_LOGIC;
         din : in STD_LOGIC;
         reset : in STD_LOGIC;
         dout : out STD_LOGIC
         );
end d_flip_flop;

architecture d_flip_flop_arc of d_flip_flop is    
begin

    dff : process (din,clk,reset) is
    begin
        if (reset='1') then
            dout <= '0';
        elsif (rising_edge (clk)) then
            dout <= din;
        end if;
    end process dff;


end d_flip_flop_arc;

--TFF:

    library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity tff_using_dff is
     port(
         clk : in STD_LOGIC;
         t : in STD_LOGIC;
         reset : in STD_LOGIC;
         dout : out STD_LOGIC
         );
end tff_using_dff;

architecture tff_using_dff_arc of tff_using_dff is    

component d_flip_flop is
     port(
         clk : in STD_LOGIC;
         din : in STD_LOGIC;
         reset : in STD_LOGIC;
         dout : out STD_LOGIC
         );
end component d_flip_flop;

signal ip : std_logic;
signal op : std_logic;    

begin

    ip <= op xor t ;
    u0 : d_flip_flop port map (clk => clk,
                            din => ip,
                            reset => reset,
                            dout => op);

    dout <= op;


end tff_using_dff_arc;

--和当前的测试平台:

 library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity T_FF_tb is
end T_FF_tb;

architecture T_FF_tb of T_FF_tb is
component tff_using_dff is 
     port(
         clk : in STD_LOGIC;
         t : in STD_LOGIC;
         reset : in STD_LOGIC;
         dout : out STD_LOGIC
         );
end component;

signal clk,t,reset: std_logic:='0';
signal dout: std_logic:='0';
begin
U0: tff_using_dff port map(clk,t,reset,dout);
clk<=not clk after 5 ns;
t<= not t after 30 ns;

end T_FF_tb;

【问题讨论】:

    标签: vhdl flip-flop object-test-bench


    【解决方案1】:

    您的“U”是由 D 触发器的输出在组合表达式中使用而未重置为已知状态引起的。

    将埋在 T 触发器实体中的 D 触发器重置为已知值的最简单方法是在测试台中添加第二个进程,如下所示:

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

    【讨论】:

      【解决方案2】:

      除了在您的测试台中选通reset 信号(无论如何都应该这样做),您可以定义d_flip_flop 输出的初始状态。这可以通过为具有初始状态分配的寄存器输出定义一个临时信号dout_i 来完成。例如

      library IEEE;
      use IEEE.STD_LOGIC_1164.all;
      
      entity d_flip_flop is
        port(
           clk : in STD_LOGIC;
           din : in STD_LOGIC;
           reset : in STD_LOGIC;
           dout : out STD_LOGIC
           );
      end d_flip_flop;
      
      architecture d_flip_flop_arc of d_flip_flop is    
        signal dout_i : STD_LOGIC := '0';
      begin
      
      dff : process (clk,reset) is
      begin
          if (reset='1') then
              dout_i <= '0';
          elsif (rising_edge (clk)) then
              dout_i <= din;
          end if;
      end process dff;
      
      dout <= dout_i;
      
      end d_flip_flop_arc;
      

      这应该达到相同的预期效果。它还有一个额外的好处是使d_flip_flop 更加强大。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多