Windows上使用iverilog+gtkwave仿真

关注、星标公众,精彩内容每日送达

来源:网络素材

主要参考了:

https://www.cnblogs.com/lsgxeva/p/8280662.html

谢谢!

--------------------------------------------------------------------------------------------------------------------

使用Verilog编写好了功能模块以及对应的testbench之后,一般需要对其功能进行仿真测试。由于工作场合、必须使用正版软件,然而ModelSim的license又非常有限、经常出现的状况是一方在使用其进行仿真、另一方就不能够进行仿真了。

在这个情况下,可以有的选择包括:

1、继续等待别人用完,然后再使用ModelSim进行仿真;

2、使用集成在VIVADO里的simulation工具(ISE下自带的是ISim),基本可以胜任绝大多数的功能仿真任务;操作也很简单,直接Run Simulation就可以了;

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

下面对第三种方式的操作流程进行记录。系统环境为Windows7

从官网下载包含iverilog+GTKWave的安装包,地址为http://bleyer.org/icarus/ 。安装好之后开始逐步执行命令。(或者也可以将命令编写在一个脚本文件中。)

本文所仿真的verilog小实例如下,是一个简单的loadable四位加一计数器:(代码来自在学习testbench期间在网上找到的Lattice公司的“A Verilog HDL Test Bench Primer”手册中的示例代码)

7a2f8de46a20c7b75bab9679a403e19d.jpeg

//-------------------------------------------------
// 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

d7fa04858fe5510e86796c6318685856.jpeg

为其编写的testbench文件如下:

26a3fa16d9cf03076212f88d5db33992.jpeg

//-------------------------------------------------
// 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

086718bd9e4456be77df766e89f8d29d.jpeg

为了方便执行,编写了批处理脚本,如下:

fcabe0f616c6ea7a1ed39707c14683a2.jpeg

set iverilog_path=C:\iverilog\bin;
set gtkwave_path=C:\iverilog\gtkwave\bin;
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

2e1bf80b9bf5105fcbdad39c5dfb6ccf.jpeg

首先,设置iverilog和GTKWave可执行文件路径到PATH。由于工作场合下、本人只是所使用电脑系统的普通用户权限、而不是管理员权限,所以不方便为本机系统添加环境变量,所以需要在开始执行上述操作。

然后设置两个变量,后面会使用

  testbentch_module设置为testbench文件的模块名

  source_module设置为DUT模块名

然后使用iverilog编译verilog

  -o指定输出文件名,这里使用模块名+.vvp

  之后指定源文件

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

然后使用vvp开始仿真,参数为上面iverilog的输出文件

之后开始仿真数据波形显示

  设置了一个变量,为GTKWave保存文件的文件名,这里使用模块名+.gtkw

  然后判断GTKWave保存文件是否存在,若存在则直接使用GTKWave打开该.gtkw文件,否则打开刚仿真生成的.vcd文件。

这里有两点需要注意:

1、vvp命令使用了-n选项是为了让testbench在执行完测试流程之后自动结束,也可以不在执行命令这里使用-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的参数需要为testbench的模块名。

添加了这两个命令之后就可以将生成的波性文件保存在本地。

在GTKWave中打开的仿真波形结果如下图所示:

b7cfe4896a9508c61dabe22cd3d84d3d.png

 直接运行iverilog -helpiverilog则会显示以下帮助信息,显示了iverilog支持的参数

edc025c81d451e78b9d5a75e504eea78.jpeg

Usage: iverilog [-ESvV] [-B base] [-c cmdfile|-f cmdfile]
                [-g1995|-g2001|-g2005|-g2005-sv|-g2009|-g2012] [-g<feature>]
                [-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)

5680f62716769ae6b8dc4dcc2f9a9b2f.jpeg

详细参数列表请查看http://iverilog.wikia.com/wiki/Iverilog_Flags

 此外,如果运行批处理需要在DOS窗口查看verilog中$display的打印,有时iverilog编译打印的信息较多时会导致部分信息无法查看,所以需要加大DOS窗口的高度:在DOS窗口标题栏右键->默认值->布局中设置屏幕缓冲区中高度为较大的值(如1000)即可。

最后是可能会用到的网址:

iverilog 官网:http://iverilog.icarus.com/

iverilog windows版本:http://bleyer.org/icarus/

iverilog User Guide:http://iverilog.wikia.com/wiki/User_Guide

iverilog GitHub:https://github.com/steveicarus/iverilog

GTKWave 官网:http://gtkwave.sourceforge.net/

GTKWave 手册:http://gtkwave.sourceforge.net/gtkwave.pdf

<think>好的,用户想要查找关于GTKWave的安装方法或教程,具体询问GTKWave的安装教程或如何安装。我需要根据提供的引用内容来整理回答。 首先,查看用户提供的引用内容。引用[1]、[2]、[3]、[4]都提到了在不同系统下安装GTKWave的方法,特别是Linux和Windows。引用[1]和[2]说明在Ubuntu下可以通过apt-get直接安装,引用[4]提到了在Windows使用vscode配置时需要注意路径问题。引用[3]还提到了验证安装是否成功的方法。 接下来,我需要将信息结构化。用户可能需要不同操作系统的安装步骤,所以分点说明Linux(Ubuntu)、Windows以及macOS的安装方法会更清晰。同时,引用中提到的注意事项,比如路径不能有中文或空格,需要特别强调。 另外,用户可能对安装后的验证步骤感兴趣,如如何检查是否安装成功,所以需要包含验证命令,如which gtkwave。此外,引用[4]提到vscode的配置问题,可能需要简要说明,但用户主要问的是安装,这部分可以作为补充。 需要确保回答中的命令正确无误,并正确标注引用来源。比如在Linux部分引用[1][2][3],Windows部分引用[4],macOS部分可能没有直接引用,但可以根据常见方法建议Homebrew。 最后,生成相关问题时要围绕安装可能遇到的问题、使用教程、验证方法、跨平台使用等,确保问题相关且有助于用户进一步了解。</think>关于GTKWave的安装方法,根据系统平台不同可分为以下步骤: ### Linux系统安装(以Ubuntu为例) 1. 通过apt-get直接安装: ```bash sudo apt-get update sudo apt-get install gtkwave # 安装波形查看工具[^1][^2] ``` 2. 验证安装: ```bash which gtkwave # 显示路径如/usr/bin/gtkwave即成功[^3] ``` ### Windows系统安装 1. 访问[官方下载页面](http://gtkwave.sourceforge.net/)获取安装包 2. 安装时需注意: - 安装路径**不能包含中文或空格**(例如避免`Program Files`目录)[^4] - 建议选择`D:\GTKWave`等纯英文路径 ### macOS系统安装 通过Homebrew包管理器安装: ```bash brew update brew install --cask gtkwave ``` ### 验证安装成功 安装完成后,在终端执行: ```bash gtkwave --version # 输出版本信息即正常 ``` ### 跨平台关联工具建议 建议配合iverilog仿真使用,安装命令: ```bash sudo apt-get install iverilog # Linux系统专用[^1] ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值