0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

Windows上使用iverilog+gtkwave仿真

FPGA之家 ? 來源:FPGA之家 ? 2023-04-28 14:06 ? 次閱讀

使用Verilog編寫好了功能模塊以及對應的testbench之后,一般需要對其功能進行仿真測試。由于工作場合、必須使用正版軟件,然而ModelSim的license又非常有限、經常出現(xiàn)的狀況是一方在使用其進行仿真、另一方就不能夠進行仿真了。

在這個情況下,可以有的選擇包括:

1、繼續(xù)等待別人用完,然后再使用ModelSim進行仿真;

2、使用集成在VIVADO里的simulation工具(ISE下自帶的是ISim),基本可以勝任絕大多數(shù)的功能仿真任務;操作也很簡單,直接Run Simulation就可以了;

3、使用開源的工具:iverilog+gtkwave工具。

下面對第三種方式的操作流程進行記錄。系統(tǒng)環(huán)境為Windows7

從官網下載包含iverilog+GTKWave的安裝包,地址為http://bleyer.org/icarus/。安裝好之后開始逐步執(zhí)行命令。(或者也可以將命令編寫在一個腳本文件中。)

本文所仿真的verilog小實例如下,是一個簡單的loadable四位加一計數(shù)器:(代碼來自在學習testbench期間在網上找到的Lattice公司的“A Verilog HDL Test Bench Primer”手冊中的示例代碼)

//-------------------------------------------------
// File: count16.v
// Purpose: Verilog Simulation Example
//-------------------------------------------------
`timescale 1 ns / 100 ps
module count16 (count, count_tri, clk, rst_l, load_l, enable_l, cnt_in,
oe_l);
output [3:0] count;
output [3:0] count_tri;
input clk;
input rst_l;
input load_l;
input enable_l;
input [3:0] cnt_in;
input oe_l;
reg [3:0] count;
// tri-state buffers
assign count_tri = (!oe_l) ? count : 4'bZZZZ;
// synchronous 4 bit counter
always @ (posedge clk or negedge rst_l)
    begin
        if (!rst_l) begin
            count <= #1 4'b0000;
        end
        else if (!load_l) begin
            count <= #1 cnt_in;
        end
        else if (!enable_l) begin
            count <= #1 count + 1;
        end
    end
endmodule //of count16

為其編寫的testbench文件如下:

//-------------------------------------------------
// File: cnt16_tb.v
// Purpose: Verilog Simulation Example
// Test Bench
//-----------------------------------------------------------
`timescale 1 ns / 100 ps
module cnt16_tb ();
//---------------------------------------------------------
// inputs to the DUT are reg type
reg clk_50;
reg rst_l, load_l, enable_l;
reg [3:0] count_in;
reg oe_l;
//--------------------------------------------------------
// outputs from the DUT are wire type
wire [3:0] cnt_out;
wire [3:0] count_tri;
//---------------------------------------------------------
// instantiate the Device Under Test (DUT)
// using named instantiation
count16 U1 ( .count(cnt_out),
.count_tri(count_tri),
.clk(clk_50),
.rst_l(rst_l),
.load_l(load_l),
.cnt_in(count_in),
.enable_l(enable_l),
.oe_l(oe_l)
);
//----------------------------------------------------------
// create a 50Mhz clock
always
#10 clk_50 = ~clk_50; // every ten nanoseconds invert
//-----------------------------------------------------------
// initial blocks are sequential and start at time 0
initial
        begin            
            $dumpfile("cnt16_tb.vcd");
            $dumpvars(0,cnt16_tb);
        end

