- 零点起飞学Xilinx FPG
- 高敬鹏 武超群 白锦良
- 1157字
- 2020-08-28 21:06:24
3.2 仿真验证
ISE中集成了测试激励生成器(HDL Bencher),在没有专业仿真工具的情况下,可以使用测试激励生成器产生激励信号,并调用ISE集成的仿真工具完成功能验证。此外,还可以联合ModelSim进行仿真验证。
3.2.1 在ISE中仿真验证
【例3-12】在ISE中进行仿真验证。
(1)在用ISE仿真前需要确认工程设置,单击菜单命令Project→Design Properties,如图3-28所示。确认Simulator的选择为ISim(VHDL/Verilog),这在新建工程时已经设定好了,为保万无一失,我们还是确认一下,如图3-29所示。

图3-28 选择Design Properties命令

图3-29 仿真器设置界面
(2)接下来写测试脚本文件,单击Project→New Source命令,如图3-30所示。

图3-30 新建脚本文件
(3)如图3-31所示,选择新建源文件类型为Verilog Test Fixture,再输入测试脚本文件的名字vtf_led_test和存放目录。

图3-31 定义文件名
(4)这里Associate Source界面用于选择测试脚本对应的设计源文件,由于只有一个设计源文件,因此选中led_test.v,然后单击Next按钮,如图3-32所示。

图3-32 关联设置
(5)单击Finish按钮完成设置,如图3-33所示。

图3-33 工程概要
(6)这里的测试脚本只是一个基本的模板,以流水灯为例,它把设计文件led_test的接口在这个模块里面例化声明了。我们还需要自己动手添加复位和时钟的激励设置,完成后的脚本文件如下。

(7)保存后vtf_led_test.v已经生成这个仿真Hierarchy的顶层了,下层是设计文件led_test.v。选中vtf_led_test.v文件,随后启动仿真,如图3-34所示。

图3-34 仿真图
3.2.2 在ISE中调用ModelSim
ModelSim是目前最流行的仿真工具,在ISE集成环境中有ModelSim的接口,可以调用ModelSim进行仿真。
【例3-13】在ISE中调用ModelSim。
(1)在用ISE仿真前需要确认项目设置,单击菜单命令Project→Design Properties,如图3-35所示。如图3-36所示,将Simulator的选择改为ModelSim-SE Mixed。

图3-35 仿真器设置

图3-36 仿真器选择
(2)切换到Simulation模式,选中led_test.v文件,右击选择Simulate Behavioral Model后选择Process Properties,在对话框右边的Compiled Library Directory输入框填入之前编译库时设置的已编译库的路径C:\Xilinx\Xilinx_lib。其他选项使用默认设置即可,单击OK按钮完成设置,如图3-37所示。

图3-37 路径设置
本节(3)~(6)步与3.2.1节(3)~(6)步骤相同,这里不再重复。
(7)保存后vtf_led_test.v成为这个仿真Hierarchy的顶层,它下面是设计文件led_test.v。选中vtf_led_test.v文件,随后启动仿真程序,如图3-38所示。

图3-38 ModelSim界面
(8)弹出ModelSim窗口后,可以打开Wave窗格查看仿真结果。ModelSim的使用并不难,如何使用的资料网上也很多,大家要多动手,多尝试,相信很快就会上手。这里我们把led_test.v程序里的timer计数器放到Wave窗格中观察,如图3-39所示。

图3-39 添加波形
(9)将时间单位设置为1μs,单击Restart按钮复位,再多次单击Run按钮,ModelSim会运行到$stop行地方,如图3-40所示。

图3-40 运行界面
(10)在Wave格可以看到timer寄存器在复位信号rst_n变高后开始计数,如图3-41所示。

图3-41 计数波形
(11)因为在仿真程序vtf_led_test.v里设置的仿真时间比较短,所以可以屏蔽掉vtf_led_test.v程序中的$stop的语句,让程序一直运行。修改vtf_led_test.v文件后保存,如图3-42所示。

图3-42 屏蔽语句
(12)重新打开ModelSim软件,单击按钮和
按钮,ModelSim开始运行程序,多次单击
按钮,可以看到led的信号会逐个变0,说明LED灯会逐个点亮,如图3-43所示。

图3-43 运行计数