Writing Testbenches

Tb/clock

`timescale 1ps/1ps
module top_module ;
    
    reg clk;
    
    dut dut ( .clk(clk) ) ;
    
    initial begin
       clk <= 0; 
    end
    
    always #5 clk <= ~clk;
    //#5ps clk翻转一次,周期10 ps;
    
endmodule

Tb/tb1

`timescale 1ps/1ps
module top_module (output reg A, output reg B);//

    // generate input patterns here
    initial begin
        A <= 0; B <= 0;
		#10 A <= 1; //10ps后A为1;
        #5 B <= 1; //5ps后B为1;
        #5 A <=0; //5ps后A为0;
        #20 B <= 0; //20ps后B为0;
    end

endmodule

Tb/and

module top_module;
    
    reg [1:0] in;
    wire out;
    
    initial begin
       	in <= 2'b0;
		#10		in <= 2'b01;
		#10		in <= 2'b10;
		#10		in <= 2'b11;
    end
    
    andgate andgate (.in(in),.out(out));

endmodule

Tb/tb2

module top_module;
    reg clk,in;
    reg [2:0] s;
    wire out;
    
    q7 q7 (.clk(clk),.in(in),.s(s),.out(out));
    
    initial begin
    	clk<=0;in<=0;s<=2;
    	#10 s<=6;
        #10 s<=2;in<=1;
        #10 s<=7;in<=0;
        #10 s<=0;in<=1;
        #30 in<=0;
    end
    
    always #5 clk<=~clk;

endmodule

Tb/tff

module top_module;
    reg clk,reset,t;
    wire q;
    
    tff tff (.clk(clk),.reset(reset),.t(t),.q(q));
    
    initial begin
        clk<=0;reset<=0;t<=0;
        #10 reset<=1;t<=1;
        #10 reset<=1;t<=0;
        #10 reset<=0;t<=1;
        #10 reset<=0;t<=0; //测试所有可能情况;
    end
             
    always #5 clk<=~clk;
             
endmodule

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值