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所以可以不用加