ModelSim-Altera使用方法

合集下载

用ModelSimSE进行功能仿真和时序仿真的方法(ALTERA篇)

用ModelSimSE进行功能仿真和时序仿真的方法(ALTERA篇)

用ModelSimSE进行 功能仿真和时序仿真的方法 (ALTERA篇)黄俊April 2007用ModelSim SE进行功能仿真和时序仿真的方法 (ALTERA篇)软件准备(1) QuartusII,本文截图是QuartusII 6.1界面的。

我个人认为,如果是开发StratixII或CycloneII或MAXII,用QuartusII6.0+SP1+SP2比较稳定。

(2) ModelSim SE. ALTERA仿真库要已经装好,安装仿真库的笔记已记录于《在ModelSimSE中添加ALTERA仿真库的详细步骤》中。

我电脑上装的是ModelSim SE6.1b。

例子程序的制作先在Quartus II里生成一个例子程序,以方便介绍三种仿真的方法。

步骤如下:1、新建一个工程(Project),工程名取lpm_shift, 器件选CycloneII EP2C5Q208C, 第三方的工具暂时都不选。

2、菜单栏上ToolsÆMegaWizard Plug-In Manager, 点Next,在storage中选LPM_SHIFTREG,输出文件格式根据习惯选一种语言,在这里以Verilog的为例,在右边的output file名字中加上lpm_shift。

点Next。

3、这个例子是做一个移位寄存器,调用lpm库,和cycloneII元件库,也正好可以作为对前面建好的ALTERA库的一个验证。

点可以查到该模块的使用说明和详细介绍。

移位寄存器比较简单,就不用细看了。

如下图设置.点Next.4、加上一个异步清零端,点Next,再点Next,最后点Finish.Add/Remove Files in Project…,6、点图标,选中生成的lpm_shift,点打开再点Add都加到项目中去。

7、在这里直接把lpm_shift.v当成顶层文件,就不需要再例化它了。

8、下面写一个简单的TestBench.a)Quartus II工具栏上点图标,选Verilog HDL;b)点,设文件名为top_tb;c)如下所述写一个简单的TestBench.(例子见附件)开始仿真z ModelSim仿真有很多种流程,下面我采用个人感觉比较好一个流程进行仿真验证:基于工程(Project)的流程Step1 新建一个工程Step2 添加文件到工程中去Step3 编译设计文件Step4 启动仿真器,指定顶层设计单元Step5 查看和调试结果z对的设计有三个阶段的仿真。

在quartusII中用modelsim-altera仿真

在quartusII中用modelsim-altera仿真

在quartusII中用modelsim_altera做功能仿真1.设置modelsim_altera的执行路径(即其安装路径中的可执行文件的路径)(1)Tool→Options(2)打开如下图:(3)选择general →EDA Tool Options,在右侧的窗口中选择Modelsim_Altera,在Location of Executable中单击,用浏览的方式找到该软件的安装路径中的可执行文件路径,单击确定。

到此仿真软件的设置基本完成了。

2.项目仿真当我们建立一个新的项目时是需要对其中代码进行仿真的,整个过程需要三步:2.1首先,要预先设置仿真软件;下面介绍如何预设仿真软件。

1.Assignments→Settings…2.打开如下界面3选择“Simulation”,右侧设置按上图设置。

2.2其次,仿真之前需要编写测试平台,测试平台有两种的方法:●直接建立XX.v文件●在quartusII中自动生成测试平台模板文件,文件为XX.vt文件下面介绍如何自动生成测试平台模板文件。

1.Processing→Start→Start Test Bench Template Writer注意:要生成testbench模板的前提条件是为项目选择预用的仿真软件,然后模块必须编译成功。

Testbench模板生成后的默认路径为:项目目录\simulation\modelsim\项目名.vt(因为刚才在预设置仿真软件时的“Output Directory”选择的是默认的值simulation\modelsim)。

2.对于自动生成的测试平台模版需要打开修改测试激励信号,这里不做介绍,很简单的。

2.3改写完后要在项目里添加测试平台文件到项目里。

1.Assignments→Settings…2.在打开界面做如下操作:(1)选择“Compile test bench”,然后单击“Test Benches…”(2)打开下面的窗口(3)单击“New”打开下面的窗口,且按图中填写相关信息这个窗口是用来输入testbench的资料和选择testbench的路径的。

ModelSim中Altera仿真库的添加

ModelSim中Altera仿真库的添加

ModelSim中Altera仿真库的添加最近,做一个IP核的调试,但是里面调用了Altera的syncram,这样ModelSim就不能直接进行仿真,而QuartusII又不支持Tesbbench的仿真,所以为了在ModelSim中仿真就必须将Altera的这些仿真库添加到ModelSim中。

通常,在ModelSim中进行仿真需要加入Quartus提供的仿真库,原因是下面三个方面:·Quartus不支持Testbench;·调用了megafunction或者lpm库之类的Altera的函数;·时序仿真要在Modelsim下做仿真。

下面以Altera器件为例,介绍如何在ModelSim中加入Altera的仿真库,Quartus II软件中自带有Altera的仿真库,只要把它拿到ModelSim中去编译一下就可以了,具体步骤如下:1.设置仿真库路径打开ModelSim安装目录(我用的是ModelSim SE 6.2版本,安装在D:\ModelSim\Installfiles目录下),新建文件夹altera,我们就在该目录下存放预编译的各种Altera库。

启动ModelSim SE 6.2,在主窗口执行【File】/【Change Directory】命令将路径转到altera文件夹。

或在命令行中执行cd D:/ModelSim/Installfiles/altera。

2.新建库Quartus II中提供的仿真库文件存放的路径是...\altera\80\quartus\eda\sim_lib,每个库文件提供了两种形式:.v(Verilog)格式和.vhd(VHDL)格式两种,根据你所用的语言选择使用。

用于编译资源库的文件有220model.v,220model.vhd,220pack.vhd,altera_mf.v,altera_mf.vhd,altera_mf_components.vhd,altera_primitives.v,altera_primitives.vhd,altera_primitives_components.vhd文件。

