Post date: May 21, 2020 4:4:25 AM
I've always I need to use a full-brown IDE to edit Verilog. It turns out, using Verilog on Mac (and Linux, although the installation procedure is slightly different) is a piece of 🎂.
$ brew install icarus-verilog
Next, enter the simplest code:
$ nano hello.v
module hello; initial begin $display("Hello, World"); $finish ; end endmodule
Compile with the command
$ iverilog -o hello hello.v
The result will be in a file "hello. Next, execute it:
$ vvp hello
Hello, World
For bigger project, there be multiple files. For example, the counter in the following file counter.v
module counter(out, clk, reset); parameter WIDTH = 8; output [WIDTH-1 : 0] out; input clk, reset; reg [WIDTH-1 : 0] out; wire clk, reset; always @(posedge clk or posedge reset) if (reset) out <= 0; else out <= out + 1; endmodule // counter
and the testbench counter_tb.v
module test; /* Make a reset that pulses once. */ reg reset = 0; initial begin # 17 reset = 1; # 11 reset = 0; # 29 reset = 1; # 11 reset = 0; # 100 $stop; // I replaced with $finish to have a clean exit end /* Make a regular pulsing clock. */ reg clk = 0; always #5 clk = !clk; wire [7:0] value; counter c1 (value, clk, reset); initial $monitor("At time %t, value = %h (%0d)", $time, value, value); endmodule // test
Compile and run using this command:
$ iverilog -o mydesign counter_tb.v counter.v
$ vvp mydesign
This is the output:
At time 0, value = xx (x)
At time 17, value = 00 (0)
At time 35, value = 01 (1)
At time 45, value = 02 (2)
At time 55, value = 03 (3)
At time 57, value = 00 (0)
At time 75, value = 01 (1)
At time 85, value = 02 (2)
At time 95, value = 03 (3)
At time 105, value = 04 (4)
At time 115, value = 05 (5)
At time 125, value = 06 (6)
At time 135, value = 07 (7)
At time 145, value = 08 (8)
At time 155, value = 09 (9)
At time 165, value = 0a (10)
There's further options in the short tutorial below.
Reference: