Module 6: Verilog for Testbench & Simulation · 6.5 Waveform Analysis

VCD Files

A self-checking testbench detects verification failures. Waveform analysis helps engineers determine why a failure occurred. A Value Change Dump (VCD) file logs signal transitions and simulation timestamps in an ASCII text format. Waveform viewers like GTKWave read this file to display graphical signal traces. Engineers must record the correct signals during relevant simulation windows to debug issues efficiently.

Basic Waveform Generation

Generating a VCD file requires two system task calls:

`timescale 1ns / 1ps

module tb_alu();
    reg  [7:0] a, b;
    reg  [2:0] op;
    wire [7:0] result;
    wire       overflow;

    alu dut (.a(a), .b(b), .op(op), .result(result), .overflow(overflow));

    initial begin
        $dumpfile("alu_sim.vcd");
        $dumpvars(0, tb_alu);

        a = 8'd10;  b = 8'd20; op = 3'd0; #20;
        a = 8'd255; b = 8'd1;  op = 3'd0; #20;
        a = 8'd15;  b = 8'd15; op = 3'd1; #20;
        $finish;
    end
endmodule

The $dumpfile task specifies the target output filename. The simulator saves this file relative to the current working directory. The $dumpvars(depth, scope) task selects which signals to record. The scope argument defines the starting module hierarchy. The depth argument sets how many hierarchical levels below the scope are recorded. A depth value of 0 records all signals across all descendant modules.

Place both system tasks at the start of the primary initial procedural block. Recording begins immediately when the simulator executes $dumpvars.

Managing File Size and Signal Scope

Large designs toggle tens of thousands of signals per clock cycle. Dumping every signal produces gigabytes of unneeded trace data. Use multiple $dumpvars calls to record specific submodules:

initial begin
    $dumpfile("targeted_sim.vcd");
    $dumpvars(1, tb_top.dut);              // Record top-level ports only
    $dumpvars(0, tb_top.dut.alu_block);    // Record the target submodule completely
    $dumpvars(1, tb_top.dut.state_reg);    // Record a single register signal
end

Recording top-level boundary ports with depth 1 and suspect submodules with depth 0 minimizes file sizes.

Windowed Recording

Use simulation control tasks to record specific intervals of time:

initial begin
    $dumpfile("windowed.vcd");
    $dumpvars(0, tb_top);
    $dumpoff;                        // Disable dumping during initialization

    repeat (100) @(posedge clk);

    $dumpon;                         // Enable dumping for the target transaction
    $dumpall;                        // Write a current state snapshot
    send_packet();
    $dumpoff;                        // Suspend dumping after transaction

    repeat (10000) @(posedge clk);
    $finish;
end

The $dumpoff task suspends signal dumping to disk. The $dumpon task resumes recording. The $dumpall task forces a snapshot of all monitored signals so the viewer retains valid states across time gaps. Windowed recording decreases file storage requirements by orders of magnitude.

VCD File Internal Format

VCD files use human-readable plain text:

$timescale 1ns $end

$scope module tb_counter $end
$var reg  1 ! clk $end
$var reg  1 " rst_n $end
$var reg  4 # count [3:0] $end
$var wire 1 $ done $end
$upscope $end
$enddefinitions $end

#0
0!
1"
b0000 #
0$
#5
1!
#10
0!
#15
1!
b0001 #
#25
1!
b0010 #

The header section assigns a short ASCII character identifier to each signal. The simulation body records timestamp markers with # followed by signal value changes. If a waveform viewer displays an empty signal list, open the VCD file in a text editor. An empty header confirms that the simulation terminated before reaching $dumpvars.

Fast Signal Trace (FST) Format

VCD files are standard but use substantial disk storage. Icarus Verilog supports Fast Signal Trace (FST), a compressed binary alternative. Run the simulation executable using vvp sim.vvp -fst to write an FST file. FST files occupy less disk space and open significantly faster in GTKWave. Commercial simulators provide comparable proprietary formats, such as FSDB.

Complete Selective Testbench Example

`timescale 1ns / 1ps

module tb_counter_vcd();
    parameter CLK_PERIOD = 10;

    reg        clk;
    reg        rst_n;
    wire [3:0] count;
    wire       done;

    counter_4bit dut (.clk(clk), .rst_n(rst_n), .count(count), .done(done));

    initial clk = 0;
    always #(CLK_PERIOD / 2) clk = ~clk;

    initial begin
        $dumpfile("counter_vcd.vcd");
        $dumpvars(1, tb_counter_vcd);         // Record testbench signals
        $dumpvars(0, tb_counter_vcd.dut);     // Record complete DUT hierarchy

        rst_n = 0;
        repeat (3) @(posedge clk); #2;
        rst_n = 1;

        repeat (20) @(posedge clk);

        $display("done at %0t ns", $time);
        $finish;
    end
endmodule

Selective dumping captures necessary debug data while preventing excessive file storage growth.

← Directed Tests Getting Around GTKWave →