本帖最后由 GoldSunMonkey 于 2013-7-4 21:20 编辑
5. Simulation Terminate以上可见到,其实异步enable信号的initial到10个clk以后,test case没完,但是simulate 已经终止了。但如果有到个test case,每个case simulate完都进入terminate_sim,进行某些操作,会很方便。可在代码中稍作修改,写成 terminate_sim的event,代码如下:
//-------------------------------
//asynchronous reset & enable
event terminate_sim;
initial
begin
#10 -> reset_trigger; //asynchronous reset
@(reset_done_trigger); //reset done
@(negedge clk); //asynchronous enable
enable = 1;
repeat(10) //hold 10 cycles
@(negedge clk);
enable = 0; //asynchronous release
#10 -> terminate_sim;
end
//------------------------------
//terminate state
initial
begin
@(terminate_sim);
$display("Terminating Simulation!");
#10 $finish;
end
6. Task任务模块对于需要多次操作或者循环的任务,可以用task封装,方便调用。
此处只做简单的介绍:
//-------------------------------
//stimulate random drive
task din_task;
begin
//for()
din1 = $random % 256;
din2 = $random % 256;
end
endtask
always@(negedge clk)
datain_task;
7. System task之自检Error在系统模拟验证中,采用比较模拟验证法代替波形观察法,以提高效率.
无非是复制verilog中的内容,再写一遍,结果是不是一样,没有什么需要提的.
8. System task之打印数据//-------------------------------
//print the value to screen
initial begin
$display("\t\ttime,\tdout");
$monitor("%d,\t4'h%x,",$time,dout);
end
Display: 正如C语言中的printf
Monitor: 比print个稍微强大点,实时监测数据变化,变化的时候输出数据
如下图所示,数据打印到screen如下(monitor检测的数据输出不能顶格很郁闷)
9. System task之生成vcd文件Vcd文件即为value change dump,用固定格式保存波形数据。
//-------------------------------
//save the warmform
initial begin
$dumpfile("wave_test.vcd" );
$dumpvars;
End
当本次仿真结束的时候,将波形数据保存到wave_test.vcd中,一边以后用warmform viewer查看。如下所示(不知道怎么看~~~~(>_<)~~~~ ):
10. System task之生成vec文件Vec文件即为vector file矢量数据文件,用于Modelsim中保存数据的文件,在仿真测试中,相关数据测试,在必要的情况 下有很大的好处。相关testbench代码如下所示,保存了仿真400ns过程中addout的变化:
//-------------------------------
//generate vector file
integer openfile;
initial
begin
//output to "wave_test.vec" and standard display
openfile = $fopen("wave_test.vec");
//generate header file of vector file
$fdisplay(openfile,"/*---------------------------- --------------------------------------------");
$fdisplay(openfile,"This confidential and proprietary software may be only used as authorized");
$fdisplay(openfile,"by a licensing agreement from CrazyBingo.");
$fdisplay(openfile,"(C) COPYRIGHT 2012 CrazyBingo. ALL RIGHTS RESERVED");
$fdisplay(openfile,"This is the wave_test.vec vector file");
$fdisplay(openfile,"------------------------------ -------------------------------------------*/");
$fdisplay(openfile,"\t\t\t\ttime,\taddout");
//output all the information of node transition in the vector file
$fmonitor(openfile,"%d,\t4'h%x",$time,addout);
end
生成的文件信息如下所示:
11. Others$display,$fdisplay,$monitor,
$strobe,$fopen,$fclose,$dump,$finish,
$time,$write,$stop
$random
1) fork...join:并行任务
2) integer i;for(i=0,i<256,i++) 循环
3) $readmemb(“File_Name”, Test_Vector); 从文件中读取二进制输入激励码向量
4) $readmemh(“File_Name”, Test_Vector); 从文件中读取二进制输入激励码向量
5) reg [7:0] stim_array[0:15] 数组的运用 |