Quartus II 13.1 +ModelSim-Altera 10.1d (Quartus

Quartus II 13.1 +ModelSim-Altera 10.1d (Quartus

Quartus II 13.1 +ModelSim-Altera 10.1d仿真步骤华中科技大学自卓1701 吴宜正一、建立工程1、打开Quartus Ⅱ,点击new project图标即可新建一个Verilog工程,选好自己想要建立工程的文件夹,输入工程名和顶层实体名,点击next,进入下一步。

、2、可以向工程中加入已经存在的文件,如果没有点击next即可。

3、选取自己想要的器件,点击next即可。

4、在实验中最好在方框中选取Verilog HDL,以便之后编写Testbench文件。

点击next按钮。

之后finish即可。

5、添加Verilog文件在file菜单中选择new,之后输入自己的代码保存即可添加到工程中。

二、编译代码以二进制-ASCII码转化器为例输入代码后进行编译,编译可以按照以下步骤进行1、分析与综合。

点击菜单项Processing->start->Start Analysis &Synthesis也可以直接在工具栏找到。

如果编译成功,左下角窗口有如下显示。

2、全编译文件。

点击菜单项Processing->start compilation,或使用CTRL+L执行全编译。

执行后,如果程序没有问题左下角窗口有如下显示:三、电路仿真1、设定仿真工具此版本Quartus不提供仿真功能,需要调用Modelsim进行仿真,而如果要使用Modelsim 进行仿真首先要编写Testbench文件,在Quartus中,首先要设定仿真工具assignments-setting -EDA tool setting -simulation选择你需要的工具。

这里如果你使用的是下载Quartus时自动下载的ModelSim-Altera那么就选择这个,而如果使用的是单独下载的ModelSim那么就要选择ModelSim。

2. 自动产生测试激励文件模板:在菜单项中选择processing - start - Start test bench template writer3、添加testbench这时Quartus已经自动为你生成一个.vt文件,但是没有自动添加到你的工程内,需要自己去工程目录内寻找。

在Modelsim中加入altera的仿真库

在Modelsim中加入altera的仿真库
在Modelsim中加入Quartus的仿真库
虽然这是个老话题了,但总会有刚入门的朋友不知道的。我在这里还是讲讲吧!问什么要这样做?
1、Quartus不支持Testbench
2、调用了megafunction或者lpm库之类的Altera的函数
3、时序仿真要在Modelsim下做仿真,
总会遇到上面这几个问题,因为需要在Modelsim中加入Quartus的仿真库。 Altera公司推荐的具体的做法是: 1、在Modelsim中,File->Change Directory,将工作目录改变到想要存放仿真库的地方,然后点击OK。将来产生的一大堆仿真库要用的文件就存放在这里。 2、Design->Create a New Library,建立一个新的库:Altera,点击OK。 3、Compile ..quartusedasim_lib下面的两个文件,220model.v和altera_mf.v,记得编译的时候上面的library一定是Altera。这样三步以后,就完成了在Modelsim中添加Altera的库!实际中,这样做不方便。我是这样做的。把220model.v和altera_mf.v拷贝到你要编译的文件所在的文件夹里。先编译这两个文件,等于是把Altera的器件加到了work这个library里。然后再在library下编译你要用的文件就可以了。这样方便些。
4 start compilation... ARTUS中调用Modelsim,verilog下,步骤如下,并作一说明。
1 将modelsim启动路径(如:c:modelsimmodeltechwin32;)加入到环境变量path中。
2 在quartus中建立project,并产生所用的testbench

如何在ModelSim里仿真Altera的lpm_rom文件

如何在ModelSim里仿真Altera的lpm_rom文件

如何在ModelSim里仿真Altera的lpm_rom文件
By ChinaLeo on July 1st, 2005
<这里我使用的是QuartusII5.0和ModelSim SE Plus 6.0>
1.在QuartusII中生成rom的初始化文件,选择生成hex文件,因为ModelSim不支持mif
文件的转化。

这里要注意一下的是,不要擅自改动Quartus->Tools->Options->Memory Editor中的内容,默认的设置就好,不然生成的hex文件会有地址上的偏差;
2.在ModelSim安装的目录下找到modelsim.ini文件,将其只读属性去掉,在vsim部分里
添加一行“Veriuser = D:/altera/quartus50/eda/mentor/modelsim/convert_hex2ver.dll”,保存文件,将只读属性改回来。

当然,这里的路径要改成实际上您Quartus的安装路径。

其中的convert_hex2ver.dll就是把hex文件转换成ModelSim能认出来的ver文件的动态链接库文件;
3.按普通方式在ModelSim中新建项目,建立work库,在库中添加需要仿真的文件和Altera
的系统库文件altera_mf.v和220model.v,一起编译。

编译成功后即可添加波形仿真了!
convert_hex2ver.dll文件会自动调入来转化hex文件。

我已照此方法仿真成功。

在ModelSimSE中添加ALTERA仿真库的详细步骤

在ModelSimSE中添加ALTERA仿真库的详细步骤

ModelSim学习笔记(二)在ModelSimSE中添加ALTERA仿真库的详细步骤黄俊April 2007以前用的是LATTICE的,ispLEVER有自带了一个OEM版的ModelSim。

要仿真时,不需要添加库,用起来比较方便,自己有点懒,所以就一直凑合着用。

现在转向用ALTERA 了,ALTERA也有OEM版的ModelSim,也不用添加库。

后来听说ModelSim SE的功能更强大,速度更快,所以就决定把ModelSim SE好好摸索一下,再多学习一点关于TestBench 技巧方面的知识。

我的学习资料主要是ModelSim SE自带的教程、ALTERA提供的资料以及edacn上面ModelSim专栏由网友们上传的资料。

因为是初学,加上看到英文资料一大堆,烦都烦死,而有些中文文档可能是有些步骤没有讲清楚,我实际按照文档上面说的一步一步做下来也老是完成不了,花了不少时间。

我于是就想自己摸清楚后,把步骤截图下来,整理清楚,做成笔记。

一方面加深自己的认识,另一方面对初学者也许会有些许用处。

我近期计划陆续整理出以下几个方面的学习笔记:初学ModelSimSE时被迷糊了几天的若干概念在ModelSimSE中添加ALTERA仿真库的详细步骤用ModelSimSE进行功能仿真和时序仿真的方法(ALTERA篇)ModelSimSE中常用到的几个命令及DO文件的学习笔记近来学到的几招TestBench的技巧MSN: paulhuang_sz@E-mail: huangjun5927@Blog: /index.php/2599在ModelSimSE中添加ALTERA仿真库的详细步骤装仿真库前要先了解几个概念1、装ModelSim之前,要先装QuartusII。

安装好QuartusII后,在其安装目录下…\quartus\eda\sim_lib里面存放了所有的仿真原型文件(simulation modelfiles)。

如何在modelsim中添加altera的仿真库

如何在modelsim中添加altera的仿真库

1.在quartus中运行2.选择器件及输出目录,编译后生成库。

3.打开D:\altera\modeltech64_10.1c\altera_lib\modelsim.ini查看[Library] 中的这就是所选的器件对应的生成库。

altera_ver = D:/altera/modeltech64_10.1c/altera_lib/verilog_libs/altera_ver lpm_ver = D:/altera/modeltech64_10.1c/altera_lib/verilog_libs/lpm_versgate_ver = D:/altera/modeltech64_10.1c/altera_lib/verilog_libs/sgate_veraltera_mf_ver = D:/altera/modeltech64_10.1c/altera_lib/verilog_libs/altera_mf_veraltera_lnsim_ver = D:/altera/modeltech64_10.1c/altera_lib/verilog_libs/altera_lnsim_vermaxii_ver = D:/altera/modeltech64_10.1c/altera_lib/verilog_libs/maxii_vercycloneii_ver = D:/altera/modeltech64_10.1c/altera_lib/verilog_libs/cycloneii_ver可以复制这些项存到D:\altera\modeltech64_10.1c\modelsim.ini即根目录下的modelsim.ini中的[Library] 注意修改只读属性; Altera library add by Sylaraltera_ver = $MODEL_TECH/../altera_lib/verilog_libs/altera_verlpm_ver = $MODEL_TECH/../altera_lib/verilog_libs/lpm_versgate_ver = $MODEL_TECH/../altera_lib/verilog_libs/sgate_veraltera_mf_ver = $MODEL_TECH/../altera_lib/verilog_libs/altera_mf_veraltera_lnsim_ver = $MODEL_TECH/../altera_lib/verilog_libs/altera_lnsim_vermaxii_ver = $MODEL_TECH/../altera_lib/verilog_libs/maxii_vercycloneii_ver = $MODEL_TECH/../altera_lib/verilog_libs/cycloneii_ver或者如何在modelsim中添加altera的仿真库上一篇/ 下一篇2009-07-31 14:36:17查看( 6137 ) / 评论( 1 ) / 评分( 0 / 0 )呵呵,这个问题纠结了我两天了,刚才又试了一下就通过了,其实网上的资料说的很清楚的,但是操作起来还真的容易失误,所以说不会的时候觉得怎么这么难搞,会了之后、发现怎么这么简单!首先为什么要在modelsim中加仿真库呢?我的理解是这样的,modelsim仿真功能强大,但是没有跟具体的器件相结合所以不能够进行时序仿真和后仿真。

ModelSim的使用(Altera官网)

ModelSim的使用(Altera官网)

About Using the ModelSim Software with theQuartus II SoftwareAuthor: Kerwin. XieModelSim-Altera Design Flow(For Altera Version)1.Set up the ModelSim-Altera working environment2.Set up a project with the ModelSim-Altera software3.Perform a functional simulation with the ModelSim-Altera software4.Perform a timing simulation with the ModelSim-Altera softwareModelSim PE/SE Design Flow(For PE/SE Version)1.Set up the ModelSim working environment2.Set up a project with the ModelSim softwarepile libraries and design files with the ModelSim software4.Perform a functional simulation with the ModelSim software5.Perform a timing simulation with the ModelSim software目录MODELSIM-ALTERA版本仿真流程 (3)1、建立M ODEL S IM-A LTERA工作环境 (3)2、用M ODEL S IM-A LTERA建立工程 (3)3、用M ODEL S IM-A LTERA执行功能仿真 (3)4、用M ODEL S IM-A LTERA执行时序仿真 (4)MODELSIM-PE/SE版本仿真流程 (6)P ERFORMING A F UNCTIONAL S IMULATION WITH THE M ODEL S IM S OFTWARE (6)P ERFORMING A T IMING S IMULATION WITH THE M ODEL S IM S OFTWARE (7)相关知识链接 (9)M ODEL S IM P RECOMPILED L IBRARIES(预编译库) (9)A LTERA F UNCTIONAL S IMULATION L IBRARIES(功能仿真库) (12)A LTERA P OST-F IT L IBRARIES(后适配库) (20)P ERFORMING P OWER A NALYSIS WITH THE Q UARTUS II S OFTWARE AND O THER EDA T OOLS (30)使用QUARTUSII自动运行MODELSIM仿真 (37)1、配置N ATIVE L INK (37)2、运行仿真 (39)3、产生T ESTBENCH (40)相关链接:ModelSim-Altera软件支持谢银坤Kerwin Xie2010年1月20日ModelSim-Altera版本仿真流程1、建立ModelSim-Altera工作环境1.1版本说明ModelSim-Altera(OEM)version 6.4aQuartusII version 9.0该ModelSim版本支持所有QuartusII支持的Altera器件。

ModelSim-Altera使用简介20130710

ModelSim-Altera使用简介20130710

使用ModelSim的基本思路:1、打开ModelSim后的界面,选择File>New>Preject创建一个新工程,打开的CreateProject对话框窗口,可以指定工程的名称、路径和缺省库名称。

一般情况下,设定Default Library Name为work。

图 12、单击OK后将出现Add items to the Project对话框。

有四个选项可以选择图 23、我们单击单击Create New File,出现如下窗口。

File Name填写modelsim_1,选择Verilog。

图34、选择OK后,新建设计文件modelsim_1。

图 45、双击modelsim_1文件,打开后便可输入代码。

图 56、代码输入完成后,及时保存。

之后就可以编译文件了。

在Project标签下的Status列的问号,表示文件尚未编译进工程,或者在最后编译前,源文件有所改动。

欲编译文件,选择Compile<Compile ALL,或者右击Project标签,选择Compile>Compile All。

倘若此处没有错误,编译成功的消息,就会在Transcript窗口。

图 67、编译成功后,就可以开始仿真。

单击Library图标,选择work,单击+以展开选项,然后选择要仿真的文件。

单击右键,选择编译,如图所示。

图7单击Simulate,进入仿真窗口。

图88、在图8中,单击compareTop,单击右键,然后选择Add>To Wave>All Items in region,然后单击左键。

出现图9所示画面。

图99、在Run Length列可选择仿真时间长度。

单击Run按钮或Run All按钮,运行若干时间后便可以看到仿真波形,可以通过放大或缩小来调整。

图10。

ModelSim-Altera使用方法

ModelSim-Altera使用方法

ModelSim-Altera使用方法平台软件:ModelSim-Altera 6.5e (Quartus II 10.0) Starter Edition 内容1 设计流程使用ModelSim仿真的基本流程为:图1.1 使用ModelSim仿真的基本流程2 开始2.1 新建工程打开ModelSim后,其画面如图2.1所示。

图2.1 ModelSim画面1. 选择File>New>Preject创建一个新工程。

打开的Create Project对话框窗口,可以指定工程的名称、路径和缺省库名称。

一般情况下,设定Default Library Name 为work。

指定的名称用于创建一个位于工程文件夹内的工作库子文件夹。

该对话框如图2. 2所示,此外还允许通过选择.ini文件来映射库设置,或者将其直接拷贝至工程中。

图2.2 创建工程的对话框2. 按照图2.3所示,设置Project Name为LED_FLOW,Project Location为D: /led_flow。

图2.3 输入工程信息当单击OK按钮后,在主体窗口的下方将出现Project标签,如图2.4所示。

图2.4 Project标签3. 之后,将出现Add Items to the Project的对话框,如图2.5所示。

图2.5 在工程中,添加新项目2.2 在工程中,添加新项目在Add Items to the Project对话框中,包括以下选项:Create New File——使用源文件编辑器创建一个新的Verilog、VHDL、TCL 或文本文件Add Existing File——添加一个已存在的文件Create Simulation——创建指定源文件和仿真选项的仿真配置Create New Folder——创建一个新的组织文件夹1. 单击Create New File。

打开图2.6所示窗口。

图2.6 创建工程文件夹2. 输入文件名称:LED_FLOW,然后选择文件类型为Verilog。

ModelSim ALTERA 6.3g_p1使用方法

ModelSim ALTERA 6.3g_p1使用方法

Modelsim ALTERA 6.31、安装1)打开运行81_modelsim_ae_windows.exe,如下图:安装时选择Full product安装。

当出现Install Hardware Security Key Driver时选择“否”。

当出现Add Modelsim To Path选择“是”。

出现Modelsim License Wizard时选择“Close”。

2)在C盘的根目录下新建文件夹“flexlm”,,打开文件夹,运行里面的,将生成的licensefile.dat文件放入flexlm文件夹中,如果有其他程序破解用到这个文件夹以及其中的licensefile.dat,请将生成的licensefile.dat更名为licensefile1.dat或者其他的名字。

