HDLbits——Testbench

Testbench

1 Tb/clock

一个已知的的模块具有以下声明:

module dut ( input clk ) ;

编写一个测试文件,创建一个模块dut的实例(实例名称任意),并创建一个时钟信号以驱动模块的clk输入。时钟的周期为10 ps。时钟应初始化为零,其第一次转换为0到1。

img

module top_module ( );
    reg clk=1'd0;   
    always #5 clk=~clk;
    dut dut(.clk(clk));
endmodule

2 Tb/tb1

编写一个Verilog测试文件,为输出A和B生成以下波形:

img

module top_module ( output reg A, output reg B );//

    // generate input patterns here
    initial begin
        A=0;
        B=0;
        #10 A=1;
        #5 B=1;
        #5 A=0;
        #20 B=0;
    end
endmodule

//可以5s得写

3 Tb/and

module top_module();
    reg [1:0] in;
    reg out;
    initial begin
        in[1]=0;
        in[0]=0;
        #10 in[0]=1;
        #10 in[0]=0;
        in[1]=1;
        #10 in[0]=1;
    end
    andgate andgate1(.in(in),.out(out));
endmodule

4 Tb/tb2

module top_module();
    reg clk=0;
    always #5 clk=~clk;
    reg in,out;
    reg [2:0] s;
    initial begin
        in=0;
        s=3'h2;
        #10 in=0;
        s=3'h6;
        #10 in=1;
        s=3'h2;
        #10 in=0;
        s=3'h7;
        #10 in=1;
        s=3'h0;
        #30 in=0;
    end
    q7 q71(.clk(clk),.in(in),.s(s),.out(out));
endmodule

5 Tb/tff

module top_module ();
    reg clk=0;
    always #5 clk=~clk;
    reg reset,t,q;
    initial begin
        reset=1;
        t=0;
        #10 reset=0;
        t=0;
        #10 t=1;
    end
        tff tff1(.clk(clk),.reset(reset),.t(t),.q(q));
endmodule
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NDLilaco

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值