HDLBits Tb/tff

1、这个题刚开始以为要一个时间尺度后来发现不用,以及要根据时钟上升沿同步复位。

2、reset刚开始是1在下一个时钟上升沿来临之前要降下来 。还有个时钟的换算单位可能也要用到

(5条消息) 时间单位的换算(秒,毫秒,微秒,纳秒,皮秒)_秒 毫秒 微秒 纳秒 皮秒_lucky_zbaby的博客-CSDN博客

完整代码如下:


module top_module ();

    reg clk,t,q,reset;
    
    tff tff_1(.clk(clk),.reset(reset), .t(t),.q(q));
    initial begin
          clk=0;
        forever
        #4//不一定非得是5
        clk=~clk;
    end
  initial begin
        reset = 1'b0;
        #3
        reset = 1'b1;
        #10//要根据时钟那里来变
        reset = 1'b0;   
  end
     always@(posedge clk)begin
        if(reset)begin
            t <= 1'b0;
        end
        else begin
            t <= 1'b1;
        end
     end

endmodule

之前几个的也在这了

1、Tb/clock
`timescale 1ps / 1ps 
module top_module ( );
reg clk;
     
    dut dut1(  .clk(clk) ) ;
 initial begin  
     clk=0;
    forever
    #5
    clk=~clk;
    end
endmodule
//这个1ps这个还是有带你没看懂,写其他的又不对。,第二种写法也对。

`timescale 1ps / 1ps 
module top_module ( );
reg clk;
 initial begin
        clk = 1'b0;
    end
    
    always begin
        #5
        clk = ~clk;
    end
endmodule

2、Tb/tb1
module top_module ( output reg A, output reg B );//
	reg a,b;
    // generate input patterns here
    initial begin
		a=0;
        b=0;
        #10
        a=1;
        #5
        b=1;
        #5
        a=0;
        #20
        b=0;
    end
    assign A=a;
    assign B=b;

endmodule
//一点也不优雅正确的应该是1'b1或者1'b0;

3、Tb/and
module top_module();

    reg[1:0]a;
    reg b;
    andgate andgate_1(a,b);
    
    initial begin
        a=2'b0;
        
        #10
        a=a+1'b1;
    	#10
        a=a+1'b1;
        #10
        a=a+1'b1;
        
    end
endmodule
//我觉得那几个#10永一个forever也可以实现。只是后面会出错。
4、Tb/tb2
`timescale 1ps/1ps
module top_module();
    reg clk,in,out;
    reg [2:0]s;
    
    initial begin
        clk=0;
        forever
            #5
            clk=~clk;    
    end
     initial begin
         in=0;
       s=3'd2;
         #10
         s=3'd6;
         #10
         s=3'd2;
         in=1;
         #10
          s=3'd7;
         in=0;
         #10
          s=3'd0;
         in=1;
         #30
         in=0;
    end
    q7 q7_1(.clk(clk),.in(in),.s(s),.out(out));
endmodule

5、Tb/tff

module top_module ();

    reg clk,t,q,reset;
    
    tff tff_1(.clk(clk),.reset(reset), .t(t),.q(q));
    initial begin
          clk=0;
        forever
        #5
        clk=~clk;
    end
  initial begin
        reset = 1'b0;
        #3
        reset = 1'b1;
        #5
        reset = 1'b0;   
  end
     always@(posedge clk)begin
        if(reset)begin
            t <= 1'b0;
        end
        else begin
            t <= 1'b1;
        end
     end

endmodule
//题目没说时钟刻度尺是1ps所以可以不用加

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值