2014-12-07 173 views
2

我有一個D觸發器的VHDL代碼和一個結構上使用它的T觸發器:它包括一個D輸入,D輸入被T存儲爲Q,a時鐘。但是我的模擬給了我一個只有紅色直線「U」的輸出的波形。我認爲這是因爲從Q到D的反饋,並且在開始時未初始化。但我不知道如何寫它。這是代碼:使用VHDL中的D觸發器的T觸發器的測試臺

- 這是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; 

--and電流測試平臺:

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; 

回答

1

到選通的另一種測試平臺中的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更強大一點。

2

你的「U '是由D觸發器的輸出在組合表達式中使用而未被重置爲已知狀態而引起的。

獲得埋在T觸發器實體重置爲已知的d觸發器將第二工藝添加到測試臺沿着切斷預定線的最簡單方法:

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