3)修改系统的环境变量。

右键点击桌面我的电脑图标,属性->高级->环境变量->(系统变量)新建。

按下图所示内容填写,变量值内如果已经有别的路径了,请用“;”将其与要填的路径分开。

LM_LICENSE_FILE = c:\flexlm\license.dat;c:\flexlm\licensefile.dat4)安装完成,运行!2、Modelsim ALTERA 6.3的使用方法Modelsim的仿真主要有以下几个步骤:建立库并映射库到物理目录;编译原代码(包括Testbench;执行仿真。

1)建立库运行Modelsim ALTERA 6.3,点击工具栏的“File”—>“Change Directory…”选择你要建立库的位置:仿真库是存储已编译设计单元的目录,modelsim中有两类仿真库,一种是工作库,默认的库名为work,另一种是资源库。

Work库下包含当前工程下所有已经编译过的文件。

所以编译前一定要建一个work库,而且只能建一个work库。

资源库存放work库中已经编译文件所要调用的资源,这样的资源可能有很多,它们被放在不同的资源库内。

QuartusModelSim-Altera联合仿真(Verilog版)(精)

QuartusModelSim-Altera联合仿真(Verilog版)(精)

Quartus+ModelSim-Altera联合仿真(Verilog版)作者:L.xiang (注:默认Next/OK/Finish)Step1:新建工程New Project Wizard...设置路径+工程名+entity名(project、entity必须同名);Step2:选择器件:Cyclone II EP2C5F26C8(例如);Step3:Simulation设置:ModelSim-Altera+Verilog HDL;Step4:新建文件,选Verilog HDL File;Step5:输入代码,并保存为led(.v文件);Step6:调试,修改直到没有Error为止(工程目录下同时自动生成了simulation文件);Step7:生成Test Bench文件(.vt):Processing->Start->Start Test Bench Template Writer;Step8:工程目录下C:\altera\text\led1\simulation\modelsim打开led.vt文件,并复制“led_vlg_tst”;Step9:设置Simulation:Assignments+Settings;Step10:Simulation->仿真扫描时间Time scale:100ps(或其它值),Comple test bench-> Tset Benchse...;Step11:点击New...;Step12:粘贴Test bench name:led_vlg_tst(Step8中已复制),Top level module in test bench:led_vlg_tst(必须和.vt文件里的module名一致);Step13:添加Test bench files:simulation/modelsim/led.vt,并点击Add;Step14:点击,即启动ModelSim进入仿真;Step14:工作区中双击打开i1文件,并将所需要的信号添加到仿真波形图中:Add->To Wave;Step15:点击,便可看到完整的波形图了。

ModelSim的使用(Altera官网)

ModelSim的使用(Altera官网)

