自从接触FPGA,Modelsim一直以来都是好帮手,咱以前主要是做算法实现的,因此仿真是少不了的。咱比较懒,一直以来用的都是Altera(AE)或者Xilinx(XE)专用版,里面的库都帮你加完了,无需手动加入,但是这两个版本的Modelsim有一个弊端:工程中如果同时有Verilog和VHDL,它就瘫痪了。因此使用专业版(SE)还是很有必要的。
学了Tcl之后,发现Modelsim中支持很多Tcl指令,包括库的建立、映射、编译等,这样就能自动添加所有库,而无需手动操作,正所谓“磨刀不误砍材功”。下面介绍几个Modelsim中关于添加库的Tcl指令:
vlib :新建库
用法:vlib <library_name>
vmap :映射库,将逻辑库名映射到对应库的实际路径
用法:vmap <logical_library_name> <library_directory>
vlog :编译库,将Verilog或SystemVerilog代码编译到对应库
用法:vlog –work <library_name> <Verilog or SystemVerilog source>
vcom :编译库,将VHDL代码编译到对应库
用法:vcom –work <library_name> -2002 –explicit <VHDL source>
由上述Tcl指令可以发现编译Verilog和VHDL的指令有所区别,因此需要分别加入Verilog和VHDL的库。此处主要对添加Altera库进行说明,在QuartusII安装目录(../altera/11.0/quartus/eda/sim_lib)下包含所有仿真所需的库文件,编译的时候只需要将工作目录指向QuartusII的路径即可。
如需添加cyclone器件的verilog库如以下代码所示:
vlib cyclone_ver
vmap cyclone_ver cyclone_ver
vlog -work cyclone_ver $path_to_quartus/eda/sim_lib/cyclone_atoms.v
如需添加cyclone器件的VHDL库如以下代码所示:
vlib cyclone
vmap cyclone cyclone
vcom -work cyclone -2002 –explicit $path_to_quartus/eda/sim_lib/cyclone_atoms.vhd
vcom -work cyclone -2002 –explicit $path_to_quartus/eda/sim_lib/cyclone_components.vhd
在Altera官网上可以下载添加Altera库的Tcl脚本,结果发现是针对QuartusII 7.1版本的,现在都11.0了,里面有很多器件都没添加,因此咱修改了一下,将所有器件都添加进去,verilog-library-setup-11.tcl,vhdl-library-setup-11.tcllibrary_setup_11.zip这两个文件分别是针对添加verilog库和vhdl库的Tcl脚本,对应QuartusII 11.0版本,如果安装的QuartusII不是11.0,只需在文件中将第一条语句中路径修改一下,修改如下:
11.0版本:set path_to_quartus d:/altera/11.0/quartus
修改成其它版本:set path_to_quartus d:/altera/其它版本号/quartus
添加Altera库可分为一下几步:
(1)确认安装的Modelsim是SE版本的,咱安装的是6.6b,然后在安装目录下新建名为altera的文件夹,将verilog-library-setup-11.tcl,vhdl-library-setup-11.tcl两个文件拷贝到文件夹中。
(2)打开modelsim,在Transcript窗口中输入如图1指令,其中cd命令是将当前工作目录设置到存放verilog-library-setup-11.tcl,vhdl-library-setup-11.tcl文件的,source命令是执行Tcl脚本,图中是执行添加verilog库的脚本,这样verilog库就自动会加入,同理输入source vhdl-library-setup-11.tcl就添加vhdl库。如果编译出错可能是版本问题,咱现在编译的是针对QuartusII 11.0版本的,如果映射到低版本QuartusII的库,可能某些器件缺失,只需要将对应代码删除就行。
图1
以上操作都是在Modelsim安装目录的altera文件夹下完成的,因此编译完的库文件都在这个文件中,如图2所示,针对每个库都有一个对应文件夹。
图2
在Modelsim中,添加完库如图3所示。
图3
(3)经过1、2两步,库算是添加进来了,但是会发现下次重新启动Modelsim后库并没有自动加载,因此还需一步。找到Modelsim安装目录下的modelsim.ini文件,将其只读属性去掉,打开此文件,在文件如图4位置中添加如下代码:
图4
添加代码:
;Altera Verilog Library
220model_ver = $MODEL_TECH/../altera/220model_ver
altera_lnsim_ver = $MODEL_TECH/../altera/altera_lnsim_ver
altera_mf_ver = $MODEL_TECH/../altera/altera_mf_ver
altera_ver = $MODEL_TECH/../altera/altera_ver
altgxb_ver = $MODEL_TECH/../altera/altgxb_ver
arriagx_hssi_ver = $MODEL_TECH/../altera/arriagx_hssi_ver
arriagx_ver = $MODEL_TECH/../altera/arriagx_ver
arriaii_hssi_ver = $MODEL_TECH/../altera/arriaii_hssi_ver
arriaii_pcie_hip_ver = $MODEL_TECH/../altera/arriaii_pcie_hip_ver
arriaii_ver = $MODEL_TECH/../altera/arriaii_ver
arriaiigz_hssi_ver = $MODEL_TECH/../altera/arriaiigz_hssi_ver
arriaiigz_pcie_hip_ver = $MODEL_TECH/../altera/arriaiigz_pcie_hip_ver
arriaiigz_ver = $MODEL_TECH/../altera/arriaiigz_ver
cyclone_ver = $MODEL_TECH/../altera/cyclone_ver
cycloneii_ver = $MODEL_TECH/../altera/cycloneii_ver
cycloneiii_ver = $MODEL_TECH/../altera/cycloneiii_ver
cycloneiiils_ver = $MODEL_TECH/../altera/cycloneiiils_ver
cycloneiv_hssi_ver = $MODEL_TECH/../altera/cycloneiv_hssi_ver
cycloneiv_pcie_hip_ver = $MODEL_TECH/../altera/cycloneiv_pcie_hip_ver
cycloneiv_ver = $MODEL_TECH/../altera/cycloneiv_ver
cycloneive_ver = $MODEL_TECH/../altera/cycloneive_ver
hardcopyii_ver = $MODEL_TECH/../altera/hardcopyii_ver
hardcopyiii_ver = $MODEL_TECH/../altera/hardcopyiii_ver
hardcopyiv_hssi_ver = $MODEL_TECH/../altera/hardcopyiv_hssi_ver
hardcopyiv_pcie_hip_ver= $MODEL_TECH/../altera/hardcopyiv_pcie_hip_ver
hardcopyiv_ver = $MODEL_TECH/../altera/hardcopyiv_ver
lpm_ver = $MODEL_TECH/../altera/lpm_ver
max_ver = $MODEL_TECH/../altera/max_ver
maxii_ver = $MODEL_TECH/../altera/maxii_ver
maxv_ver = $MODEL_TECH/../altera/maxv_ver
sgate_ver = $MODEL_TECH/../altera/sgate_ver
stratix_ver = $MODEL_TECH/../altera/stratix_ver
stratixgx_gxb_ver = $MODEL_TECH/../altera/stratixgx_gxb_ver
stratixgx_ver = $MODEL_TECH/../altera/stratixgx_ver
stratixiigx_hssi_ver = $MODEL_TECH/../altera/stratixiigx_hssi_ver
stratixii_ver = $MODEL_TECH/../altera/stratixii_ver
stratixiii_ver = $MODEL_TECH/../altera/stratixiii_ver
stratixiv_hssi_ver = $MODEL_TECH/../altera/stratixiv_hssi_ver
stratixiv_pcie_hip_ver = $MODEL_TECH/../altera/stratixiv_pcie_hip_ver
stratixiv_ver = $MODEL_TECH/../altera/stratixiv_ver
stratixv_hssi_ver = $MODEL_TECH/../altera/stratixv_hssi_ver
stratixv_pcie_hip_ver = $MODEL_TECH/../altera/stratixv_pcie_hip_ver
stratixv_ver = $MODEL_TECH/../altera/stratixv_ver
;Altera VHDL Library
220model = $MODEL_TECH/../altera/220model
altera = $MODEL_TECH/../altera/altera
altera_lnsim = $MODEL_TECH/../altera/altera_lnsim
altera_mf = $MODEL_TECH/../altera/altera_mf
altgxb = $MODEL_TECH/../altera/altgxb
altgxb_lib = $MODEL_TECH/../altera/altgxb_lib
arriagx = $MODEL_TECH/../altera/arriagx
arriagx_hssi = $MODEL_TECH/../altera/arriagx_hssi
arriaii = $MODEL_TECH/../altera/arriaii
arriaii_hssi = $MODEL_TECH/../altera/arriaii_hssi
arriaii_pcie_hip = $MODEL_TECH/../altera/arriaii_pcie_hip
arriaiigz = $MODEL_TECH/../altera/arriaiigz
arriaiigz_hssi = $MODEL_TECH/../altera/arriaiigz_hssi
arriaiigz_pcie_hip = $MODEL_TECH/../altera/arriaiigz_pcie_hip
cyclone = $MODEL_TECH/../altera/cyclone
cycloneii = $MODEL_TECH/../altera/cycloneii
cycloneiii = $MODEL_TECH/../altera/cycloneiii
cycloneiiils = $MODEL_TECH/../altera/cycloneiiils
cycloneiv = $MODEL_TECH/../altera/cycloneiv
cycloneiv_hssi = $MODEL_TECH/../altera/cycloneiv_hssi
cycloneiv_pcie_hip = $MODEL_TECH/../altera/cycloneiv_pcie_hip
cycloneive = $MODEL_TECH/../altera/cycloneive
hardcopyii = $MODEL_TECH/../altera/hardcopyii
hardcopyiii = $MODEL_TECH/../altera/hardcopyiii
hardcopyiv_hssi = $MODEL_TECH/../altera/hardcopyiv_hssi
hardcopyiv = $MODEL_TECH/../altera/hardcopyiv
hardcopyiv_pcie_hip= $MODEL_TECH/../altera/hardcopyiv_pcie_hip
lpm = $MODEL_TECH/../altera/lpm
max = $MODEL_TECH/../altera/max
maxii = $MODEL_TECH/../altera/maxii
maxv = $MODEL_TECH/../altera/maxv
sgate = $MODEL_TECH/../altera/sgate
stratix = $MODEL_TECH/../altera/stratix
stratixgx = $MODEL_TECH/../altera/stratixgx
stratixgx_gxb = $MODEL_TECH/../altera/stratixgx_gxb
stratixii = $MODEL_TECH/../altera/stratixii
stratixiigx = $MODEL_TECH/../altera/stratixiigx
stratixiigx_hssi = $MODEL_TECH/../altera/stratixiigx_hssi
stratixiii = $MODEL_TECH/../altera/stratixiii
stratixiv = $MODEL_TECH/../altera/stratixiv
stratixiv_hssi = $MODEL_TECH/../altera/stratixiv_hssi
stratixiv_pcie_hip = $MODEL_TECH/../altera/stratixiv_pcie_hip
stratixv = $MODEL_TECH/../altera/stratixv
stratixv_hssi = $MODEL_TECH/../altera/stratixv_hssi
stratixv_pcie_hip = $MODEL_TECH/../altera/stratixv_pcie_hip
经过以上3步之后,Altera库算是全部添加完成了,打开软件后会发现,library窗口中的库与Modelsim AE版本的一样,以后仿真是再也不用手动添加库了,相当方便了。
用户377235 2012-11-27 21:25
zcf287 2011-9-5 17:45