Icarus Verilog

iverilog和gtkwave是verilog編譯和產生波形的輕量化工具。
僅能檢查波形和驗證功能,不能對電路面積和效能進行分析。

1.Download VSCode

(1) 載點: https://code.visualstudio.com/

(2) 下載VScode擴充套件:
點擊延伸模組搜尋:
Verilog-HDL: 提供基本的語法檢查
Chinese(Traditional): 提供繁體中文環境

image

image

2.Download iverilog

(1) 載點: https://bleyer.org/icarus/

image

基本都打勾就好,add to user path必勾,不然之後需要添加環境變數

image

載完會創建iverilog資料夾

image

(2) 添加環境變數:

image

點選環境變數

image

點選Path->編輯

image

新增loccal/iverilog/bin和local/iverilog/gtkwave路徑

image

(3) 修改VScode之verilog擴充設定

image

image

(4) 在VScode的terimal(點選vscode視窗最下方像電塔的圖示

image)輸入iverilog,檢查是否安裝成功
跳出內容表示成功
image

檢查gtkwave,輸入gtkwave,跳出視窗表示成功

image

image

之後重啟電腦,使環境生效

3.iverilog introduction

(1) Icarus Verilog編譯器主要包含:

iverilog 編譯verilog和vhdl檔案,檢查語法並生成執行檔
vvp 根據執行檔,產生波形檔
gtkwave 打開波形檔,顯示波形

(2) 常用參數介紹
-o: 指定編譯後的檔案名稱,預設為a.out
編譯top.v產生top: iverilog -o top tb_top.v

-g:擴展版本,若要使用systemverilog,可以使用 -g 2012

-D: 切換tb指定的define

-y: 指定包含的資料夾
編譯在D:/test的tb_top.v: iverilog -y D:/test/tb_top.v
在跟ternimal的同目錄:iverilog -y ./tb_top.v

-I: include其他檔案或資料夾
編譯tb_top.v,同時會用到top.v: iverilog -I ./top.v tb_top.v

3.環境測試

(1) 在桌面建立測試資料夾iverilog_ex

image

(2) 編寫範例程式:
計數器,每10 cycles計數+1,當計數10次後,會拉起一個done訊號
其中tb要增加的只有產生波形檔vcd的部分

initial begin $dumpfile("wave.vcd"); //產生vcd name $dumpvars(0, tb_counter); //tb module name end

image

counter.v:

module counter( input clk, input rst, output reg count_done ); reg [7:0] cnt; always @ (posedge clk) begin if(rst) cnt <= 8'd0; else if(cnt >= 8'd10) cnt <= 8'd0; else cnt <= cnt + 8'd1; end always @ (posedge clk) begin if(rst) count_done <= 1'b0; else if(cnt == 8'd10) count_done <= 1'b1; else count_done <= 1'b0; end endmodule

tb_counter.v:

`timescale 1ns/100ps `include "counter.v" //加了比較保險,讓tb能讀到top module module tb_counter; parameter CLK_PERIOD = 10; reg CLK; reg RESET; wire count_done; //module be tested counter t0 ( .rst(RESET), .clk(CLK), .count_done(count_done) ); //stimilu initial begin CLK = 1'b0; RESET = 1'b1; end initial begin #100 RESET = 1'b0; #1000 $finish; end always @(CLK) #(CLK_PERIOD/2) CLK <= !CLK; /*iverilog */ initial begin $dumpfile("wave.vcd"); //產生vcd name $dumpvars(0, tb_counter); //tb module name end endmodule

(3) 打開vscode的terminal,移動至code所在的資料夾
移動當前位置指令: cd <file_path>

image

(5) 編譯: iverilog -o wave top_tb.v

image

產生檔案wave

image

(6) 生成波形檔: vvp wave

image

產生波形檔wave.vcd

image

(7) 打開波形: gtkwave wave.vcd+mda 可觀察矩陣資料

image
image

(8) 插入訊號: 點擊insert

image
縮放時間軸大小:
image

調整時間軸位置:
image

4.寫成腳本自動化

(1) 創建cmd檔,將編譯和產生波形檔指令寫入

image

del wave //delete file wave del wave.vcd //delete file wave.vcd iverilog -o wave tb_counter.v //compile tb_cvounter.v & generate file wave vvp wave //generate waveform wave.vcd by file wave pause //terminal pause

(2) 回到終端機,輸入.\run.cmd,執行該執行檔

image

即可產生wave和wave.vcd

image

(3) 之後要修改,點選右鍵編輯內容即可

image

(4) linux下使用Makefile 待更新
新增Makefile:touch Makefile

image

Reference

一定學得會!!! 在vscode上架設易於開發verilog/system verilog的環境之教學(win10環境)
超簡易!!! 在vscode上利用TerosHDL架設易於開發verilog/system verilog的環境之教學(win11環境)
全平台轻量开源verilog仿真工具iverilog+GTKWave使用教程