目录
5 Verification: Reading Simulation
前言
今天终于来到了最后一个部分,HDLbits的178道题目答案更新系列终于完成了!一口气完成这全部的题目,相信同学们和我一样,心中还是有一点点小成就感的,这里面的题目有简单的有难的,将这些小模块完成之后,设计起大的模块来会更加游刃有余,让我们一起继续进步吧~
5 Verification: Reading Simulation
5.1 Clock(Tb/clock)
`timescale 1ps / 1ps
module top_module ( );
reg clk;
dut u_dut(
.clk (clk)
);
initial begin
clk = 1'b0;
forever
#5
clk = ~clk;
end
/*
//second way
initial begin
clk = 1'b0;
end
always begin
#5
clk = ~clk;
end
*/
endmodule
这道题需要产生一个周期为10ns的时钟,博主给出两种方式。
5.2 Testbench1(Tb/tb1)
`timescale 1ps / 1ps
module top_module ( output reg A, output reg B );//
// generate input patterns here
initial begin
A=1'b0;
B=1'b0;
#10;
A = 1'b1;
B = 1'b0;
#5;
A = 1'b1;
B = 1'b1;
#5;
A = 1'b0;
B = 1'b1;
#20;
A = 1'b0;
B = 1'b0;
end
endmodule
这道题目是根据波形写出A、B对应时刻的值。
5.3 AND gate(Tb/and)
`timescale 1ps / 1ps
module top_module();
reg [1:0]in;
wire out;
andgate u_andgate(
.in (in ),
.out (out )
);
initial begin
in = 2'b00;
#10;
in = 2'b01;
#10;
in = 2'b10;
#10;
in = 2'b11;
end
/*
initial begin
in[1] = 1'b0;
in[0] = 1'b0;
#10;
in[1] = 1'b0;
in[0] = 1'b1;
#10;
in[1] = 1'b1;
in[0] = 1'b0;
#10;
in[1] = 1'b1;
in[0] = 1'b1;
end
*/
endmodule
这道题目作者给了我们一个与门的module,我们需要调用一下,然后就是按照时刻给in赋值。
5.4 Testbench2(Tb/tb2)
module top_module();
reg clk;
reg in;
real s;
wire out;
q7 u_q7(
.clk (clk ),
.in (in ),
.s (s ),
.out (out )
);
initial begin
clk = 1'b0;
forever
#5
clk = ~clk;
end
initial begin
in = 1'b0;
s = 3'd2;
#10;
in = 1'b0;
s = 3'd6;
#10;
in = 1'b1;
s = 3'd2;
#10;
in = 1'b0;
s = 3'd7;
#10;
in = 1'b1;
s = 3'd0;
#30;
in = 1'b0;
s = 3'd0;
end
endmodule
这道题目作者同样给出了一个module,我们只需调用即可。
5.5 T flip-flop(Tb/tff)
module top_module ();
reg clk;
reg reset;
reg t;
wire q;
tff u_tff(
.clk (clk ),
.reset (reset ),
.t (t ),
.q (q )
);
initial begin
clk=1'b0;
forever
#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
这道题目作者给出了一个T触发器的module,我们只需要将其复位,然后切换到状态1就可以了。
结语
这个系列终于算是完成更新了,HDLbits网站的题目搞定啦~~~还是那句话,如果有错误的地方,欢迎随时指出,我会尽快改正。