打印
[Quartus]

QuartusII Modelsim使用教程 转

[复制链接]
414|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
QuartusII中Modelsim是一个很好的仿真软件,相较于VWF,它的仿真时间更长、显示更具体、界面更友好,另外Modelsim还可以结合TestBench来进行仿真,省去了自己设置信号的过程。本文将从以下几个方面来介绍Modelsim的使用:

1、Modelsim联合TestBench进行仿真;
2、Modelsim仿真的几个小窍门;
3、Modelsim软件的bug
在Verilog代码写好编译好之后,可以通过Processing->Start->Start Test Bench Template Writer来自动生成一个TestBench模板。


// Copyright (C) 2017  Intel Corporation. All rights reserved.
// Your use of Intel Corporation's design tools, logic functions
// and other software and tools, and its AMPP partner logic
// functions, and any output files from any of the foregoing
// (including device programming or simulation files), and any
// associated documentation or information are expressly subject
// to the terms and conditions of the Intel Program License
// Subscription Agreement, the Intel Quartus Prime License Agreement,
// the Intel FPGA IP License Agreement, or other applicable license
// agreement, including, without limitation, that your use is for
// the sole purpose of programming logic devices manufactured by
// Intel and sold by Intel or its authorized distributors.  Please
// refer to the applicable agreement for further details.

// *****************************************************************************
// This file contains a Verilog test bench template that is freely editable to  
// suit user's needs .Comments are provided in each section to help the user   
// fill out necessary details.                                                  
// *****************************************************************************
// Generated on "05/17/2020 21:30:07"
                                                                                
// Verilog Test Bench template for design : AES_encryp
//
// Simulation tool : ModelSim-Altera (Verilog)
//

`timescale 1 ps/ 1 ps
module AES_encryp_vlg_tst();
// constants                                          
// general purpose registers
reg eachvec;
// test vector input registers
reg clk;
reg [127:0] iKey;
reg [127:0] iPlaintext;
reg rst_n;
// wires                                               
wire [127:0]  oCiphertext;

// assign statements (if any)                          
AES_encryp i1 (
// port map - connection between master ports and signals/registers   
        .clk(clk),
        .iKey(iKey),
        .iPlaintext(iPlaintext),
        .oCiphertext(oCiphertext),
        .rst_n(rst_n)
);
initial                                                
begin                                                  
// code that executes only once                        
// insert code here --> begin                          
                                                      
// --> end                                             
$display("Running testbench");                       
end                                                   
always                                                
// optional sensitivity list                           
// @(event1 or event2 or .... eventn)                  
begin                                                  
// code executes for every event on sensitivity list   
// insert code here --> begin                          
                                                      
@eachvec;                                             
// --> end                                             
end                                                   
endmodule
在这里特别提一下最后一个@eachvec 这一串代码,虽然具体不知道这段代码的作用,但如果加上这段代码,那么在进行Modelsim仿真的时候,仿真时间会特别短,clk也无法振动起来,因此再写需要clk的TestBench时建议将@eachvec这一段去了。

那么接下来编写TestBench就变得十分容易,你可以在initial中加入你要初始化的变量,例如rst_n,初始输入的数据等等,除此之外还可以通过#延时,来增加新的输入。然后在always中进行clk的实现,下面是加入初始化变量和时钟的部分TestBench代码。

initial                                                
begin                                                  
// code that executes only once                        
// insert code here --> begin                          
begin                                                  
        #0         clk = 0;
                rst_n = 0;
        #5        rst_n = 1;
                iKey = 128'h31_32_33_34_35_36_37_38_39_30_31_32_33_34_35_36;
                iPlaintext = 128'h30_39_38_37_36_35_34_33_32_31_36_35_34_33_32_31;
        #1000        rst_n = 0;
        #5      rst_n = 1;
                iKey = 128'h30_39_38_37_36_35_34_33_32_31_36_35_34_33_32_31;
                iPlaintext = 128'h31_32_33_34_35_36_37_38_39_30_31_32_33_34_35_36;
// --> end                                             
$display("Running testbench");                       
end                                                   
always                                                
// optional sensitivity list                           
// @(event1 or event2 or .... eventn)                  
begin                                                  
// code executes for every event on sensitivity list   
// insert code here --> begin                          
    #10 clk = ~clk;                                                                                             
// --> end                                             
end                                                   
endmodule

在写了一两个TestBench之后,也可以去了解一下repeat等的函数,来进一步提高编写TestBench的能力。

以下是配置Modelsim启用TestBench。

点击菜单栏的Assignments->setting->EDA Tool Settings->Simulation如下图所示









之后就一直Ok,然后就可以打开Modelsim进行仿真了。

2、Modelsim仿真的几个小窍门
1、在使用Modelsim时,我们常常会发现代码的问题然后去修改,那么修改了代码之后如何重新Modelsim仿真呢



如上图所示,只要在Modelsim中的Library->work->修改代码的文件->Recompile即可重新编译,不需要再每次重启Modelsim。

在之后如何重新运行Modelsim



如图所示,Simulate->Restart 选择OK即可,在之后run即可

值得一提的是,run不仅可以通过Simulate->run 还可以在如下图中直接输入run 100来运行仿真



2、如何在Modelsim中加入别的变量?



如上图所示,我们可以在sim中选择相应的模块,其中的assign是你在头文件中定义的变量。

另外再加入变量后,需要Restart Modelsim仿真,这样才可以看到数据一开始的变化过程,当然如果不进行Restart,也可以看到你加入变量之后的时间段的结果。
————————————————
原文链接:https://blog.csdn.net/qq_41783470/article/details/106630672

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:这个社会混好的两种人:一是有权有势,二是没脸没皮的。

1025

主题

11271

帖子

25

粉丝