VHDL - How should I create a clock in a testbench?

后端 未结 4 1508
你的背包
你的背包 2021-01-30 17:57

How should I create a clock in a testbench? I already have found one answer, however others on stack overflow have suggested that there are alternative or better ways of achievi

4条回答
  •  情书的邮戳
    2021-01-30 18:21

    My favoured technique:

    signal clk : std_logic := '0'; -- make sure you initialise!
    ...
    clk <= not clk after half_period;
    

    I usually extend this with a finished signal to allow me to stop the clock:

    clk <= not clk after half_period when finished /= '1' else '0';
    

    Gotcha alert: Care needs to be taken if you calculate half_period from another constant by dividing by 2. The simulator has a "time resolution" setting, which often defaults to nanoseconds... In which case, 5 ns / 2 comes out to be 2 ns so you end up with a period of 4ns! Set the simulator to picoseconds and all will be well (until you need fractions of a picosecond to represent your clock time anyway!)

提交回复
热议问题