$dumpvars and $dumpfile Verilog

In the waveform genration tutorial we had used $dumpfile and $dumpvars system tasks. We will now take a deeper look into these two system variables.


The $dumpvars is used to dump the changes in the values of nets and registers in a file that is named as its argument. For example


will dump the changes in a file named test.vcd. The changes are recorded in a file called VCD file that stands for value change dump. A VCD (value change dump) stores all the information about value changes. We can not have more than one $dumpfile statements in verilog simulation. But what exactly are we going to dump in this file ? Thhis is specified by $dumpvars that we will cover next. One more thing, the declaration onf $dumpfile must come before the $dumpvars or any other system tasks that specifies dump.


The $dumpvars is used to specify which variables are to be dumped ( in the file mentioned by $dumpfile). The simplest way to use it is without any argument.


In this case, it dumps ALL variables in the current testbench module and in all other modules instantiated by it. The general syntax of the $dumpvars include two arguments as in

$dumpvars(<levels> <, <module_or_variable>>* );

We basically can specify which modules , and which variables in modules will be dumped. The simplest way to use this is to set the level to 0 and module name as the top module ( typically the top testbench module) as in

$dumpvars(0, toptestbench_module);

When level is set to 0, and only the module name is specified, it dumps ALL the variables of that module and all the variables in ALL lower level modules instantiated by this top module. If any module in not instantiated by this top module, then its variable will not be covered.

. If you wish to also cover variables of a module that is not instantiated by the top module , you could write

$dumpvars(0, toptestbench_module, not_instantiated_module);

If we wish to dump the variables only in the top module but not the modules instantiated below it, we could have 1 as its first argument as in

$dumpvars(1, toptestbench_module);

This is helpful when you do not wish to be bothered about the registers and the variables inside the instantiated module. But, during the debug and to find root cause, it may be helpful to use 0 as its first argument and dump all variables.
The following example will dump all variables in the in the module named toptestbench_module and the modules one level below it.

$dumpvars(2, toptestbench_module);

value of level more than 2 are rarely used.

Limiting the size of dump file

It is possible that you inadvertantly generate huge file in Gigabytes ( for examples while dumping a Gigahertz clock for one second). To reduce such occurrences, we may use $dumplimit. It usage is


represents that maximum size in bytes.

$dumpoff and $dumpon

During the simulation if you are bothered about about only during a certain interval then you can use $dumpoff and $dumpon. The following example shows its usage. It will dump the changes for first 100 units of time and then between 10200 and 10400 units of time.

            $monitor($time, " reset=%b,clk_out=%b",reset,clk_out);