「HDLBits题解」Verification: Writing Testbenches

本专栏的目的是分享可以通过HDLBits仿真的Verilog代码 以提供参考 各位可同时参考我的代码和官方题解代码 或许会有所收益


题目链接:Tb/clock - HDLBits

`timescale 1ps/1ps
module top_module ( );
    parameter time_period = 10 ; 
    reg clk ; 
    initial clk = 0 ; 
    always  begin
        # (time_period / 2) clk = ~clk ; 
    end

    dut u1(
        .clk(clk)
    );
endmodule

题目链接:Tb/tb1 - HDLBits

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

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

endmodule

题目链接:Tb/and - HDLBits

`timescale 1ps/1ps

module top_module();
    reg [1:0] in ; 
    wire out ; 

    initial begin 
        in = 2'b00 ; 
        # 10 ; 
        in = 2'b01 ; 
        # 10 ; 
        in = 2'b10 ; 
        # 10 ; 
        in = 2'b11 ; 
    end

    andgate u1(
        .in(in),
        .out(out) 
    );

endmodule

题目链接:Tb/tb2 - HDLBits

`timescale 1ps/1ps
module top_module();
    reg clk, in ; 
    reg [2:0] s ; 
    wire out ; 
    initial begin
        clk = 0 ; 
        in = 0 ; 
        s = 2 ; 
        # 10 
        s = 6 ; 
        # 10 
        in = 1 ; 
        s = 2 ; 
        # 10 
        in = 0 ; 
        s = 7 ; 
        # 10 ; 
        in = 1 ; 
        s = 0 ; 
        # 30 ; 
        in = 0 ; 
    end

    always  begin
        # 5 ; 
        clk = ~clk ;
    end

    q7 u1(
        .clk(clk), 
        .s(s),
        .in(in), 
        .out(out) 
    );

endmodule

题目链接:Tb/tff - HDLBits

module top_module ();
    reg clk ;
    reg reset ; 
    reg t ;
    wire q ;

    tff u1(
        .clk(clk),
        .reset(reset),
        .t(t),
        .q(q)
    );

    initial begin
        clk = 1'b0 ; 
        forever begin
            # 5 ;
            clk = ~clk ;
        end
    end

    initial begin
        reset = 1'b0 ; 
        # 3 ; 
        reset = 1'b1 ; 
        # 10 ; 
        reset = 1'b0 ;  
    end

    always @(posedge clk) begin
        if (reset) t <= 1'b0 ;
        else t <= 1'b1 ; 
    end


endmodule
  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

UCSD.KS

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

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

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

打赏作者

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

抵扣说明:

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

余额充值