Modelsim仿真.do脚本示例
#“#”为注释
#删除原有工程,需重启Modelsim
#vdel -all -lib work
#退出当前仿真
quit -sim
#清空命令行显示
.main clear
#创建库,是实际存在的物理库
vlib ./lib
vlib ./lib/design_work
vlib ./lib/sim_work
vlib ./lib/altera_work
#映射逻辑库到指定的物理库
vmap d_work ./lib/design_work
vmap s_work ./lib/sim_work
vmap a_work ./lib/altera_work
#编译代码文件到逻辑库
vlog -work s_work ./tb_serial_detec.v
vlog -work d_work ./../design/*.vo
vlog -work a_work ./altera_lib/*.v
#连接逻辑库,并启动仿真
vsim -t ns -sdfmax tb_serial_detec/serial_detec_inst=serial_detec_v.sdo -voptargs=+acc -L s_work -L d_work -L a_work s_work.tb_serial_detec
#状态机中状态的定义,用于显示
virtual type {
{0x001 s0}
{0x002 s1}
{0x004 s2}
{0x008 s3}
{0x010 s4}
{0x020 s5}
{0x040 s6}
{0x080 s7}
{0x100 s8}
} new_state
virtual function {(new_state)/tb_serial_detec/serial_detec_inst/c_state} state
#添加波形
add wave -divider {tb_serial_detec}
add wave -color yellow tb_serial_detec/*
add wave -divider {serial_detec}
add wave -color blue tb_serial_detec/serial_detec_inst/sclk
add wave -color blue tb_serial_detec/serial_detec_inst/rst_n
add wave -color blue tb_serial_detec/serial_detec_inst/i_bit
add wave -color blue tb_serial_detec/serial_detec_inst/detec_success
#状态机状态显示
add wave -color red tb_serial_detec/serial_detec_inst/state
#设定仿真运行时间
run 50us