About Using the ModelSim Software with theQuartus II SoftwareAuthor: Kerwin. XieModelSim-Altera Design Flow(For Altera Version)1.Set up the ModelSim-Altera working environment2.Set up a project with the ModelSim-Altera software3.Perform a functional simulation with the ModelSim-Altera software4.Perform a timing simulation with the ModelSim-Altera softwareModelSim PE/SE Design Flow(For PE/SE Version)1.Set up the ModelSim working environment2.Set up a project with the ModelSim softwarepile libraries and design files with the ModelSim software4.Perform a functional simulation with the ModelSim software5.Perform a timing simulation with the ModelSim software目录MODELSIM-ALTERA版本仿真流程 (3)1、建立M ODEL S IM-A LTERA工作环境 (3)2、用M ODEL S IM-A LTERA建立工程 (3)3、用M ODEL S IM-A LTERA执行功能仿真 (3)4、用M ODEL S IM-A LTERA执行时序仿真 (4)MODELSIM-PE/SE版本仿真流程 (6)P ERFORMING A F UNCTIONAL S IMULATION WITH THE M ODEL S IM S OFTWARE (6)P ERFORMING A T IMING S IMULATION WITH THE M ODEL S IM S OFTWARE (7)相关知识链接 (9)M ODEL S IM P RECOMPILED L IBRARIES(预编译库) (9)A LTERA F UNCTIONAL S IMULATION L IBRARIES(功能仿真库) (12)A LTERA P OST-F IT L IBRARIES(后适配库) (20)P ERFORMING P OWER A NALYSIS WITH THE Q UARTUS II S OFTWARE AND O THER EDA T OOLS (30)使用QUARTUSII自动运行MODELSIM仿真 (37)1、配置N ATIVE L INK (37)2、运行仿真 (39)3、产生T ESTBENCH (40)相关链接:ModelSim-Altera软件支持谢银坤Kerwin Xie2010年1月20日ModelSim-Altera版本仿真流程1、建立ModelSim-Altera工作环境1.1版本说明ModelSim-Altera(OEM)version 6.4aQuartusII version 9.0该ModelSim版本支持所有QuartusII支持的Altera器件。

Quartus II调用ModelSim仿真方法

Quartus II调用ModelSim仿真方法

系统的仿真方法图1在Quartus II中配置ModelSim-Altera应用第三方软件路径首先,建立工程时,选择仿真软件选ModelSim-Altera,我用的是Verilog硬件描述语言,然后继续内容的编写。

内容编写之后,打开菜单Tool下的Options,在EDA Tool Options中的ModelSim-Altera进行第三方路径的设置,如图1-1 所示,已完成在Quartus II中配置ModelSim-Altera应用第三方软件路径。

如图2 NativeLink settings然后,选择Assignments下的EDA Tool Settings下的Simulation中的NativeLink settings,选择Compile test bench,设置其中的Test Benches,New,然后编辑里头内容,然后具体内容如图 2 所示,然后,Test bench name填入的是设计的顶层文件、Top level module in test bench和Design instance name in test bench是填入仿真的文件的名字,Test bench files填入仿真的文件路径。

最后生成测试文件,选择在Quartus II开发界面菜单栏下Processing下的Start 下面的Start Test Bench Template Writer,提示生成成功。

生成测试仿真文件的大框,里头一些内容还需自己添加。

以下告诉你如何添加内容,在仿真目录下找到为“.vt”的文件,然后打开这个文件,根据需要给以激励和时钟进行编辑。

具体的Test Bench的编写正在附录四中,写完Test Bench之后就可以进行在菜单栏Tools 下的Run EDA Simulation下的EDA RTL Simulation仿真。

modelsim使用方法

modelsim使用方法

