2009.5.23
初学TestBench
`timescale 1ns/10ps //单位时间/精度
`include "adder.v"
module adder_testbench;
reg a,b;
wire sum,cout;
adder adder_t( //调用待测模块
.sum(sum),
.c(count),
.a(a),
.b(b)
);
initial begin
a = 0; //初始值a=0
forever #20 a = ~a; //每经过20个单位时间,a取反
end
initial begin
b = 0; //初始值b=0
forever #10 b = ~b; //每经过10个单位时间,b取反
end
initial begin
$monitor ($time,,,"%d + %d = {%d,%d}",a,b,cout,sum); //监控输出
#40 $stop;
end
小结:
$monitor 输出打印显示
$stop停止当前仿真
$finish结束仿真,询问是否退出ModelSim
时钟产生方法:
1.用intial语句
reg clock;
initial begin
clock = 0;
forever #10 clock = ~clock;
end
2.用always语句
reg clock;
initial
clock = 0;
always
#10 clock = ~clock;
以上写法产生的时钟如下:
文章评论(0条评论)
登录后参与讨论