Easy Tutorial
❮ All Vim Cheatsheat 3 Zookeeper Data Sync ❯

7.5 Other System Tasks in Verilog

Classification Advanced Verilog Tutorial

Simulation Control: $finish, $stop

System Task Call Format Task Description
Exit Simulation $finish( type ); End the simulation, the parameter type can choose whether to print information when exiting the simulation <br> type=0: Exit directly without printing <br> type=1: Print simulation time and the line information where the statement is located <br> type=2: Print simulation time, location, memory, and CPU time usage
Suspend Simulation $stop( type ); Suspend the simulation, the usage format is the same as $finish

Both $finish and $stop have the function of stopping the simulation, but they still have differences.

$finish is to end the current simulation. $stop is to suspend the current simulation. After the simulation is suspended, it can still be continued through the Verilog simulation tool or command line, but after the simulation is ended, it cannot be continued in any case. $stop is similar to the breakpoint debugging function in the C language.

The following simulation illustrates the printed information corresponding to the type type.

Example

initial begin
      forever begin
         #100;
         if ($time >= 10000)  $finish(0) ;
         //if ($time >= 10000)  $finish(1) ;
         //if ($time >= 10000)  $finish(2) ;
      end
   end

$finish(0), no information is printed when the simulation exits.

$finish(1), the simulation time and the line information where $finish is located are printed when the simulation exits, as shown below.

The module test has a time precision of ns, but the simulator's time precision is ps, so the printed time information is 1000 times different.

$finish(2), not only the simulation time and line information are printed when the simulation exits, but also the PC machine usage time and memory usage are printed, as shown below.

Time Format: $printtimescale, $timeformat

System Task Call Format and Description
Print Time <br> Units and Precision $printtimescale( hierarchy );
This system task prints the timescale information in the following format <br> TimeScale of ( hierarchy ) is 1 ( unit ) / 1 ( precision ) <br> hierarchy is the module access level, which can be omitted, in which case the current module's timescale information is printed
Set Time <br> Units and Precision $timeformat(unit_num, precision_num, suffix_string, min_field_width)
unit_num, sets the time unit, the default is based on `timescale <br> precision_num, sets the number of decimal places for the time unit, the default is 0 <br> suffix_string, sets the suffix information after the time, such as "ns", the default is empty <br> min_field_width, sets the number of characters occupied by the time information, the default is 20

When display tasks (such as $display, $monitor, etc.) and file writing tasks (such as $display, etc.) use the format "%t" for data output, $timeformat can specify the output format of the time unit information.

In $timeformat, unit_num is a signed number that specifies the time unit, and its correspondence is as shown in the following table:

unit_num Time Unit unit_num Time Unit
0 1 s -8 10 ns
-1 100 ms -9 1 ns
-2 10 ms -10 100 ps
-3 1 ms -11 10 ps
-4 100 us -12 1 ps
-5 10 us -13 100 fs
-6 1 us -14 10 fs
-7 100 ns -15 1 fs

The following code simulates the two system tasks of the time scale.

Example

``` //change timescale    initial begin       # 10 ;       //ps precision, 5 decimal places, unit suffix "my-ps", 15 characters wide       $timeformat(-12, 5, " my-ps", 15) ;    end    initial begin       # 5 ;

WeChat Follow

❮ All Vim Cheatsheat 3 Zookeeper Data Sync ❯