Using ModelSim to Simulate LogicCircuits for Altera FPGA Devices1IntroductionThis tutorial is a basic introduction to ModelSim,a Mentor Graphics’simulation tool for logic circuits.We show how to perform functional and timing simulations of logic circuits implemented by using Quartus II CAD software.The reader is expected to have the basic knowledge of Verilog hardware description language,and the Altera Quartus II CAD software.Contents:•Introduction to simulation•What is ModelSim?•Functional simulation using ModelSim•Timing simulation using ModelSim1 Altera Corporation-University ProgramSeptember20102BackgroundDesigners of digital systems are inevitably faced with the task of testing their designs.Each design can be composed of many modules,each of which has to be tested in isolation and then integrated into a design when it operates correctly.To verify that a design operates correctly we use simulation,which is a process of testing the design by applying inputs to a circuit and observing its behavior.The output of a simulation is a set of waveforms that show how a circuit behaves based on a given sequence of inputs.The generalflow of a simulation is shown in Figure1.Figure1.The simulationflow.There are two main types of simulation:functional and timing simulation.The functional simulation tests the logical operation of a circuit without accounting for delays in the circuit.Signals are propagated through the circuit using logic and wiring delays of zero.This simulation is fast and useful for checking the fundamental correctness of the designed circuit.The second step of the simulation process is the timing simulation.It is a more complex type of simulation,where logic components and wires take some time to respond to input stimuli.In addition to testing the logical operation of the circuit,it shows the timing of signals in the circuit.This type of simulation is more realistic than the functional simulation;however,it takes longer to perform.2Altera Corporation-University ProgramSeptember2010In this tutorial,we show how to simulate circuits using ModelSim.You need Quartus II CAD software and ModelSim software,or ModelSim-Altera software that comes with Quartus II,to work through the tutorial.3Example DesignOur example design is a serial adder.It takes8-bit inputs A and B and adds them in a serial fashion when the g o input is set to1.The result of the operation is stored in a9-bit sum register.A block diagram of the circuit is shown in Figure2.It consists of three shift registers,a full adder,aflip-flop to store carry-out signal from the full adder and afinite state machine(FSM).The shift registers A andB are loaded with the values of A and B.After the st ar t signal is set high,these registers are shifted right one bit at a time.At the same time the least-significant bits of A and B are added and the result is stored into the shift register sum.Once all bits of A and B have been added,the circuit stops and displays the sum until a new addition is requested.Figure2.Block diagram of a serial-adder circuit.The Verilog code for the top-level module of this design is shown in Figure3.It consists of the instances of the shift registers,an adder and afinite state machine(FSM)to control this design.3 Altera Corporation-University ProgramSeptember20101.module serial(A,B,start,resetn,clock,sum);2.input[7:0]A,B;3.input resetn,start,clock;4.output[8:0]LEDR;5.6.//Registers7.wire[7:0]A_reg,B_reg;8.wire[8:0]sum;9.reg cin;10.11.//Wires12.wire reset,enable,load;13.wire bit_sum,bit_carry;14.15.//Confrol FSM16.FSM my_control(start,clock,resetn,reset,enable,load);17.18.//Datapath19.shift_reg reg_A(clock,1’b0,A,1’b0,enable,load,A_reg);20.shift_reg reg_B(clock,1’b0,B,1’b0,enable,load,B_reg);21.22.//a full adder23.assign bit_carry,bit_sum=A_reg[0]+B_reg[0]+cin;24.25.always@(posedge clock)26.begin27.if(enable)28.if(reset)29.cin<=1’b0;30.else31.cin<=bit_carry;32.end33.34.shift_reg reg_sum(clock,reset,9’d0,bit_sum,enable,1’b0,sum);35.defparam reg_sum.n=9;36.endmoduleFigure3.Verilog code for the top-level module of the serial adder.The Verilog code for the FSM is shown in Figure4.The FSM is a3-state Mealyfinite state machine,where thefirst and the third state waits for the st ar t input to be set to1or0,respectively.The computation of the sum of A and B4Altera Corporation-University ProgramSeptember2010happens during the second state,called WORK_STATE.The FSM completes computation when the counter reachesa value of8,indicating that inputs A and B have been added.The state diagram for the FSM is shown in Figure5.1.module FSM(start,clock,resetn,reset,enable,load);2.parameter WAIT_STATE=2’b00,WORK_STATE=2’b01,END_STATE=2’b11;3.input start,clock,resetn;4.output reset,enable,load;5.6.reg[1:0]current_state,next_state;7.reg[3:0]counter;8.9.//next state logic10.always@(*)11.begin12.case(current_state)13.WAIT_STATE:14.if(start)next_state<=WORK_STATE;15.else next_state<=W AIT_STATE;16.WORK_STATE:17.if(counter==4’d8)next_state<=END_STATE;18.else next_state<=WORK_STATE;19.END_STATE:20.if(∼start)next_state<=W AIT_STATE;21.else next_state<=END_STATE;22.default:next_state<=2’bxx;23.endcase24.end25.26.//state registers and a counter27.always@(posedge clock or negedge resetn)28.begin29.if(∼resetn)30.begin31.current_state<=W AIT_STATE;32.counter=’d0;33.end34.else35.beginFigure4.Verilog code for the FSM to control the serial adder(Part a).5 Altera Corporation-University ProgramSeptember201036.current_state<=next_state;37.if(current_state==W AIT_STATE)38.counter<=’d0;39.else if(current_state==WORK_STATE)40.counter<=counter+1’b1;41.end42.end43.//Outputs44.assign reset=(current_state==WAIT_STATE)&start;45.assign load=(current_state==W AIT_STATE)&start;46.assign enable=load|(current_state==WORK_STATE);47.endmoduleFigure4.Verilog code for the FSM to control the serial adder(Part b).Figure5.State diagram.The Verilog code for the shift register is given in Figure6.It consists of synchronous control signals to allow data to be loaded into the shift register,or reset to0.When enable input is set to1and the data is not being loaded or reset, the contents of the shift register are moved one bit to the right(towards the least-significant bit).6Altera Corporation-University ProgramSeptember20101.module shift_reg(clock,reset,data,bit_in,enable,load,q);2.parameter n=8;3.4.input clock,reset,bit_in,enable,load;5.input[n-1:0]data;6.output reg[n-1:0]q;7.8.always@(posedge clock)9.begin10.if(enable)11.if(reset)12.q<=’d0;13.else14.begin15.if(load)16.q<=data;17.else18.begin19.q[n-2:0]<=q[n-1:1];20.q[n-1]<=bit_in;21.end22.end23.end24.endmoduleFigure6.Verilog code for the shift register.The design is located in the example/functional and example/timing subdirectories provided with this tutorial.A Quartus II project for this design has been created as well.In the following sections,we use the serial adder example to demonstrate how to perform simulation using Mod-elSim.We begin by describing a procedure to perform a functional simulation,and then discuss how to perform a timing simulation.4Functional Simulation with ModelSimWe begin this tutorial by showing how to perform a functional simulation of the example design.We start by opening the ModelSim program.7 Altera Corporation-University ProgramSeptember2010Figure7.ModelSim window.The ModelSim program window,shown in Figure7,consists of four sections:the main menu at the top,a set of workspace tabs on the left,a work area on the right,and a command prompt at the bottom.The menu is used to access functions available in ModelSim.The workspace contains a list of modules and libraries of modules available to you,as well as details of the project you are working on.The work area on the right is the space where windows containing waveforms and/or textfiles will be displayed.Finally,the command prompt at the bottom shows feedback from the simulation tool and allows users to enter commands.To perform simulation with ModelSim follow a basicflow shown in Figure1.We begin by creating a project where all designfiles to be simulated are included.We compile the design and then run the simulation.Based on the results of the simulation,the design can be altered until it meets the desired specifications.4.1Creating a ProjectTo create a project in ModelSim,select New>Project...from the File menu.A create project window shown in Figure8will appear.8Altera Corporation-University ProgramSeptember2010Figure8.Creating a new project.The create project window consists of severalfields:project name,project location,default library name,and copy settingsfield.Project name is a user selected name and the location is the directory where the sourcefiles are located.For our example,we choose the project name to be serial,to match the top-level module name of our example design,and the location of the project is the example/functional subdirectory.The default library namefield specifies a name by which ModelSim catalogues designs.For example,a set offiles that describe the logical behaviour of components in an Altera Cyclone II device are stored in the cycloneii library. This allows the simulator to include a set offiles in simulation as libraries rather than individualfiles,which is particularly useful for timing simulations where device-specific data is required.For the purpose of this tutorial, specify tutorial as the library name for your project.The lastfield in the create project window is the copy settingsfield.This allows default settings to be copied from the initializationfile and applied to your project.Now,click OK to proceed to addfiles to the project using the window shown in Figure9.Altera Corporation-University Program September20109Figure9.Add afile to project window.The window in Figure9gives several options to addfiles to the project,including creating newfiles and directories, or adding existingfiles.Since thefile for this tutorial exists,click Add Existing File and select serial.vfile.Once thefile is added to the project,it will appear in the Project tab on the left-hand side of the screen,as shown in Figure10.Figure10.Workspace window after the project is created.Now that all designfiles have been included in the project,click Close to close the window in Figure9.10Altera Corporation-University ProgramSeptember20104.2Compiling a ProjectOnce the project has been created,it is necessary to compile pilation in ModelSim checks if the project files are correct and creates intermediate data that will be used during simulation.To perform compilation,select Compile All from the Compile menu.When the compilation is successful,a green check mark will appear to the right of the serial.vfile in the Project tab.4.3SimulationTo begin a simulation of the design,the software needs to be put in simulation mode.To do this,select Start Simulation...from the Simulate menu.The window in Figure11will appear.Figure11.Start simulation mode in ModelSim.The window to start simulation consists of many tabs.These include a Design tab that lists designs available for simulation,VHDL and Verilog tabs to specify language specific options,a Library tab to include any additional libraries,and timing and other options in the remaining two tabs.For the purposes of the functional simulation,we only need to look at the Design tab.In the Design tab you will see a list of libraries and modules you can simulate.In this tutorial,we want to simulate a module called serial,described in serial.vfile.To select this module,scroll down and locate the tutorial library and click on the plus(+)sign.You will see three modules available for simulation:FSM,serial,and shift_reg.Select the serial module,as shown in Figure11and click OK to begin simulation.When you click OK,ModelSim will begin loading the selected libraries and preparing to simulate the circuit.For the example in this tutorial,the preparation should complete quickly.Once ModelSim is ready to simulate your design, you will notice that several new tabs on the left-hand side of the screen and a new Objects window have appeared, as shown in Figure12.Figure12.New displays in the simulation mode.A key new tab on the left-hand side is the sim tab.It contains a hierarchical display of design units in your circuit in a form of a table.The columns of the table include the instance name,design unit and design unit type names. The rows of the table take a form of an expandable tree.The tree is rooted in the top-level entity called serial.Each module instance has a plus(+)sign next to its name to indicate it can be expanded to allow users to examine the contents of that module instance.Expanding the top-level entity in this view gives a list of modules and/or constructs within it.For example,in Figure12the top-level entity serial is shown to contain an instance of the FSM module,called my_control,three instances of a shift_reg module,four assign statements and an always block.Double-clicking on any of the constructs will cause ModelSim to open a sourcefile and locate the given construct within it.Double-clicking on a module instance will open a sourcefile and point to the description of the module in the sourcefile.In addition to showing modules and/or constructs,the sim tab can be used to locate signals for simulation.Notice that when the serial module is highlighted,a list of signals(inputs,outputs and local wires)is shown in the Objects window.The signals are displayed as a table with four columns:name,value,kind and mode.The name of a signal may be preceded by a plus(+)sign to indicate that it is a bus.The top-level entity comprises signals A,B,resetn, start,and clock as inputs,a sum output and a number of internal signals.12Altera Corporation-University ProgramWe can also locate signals inside of module instances in the design.To do this,highlight a module whose signals you wish to see in the Objects window.For example,to see the signals in the my_control instance of the FSM module, highlight the my_control instance in the sim tab.This will give a list of signals inside of the instance as shown in Figure13.Figure13.Expanded my_control instance.Using the sim tab and the Objects window we can select signals for simulation.To add a signal to simulation, right-click on the signal name in the Objects window and select Add>T o Wave>Selected items from the pop-up ing this method,add signals A,B,clock,resetn,start,sum,and current_state to the simulation.When you do so,a waveform window will appear in the work area.Once you have added these signals to the simulation, press the Undock button in the top-right corner of the waveform window to make it a separate window,as shown in Figure14.Figure14.A simulation window.Before we begin simulating the circuit,there is one more useful feature worth noting.It is the ability to combine signals and create aliases.It is useful when signals of interest are not named as well as they should be,or the given names are inconvenient for the purposes of simulation.In this example,we rename the start signal to go by highlighting the start signal and selecting Combine Signals...from the Tools menu.The window in Figure15will appear.14Altera Corporation-University Programbine signals window.In the textfield labeled Result name type go and press the OK button.This will cause a new signal to appear in the simulation window.It will be named go,but it will have an orange diamond next to its name to indicate that it is an alias.Once the go alias is created,the original start input is no longer needed in the simulation window,so removeit by highlighting it and pressing the delete key.Your simulation window should now look as in Figure16.Figure16.Simulation window with aliased signals.Now that we set up a set of signals to observe we can begin simulating the circuit.There are two ways to run a simulation in ModelSim:manually or by using scripts.A manual simulation allows users to apply inputs and advance the simulation time to see the results of the simulation in a step-by-step fashion.A scripted simulation allows the user to create a script where the sequence of input stimuli are defined in afile.ModelSim can read thefile and apply input stimuli to appropriate signals and then run the simulation from beginning to end,displaying results only when the simulation is completed.In this tutorial,we perform the simulation manually.In this simulation,we use a clock with a100ps period.At every negative edge of the clock we assign new values to circuit inputs to see how the circuit behaves.To set the clock period,right-click on the clock signal and select Clock...from the pop-up menu.In the window that appears,set the clock period to100ps and thefirst edge to be the falling edge,as shown in Figure17.Then click OK.16Altera Corporation-University ProgramFigure17.Set the clock period.We begin the simulation be resetting the circuit.To reset the circuit,set the resetn signal low by right-clicking on it and selecting the Force...option from the pop-up menu.In the window that appears,set Value to0and click OK. In a similar manner,set the value of the go signal to0.Now that the initial values for some of the signals are set,wecan perform thefirst step of the simulation.To do this,locate the toolbar buttons shown in Figure18.The toolbar buttons shown in Figure18are used to step through the simulation.The left-most button is the restartbutton,which causes the simulation window to be cleared and the simulation to be restarted.The textfield,shownwith a100ps string inside it,defines the amount of time that the simulation should run for when the Run button(tothe right of the textfield)is pressed.The remaining three buttons,Continue,Run-All and Break,can be used toresume,start and interrupt a simulation,respectively.We will not need them in this tutorial.To run a simulation for100ps,set the value in the textfield to100ps and press the Run button.After the simulationrun for100ps completes,you will see the state of the circuit as shown in Figure19.Figure19.Simulation results after100ps.In thefigure,each signal has a logic state.Thefirst two signals,A and B,are assigned a value between0and1in a blue color.This value indicates high impedance,and means that these signals are not driven to any logic state.The go and resetn signals is at a logic0value thereby resetting the circuit.The clock signal toggles state every50ps, starting with a falling edge at time0,a rising edge at time50ps and another falling edge at100ps.Now that the circuit is reset,we can begin testing to see if it operates correctly for desired inputs.To test the serial adder we will add numbers143and57,which should result in a sum of200.We can set A and B to143and57, respectively,using decimal notation.To specify a value for A in decimal,right-click on it,and choose Force... from the pop-up menu.Then,in the Valuefield put10#143.The10#prefix indicates that the value that follows is specified in decimal.Similarly,set the value of input_B to57.To see the decimal,rather than binary,values of buses in the waveform window we need to change the Radix of A and B to unsigned.To change the radix of these signals,highlight them in the simulation window and select Radix >Unsigned from the Format menu,as shown in Figure20.Change the radix of the sum signal to unsigned as well.18Altera Corporation-University ProgramFigure20.Changing the radix of A,B and sum signals.Now that inputs A and B are specified,set resetn to1to stop the circuit from resetting.Then set go to1to begin serial addition,and press the Run button to run the simulation for another100ps.The output should be as illustrated in Figure21.Notice that the values of inputs A and B are shown in decimal as is the sum.The circuit also recognizeda go signal and moved to state01to begin computing the sum of the two inputs.Figure21.Simulation results after200ps.To complete the operation,the circuit will require9clock cycles.To fast forward the simulation to see the result,specify900ps in the textfield next to the run button,and press the run button.This brings the simulation to time1100ps,at which point a result of summation is shown on the sum signal,as illustrated in Figure22.Figure22.Simulation results after1100ps.We can see that the result is correct and thefinite state machine controlling the serial adder entered state11,in which it awaits the go signal to become0.Once we set the go signal to0and advance the simulation by100ps,the circuit will enter state00and await a new set of inputs for addition.The simulation result after1200ps is shown inFigure23.Figure23.Simulation results after1200ps.At this point,we can begin the simulation for a new set of inputs as needed,repeating the steps described above.Wecan also restart the simulation by pressing the restart button to begin again from time0.By using the functional simulation we have shown that the serial.vfile contains an accurate Verilog HDL description20Altera Corporation-University Programof a serial adder.However,this simulation did not verify if the circuit implemented on an FPGA is correct.This is because we did not use a synthesized,placed and routed circuit as input to the simulator.The correctness of the implementation,including timing constraints can be verified using timing simulation.5Timing Simulation with ModelSimTiming simulation is an enhanced simulation,where the logical functionality of a design is tested in the presence of delays.Any change in logic state of a wire will take as much time as it would on a real device.This forces the inputs to the simulation be realistic not only in terms of input values and the sequence of inputs,but also the time when the inputs are applied to the circuit.For example,in the previous section we simulated the sample design and used a clock period of100ps.This clock period is shorter than the minimum clock period for this design,and hence the timing simulation would fail to produce the correct result.To obtain the correct result,we have to account for delays when running the simulation and use a clock frequency for which the circuit operates correctly.For Altera FPGA-based designs the delay information is available after the design is synthesized,placed and routed, and is generated by Quartus II CAD software.The project for this part of the tutorial has been created for you in the example/timing subdirectory.5.1Setting up a Quartus II Project for Timing Simulation with ModelSimTo perform timing simulation we need to set up Quartus II software to generate the necessary delay information for ModelSim by setting up EDA Tools for simulation in the Quartus II project.To set up EDA Tools for simulation, open the Quartus II project in example/timing subdirectory,and select Settings...from the Assignments menu.A window shown in Figure24will appear.The window in thefigure consists of a list on the left-hand side to select the settings category and a window area on the right-hand side that displays the settings for a given category.Select Simulation from the EDA Tool Settings category to see the screen shown on the right-hand side of Figure24.The right-hand side of thefigure contains the tool name at the top,EDA Netlist Writer settings in the middle,and NativeLink settings at the bottom.The tool name is a drop-down list containing the names of simulation tools for which Quartus II can produce a netlist with timing information automatically.This list contains many well-known simulation tools,including ModelSim.From the drop-down list select ModelSim-Altera.Once a simulation tool is selected,EDA Netlist Writer settings become available.These settings configure Quartus II to produce input for the simulation tool.Quartus II will use these parameters to describe an implemented design using a given HDL language,and annotate it with delay information obtained after compilation.The settings we can define are the HDL language,simulation time scale that defines time step size for the simulator to use,the location where the writer saves design and delay information,and others.For the purpose of this tutorial,only thefirst three settings are used.Set these settings to match those shown in Figure24and click OK.With the EDA Tools Settings specified,we can proceed to compile the project in Quartus II.The compilation process synthesizes,places,and routes the design,and performs timing analysis.Then it stores the compilation result in theFigure24.Quartus II EDA simulation tool settings.simulation directory for ModelSim to use.Take a moment to examine thefiles generated for simulation using a text editor.The two mainfiles are serial.vo,and serial_v.sdo.The serial.vofile is a Verilogfile for the design.Thefile looks close to the original Verilogfile,except that the design now contains a wide array of modules with a cycloneii_prefix.These modules describe resources on an Altera Cyclone II FPGA,on which the design was implemented using lookup tables,flip-flops,wires and I/O ports. The list delays for each module instance in the design is described in the serial_v.sdofile.22Altera Corporation-University Program5.2Running a Timing SimulationTo simulate the design using timing simulation we must create a ModelSim project.The steps are the same as in the previous section;however,the project is located in the example/timing/simulation/modelsim subdirectory,and the sourcefile is serial.vo.We do not need to include the serial_v.sdofile in the project,because a reference to it is included in the serial.vofile.Once you added the sourcefile to the project,compile it by selecting Compile All from the Compile menu.The next step in the simulation procedure is to place the ModelSim software in simulation mode.In the previous section,we did this by selecting Start Simulation...from the Simulate menu,and specifying the project name. To run a timing simulation there is an additional step required to include the Altera Cyclone II device library in the simulation.This library contains information about the logical operation of modules with cycloneii_prefix.To include the Cyclone II library in the project,select Start Simulation...from the Simulate menu and select the Library tab as shown in Figure25.Figure25.Including Altera Cyclone II library in ModelSim project.The Altera Cyclone II library is located in the altera/verilog/cycloneii directory in the ModelSim-Altera software. To add this library to your project,include the altera/verilog/cycloneii directory using the Add...button.Then,clickon the Design tab,select your project for simulation,and click OK.When the ModelSim software enters simulation mode,you will see a significant difference in the contents of the workspace tabs on the left-hand side of the window as compared to when you ran the functional simulation.In particular,notice the sim tab and the Objects window shown in Figure26.The list of modules in the sim tab is larger,and the objects window contains more signals.This is due to the fact that the design is constructed using components on an FPGA and is more detailed in comparison to an abstract description we used in the previous section of the tutorial.Figure26.Workspace tabs and Objects window for timing simulation.We simulate the circuit by creating a waveform that includes signals A,B,go,and resetn aliases as before.In addition,we include the clock,reg_sum|q,reg_A|q,and reg_B|q signals from the Objects window.Signals reg_A|q and reg_B|q are registers that store A and B at the positive edge of the clock.The reg_sum|q signal is a register that stores the resulting sum.Begin the simulation by resetting the circuit.To do this,set go and resetn signals to0.Also,set the clock input to have a period of20ns,whosefirst edge is a falling edge.To run the simulation,set the simulation step to20ns and press the Run button.The simulation result is shown in Figure27.24Altera Corporation-University Program。

