quartus工具篇——modelsim的使用

quartus工具篇——modelsim的使用

1、modelsim简介

Quartus Prime是一款由英特尔开发的集成电路设计软件,而ModelSim是Quartus的一个可选工具,用于进行数字电路仿真和验证。下面是对ModelSim在Quartus中的一些简要介绍:

  1. 工作原理:ModelSim是一款基于事件驱动的数字仿真器,使用硬件描述语言(如VHDL或Verilog)来描述和模拟电路行为。它可以帮助设计人员验证他们的电路设计在真实硬件上的功能和时序。
  2. 仿真功能:ModelSim提供了丰富的仿真功能,包括单步执行、断点设置、波形查看、变量监视等。您可以在仿真环境中模拟和观察电路的行为,以确保其在各种情况下都能正确运行。
  3. 波形编辑器:ModelSim配备了强大的波形编辑器,可以用于查看和分析仿真波形。您可以对信号值、时间、层次结构等进行详细设置和调整,以便更好地理解电路的工作方式。
  4. 调试功能:ModelSim还提供了强大的调试功能,可用于定位和修复电路设计中的问题。您可以设置断点、监视变量、跟踪信号路径等,以辅助调试过程。
  5. 与Quartus集成:Quartus提供了与ModelSim的紧密集成,使您可以在Quartus环境中直接启动ModelSim仿真。这种无缝集成简化了设计流程,并使您能够快速切换设计和仿真环境。

需要注意的是,ModelSim作为Quartus的可选工具,通常需要单独安装,并且可能会需要额外的许可证。因此,在使用ModelSim之前,您需要检查您的Quartus版本以及相关许可证要求。

二、使用教程

1、新建工程添加文件

这里操作很简单,这里就不再赘述,结果如下图:

在这里插入图片描述

2、生成编写仿真文件

生成仿真文件

在这里插入图片描述

生成的文件会在你创建工程的目录下,如图:

在这里插入图片描述

我这里是工程是创建在prj下,所以文件会生成在simulation->modelsim文件夹下,将.vt的文件添加进工程

在这里插入图片描述

重写.vt文件,可以将里面的内容替换成你自己编写的仿真文件的内容,一般是修改initial后的内容,

修改前:

// Copyright (C) 2018  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 "07/16/2023 17:23:03"
                                                                                
// Verilog Test Bench template for design : pwm
// 
// Simulation tool : ModelSim-Altera (Verilog)
// 

`timescale 1 ps/ 1 ps
module pwm_vlg_tst();
// constants                                           
// general purpose registers
reg eachvec;
// test vector input registers
reg clk;
reg rst_n;
// wires                                               
wire led;

// assign statements (if any)                          
pwm i1 (
// port map - connection between master ports and signals/registers   
	.clk(clk),
	.led(led),
	.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

修改后:

// Copyright (C) 2018  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 "07/16/2023 17:23:03"
                                                                                
// Verilog Test Bench template for design : pwm
// 
// Simulation tool : ModelSim-Altera (Verilog)
// 

`timescale 1 ps/ 1 ps
module pwm_vlg_tst();
reg clk;
reg rst_n;

wire led;

parameter SYS_CLK = 20;
parameter TIME_US = 5;
parameter TIME_MS = 10;
parameter TIME_S = 10;

always #(SYS_CLK/2) clk = ~clk;

initial begin
	clk<=1'b0;
	rst_n<=1'b0;
	#(SYS_CLK*2);
	rst_n<=1'b1;
	#(2*(TIME_S+1)*(TIME_MS+1)*(TIME_US+1)*SYS_CLK);
	$stop;
end
pwm #(
		.COUNT1(TIME_US),
		.COUNT2(TIME_MS),
		.COUNT3(TIME_S)
	) inst_pwm (
		.clk   (clk),
		.rst_n (rst_n),
		.led   (led)
	);                               
endmodule

3、设置仿真

打开simuation选项:

在这里插入图片描述

在这里插入图片描述

添加.vt文件
在这里插入图片描述

testbench填入仿真文件中的模块名

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-a3CSTLKZ-1689500876759)(C:/Users/HP/AppData/Roaming/Typora/typora-user-images/image-20230716173546161.png)]

