开发者

Can Verilog testbenches work with a real clock?

开发者 https://www.devze.com 2023-01-05 09:02 出处:网络
I wrote a counter in Verilog, and then a testbench to test it. My testbench gives the correct results, so my code is OK. But is it gives the result of a long time instantly.

I wrote a counter in Verilog, and then a testbench to test it. My testbench gives the correct results, so my code is OK. But is it gives the result of a long time instantly.

Is it开发者_开发知识库 possible to take the result with real time. I mean in every one second my testbench will produce a new line of result?? (and if it is possible how?)


It is not exactly clear to me what you are trying to accomplish, but the $system system task can be used to execute a shell command during simulation. If you execute sleep 1 as follows, the simulation will pause for 1 second of wall-clock time for each time step. This will cause your simulation to display a message once per second. Of course, your simulation will be extremely slow. Note that $system is not part of the IEEE Standard for Verilog (but it is part of the System-Verilog Std).

`timescale 1ns/1ns

module tb;

initial begin
    $timeformat(-9, 1, "ns");
    #5 $finish;
end

integer sec = 0;
always begin
    #1;
    $system("sleep 1");
    sec = sec + 1;
    $display("seconds = %0d, time = %0t", sec, $time);
end

endmodule

This prints the following:

seconds = 1, time = 1.0ns
seconds = 2, time = 2.0ns
seconds = 3, time = 3.0ns
seconds = 4, time = 4.0ns
$finish called from file "tb.v", line 8.
$finish at simulation time                5.0ns
0

精彩评论

暂无评论...
验证码 换一张
取 消