测试平台
格式
module module_tb
//变量的声明
//产生相应的激励信号
//实例化被测试的模块
//监视输入输出信号
//保存被监视信号的信息
endmodule
tb指testbench
模块实例化
/*------- module --------*/
`timescale 1ns/1ns
module gate_construct
(
input i_a,
input i_b,
input i_c,
input i_d,
input i_e,
output o_y
);
//定义门电路之间的连线信号
wire w_and_o;
wire w_or1_o;
wire w_xor_o;
//实例化门电路模块
and I_and(w_and_o, i_a, i_b);
or I1_or(w_or1_o, i_c, i_d);
xor I_xor(w_xor_o, w_and_o, w_or1_o );
or I2_or(o_y, w_xor_o, i_e);
endmodule
/*------------ testbench ---------*/
`timescale 1ns / 1ns
module gate_construct_simulation();
reg r_a;
reg r_b;
reg r_c;
reg r_d;
reg r_e;
reg[4:0] r_cnt;
//定义输出信号连线
wire w_v;
//实例化
gate_construct I_gate_construct_tb
(
.i_a(r_a),
.i_b(r_b),
.i_c(r_c),
.i_d(r_d),
.i_e(r_e)
);
initial
begin
r_cnt = 5'd0;
forever
#2 r_cnt = r_cnt + 5'd1;
end
always@(r_cnt)
begin
r_a = r_cnt[0];
r_b = r_cnt[1];
r_c = r_cnt[2];
r_d = r_cnt[3];
r_e = r_cnt[4];
end
endmodule
产生激励信号
重复的信号,如时钟信号
initial begin a = 0; #10 a = 1; end
一次特定的序列
initial begin a = 0; forever #10 a = ~a; end /*------*/ initial b = 0; always #4 b = ~b;