Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

VCD Dump: A Complete Example

Verilog Examples

Runnable example from the Verilog VCD Dump tutorial (A Complete Example)

Open in IDE
testbench.v
`timescale 1ns/1ns

module counter (input clk, rstn, output reg [3:0] count);
  always @(posedge clk or negedge rstn)
    if (!rstn) count <= 0;
    else       count <= count + 1;
endmodule

module tb;
  reg        clk  = 0;
  reg        rstn = 0;
  wire [3:0] count;

  counter u_cnt (.clk(clk), .rstn(rstn), .count(count));

  always #5 clk = ~clk;

  initial begin
    $dumpfile ("counter.vcd");
    $dumpvars (0, tb);         // tb and the counter instance

    #12  rstn = 1;
    #50  $dumpoff;             // Pause at 62 ns
    #100 $dumpon;              // Resume at 162 ns
    #30  $finish;              // End at 192 ns
  end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.