在我们用modelsim仿真的时候经常是修改一点一点修改代码,这样会造成一个无奈的操作循环:修改代码--->编译代码--->仿真设置--->进入仿真页面--->添加需要观察的波形--->运行仿真。如果仿真结果不理想,还得需要重新修改代码,重复上述的操作。
计算机擅长做重复的事情,为什么不让计算机代劳呢?
我们可以参照xilinx ise是如何调用modelsim进行仿真的,尤其是脚本的编写。
下面一个脚本是我用ise10.1建立了一个aes256的工程,然后在调用modelsim6.5的时候,ise会生成这几个脚本文件,aes256_tb.fdo, aes256_tb_wave.fdo 和 aes256_tb.udo。
下面的代码是aes256_tb.fdo文件的内容。
1: vlib work #创建名字是work的库,这个仿真之前必须做的
2: vcom -explicit -93 sbox_rom.vhd #编译vhd代码
3: vcom -explicit -93 inv_sbox_rom.vhd
4: vcom -explicit -93 aes_package.vhd
5: vcom -explicit -93 subbytes.vhd
6: vcom -explicit -93 sbox_rom_reg.vhd
7: vcom -explicit -93 round_key_bram.vhd
8: vcom -explicit -93 inv_subbytes.vhd
9: vcom -explicit -93 keyexpansion_yao.vhd
10: vcom -explicit -93 aes256_enc_dec.vhd
11: vcom -explicit -93 aes256_top.vhd
12: vcom -explicit -93 aes256_tb.vhd
13: vsim -t 1ps -lib work aes256_tb #进入仿真设置,时间单位为1ps,库指定为work,aes256_tb就是指你的top层设计的名字
14: do {aes256_tb_wave.fdo} #执行*.fdo文件,用来添加信号和变量或者内部的寄存器到波形(wave)窗口
15: view wave #打开波形窗口
16: view structure #打开架构(structure)窗口
17: view signals #打开信号列表窗口
18: run 1000ns #运行1000ns
19: do {aes256_tb.udo} #运行用户定义的脚本
只要编译的时候没有出现语法错误或者是找不到定义的库文件等错误提示,一般会很容易的看到仿真的波形,而不用手动进行操作。这样方便了仿真的整个过程,而无需用很多鼠标点击操作。
现在通过一个具体的实例来说明如何运用脚本来实现modelsim的仿真。
工具版本:ise10.1 ,modelsim 6.5a
1. 创建ise工程
首先通过ise创建test.vhd 和test_tb.vhd文件并添加到工程中,这里不细说如何创建hdl源代码。
然后配置ise的仿真器,右键选中fpga芯片,点击properties,然后在simulator选择modelsim-se vhdl。
图1. 工程属性
在source窗口选择“behavioral simulation”,可以看到工程中的test_tb.vhd(testbench文件)。选中test_tb.vhd文件,在process窗口中双击simulate behavioral model,ise开始调用modelsim,这是ise自动生成了三个脚本文件:test_tb.fdo, test_tb_wave.fdo和test_tb.udo。
图2. behavioral simulation 窗口
看看三个脚本文件的内容吧。
test_tb.fdo内容如下:
1: vlib work #添加library
2: vcom -explicit -93 test.vhd #编译test的顶层文件
3: vcom -explicit -93 test_tb.vhd #编译test_tb的testbench文件
4: vsim -t 1ps -lib work test_tb #进入仿真,时间单位1ps,仿真test_tb
5: do {test_tb_wave.fdo} #执行*.fdo脚本文件,用于添加仿真波形
6: view wave #打开波形窗口
7: view structure #打开structure窗口
8: view signals #打开信号窗口
9: run 1000ns #仿真运行1000ns
10: do {test_tb.udo} #执行*.udo脚本文件,用于执行用户定义的脚本命令
test_tb_wave.fdo内容如下():
1: ## project navigator simulation template: test_tb_wave.fdo
2: ## you may edit this file to control your simulation.
3: add wave * ##添加top层所有的端口信号
test_tb.ufo内容为空白,是留着给用户自己添加。
对我们来说最有用的就是test_tb.fdo文件了,只要稍微修改就可以成为一个针对这个工程的很好的用于仿真的脚本。当然我们可以自己手动来编写类似的脚本,用ise自动生成主要是为了涂个省事。
2.调用modelsim进行仿真
在图2中,process窗口中双击simulate behavioral model,进入modelsim仿真环境。请仔细观察modelsim transcript窗口中消息的输出。内容如下:
1: # do {test_tb.fdo} #<-------执行脚本文件
2: # ** warning: (vlib-34) library already exists at work.
3: # model technology modelsim se vcom 6.5 compiler 2009.01 jan 22 2009 #<-----编译test.vhd得到的message
4: # -- loading package standard
5: # -- loading package std_logic_1164
6: # -- loading package std_logic_arith
7: # -- loading package std_logic_unsigned
8: # -- compiling entity test
9: # -- compiling architecture test of test
10: # model technology modelsim se vcom 6.5 compiler 2009.01 jan 22 2009 #<-----编译test.vhd得到的message
11: # -- loading package standard
12: # -- loading package std_logic_1164
13: # -- loading package std_logic_arith
14: # -- loading package std_logic_unsigned
15: # -- compiling entity test_tb
16: # -- compiling architecture behavior of test_tb
17: # vsim -lib work -t 1ps test_tb #仿真设置命令行
18: # loading std.standard
19: # loading ieee.std_logic_1164(body)
20: # loading ieee.std_logic_arith(body)
21: # loading ieee.std_logic_unsigned(body)
22: # loading work.test_tb(behavior)#1 #加载test_tb
23: # .main_pane.wave.interior.cs.body.pw.wf #打开wave窗口
24: # .main_pane.structure.interior.cs.body.struct #列出structure
25: # .main_pane.objects.interior.cs.body
注:在test_tb.fdo的每一行都可以在modelsim transcript窗口中分开一行一行执行。
然后可以观察到仿真波形文件。
3. 调试代码
或许仿真出来的结果不是我们想要的,必须的修改代码,然后再仿真。那我们应该怎么办呢?
在trasncript窗口输入:
1: quit -sim #退出仿真
2: do test_tb.fdo #修改代码完成后重新执行该脚本进行仿真
在仿真的波形的时候,我们不仅仅希望看到top层设计的端口信号的波形,还希望能观察到内部信号是如何变化的,所以我们在sim窗口中找到内部的信号放到wave中进行观察。但是如果我们重新运行当初test_tb.fdo文件,我们又再一次只能看到top层设计的端口信号的波形,而内部信号的波形已经被删除。那我们应该如何保存和运用我们仿真波形文件呢?
我现在需要观察内部的一个寄存器输出:tmp信号,见图4。ctrl+s,保存波形文件。默认保存为工程目录下/wave.do,但是我们将用波形文件保存为test_tb_wave.fdo文件,这样做的好处可以不用修test_tb.fdo文件。
图4.内部信号观察
我们重新运行test_tb.fdo脚本文件之后,输出的波形是图4,而不是图3。
差不多常用的vhdl仿真命令都用上了,我相信这样做肯定会提高仿真的效率。如果想要熟悉更多的modelsim的仿真命令,请查看modelsim的用书手册。
长征八号的独特之处
如何在Python或MATLAB环境中使用ACE快速评估数据转换器
变压器s11的含义和技术参数
Vishay HVCC系列产品荣获2019 AspenCore全球电子成就奖
TI C2000 引导模式原理的理解
Xilinx ISE是如何调用ModelSim进行仿真的
使用静态分析查找并发错误
什么是光电效应
土壤墒情自动监测设备安装
集成开发环境IAR Embedded Workbench for Arm9.40版发布
升级内存是否要有必要考虑容量问题
人工智能防灾 国研院展出地震预警与结构安全监测系统
SiTime AEC-Q100认证 汽车级振荡器为自动驾驶(ADAS)保驾护航
2023 Matter中国区开发者大会直播回放-芯科科技全栈Matter开发方案
丰元股份20亿扩产锂电材料
ad怎么添加pcb底层丝印层
AI技术可以为药物研发分忧?
NORA-B1双核MCU为复杂解决方案铺平道路
纸张在线检测设备的原理、功能及技术参数
凯迪仕智能锁完成C轮6亿融资10亿综合授信,开启全球化战略新篇章