磨刀不误砍柴工—基于TCL文件的 Modelsim仿真

2010年08月23日 16:50    发布者:绝对好文
Kevin以前用Modelsim仿真工程的时候,一般采用手工建立工程,然后通过鼠标点击命令或者在Transcript中键入命令,导入波形,这样做也是可以,但有个问题,在工程反复调试的时候,如果采用这种方法就很痛苦,Kevin就尝试过这种痛苦,反反复复输入命令,关键是每次都要重新调整波形,十分不方便,后来在使用Altera的一款IP核时,他提供了关于testbench的一些文件,其中就包含本文的重点:tcl文件和do文件

在这个仿真文件中,有几十个信号,而且是没有分类的,若每次都要重新编辑波形,工作量相当大,使用它的tcl文件,只要在modelsim中load一下就OK了,其他的工作主动完成,相当方便,下面介绍一个简单的例子供参考

1.导入altera的仿真库

vlib lpm

vmap lpm lpm

vcom -93 -work lpm $env(QUARTUS_ROOTDIR)/eda/sim_lib/220pack.vhd

vcom -93 -work lpm $env(QUARTUS_ROOTDIR)/eda/sim_lib/220model.vhd

vlib altera_mf

vmap altera_mf altera_mf

vcom -93 -work altera_mf $env(QUARTUS_ROOTDIR)/eda/sim_lib/altera_mf_components.vhd

vcom -93 -work altera_mf $env(QUARTUS_ROOTDIR)/eda/sim_lib/altera_mf.vhd

vlib sgate

vmap sgate sgate

vcom -93 -work sgate $env(QUARTUS_ROOTDIR)/eda/sim_lib/sgate_pack.vhd

vcom -93 -work sgate $env(QUARTUS_ROOTDIR)/eda/sim_lib/sgate.vhd

当你的工程中用到altera的一些IP或自带的文件时,这些库会用到,否则可以把它注释掉

2.建立当前库,这步是必须的

vlib work

相当于我们在modelsim中建立work库(当前库)

3.编译工程中用到的文件,一个一个地编译你工程中的文件,注意:modelsim好像不认识相对路径,我一般采用绝对路径,当你的文件换了路径,一定要记得更改!这一点是瑕疵,我很迷惑,哪位如果知道怎么在modelsim中使用相对路径,请告知,谢谢!

vcom -work work -93 D:/kevin/XG5051_FPGA/Test/ram_test/Sim/XG5051_FPGA.vho

vcom -work work -93 D:/kevin/XG5051_FPGA/Test/ram_test/Sim/XG5051_FPGA_tb.vhd

如果文件很多可以采用通配符的方式

vcom -work work -93 D:/kevin/XG5051_FPGA/Test/ram_test/Sim/*.vhd

这样就会编译这个目录中的所有后缀为VHD的文件

4.开始仿真,导入仿真文件

vsim XG5051_FPGA_tb

5.导入波形文件,这里要事先建立一个波形文件,在下边会介绍

do XG5051_FPGA_wave.do

6.运行,后面添加你要仿真的时间

run 20us

文件建立后就以.tcl文件命名

下面介绍下波形文件的建立

add wave -noupdate -format Logic /xg5051_fpga_tb/clk_in

add wave -noupdate -format Logic /xg5051_fpga_tb/clk_out

add wave -noupdate -format Logic -radix hexadecimal /xg5051_fpga_tb/ff_rx_data

add wave -noupdate -format Logic /xg5051_fpga_tb/ff_rx_sop

add wave -noupdate -format Logic /xg5051_fpga_tb/ff_rx_eop

add wave -noupdate -format Logic /xg5051_fpga_tb/ff_rx_dval

add wave -noupdate -format Logic /xg5051_fpga_tb/ff_rx_dsav

add wave -noupdate -format Logic /xg5051_fpga_tb/cnt_en

add wave -noupdate -format Logic /xg5051_fpga_tb/cnt_clr

add wave -noupdate -format Logic -radix hexadecimal /xg5051_fpga_tb/ff_rx_err

add wave -noupdate -format Logic -radix hexadecimal /xg5051_fpga_tb/loop_set



add wave -noupdate -format Logic -radix hexadecimal /xg5051_fpga_tb/ff_tx_data

add wave -noupdate -format Logic /xg5051_fpga_tb/ff_tx_sop

add wave -noupdate -format Logic /xg5051_fpga_tb/ff_tx_eop

add wave -noupdate -format Logic /xg5051_fpga_tb/ff_tx_wren

add wave -noupdate -format Logic -radix hexadecimal /xg5051_fpga_tb/ff_tx_err

add wave -noupdate -format Logic /xg5051_fpga_tb/ff_tx_crc_fwd

add wave -noupdate -format Logic -radix hexadecimal /xg5051_fpga_tb/rd_addr

add wave -noupdate -format Logic -radix hexadecimal /xg5051_fpga_tb/wr_addr

add wave -noupdate -format Logic -radix hexadecimal /xg5051_fpga_tb/ram_in

add wave -noupdate -format Logic -radix hexadecimal /xg5051_fpga_tb/ram_out

文件要以.do命名文件,然后在modelsim中load上面建立的.tcl文件就可以了。

网友评论

绝对好文 2010年08月23日
好文
yongjiefan 2011年01月22日
非常非常非常的好
aluny 2011年02月16日
好东西,谢谢分享!
higoogle 2012年02月22日
tcl 原来以为是那个卖电视的
higoogle 2012年02月22日
run 20us  这个用的最多