ModelSim-Altera使用方法.pdf[1]

合集下载

modelsim_altera破解

modelsim_altera破解

做FPGA用到ModelSim仿真,QuartusII 13.0调用发现"unable
to check out a license .run the modelsim licensing
wizard from start.programs menu to dignose problem"
的问题,才发现Quarttus13.0破解后还要再破解Modelsim,方法如下:
1.下载破解文件,自行百度
2.复制破解文件中的MentorKG.exe和patch_dll.bat到Modelsim安
装目录的win32aloem文件夹下
3.运行patch_dll.bat,将生成的LICENSE.TXT文件另存为
LICENSE.dat并置于此文件夹下
4.在环境变量的用户环境变量一栏新建环境变量MGLS_LICENSE_FILE、LM_LICENSE_FILE指向LICENSE.dat
关于环境变量的配置:
右击计算机--》点属性--》左侧点‘高级系统设置’ --》点‘高级’
选项最下方的‘环境变量’
--》在‘系统环境变量’下方点‘新建’--》输入环境变量名和路径
即可,如下:
变量名:LM_LICENSE_FILE:
路径:自己的安装路径\win32aloem\LICENSE.dat
变量名:MGLS_LICENSE_FILE:
路径:自己的安装路径\win32aloem\LICENSE.dat。

在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使用方法.pdf[1]

ModelSim-Altera使用方法.pdf[1]

平台软件: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的仿真库

在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

在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使用教程

modelsim使用教程

modelsim使用教程ModelSim是一款常用的硬件描述语言(HDL)仿真工具,本教程将向您介绍如何使用ModelSim进行仿真。

步骤1:安装ModelSim首先,您需要下载和安装ModelSim软件。

在您的电脑上找到安装程序并按照提示进行安装。

步骤2:创建工程打开ModelSim软件,点击"File"菜单中的"New",然后选择"Project"。

在弹出的对话框中,选择工程的存储位置,并为工程命名。

点击"OK"完成工程创建。

步骤3:添加设计文件在ModelSim的工程窗口中,右键点击"Design"文件夹,选择"Add Existing File"。

然后选择包含您的设计文件的目录,并将其添加到工程中。

步骤4:配置仿真设置在工程窗口中,右键点击"Design"文件夹,选择"Properties"。

在弹出的对话框中,选择"Simulation"选项卡。

在"Top level entity"字段中,选择您的设计的顶层模块。

点击"Apply"和"OK"保存设置。

步骤5:运行仿真在ModelSim的工具栏中,找到"Simulate"按钮,点击并选择"Start Simulation"。

这将打开仿真窗口。

在仿真窗口中,您可以使用不同的命令来控制和观察设计的行为。

步骤6:查看仿真结果您可以在仿真窗口中查看信号波形、调试设计并分析仿真结果。

在仿真窗口的菜单栏中,您可以找到一些常用的查看和分析工具,如波形浏览器、信号分析器等。

步骤7:结束仿真当您完成仿真时,可以选择在仿真窗口的菜单栏中找到"Simulate"按钮,并选择"End Simulation"以结束仿真。

modelsim的详细使用方法

modelsim的详细使用方法

一、简介ModelSim是一款由美国Mentor Graphics公司推出的集成电路仿真软件,广泛应用于数字电路和系统设计领域。

它提供了强大的仿真和验证功能,能够帮助工程师快速高效地进行电路设计与验证工作。

本文将详细介绍ModelSim的使用方法,以帮助读者更好地掌握这一工具的操作技巧。