modelism10.1c和modelsim__altera10.1d安装教程(win7x64)

modelism10.1c和modelsim__altera10.1d安装教程(win7x64)

一:modelsim10.1c软件安装:首先双击modelsim‐win32‐6.5g‐se.exe,运行此程序(注意防火墙或者杀毒软件的拦截问题)出现如下界面点击next ,直到安装路径的选择,自己选择安装路径(图2)(如果提示需要新建文件夹的话,选择Yes, 选择好安装路径后,点击next点击agree(否则无法安装),然后等待安装的进行。

安装到50%后会出现让你选择是否添加到桌面快捷方式,界面如下:如果需要的话,选择Yes,桌面会出现下面的快捷方式图标选择是否添加快捷方式后,再次出现是否将Modelsim的路径添加到你的路径(Start菜单吧)里面下面是路径选择截图最后会提示你是否添加硬件安全钥匙驱动,在这里我们选择No下面开始破解(我用的破解工具)MentorKG.exe和patch.dll,把MentorKG.exe和patch.dll复制到modelsim安装目录win64文件夹下,先运行patch.dll,然后在运行MentorKG.exe,保存LICENSE.TXT文件(不要是中文目录),再新建环境变量(win7是用户变量,用户变量在环境变量上面),变量名称:MGLS_LICENSE_FILE,变量值是LICENSE.TXT文件的路径,如:D:\modeltech64_10.1c\win64\LICENSE.TXT,OK,enjoy!用户变量如图:2,modelsim-altera10.1d软件安装modelsim-altera和modelsim的破解一样将patch.dll和MentorKG.exe拷贝到modelsim-altera的安装文件夹,然后运行patch.dll,会自动生成一个license文件,把该文件放在一个不含中文和空格的文件夹下,再然后添加系统变量,变量名:MGLS_LICENSE_FILE,变量值是license的路径(要加上license.txt),如果已经安装了modelsim,可以直接在MGLS_LICENSE_FILE的值后面再添加一个modelsim-altera的license路径,两个值用;分开。

Quartus II 13.1与自带modelsim_Altera 10.0d仿真软件的联调

Quartus II 13.1与自带modelsim_Altera 10.0d仿真软件的联调

Quartus II 13.1与自带modelsim_Altera 10.0d仿真软件的联调Step11、编写好Verilog代码后,编译(点),直到没有错误为止;2、接下来生成testbench文件,Processing →Start →Start Test Bench Template Writer,注意下方Message栏中,EDA Netlist Writer是否生成成功,成功的提示如下:Step21、接下来完成调用modelsim_Altera 10.0d的设置1.首先要在quartus 2中正确填入modelsim程序的地址:Tools →Options →General →EDA Tool Options ,如下图:2.因为我调用的是Modelsim-Altera,所以填入Modelsim-Altera程序所在地址:D:\altera\13.1\modelsim_ase\win32aloem(注:一般只是盘符不一样,我装在D 盘,如果你装在C盘,那地址就是C:\altera\13.1\modelsim_ase\win32aloem)3.接下来,就是正确载入测试文件了,载入前,先要修改testbench:(测试文件只是模板,要自己加入时钟信号,输入信号,即添加激励,否则无法出现仿真波形)Assignments →Settings 出现如下界面:i.勾选下图的小方格,当在Quartus中编译快完成时,自带调出Modelsim_Altera;ii.如果你的代码是用Verilog写的,则此处要选Verilog HDL;iii.下面这个选项是仿真时间单位:`timescale 仿真时间单位/时间精度(eg: `timescale 100ns/10ns)仿真时间单位和时间精度,就比如常见的刻度尺,仿真时间单位以cm为单位,时间精度以mm为单位,所以仿真时间单位是大于或等于时间精度的。

