Icarus/GTKWave Quickstart

Icarus and GtkWave/drom Quickstart #

This tutorial covers the basics of how to use the icarus verilog simulator and GTKWave waveform viewer.

Github Link #

Counter Module #

Let’s make a super simple module, called counter.v.


  • clock
  • reset


  • count

The output will increment by +1 on each clock. The counter will be 4 bits wide and will rollover at 15.

counter.v #

module count_up(clk, reset, count);
input clk; 
input reset; 
output [3:0] count; 
reg [3:0] counter; 

always @(posedge clk)
        counter <= 0;
        counter <= counter + 1; 
assign count = counter;

// Dump waves
initial begin
    $dumpvars(1, count_up);

For compatibility with gtkwave, you must include the last few lines at the end of any verilog module you’d like to view:

initial begin
    $dumpvars(1, count_up);

These lines create a value change dump file of the simulators output.

Writing A Verilog Testbench #

count_up_tb.v #

module count_up_tb();
wire [3:0] count;
reg clk,reset; 
count_up DUT(.clk(clk),.reset(reset),.count(count));

//create clock
initial begin
    clk = 0; 
    forever #5 clk = ~clk; 

initial begin 
    reset = 0; 
    reset = 1; 
    reset = 0;  
    reset = 1; 
    reset = 0; 
    #200 $finish;


Running Testbench With Icarus #

Let’s run the testbench to get a feel for using icarus. When using Cocotb later on much of the calls to the simulator are obfuscated away, making life easier for us, but its good to know whats going on under the hood.

> iverilog -o count_up_output count_up.v count_up_tb.v
> vvp count_up

The first command calls iverilog, which is a compiler that translates Verilog source code into executable programs for simulation. We then run vvp for simulation.

viewing results in gtkwave #

In the previous step vvp ran our simulation and placed the results in the count_up_output file. Our testbench drove our verilog module which dumped the signals to testbench.vcd (note: in count_up_tb.v we asked it to dump our variables to this file). This file can be opened in gtkwave. Steps:

  1. Open gtkwave
  2. navigate to file -> open new waveform
  3. open the testbench.vcd file
  4. in the left side pane select DUT and then click on the signals below to add to waveform


viewing results in vc.drom.io #

Simply drag and drop testbench.vcd to vc.drom.io


you can view and run this example in a browser at eda playground

learncocotb.com Copyright © 2023