二、安装与配置1. 下载ModelSim安装包,并解压到指定目录2. 打开终端,进入ModelSim安装目录,执行安装命令3. 安装完成后,配置环境变量,以便在任何目录下都能够调用ModelSim程序4. 打开ModelSim,进行软件注册和授权,确保软件可以正常运行三、工程创建与管理1. 新建工程:在ModelSim主界面点击“File” -> “New” -> “Project”,输入工程名称和存储路径,选择工程类型和目标设备,点击“OK”完成工程创建2. 添加文件:在工程目录下右键点击“Add Existing”,选择要添加的源文件,点击“OK”完成文件添加3. 管理工程:在ModelSim中可以方便地对工程进行管理,包括文件的增删改查以及工程参数的设置等四、代码编写与编辑1. 在ModelSim中支持Verilog、VHDL等多种硬件描述语言的编写和编辑2. 在ModelSim主界面点击“File” -> “New” -> “File”,选择要新建的文件类型和存储位置,输入文件名称,点击“OK”完成文件创建3. 在编辑器中进行代码编写,支持代码高亮、自动缩进、语法检查等功能4. 保存代码并进行语法检查,确保代码符合规范,没有错误五、仿真与调试1. 编译工程:在ModelSim中进行代码编译,生成仿真所需的可执行文件2. 设置仿真参数:在“Simulation”菜单下选择“S tart Simulation”,设置仿真时钟周期、输入信号等参数3. 运行仿真:点击“Run”按钮,ModelSim将开始对设计进行仿真,同时显示波形图和仿真结果4. 调试设计:在仿真过程中,可以通过波形图和仿真控制面板对设计进行调试,查找并解决可能存在的逻辑错误六、波形查看与分析1. 查看波形:在仿真过程中,ModelSim会生成相应的波形文件,用户可以通过“Wave”菜单查看波形并进行波形分析2. 波形操作:支持波形的放大、缩小、平移、选中等操作,方便用户对波形进行分析和观察3. 波形保存:用户可以将波形结果保存为图片或文本文件,以便日后查阅和分析七、性能优化与验证1. 时序优化:在设计仿真过程中,可以通过观察波形和性能分析结果,对设计进行优化,提高设计的时序性能2. 逻辑验证:通过对仿真的结果进行逻辑验证,确保设计符合预期的逻辑功能3. 时序验证:对设计的时序性能进行验证,确保信号传输和时钟同步的正确性八、项目输出与文档整理1. 输出结果:在仿真和验证完成后,可以将仿真结果、波形图和性能分析结果输出为文本文件或图片,方便后续的文档整理和报告撰写2. 结果分析:对仿真结果和验证结果进行详细的分析,确定设计的性能和功能是否符合设计要求3. 文档整理:根据仿真和验证结果,进行文档整理和报告撰写,为后续的设计和优化工作提供参考九、总结与展望ModelSim作为一款专业的集成电路仿真软件,具有着强大的功能和丰富的特性,可以帮助工程师进行电路设计与验证工作。

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 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库中已经编译文件所要调用的资源,这样的资源可能有很多,它们被放在不同的资源库内。

在modelsim中添加xilinx和altera库的方法

在modelsim中添加xilinx和altera库的方法

如何在ModelSim中增加Xilinx/Altera库的方法现在,由于很多人都是单独装Xilinx 和Modelsim,因此,在用到一些芯片厂家如Xilinx或Altera的的仿真库时,遇到Library没找到的情况;因为Modelsim 本身并不自带各FPGA 厂家的仿真库,因此就必须自己手动编译这些库。

