Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print output and create a .vcd file?

I am a beginner, and I am learning VerilogHDL. I am trying to implement a simple NOT GATE code. What I want to do is print the output of the simulation with the $monitor() function, and I want to generate a .vcd file to be able to simulate it with GTKwave. I am using the Icarus Verilog (iverilog) Compiler. Below you will find the code.

Code for NOT GATE:

module notagate(
    input a,
    output y
);

always @ (a) begin
    if(a == 1'b0) begin
        y = 1'b1;
    end
    else if(a == 1'b1) begin
        y = 1'b0;
    end
endmodule

Code for NOT GATE TESTBENCH:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

module notgate_tb;

    reg a,
    wire y;

    notgate_tb uut(y, a);

        initial begin
        $dumpfile("notgate_tb.vcd");
        $dumpvars(0,notgate_tb);
        $monitor("%t | a = %d | y = %d", $time, a, y);

        a = 0;
        # 1 a = 1;
        # 1 a = 0;
    end
endmodule

When I run the following command:

iverilog -o notgate notgate_tb.v notgate.v

I get the following errors:

notgate_tb.v:4: syntax error
notgate_tb.v:1: error: Syntax error in variable list.
notgate.v:13: syntax error
I give up.

Why am I getting these errors, and how can I fix the code?

>Solution :

There are several syntax errors.

In the notgate_tb module, change the comma to a semicolon:

    reg a;

Change the uut instance line to use notgate, not notgate_tb. And, use connection-by-name, not connection-by-order.

In the notgate module, add a closing end statement before endmodule,
declare y as reg since you assign to it inside an always block (procedural assignment), and change the module name to notgate. This code fixes all errors:


module notgate(
    input a,
    output reg y
);

always @ (a) begin
    if(a == 1'b0) begin
        y = 1'b1;
    end
    else if(a == 1'b1) begin
        y = 1'b0;
    end
end
endmodule

module notgate_tb;

    reg a;
    wire y;

    notgate uut (.y(y), .a(a));

    initial begin
        $dumpfile("notgate_tb.vcd");
        $dumpvars(0,notgate_tb);
        $monitor("%t | a = %d | y = %d", $time, a, y);

        a = 0;
        # 1 a = 1;
        # 1 a = 0;
    end
endmodule

Here is the output I get:

VCD info: dumpfile notgate_tb.vcd opened for output.
                   0 | a = 0 | y = 1
                   1 | a = 1 | y = 0
                   2 | a = 0 | y = 1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading