问题描述:

--

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

entity D_flip_flop is

port (

D : in STD_LOGIC;

Q : inout STD_LOGIC;

Q_tonos : out STD_LOGIC;

CLK : in STD_LOGIC;

RST : in STD_LOGIC

);

end D_flip_flop;

architecture Behavioral of D_flip_flop is

begin

process_flip_flip: process

begin

wait until CLK'EVENT AND CLK = '1';

if(RST='1') then

Q <= '0';

else

Q <= D;

end if;

Q_tonos <= not Q;

end process process_flip_flip;

end Behavioral;

-------------------------

--testbench

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

ENTITY test_flip_flop IS

END test_flip_flop;

ARCHITECTURE tb OF test_flip_flop IS

COMPONENT D_flip_flop

PORT(

D : IN std_logic;

Q : INout std_logic;

Q_tonos : OUT std_logic;

CLK : IN std_logic;

RST : IN std_logic

);

END COMPONENT;

signal D : std_logic ;

signal CLK : std_logic ;

signal RST : std_logic ;

signal Q : std_logic;

signal Q_tonos : std_logic;

constant CLK_period : time := 10 ns;

signal stopClk : boolean;

BEGIN

-- Instantiate the Unit Under Test (UUT)

dut: D_flip_flop PORT MAP (

D => D,

Q => Q,

Q_tonos => Q_tonos,

CLK => CLK,

RST => RST

);

CLK_process :process

begin

while not stopClk loop

CLK <= '0';

wait for CLK_period/2;

CLK <= '1';

wait for CLK_period/2;

end loop;

wait;

end process CLK_process;

-- Stimulus process

stim_proc: process

begin

-- insert stimulus here

D <= '0';

RST <= '1';

wait for 100 ns;

D <= '0';

RST <= '0';

wait for 100 ns;

D <= '1';

RST <= '0';

wait for 100 ns;

D <= '1';

RST <= '0';

wait for 100 ns;

wait;

end process;

END;

网友答案:

You are missing one line in your testbench, I think:

    D <= '1';
    RST <= '0';
    wait for 100 ns;

    stopClk <= TRUE;  -- add this line

    wait;
  end process;

END;

http://www.edaplayground.com/x/56Mm

That way, when the test is finished, the clock stopClk signal turns off the clock generator and the simulation finishes. It finishes because it reaches a state called event starvation. Every time a line of code containing a signal assignment is executed, an event is added to the simulators event queue (its "to do list"). If you create a situation where no such lines continue to be executed, then the event queue becomes empty. This is event starvation. The simulator detects that and the simulation stops. (If you think about, what else could it do?)

Without this extra line, the simulation runs forever, because the clock generation process executes signal assignments forever, so the event queue is never empty.

网友答案:

Not really an answer, but: consider using if rising_edge(CLK) or maybe if CLK='1' and CLK'event instead of wait until. Not all synhtesis tools support that kind of code and anyway it's rare to see it in professional world ;)

p.s. stopClk signal is not driven (or was it?) Your TB clock is enably by that, yet I guess it remains 'u' for the whole simulation. Unless forced in the simulation.

相关阅读:
Top