initial
begin
$display($time, " << Starting the Simulation >>");
clk_50 = 1'b0;
// at time 0
rst_l = 0;
// reset is active
enable_l = 1'b1;
// disabled
load_l = 1'b1;
// disabled
count_in = 4'h0;
oe_l = 4'b0;
// enabled
#20 rst_l = 1'b1;
// at time 20 release reset
$display($time, " << Coming out of reset >>");
@(negedge clk_50); // wait till the negedge of
// clk_50 then continue
load_count(4'hA);
// call the load_count task
// and pass 4'hA
@(negedge clk_50);
$display($time, " << Turning ON the count enable >>");
enable_l = 1'b0;
// turn ON enable
// let the simulation run,
// the counter should roll
wait (cnt_out == 4'b0001); // wait until the count
// equals 1 then continue
$display($time, " << count = %d - Turning OFF the count enable >>",
cnt_out);
enable_l = 1'b1;
#40;
// let the simulation run for 40ns
// the counter shouldn't count
$display($time, " << Turning OFF the OE >>");
oe_l = 1'b1;
// disable OE, the outputs of
// count_tri should go high Z.
#20;
$display($time, " << Simulation Complete >>");
$stop;
// stop the simulation
end
//--------------------------------------------------------------
// This initial block runs concurrently with the other
// blocks in the design and starts at time 0
/*initial
begin
// $monitor will print whenever a signal changes
// in the design
$monitor($time, " clk_50=%b, rst_l=%b, enable_l=%b, load_l=%b,
count_in=%h, cnt_out=%h, oe_l=%b, count_tri=%h", clk_50, rst_l,
enable_l, load_l, count_in, cnt_out, oe_l, count_tri);
end*/


//--------------------------------------------------------------
// The load_count task loads the counter with the value passed
task load_count;
    input [3:0] load_value;
    begin
        @(negedge clk_50);
        $display($time, " << Loading the counter with %h >>", load_value);
        load_l = 1'b0;
        count_in = load_value;
        @(negedge clk_50);
        load_l = 1'b1;
    end
endtask //of load_count


endmodule //of cnt16_tb

為了方便執(zhí)行,編寫了批處理腳本,如下:

set iverilog_path=C:iverilogin;
set gtkwave_path=C:iveriloggtkwavein;
set path=%iverilog_path%%gtkwave_path%%path%

set source_module=count16
set testbentch_module=cnt16_tb


iverilog -o "%testbentch_module%.vvp" %testbentch_module%.v %source_module%.v
vvp -n "%testbentch_module%.vvp"

set gtkw_file="%testbentch_module%.gtkw"
if exist %gtkw_file% (gtkwave %gtkw_file%) else (gtkwave "%testbentch_module%.vcd")

pause

首先,設置iverilog和GTKWave可執(zhí)行文件路徑到PATH。由于工作場合下、本人只是所使用電腦系統(tǒng)的普通用戶權限、而不是管理員權限,所以不方便為本機系統(tǒng)添加環(huán)境變量,所以需要在開始執(zhí)行上述操作。

然后設置兩個變量,后面會使用

testbentch_module設置為testbench文件的模塊名

source_module設置為DUT模塊名

然后使用iverilog編譯verilog

-o指定輸出文件名,這里使用模塊名+.vvp

之后指定源文件

在制定源文件的時候可以用通配符*,如本人用的批處理中通常使用這種方式指定RTL文件:set rtl_file="../rtl/*.v"。

然后使用vvp開始仿真,參數(shù)為上面iverilog的輸出文件

之后開始仿真數(shù)據波形顯示

設置了一個變量,為GTKWave保存文件的文件名,這里使用模塊名+.gtkw

然后判斷GTKWave保存文件是否存在,若存在則直接使用GTKWave打開該.gtkw文件,否則打開剛仿真生成的.vcd文件。

這里有兩點需要注意:

1、vvp命令使用了-n選項是為了讓testbench在執(zhí)行完測試流程之后自動結束,也可以不在執(zhí)行命令這里使用-n、而通過在testbench文件的initial塊中添加"$finish"命令來結束。(testbentch中結束仿真推薦用$finish而不用$stop;因為$finish可以直接結束仿真并退出,而不需要手動退出,這樣運行類似以上例子批處理后可以直接打開GTKWave窗口)

2、為了讓vvp命令有輸出,需要在testbench文件中額外添加一個initial塊,在上面的代碼中為:

initial
        begin            
            $dumpfile("cnt16_tb.vcd");
            $dumpvars(0,cnt16_tb);
        end

dumpfile的內容為輸出的vcd文件名,可以隨意指定,這里指定為testbench模塊名;

dumpvar的參數(shù)需要為testbench的模塊名。

添加了這兩個命令之后就可以將生成的波性文件保存在本地。

在GTKWave中打開的仿真波形結果如下圖所示:

b1b12b32-e583-11ed-ab56-dac502259ad0.png

直接運行iverilog -help或iverilog則會顯示以下幫助信息,顯示了iverilog支持的參數(shù)

Usage: iverilog [-ESvV] [-B base] [-c cmdfile|-f cmdfile]
                [-g1995|-g2001|-g2005|-g2005-sv|-g2009|-g2012] [-g]
                [-D macro[=defn]] [-I includedir]
                [-M [mode=]depfile] [-m module]
                [-N file] [-o filename] [-p flag=value]
                [-s topmodule] [-t target] [-T min|typ|max]
                [-W class] [-y dir] [-Y suf] source_file(s)

此外,如果運行批處理需要在DOS窗口查看verilog中$display的打印,有時iverilog編譯打印的信息較多時會導致部分信息無法查看,所以需要加大DOS窗口的高度:在DOS窗口標題欄右鍵->默認值->布局中設置屏幕緩沖區(qū)中高度為較大的值(如1000)即可。

審核編輯:湯梓紅

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 仿真
    +關注

    關注

    50

    文章

    3995

    瀏覽量

    133228
  • WINDOWS
    +關注

    關注

    3

    文章

    3510

    瀏覽量

    88211
  • Verilog
    +關注

    關注

    28

    文章

    1335

    瀏覽量

    109859
  • 計數(shù)器
    +關注

    關注

    32

    文章

    2248

    瀏覽量

    94181
  • 開源
    +關注

    關注

    3

    文章

    3185

    瀏覽量

    42241

原文標題:Windows上使用iverilog+gtkwave仿真

文章出處:【微信號:zhuyandz,微信公眾號:FPGA之家】歡迎添加關注!文章轉載請注明出處。

收藏 人收藏

    評論

    相關推薦

    E203用iverilog12仿真時,run_test一直卡怎么解決?

    求助??!一直卡在這里進行不下去了,請問大佬們這是為什么呀?每個步驟都是按照教程來的!iverilog用的12,ubuntu 20.04
    發(fā)表于 01-10 07:07

    基于樹莓派5的RTL仿真體驗

    《基于樹莓派5的RTL仿真體驗》 對于FPGA或者RTL愛好者來講,樹莓派5開發(fā)板可以運行RTL仿真,仿真工具使用iverilog,波形工具使用gt
    發(fā)表于 04-30 17:35

    樹莓派在windows仿真的方法

    樹莓派在windows仿真的方法是一個超簡單的方式,其實是QEMU模擬器+樹莓派系統(tǒng)的‘傻瓜包’”,壓縮文件,500m。解壓后,run.bat[hide]下載地址: http://sourceforge.net/project
    發(fā)表于 06-29 16:03

    教你怎樣一勞永逸解決Windows和MacOS等非Linux操作系統(tǒng)下的Spinal HDL環(huán)境安裝問題

    /spinal-cocotb:1.6.1這條命令創(chuàng)建的容器里,有Java環(huán)境和Python環(huán)境,也有Scala的編譯工具sbt和mill,還有verilator、iveriloggtkwave這些仿真
    發(fā)表于 07-04 15:29

    SpinalHDL是如何讓仿真跑起來的

    一些比較貼合具體業(yè)務場景的測試條件下往往需要前后很多腳本或調用C模型來進行生成測試數(shù)據和最后的數(shù)據驗證,構建case的便捷性稍顯不足(在《FPGA圖像處理—老細新說》一文中,這里的仿真測試如果用
    發(fā)表于 07-25 15:09

    基于Windows系統(tǒng)的SpinalHDL開發(fā)環(huán)境搭建步驟

    ;仿真工具使用verilator+gtkwave,為了便捷安裝使用Iverilog軟件(此軟件集成GTKWave),安裝verilator軟件在wi
    發(fā)表于 10-24 15:40

    如何在ARM使用Clang for Windows進行編譯

    Windows on Arm筆記本電腦編譯C/C++應用程序。 此原生工具鏈意味著您可以在該設備為基于Arm的設備開發(fā)軟件而不是在另一臺主機上交叉編譯或使用仿真來運行Clang的
    發(fā)表于 08-08 06:56

    在/vsim下執(zhí)行make run_test SIM=iverilog時報錯怎么解決?

    Error: VVP input file 10.3 can not be run with run time version 12.0 (stable) 求助大佬,在/vsim下執(zhí)行make run_test SIM=iverilog時收到上面的報錯,嘗試重裝iverilog
    發(fā)表于 08-12 08:29

    基于Windows平臺的分布式實時仿真系統(tǒng)

    提出了解決Windows下分布式仿真的兩種方案:基于RTX的反射內存網分布式仿真和基于以太網的令牌環(huán)分布式仿真架構。并比較了兩種架構與傳統(tǒng)Windo
    發(fā)表于 03-22 17:30 ?83次下載
    基于<b class='flag-5'>Windows</b>平臺的分布式實時<b class='flag-5'>仿真</b>系統(tǒng)

    Windows平臺的分布式實時仿真系統(tǒng)

    Windows平臺的分布式實時仿真系統(tǒng)
    發(fā)表于 10-31 09:20 ?10次下載
    <b class='flag-5'>Windows</b>平臺的分布式實時<b class='flag-5'>仿真</b>系統(tǒng)

    干貨:在Windows安裝Maven及配置

    干貨:在Windows安裝Maven及配置
    的頭像 發(fā)表于 06-20 09:24 ?2736次閱讀
    干貨:在<b class='flag-5'>Windows</b><b class='flag-5'>上</b>安裝Maven及配置

    如何使用Icarus Verilog+GTKWave來進行verilog文件的編譯和仿真

    Windows+Linux+MacOS,并且源代碼開源。通過tb文件可以生成對應的仿真波形數(shù)據文件,通過GTKWave可以查看仿真波形圖,支持將Verilog轉換為VHDL文件。 1.
    的頭像 發(fā)表于 07-27 09:16 ?5181次閱讀
    如何使用Icarus Verilog+<b class='flag-5'>GTKWave</b>來進行verilog文件的編譯和<b class='flag-5'>仿真</b>

    全平臺輕量開源verilog仿真工具iverilog+GTKWave使用教程

    如果你只是想檢查Verilog文件的語法是否有錯誤,然后進行一些基本的時序仿真,那么Icarus Verilog 就是一個不錯的選擇。相比于各大FPGA...
    發(fā)表于 01-26 19:14 ?5次下載
    全平臺輕量開源verilog<b class='flag-5'>仿真</b>工具<b class='flag-5'>iverilog+GTKWave</b>使用教程

    verilog仿真工具編譯

    Icarus Verilog(以下簡稱iverilog )號稱“全球第四大”數(shù)字芯片仿真器,也是一個完全開源的仿真器。
    的頭像 發(fā)表于 08-15 09:11 ?8227次閱讀

    利用vcs+verdi仿真工具蜂鳥E200系列處理器仿真分析

    開源RISC-V Hummingbird E203(蜂鳥E203)的仿真工具是開源的iverilog,這里利用vcs+verdi仿真工具進行仿真;
    的頭像 發(fā)表于 11-17 10:28 ?2709次閱讀