iv.选择Compile test bench ,点Test Benches…v.出现下图,点New…vi.出现下图:vii.先填写下图,点File name 空格旁的,添加生成的Testbench文件,格式是 .vt ,点Add 完成添加。

Quartus 调用ModelSim-Altera进行波形仿真

Quartus 调用ModelSim-Altera进行波形仿真

QuartusⅡ调用ModelSim-Altera进行波形仿真QuartusⅡ10.1已经不能直接建立波形文件进行仿真了,但可以通过写test bench文件,调用ModelSim-Altera进行波形仿真。

本文通过一个简单的例子——模4计数器,来说明如何调用ModelSim。

在下载QuartusⅡ10.1时,也要下载ModelSim-Altera。

说明:ModelSim有其他的版本,最好的是ModelSim SE,ModelSim-Altera是免费的,如果有ModelSim SE的破解版的话也是可以的,这里我将ModelSim分成两种,ModelSim和ModelSim-Altera。

安装完两个软件后,打开QuartusⅡ10.1,在菜单栏上打开Tools|Options,如下图。

设置ModelSim.exe的路径,有哪个版本就设置哪个,都有的话都设置。

设置完之后,新建一个工程CNT4。

只进行仿真的话,该页可不设置。

这里可以选择仿真工具ModelSim和ModelSim-Altera(亦可不设置,在后面可以设置),以及语言种类,这里以ModelSim-Altera和VHDL语言为例介绍。

新建一个VHDL文件,代码如下:LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_UNSIGNED.ALL; USE IEEE.STD_LOGIC_ARITH.ALL; ENTITY CNT4ISPORT(CLK:IN STD_LOGIC;Q:OUT STD_LOGIC_VECTOR(3DOWNTO0));END CNT4;ARCHITECTURE BEH OF CNT4ISSIGNAL Q1:STD_LOGIC_VECTOR(3DOWNTO0);BEGINPROCESS(CLK)BEGINIF CLK'EVENT AND CLK='1'THENQ1<=Q1+1;END IF;END PROCESS;Q<=Q1;END BEH;按菜单栏Processing|Start Compilation进行编译,也可以按工具栏上的快捷键。

