Writing testbench

Writing testbench

码农世界 2024-06-04 前端 85 次浏览 0个评论

1. clock

module top_module ( );
    
    reg clk;
    initial
        begin
           clk = 1'b0;
        end
    
    always #5 clk = ~clk;
    dut t1(clk);
 
endmodule

2. testbench 1

module top_module ( output reg A, output reg B );//
    // generate input patterns here
    initial begin
		A = 1'b0;
        B = 1'b0;
        #10 A = ~A;
        #5  B = ~B;
        #5 A = ~A;
        #20 B = ~B;
    end
endmodule

3.Andgate 

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

4.testbench 2 

module top_module();
    
    reg clk;
    reg in;
    reg [2:0] s;
    reg out;
    
    initial
        begin
           clk = 1'b0;
           in  = 1'b0;
            s = 3'd2;
        end
    
    always #5 clk = ~clk;
    
    initial
        begin
           #10	s = 3'd6;
           #10  in = ~in;
            	s = 3'd2;
            #10 in = ~in;
            	s = 3'd7;
            #10 in = ~in;
            	s = 3'd0;
            #30 in = ~in;
            	s = 3'd0;
  
        end
    
    q7 t1(
        .clk(clk),
        .in(in),
        .s(s),
        .out(out)
    );
    
    
endmodule

5.Flip-flop

module top_module ();
	
    reg clk;
    reg reset;
    reg t;
    reg q;
    
    initial
        begin
           clk = 1'b0;
           reset = 1'b0;
           t = 1'b0;
        end
    
    always #5 clk = ~clk;
    
    initial
        begin
           #6 reset = ~reset;
           #15 reset = ~reset;
        end
    
    always@(posedge clk)
        begin
            if(reset)
                t <= 1'b0;
            else
                t <= 1'b1;
        end
    
    tff t1(
        .clk(clk),
        .reset(reset),
        .t(t),
        .q(q)
    );
    
    
endmodule

转载请注明来自码农世界,本文标题:《Writing testbench》

百度分享代码,如果开启HTTPS请参考李洋个人博客
每一天,每一秒,你所做的决定都会改变你的人生!

发表评论

快捷回复:

评论列表 (暂无评论,85人围观)参与讨论

还没有评论,来说两句吧...

Top