以下我就介绍三种方法增加Xilinx或Altera的库问题:1. 找到modelsim的安装目录,在安装目录下找到$:\modeltech_6.5\modelsim.ini,修改modelsim.ini的属性(去掉“只读”);在目录ModelSim下的modelsim.ini文件中的[Library]到[vcom]之间加入如下代码:;Xilinx; VHDL Sectionunisim = $MODEL_TECH/../xilinx/vhdl/unisimsimprim = $MODEL_TECH/../xilinx/vhdl/simprimxilinxcorelib = $MODEL_TECH/../xilinx/vhdl/xilinxcorelibaim = $MODEL_TECH/../xilinx/vhdl/aimpls = $MODEL_TECH/../xilinx/vhdl/plscpld = $MODEL_TECH/../xilinx/vhdl/cpld; Verilog SectionUNISIMS_VER = C:\Xilinx\10.1\ISE\verilog\mti_se\unisims_verUNIMACRO_VER = C:\Xilinx\10.1\ISE\verilog\mti_se\unimacro_verUNI9000_VER = C:\Xilinx\10.1\ISE\verilog\mti_se\uni9000_verSIMPRIMS_VER = C:\Xilinx\10.1\ISE\verilog\mti_se\simprims_verXILINXCORELIB_VER = C:\Xilinx\10.1\ISE\verilog\mti_se\XilinxCoreLib_verAIM_VER = C:\Xilinx\10.1\ISE\verilog\mti_se\abel_ver\aim_verCPLD_VER = C:\Xilinx\10.1\ISE\verilog\mti_se\cpld_verSECUREIP = C:\Xilinx\10.1\ISE\verilog\mti_se\secureip(上述的安装路径是我电脑上的ISE的Library库路径)altera库的添加方法如上所示。

modelsim详细使用教程.pdf

modelsim详细使用教程.pdf

Modelsim 详细使用方法很多的modelsim教程中都讲得很丰富,但忽视了对整个仿真过程的清晰解读,而且都是拿counter范例举例子,有些小白就不会迁移了。

这里我们着眼于能顺利的跑通一个自己写的程序,一步一步的讲解,如果你是一个初学者,这再适合你不过了,虽然貌似字写得比较多,那是因为写得相当的详细,一看就会啦O(∩_∩)O~一、建立工程1、在建立工程(project)前,先建立一个工作库(library),一般将这个 library 命名为work。

尤其是第一次运行 modelsim 时,是没有这个“work”的。

但我们的 project一般都是在这个work下面工作的,所以有必要先建立这个work。

File →new→library点击library后会弹出一个对话框,问是否要创建work,点击OK。

就能看见work.2、 如果在 library 中有 work ,就不必执行上一步骤了,直接新建工程。

File→new →project会弹出在 Project Name 中写入工程的名字,这里我们写一个二分频器,所以命名 half_clk,然后点击 OK 。

会出现由于我们是要仿一个自己写的程序,所以这里我们选择Create New File。

在File Name中写入文件名(这里的file name和刚刚建立的project name可以一致也可以不一致)。

注意Add file as type要选择成Verilog(默认的是VHDL),然后OK。

发现屏幕中间的那个对话框没有自己消失,我们需要手动关闭它,点close。

并且在project中出现了一个half_clk.V的文件,这个就是我们刚刚新建的那个file。

这样工程就建立完毕了。

二、写代码:1、写主程序:双击 half_clk.v 文件会出现程序编辑区,在这个区间里写好自己的程序,这里我们写一个简单的二分频的代码:module half_clk_dai(clk_in,rst,clk_out );input clk_in;input rst;output clk_out;reg clk_out;always @(posedge clk_in or negedge rst)beginif(!rst)clk_out<=0;elseclk_out<=~clk_out;endendmodule写完代码后,不能马上就编译,要先保存,否则,编译无效。

modelsim下创建Altera仿真库的问题汇总

modelsim下创建Altera仿真库的问题汇总

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

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

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

或在命令行中执行cd D:/ModelSim_6.5b/altera。

2.新建库Quartus II中提供的仿真库文件存放的路径是.../altera/91/quartus/eda/sim_lib,每个库文件提供了两种形式:.v(V erilog)格式和.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文件。

网上的很多教程都是把这些文件一起编译,这样适用于V erilog和VHDL混合仿真,但如果只用一种语言,如V erilog则完全没必要全部编译。

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使用方法

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。

在modelsim SE 创建Altera的仿真库

在modelsim SE 创建Altera的仿真库

