




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、第9章 测试与仿真 第第9章测章测 试试 与与 仿仿 真真 9.1 测试与仿真的流程测试与仿真的流程 9.2 测试举例测试举例 第9章 测试与仿真 9.1 测试与仿真的流程测试与仿真的流程对已设计模块的测试与仿真通常可分为以下三个步骤:(1) 产生输入向量,包括输入向量的初始化与产生测试波形。(2) 将输入向量添加到已设计模块并给出相应的输出结果。(3) 将输出结果与设计要求相比较。第9章 测试与仿真 9.1.1 产生输入向量产生输入向量对输入向量的初始化可通过initial过程块来实现。【例例9-1】输入向量的初始化。initialbeginclk = 1b0;globalReset = 1
2、b1;in = 1b1;end在上面的例子中,将二进制表示形式的0值赋给变量clk。实际上,对于值0与1,没有必要采用二进制表示形式1b0与1b1,直接用0与1给出即可。当给输入向量赋值时,可以利用一定的延迟时间来控制测试与仿真程序(参见下面的例子)。第9章 测试与仿真 【例例9-2】带延迟的向量赋值。#100 globalReset = 0;#100 in = 0;#100 in = 1;#300 in = 0;经过100个时间单位的延迟后将变量globalReset的值置为0,再经过100个时间单位的延迟把变量in变为0,依次类推。这里需要注意的是,时延是一个相对的概念,即相对于上一条语句
3、执行完后的时刻而言,并非相对于仿真的起始时间。如果测试模块中没有控制仿真结束时刻的语句,那么当对测试模块进行仿真实验时,程序就会陷入死循环。通过在initial过程块中加入带有延迟的系统任务$finish或$stop,就可轻易解决该问题。第9章 测试与仿真 【例例9-3】仿真结束语句的应用。initialbegin#100 globalReset = 0;#100 in = 0;#100 in = 1;#300 in = 0;#400 $finishend采用always过程块可以很容易实现时钟信号,下面是一个产生某测试模块的时钟信号的例子。第9章 测试与仿真 【例例9-4】时钟信号的产生。a
4、lwaysbegin#10 clk = clk;end该例用来产生一个周期为20个时间单位的时钟信号。如果输入信号的值有规律地变化时,例如按相同的延迟重复出现n次,那么就可以通过repeat循环语句来实现。【例例9-5】repeat循环语句的例子。repeat(10)begin#40 in = 0;#20 in = 1;end第9章 测试与仿真 9.1.2 测试模块测试模块【例例9-6】4选1多路选择器的功能模块与测试模块。/功能模块部分module multiplexor4_1 (out, in1, in2, in3, in4, cntrl1, cntrl2);output out;inpu
5、t in1,in2,in3,in4,cntrl1,cntrl2;reg out;always (in1 or in2 or in3 or in4 or cntrl1 or cntrl2)case (cntrl1,cntrl2)2b00:out = in1;2b01:out = in2;2b10:out = in3;2b11:out = in4;default:$display(Please check control bits);endcaseendmodule第9章 测试与仿真 /测试模块部分module muxstimulus;reg IN1,IN2,IN3,IN4,CNTRL1,CNTR
6、L2;wire OUT;multiplexor4_1 mux1_4(OUT,IN1,IN2,IN3,IN4,CNTRL1,CNTRL2);initial beginIN1 = 1;IN2 = 0;IN3 = 1;IN4 = 0;$display(Initial arbitrary values);#0 $display(input1 = %b,input2 = %b,input3 = %b,input4 = %bn,IN1,IN2,IN3,IN4);CNTRL1,CNTRL2 = 2b00;#1 $display(cntrl1=%b,cntrl2=%b,output is %b,CNTRL1,
7、 CNTRL2, OUT);CNTRL1, CNTRL2 = 2b01;第9章 测试与仿真 #1 $display(cntrl1=%b,cntrl2=%b output is %b,CNTRL1,CNTRL2,OUT);CNTRL1,CNTRL2 = 2b10;#1 $display(cntrl1=%b,cntrl2=%b output is %b,CNTRL1,CNTRL2,OUT);CNTRL1,CNTRL2 = 2b11;#1 $display(cntrl1=%b,cntrl2=%b output is %b,CNTRL1,CNTRL2,OUT);endendmodule第9章 测试与仿
8、真 测试模块与功能模块相类似,都是以关键字module开头的。但由于测试模块只是为了进行仿真验证,因而不需要端口列表,也不能被其它模块调用。而功能模块则必须有端口列表。由于测试模块没有端口列表,因而不需进行端口声明。为了对功能模块的参数进行赋值,测试模块中也需进行数据类型的说明,即reg IN1,IN2,IN3,IN4,CNTRL1,CNTRL2;wire OUT;第9章 测试与仿真 接下来就是调用功能模块的部分:multiplexor4_1 mux1_4(OUT,IN1,IN2,IN3,IN4,CNTRL1,CNTRL2);可以看出,其调用格式如下: (port list);其中代表已设计的
9、功能模块的名字;是不能省略的,且调用部分的端口列表必须与功能模块的端口列表(包括端口的个数与排列顺序)相对应。第9章 测试与仿真 测试模块的主体部分包含在initial过程块中,即initial beginIN1 = 1;IN2 = 0;IN3 = 1;IN4 = 0;$display(Initial arbitrary values);#0 $display(input1 = %b,input2 = %b,input3 = %b,input4 = %bn,IN1,IN2,IN3,IN4);CNTRL1,CNTRL2 = 2b00;#1 $display(cntrl1=%b,cntrl2=%b
10、,output is %b,CNTRL1,CNTRL2,OUT);CNTRL1,CNTRL2 = 2b01;#1 $display(cntrl1=%b, cntrl2=%b output is %b,CNTRL1,CNTRL2,OUT);CNTRL1,CNTRL2 = 2b10;第9章 测试与仿真 #1 $display(cntrl1=%b, cntrl2=%b output is %b,CNTRL1,CNTRL2,OUT);CNTRL1,CNTRL2 = 2b11;#1 $display(cntrl1=%b, cntrl2=%b output is %b,CNTRL1,CNTRL2,OUT)
11、;end第9章 测试与仿真 首先对输入向量进行赋值,并通过系统任务$display显示其结果,IN1 = 1;IN2 = 0;IN3 = 1;IN4 = 0;$display(Initial arbitrary values);#0 $display(“input1 = %b,input2 = %b,input3 = %b,input4 = %bn,IN1,IN2,IN3,IN4);延迟表示#0是为了保证当给输入变量赋值后立即显示。然后通过给变量CNTRL1与 CNTRL2赋值并用连接符号 将它们连接起来作为一个整体判决条件,来验证已设计模块的输出与设计要求是否吻合。第9章 测试与仿真 9.2
12、 测测 试试 举举 例例通过上一节对测试与仿真流程的介绍,我们已对测试模块有了一个清晰的认识。在此基础上,本节给出一些常用电路的功能模块与测试模块的例子,以供读者参考。【例例9-7】模为16的增1计数器。/ 4位二进制增1计数器module counter4_bit(q,d,increment,load_data,global_reset,clock);output 3:0 q;input 3:0 d;input load_data,global_reset,clock,increment;wire t1,t2,t3; /内部连线wire see15,reset;/内部连线第9章 测试与仿真
13、/内部连线用来在模块间传递信息,/它们可被当作临时变量,用来储存/某个门的输出并输入另一个门et_ff etff0(q0,d0,increment,load_data,reset,clock);et_ff etff1(q1,d1,t1,load_data,reset,clock);et_ff etff2(q2,d2,t2,load_data,reset,clock);et_ff etff3(q3,d3,t3,load_data,reset,clock);and a1(t1,increment,q0);and a2(t2,t1,q1);and a3(t3,t2,q2);recog15 r1(se
14、e15,q); or or1(reset,see15,global_reset); endmodule 第9章 测试与仿真 module et_ff(q,data,toggle,load_data,reset,clock);output q;input data,toggle,load_data,reset,clock;wire m1,m2;mux mux0(m1,q,q,toggle);mux mux1(m2,data,m1,load_data);dff dff0(q,m2,reset,clock);endmodule第9章 测试与仿真 module mux(out,in1,in2,cntr
15、l);output out;input in1,in2,cntrl;assign out = cntrl ? in1:in2;/这是一个连续赋值,任一操作数的改变,输出将相应地改变此语句相当于if (cntrl=1) out = in1,else out = in2.endmodule第9章 测试与仿真 module dff(q,data,reset,clock);output q;input data,reset,clock;reg q;always (posedge clock) /在时钟的上升沿,如果reset为1,q复位if (reset = 1) /成0,否则q等于dataq = 0
16、; else q = data;endmodule第9章 测试与仿真 module recog15(flag,in);input 3:0 in;output flag;assign flag = (in = 4b1111) ? 1:0;/ 如果输入为15 ,则flag 被设置为1,/ 否则为0endmodule 第9章 测试与仿真 module stumulus;wire 3:0 q;reg 3:0 d;reg load_data,global_reset,clk,increment;counter4_bit mod1 (q,d,increment,load_data,global_reset
17、,clk);initial beginglobal_reset = 0;clk = 0;increment = 0;load_data = 0;d = 4b0010;#10 global_reset = 1;#20 global_reset = 0;#20 load_data = 1;第9章 测试与仿真 #20 load_data = 0;#20 increment = 1;#200 global_reset = 1;#20 global_reset = 0;#50 load_data = 1;#20 load_data = 0;#10 increment = 0;#20 $finish;en
18、d / initial beginalways #5 clk = clk;always #10 $display ($time, %b %b %b %d - %b %d,increment,load_data,global_reset,d,q,q);endmodule第9章 测试与仿真 仿真测试的输出结果如下:10 0 0 1 2 - xxxx x20 0 0 1 2 - 0000 030 0 0 0 2 - 0000 040 0 0 0 2 - 0000 050 0 1 0 2 - 0000 060 0 1 0 2 - 0010 270 0 0 0 2 - 0010 280 0 0 0 2
19、- 0010 290 1 0 0 2 - 0010 2100 1 0 0 2 - 0011 3110 1 0 0 2 - 0100 4第9章 测试与仿真 120 1 0 0 2 - 0101 5130 1 0 0 2 - 0110 6140 1 0 0 2 - 0111 7150 1 0 0 2 - 1000 8160 1 0 0 2 - 1001 9170 1 0 0 2 - 1010 10180 1 0 0 2 - 1011 11190 1 0 0 2 - 1100 12200 1 0 0 2 - 1101 13210 1 0 0 2 - 1110 14220 1 0 0 2 - 1111
20、 15第9章 测试与仿真 230 1 0 0 2 - 0000 0240 1 0 0 2 - 0001 1250 1 0 0 2 - 0010 2260 1 0 0 2 - 0011 3270 1 0 0 2 - 0100 4280 1 0 0 2 - 0101 5290 1 0 1 2 - 0110 6300 1 0 1 2 - 0000 0310 1 0 0 2 - 0000 0第9章 测试与仿真 320 1 0 0 2 - 0001 1330 1 0 0 2 - 0010 2340 1 0 0 2 - 0011 3350 1 0 0 2 - 0100 4360 1 1 0 2 - 010
21、1 5370 1 1 0 2 - 0010 2380 1 0 0 2 - 0010 2390 0 0 0 2 - 0011 3400 0 0 0 2 - 0011 3第9章 测试与仿真 【例例9-8】2选1的多路选择器的例子(用4种方法实现)。/多路选择器的行为描述1module mux_beh (out, cnt, a, b); output out; input cnt, a, b; reg out; always (cnt or a or b) if (cnt = 0) out = a; else out = b;endmodule/mux_gate第9章 测试与仿真 /多路选择器的行为
22、描述2module mux_beh_2 (out, cnt, a, b); output out; input cnt, a, b; assign out = (cnt = 0) ? a: b;endmodule/mux_gate/多路选择器的功能描述module mux_func (out, cnt, a, b); output out; input cnt, a, b; assign out = (cnt & a) |(cnt & b);endmodule/mux_gate第9章 测试与仿真 /多路选择器的门级描述module mux_gate (out, cnt, a,
23、b); output out; input cnt, a, b; wire aval, bval; wire cntbar; not (cntbar,cnt); and (aval, cntbar, a); and (bval, cnt, b); or (out, aval, bval);endmodule/mux_gate 第9章 测试与仿真 /测试模块module stimulus; reg a, b, c; wire out1, out2, out3, out4; integer i; mux_beh_2 mod1 (out1, c, a, b); mux_beh mod2 (out2,
24、 c, a, b); mux_func mod3 (out3, c, a, b); mux_gate mod4 (out4, c, a, b);第9章 测试与仿真 initial begin for (i = 0; i output is: %b %b %b %b, a, b, c, out1, out2, out3, out4); end #10 $finish; end endmodule第9章 测试与仿真 仿真测试的输出结果如下:simulation time is: 10inputs is:0 0 0 -output is:0 0 0 0simulation time is: 20in
25、puts is:0 0 1 -output is:0 0 0 0simulation time is: 30inputs is:0 1 0 -output is:0 0 0 0simulation time is: 40inputs is:0 1 1 -output is:1 1 1 1simulation time is: 50第9章 测试与仿真 inputs is:1 0 0 -output is:1 1 1 1simulation time is: 60inputs is:1 0 1 -output is:0 0 0 0simulation time is: 70inputs is:1
26、1 0 -output is:1 1 1 1simulation time is: 80inputs is:1 1 1 -output is:1 1 1 1第9章 测试与仿真 【例例9-9】触发器的例子。module ff(q, data, enable, reset, clock); output q; input data, enable, reset, clock; wire norout, muxout; mux2_1 mod1 (muxout, data, q, enable); nor (norout, reset, muxout); dff dff0 (q, norout, cl
27、ock);endmodule第9章 测试与仿真 module mux2_1(out, in1, in2, cntrl); output out; input in1, in2, cntrl; assign out = cntrl ? in1 : in2;endmodule module dff(q, data, clock); output q; input data, clock; reg q; always (posedge clock) q = data;endmodule 第9章 测试与仿真 module sti_ff; reg data, enable, reset, clock; wire q; ff mod1 (q, data, enable, reset, clock); init
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中学考试试题及答案
- 云南省宾川县四校2025届物理高二下期末经典模拟试题含解析
- 云南省宣威市第十中学2024-2025学年高二生物第二学期期末经典试题含解析
- 云南省绿春县一中2025届高二下物理期末复习检测试题含解析
- 云南省施甸县第三中学2025年生物高二下期末质量跟踪监视试题含解析
- 车展场地租赁及品牌合作营销合同范本
- 遗产继承权转让与执行合同
- 城市综合体安保服务合同
- 科技研发园区场地使用与研发人员劳动保障合同
- 餐饮连锁退伙合同范本
- 建设工程法规考试题真题及答案
- 2025-2030年中国磷酸行业市场现状供需分析及投资评估规划分析研究报告
- 2025年市场营销专业人才考核试题及答案
- 防范恶劣天气安全教育
- 分居协议(模版)
- 深圳市住房公积金管理中心员额人员招聘真题2024
- 2025年全国国家版图知识竞赛题库及答案
- 《创伤失血性休克中国急诊专家共识(2023)》解读课件
- MOOC 数字逻辑电路实验-东南大学 中国大学慕课答案
- 国家开放大学《人文英语4》边学边练参考答案
- 入团志愿书(2016版本)(可编辑打印标准A4) (1)
评论
0/150
提交评论