modelsim-altera 仿真设置

modelsim-altera 仿真设置

1、设置modelsim-altera的执行路径(即其安装路径中的可执行)(1)Tool->Option(2)General -> EDA Tool Option ,在右侧的窗口中选择Modelsim-Altera , 在Location Of Execatable中单击,并找到该软件的安装路径中的可执行文件路径,单击确定。

2、项目仿真2.1预先设置仿真软件(建立测试文件前必须选好仿真软件,且项目模块必须编译成功)(1)Assignments ->Settings(2)选择“Simulation”,设置方式如下图注:第三步要放到流程2.3再做2.2建立测试文件Processing ->Start ->Start Test Bench Template Writer2.3将Testbench链接到仿真环境下(1)Assignments ->Settings(2)选择“Simulation”,点击NativeLink settings下的Compile testbench中“Test Benches”(3)在弹出的窗口中点击“New”添加Testbench文件(该文件默认存放的路径:项目(4)目录\simulation\modelsim\项目名称.vt)第2步一定要加后缀“_vlg_tst”不然会出错第4步浏览找到Testbench文件(该文件默认存放的路径:项目(4)目录\simulation\modelsim\项目名称.vt)(4)然后一路“OK”下去。

2.4编辑TestBench文件(记得点保存)需要编辑TestBench文件中的内容,在Quarters II Files中找到其路径(该文件默认存放的路径:项目目录\simulation\modelsim\项目名称.vt)打开就好,或者直接在Modulsim中编辑更方便。

3、执行仿真选择Tools ->Run EDA Simulation Tool ->EDA RTL Simulation,然后会自动运行Modelsim_altera软件并进行编译和波形仿真。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

平台
软件:ModelSim-Altera 6.5e (Quartus II 10.0) Starter Edition 内容
1 设计流程
使用ModelSim仿真的基本流程为:
图1.1 使用ModelSim仿真的基本流程
2 开始
2.1 新建工程
打开ModelSim后,其画面如图2.1所示。

图2.1 ModelSim画面
1. 选择File>New>Preject创建一个新工程。

打开的Create Project对话框窗口,可以指定工程的名称、路径和缺省库名称。

一般情况下,设定Default Library Name 为work。

指定的名称用于创建一个位于工程文件夹内的工作库子文件夹。

该对话框如图
2. 2所示,此外还允许通过选择.ini文件来映射库设置,或者将其直接拷贝至工程中。

图2.2 创建工程的对话框
2. 按照图2.3所示,设置Project Name为LED_FLOW,Project Location为D: /led_flow。

图2.3 输入工程信息
当单击OK按钮后,在主体窗口的下方将出现Project标签,如图2.4所示。

图2.4 Project标签
3. 之后,将出现Add Items to the Project的对话框,如图2.5所示。

图2.5 在工程中,添加新项目
2.2 在工程中,添加新项目
在Add Items to the Project对话框中,包括以下选项:
∙Create New File——使用源文件编辑器创建一个新的Verilog、VHDL、TCL 或文本文件
∙Add Existing File——添加一个已存在的文件
∙Create Simulation——创建指定源文件和仿真选项的仿真配置
∙Create New Folder——创建一个新的组织文件夹
1. 单击Create New File。

打开图
2.6所示窗口。

图2.6 创建工程文件夹
2. 输入文件名称:LED_FLOW,然后选择文件类型为Verilog。

图2.7 输入工程文件信息
3. 单击OK,关闭本对话框。

新的工程文件将会在工程窗口显示。

单击Close,以关闭A dd Items to the Project。

图2.8 新的设计文件LED_FLOW.v
4. 双击打开LED_FLOW.v文件(注意:若是Verilog文件已经关联了其他的文本编辑器,则双击后在关联的文本编辑器中打开)。

图2.9 LED_FLOW代码输入窗口
在LED_FLOW.v输入下面的测试平台代码:
`timescale 1ns/1ns
module LED_FLOW;
reg CLOCK_50M;
reg RST_N;
wire [9:0] LED;
led led_inst
(
.clk_50M(CLOCK_50M),
.reset_n(RST_n),
.led(LED)
);
initial
begin
CLOCK_50M = 0;
while (1)
#10 CLOCK_50M = ~CLOCK_50M;
end
initial
begin
RST_N = 0;
while (1)
#10 RST_N = 1;
end
initial
begin
$display($time,"CLOCK_50M=%d RST_N=%d LED =%d", CLOCK_50M, RST_N, LED);
end
endmodule
录入完代码后,单击Save。

图2.10 输入testbench代码
5. 选择File>New>Source>Verilog,创建新的Verilog文件,如图2.11所示。

图2.11 创建新的Verilog文件
6. 录入下面的代码,录入画面如图2.12 所示。

`timescale 1ns/1ns
module led(
input clk_50M, // System clock 50MHz
input reset_n, // System reset
output reg [9:0] led // led
);
reg [13:0] counter = 0;
reg [3:0] state = 0;
always @ (posedge clk_50M, negedge reset_n) if (!reset_n)
counter <= 0;
else
counter <= counter + 1'b1;
always @ (posedge counter[13])
if (!reset_n)
state <= 0;
else
begin
if (state == 4'b1001)
state <= 0;
else
state <= state + 1'b1;
end
always @ (posedge clk_50M, negedge reset_n) if (!reset_n)
led <= 0;
else
begin
case (state)
4'b0000: led <= 10'b00000_00001;
4'b0001: led <= 10'b00000_00010;
4'b0010: led <= 10'b00000_00100;
4'b0011: led <= 10'b00000_01000;
4'b0100: led <= 10'b00000_10000;
4'b0101: led <= 10'b00001_00000;
4'b0110: led <= 10'b00010_00000;
4'b0111: led <= 10'b00100_00000;
4'b1000: led <= 10'b01000_00000;
4'b1001: led <= 10'b10000_00000;
default: led <= 10'b00000_00001;
endcase
end
endmodule
图2.12 录入新文件
7. 选择File>Save,输入文件名:led.v,单击Save,如图2.13所示。

图2.13 保存led.v
8. 选择Project>Add to Project>Existing File,如图2.14所示。

图2.14添加文件到工程中
9. 单击Browse,选择led.v,如图2.15 所示。

图2.15 选择待加入工程的文件
10. 单击打开,在Add file to the project窗口,单击OK。

2.3 编译文件
在Project标签下的Status列的问号,表示文件尚未编译进工程,或者在最后编译前,源文件有所改动。

欲编译文件,选择Compile<Compile ALL,或者右击Project标签,选择Compile>Compile All。

1. 倘若此处没有错误,编译成功的消息,就会在Transcript窗口如图
2.6所示。

图2.16 编译成功
3 仿真工程
3.1 开始仿真
1. 单击Library图标,选择work,单击+以展开选项,然后选择LED_FLOW。

单击右键,选择编译,如图3.1所示。

图3.1 单击Simulate
2. 单击Simulate,到达图
3.2所示画面。

图3.2 仿真窗口
4. 在图3.2中,单击LED_FLOW,单击右键,然后选择Add>To Wave>All Item s in region,然后单击左键。

出现图3.3所示画面。

图3.3 Add To Wave
3.2 仿真设置
1. 完成上述最后一步后,波形窗口出现。

图3.4 波形窗口
2. 在Run Length列输入仿真时间长度为10ms,如图
3.5所示。

图3.5 设置Run Length
3. 单击Run按钮,如图3.6所示。

图3.6 运行仿真
4. 运行若干秒后,将会如图3.9所示的仿真结果。

图3.7 显示仿真结果
5. 连续单击Zoom Out图标,可查看仿真的完整波形,如图3.8所示。

图3.8 波形窗口
6. 单击鼠标所指的+,展开LED_FLOW的波形,如图3.9所示。

图3.9 展开波形
通过放大/缩小波形,可以观察到LED的值在保持变化,即LED的时序效果。

若将其移植到Quartus II中,适当配置后,经过综合、时序分析、引脚分配、配置及下载等,即可实现跑马灯的效果。

相关文档
最新文档