Modelsim se中创建altera的仿真库*************************************************modelsim version number-----modelsim se 5.8b ****author: 西北狼****QQ:11423644 QQ:58948391 ************************************************* 一、创建altera的仿真库a)路径选择启动modelsim se仿真工具,在主窗口中选择【file】→【changedirectory】命令,将工作目录改变到你想存放仿真库的目录,点击【ok】.b)创建仿真库在生窗口中选择【file】→【new】→【library】命令,在弹出的【createa new library】窗口中将选项【create】设置为【a new libraryand a logical mapping to it】,在【libryr name】和【libraryphysical name】中键入所要创建库名字,如altera_library, ,此时在主窗口中已多了一个altera_library(empty)项;注:这个过程实质上想当于在modelsim主窗口中的脚本区域中输入了vlib和vmap命令.c)编译库在workspace中的library中选中你健入的库名altera_library(empty),在主菜单中选【compile】→【compile】命令;在弹出窗口compile source file窗口中的【libaray】下拉菜单中选中你的库名,在【查找范围】中选择quarturs安装目录\quarturs\eda\sim_lib文件夹下,对它下面的8个文件进行编译,一要编译两次或分两次编译,方法一:先选8个文件,点击【compile】,这次有错出象,完成后再点击【compile】,编译成功,点击【done】;方法二:先编译220pack,再编译altera_mf_componenta.vhd,然后编译其它6个文件, 点击【d one】d)配制modelsim将modelsim根目录下的配制文件modelsim.ini的属性只读改为可写,这可使软件记录仿真库的路径以及映射关系,以后每次启动modelsim时,就会根据ini文件中的本身寻找仿真库,并且形成映射关系,注:如果启动时出象”仿真库名(unavailable)”可选中它,点右键选择【edit】指定路径;到些仿真库已创建,以后对altera设计仿真都不需要做库处理了;e)后仿真配制如果要做后仿真;就要把你用的系列库和quartursii生成文件一起编译即可,例如你用的是altera的max7000比利时列,就要加quartursii安装目录\quarturs\eda\sim_lib下的max_atoms;vmax_atoms.vhd;max_components.vhd加这三个文件一起编译;注:在做仿真前建project时,在项目窗口default library name项中键入quartursii生成仿真文件的默认名,如max7000系列默认名max。

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软件并进行编译和波形仿真。

用quartusII再带的modelsim进行后仿真(时序仿真)的操作步骤

用quartusII再带的modelsim进行后仿真(时序仿真)的操作步骤

⽤quartusII再带的modelsim进⾏后仿真(时序仿真)的操作步

在实际的项⽬⼯程中,基本上都是在Modelsim进⾏功能仿真后,直接进⾏板级调试(⽤signaltap调试),但是中规中矩的后仿真也不能不会。

操作步骤如下:
1.将quartus II与其⾃带的Modelsim-Altera进⾏关联,quartus II软件中【Tools】--->【Options】,按图1进⾏操作
图1
2.在quartus II软件中进⾏全编译,这时会在⼯程⽂件夹产⽣“simulation”⽂件夹,打开并接着打开“modelsim⽂件夹”,这时⾥⾯会出现10个⽂件,其中“.vo”和“.sdo”是时序仿真需要的⽂件,将他们粘贴到modelsim的⼯程⽂件夹中。

图2
图3
3.接下来还需要Altera的器件库
其中Altera的器件库⽂件在:D:\altera\13.0sp1\modelsim_ase\altera\verilog\altera
D:\altera\13.0sp1\modelsim_ase\altera\verilog\cycloneive
图4
4.将testbench⽂件和“.vo”⽂件加到⼯程上,然后编译,然后右键选择【Add to project】-->【Simulation Configuration】,选择【Work】中的"xxx_tb"⽂件,然后选择【Libraries】中加载刚在粘贴的2个Altera器件库,然后在【SDF】中加载刚才粘贴的“xx.sdo”⽂件,然后点【Save】,最后点击“Simulation”即可进⾏时序仿真。

如图5 、6、7所⽰:
图5
图6
图7 。

  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中,适当配置后,经过综合、时序分析、引脚分配、配置及下载等,即可实现跑马灯的效果。

相关文档
最新文档