天天看點

【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)

Icarus Verilog官網:http://iverilog.icarus.com/

1. iverilog的安裝

Linux/Ubuntu:

官網給出的教程有點複雜,我試了一下直接用下面的指令就可以安裝。

sudo apt-get install iverilog

sudo apt-get install gtkwave

2. iverilog的IDE

使用vscode+iverilog插件作為IDE。

iverilog插件,選擇“mshr-h”這個作者建立的插件。

【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)

3.測試Demo

參考:https://www.bilibili.com/video/BV1Ef4y1X7wZ?from=search&seid=3262477841150114451

此Demo是示範“2輸入與門”的仿真。仿真波形使用gtkwave工具。

首先建立如下工程目錄結構。

【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)

and2.v

// 2-input and gate model

module and2 (
    input a,
    input b,
    output y
);
    
assign y = a & b;
endmodule
           

and2_tb.v

// Two-input and gate test-bench

`timescale 1s/100ms
`include "and2.v"

module and2_tb();
reg a;
reg b;
wire y;

and2 iand2(a, b, y);
initial begin
    $monitor("a=%b, b=%b, y=%b", a, b, y);
    $dumpfile("and2.vcd");  // 導出vcd檔案
    $dumpvars(0, and2_tb);  // 導出and2_tb子產品中的所有變量
    a = 0; b = 0; #10;
    a = 0; b = 1; #10;
    a = 1; b = 0; #10;
    a = 1; b = 1; #10;
    $finish;
end

endmodule
           

在vscode終端進行編譯

【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)

編譯後運作and2.out,輸出如下:

【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)

其中and2.vcd即可用gtkwave工具打開進行波形仿真

【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)

打開效果如下

【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)

展開and2_tb的變量清單

【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)
【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)

然後進行波形仿真

【HDL】Verilog HDL仿真工具iverilog(Icarus Verilog)

繼續閱讀