点击add添加即可,结果如下图

在这里插入图片描述

4、开启功能仿真

编译文件:

在这里插入图片描述

开启仿真:

在这里插入图片描述

运行后会打开modelsim

在这里插入图片描述

点击wave查看仿真

在这里插入图片描述

具体的modelsim操作这里就不进行细讲了

5、开启时序仿真

时序仿真需要运行项目

在这里插入图片描述

开启时序仿真

在这里插入图片描述

点击默认的,点击run开始运行

在这里插入图片描述

结果:

在这里插入图片描述

与功能仿真不同的是,时序仿真有延时,不能像功能仿真理想化

6、总结

modelsim在quartus中的操作相对简单,当然也可以直接在modelsim中进行操作,相对来说很复杂,得出的效果也是一样的。

参考视频:

讲的很详细:02_ModelSim软件使用讲解_哔哩哔哩_bilibili

  • 3
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ModelSim是一种常用的仿真工具,可用于验证和调试组合逻辑电路设计。以下是一个简单的组合逻辑电路设计的例子,其中使用ModelSim进行验证: 1. 首先,我们需要创建一个新的工程。在ModelSim中,选择“File”>“New Project”>“VHDL”,然后输入工程名称和保存路径。 2. 在工程中创建一个新的源文件。在ModelSim中,选择“File”>“New”>“VHDL File”,然后输入文件名和保存路径。 3. 在新的源文件中编写VHDL代码来描述电路。以下是一个简单的例子: ``` library ieee; use ieee.std_logic_1164.all; entity comb_logic is port ( a, b : in std_logic; c : out std_logic ); end entity comb_logic; architecture behavior of comb_logic is begin c <= a and b; end architecture behavior; ``` 在此代码中,我们定义了一个名为“comb_logic”的实体,该实体有两个输入端口(a和b)和一个输出端口(c)。在架构部分中,我们定义了一个简单的布尔表达式,将输入端口a和b的值取并,然后将结果赋给输出端口c。 4. 在工程中创建一个测试台。在ModelSim中,选择“File”>“New”>“Test Bench”,然后输入文件名和保存路径。 5. 在测试台中编写VHDL代码来生成输入并验证输出。以下是一个简单的例子: ``` library ieee; use ieee.std_logic_1164.all; entity comb_logic_tb is end entity comb_logic_tb; architecture behavior of comb_logic_tb is component comb_logic is port ( a, b : in std_logic; c : out std_logic ); end component comb_logic; signal a, b, c : std_logic; begin dut: comb_logic port map (a => a, b => b, c => c); stim_proc: process begin a <= '0'; b <= '0'; wait for 10 ns; a <= '0'; b <= '1'; wait for 10 ns; a <= '1'; b <= '0'; wait for 10 ns; a <= '1'; b <= '1'; wait for 10 ns; wait; end process stim_proc; assert_proc: process begin wait for 50 ns; assert(c = '0') report "Unexpected value on c" severity error; wait for 10 ns; assert(c = '0') report "Unexpected value on c" severity error; wait for 10 ns; assert(c = '0') report "Unexpected value on c" severity error; wait for 10 ns; assert(c = '1') report "Unexpected value on c" severity error; wait; end process assert_proc; end architecture behavior; ``` 在此代码中,我们定义了一个名为“comb_logic_tb”的实体,其中包含一个名为“dut”的组件(即我们要测试的电路)。我们还定义了三个信号a、b和c,它们将用于生成输入和验证输出。在架构部分中,我们使用port map将输入和输出信号连接到dut组件。我们还定义了两个过程:stim_proc用于生成输入,assert_proc用于验证输出。在assert_proc过程中,我们使用assert语句来测试输出值是否与预期值相同。如果不是,则报告错误。 6. 为测试台添加仿真器。在ModelSim中,选择“Simulate”>“Start Simulation”,然后选择要仿真的测试台文件并单击“OK”。 7. 运行仿真。在ModelSim中,选择“Simulate”>“Run – All”或单击工具栏上的“Run”按钮。仿真将运行并显示波形图。检查波形图以确保输出值与预期值相同。如果有错误,则需要检查代码并重新运行仿真。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值