Problem 173 Clock
问题:编写testbench产生一个驱动时钟信号,来驱动模块dut,时钟周期为10ps
解决:
`timescale 1ps/1ps //仿真单位为1ps,精度为1ps
module top_module ( );
reg clk;
dut dut_inst(clk);
initial begin
#0 clk = 0;//clk初始为0
end
always #5 clk = ~clk;//每5个时钟单位 clk取反一次
endmodule
Problem 174 Testbench1
问题:编写testbench产生A、B两个输出信号,波形如下:

解决:
`timescale 1ps/1ps
module top_module ( output reg A, output reg B );//
// generate input patterns here
initial begin
#0 A=0;
B=0;
#10 A=1;
#5 B=1;
#5 A=0;
#20 B=0;
end
endmodule
注意理解#后面的延时 而不是在某一个时刻
Problem 175 AND gate
问题:为你提供如下的与门
module andgate (
input [1:0] in,
output out
);
编写testbench测试输入的四种组合,每5个时基改变一次

解决:
`timescale 1ps/1ps
module top_module();
reg[1:0] in;
reg out;
andgate andgate_inst(in,out);
initial begin
#0 in = 2'b00;
#10 in = 2'b01;
#10 in = 2'b10;
#10 in = 2'b11;
end
endmodule
居然妄图写循环执行,发现并不需要
Problem 176 Testbench2
问题:编写testbench例化下面的模块,然后产生下图的波形输出
module q7 (
input clk,
input in,
input [2:0] s,
output out
);

解决:
`timescale 1ps/1ps
module top_module();
reg clk;
reg in;
reg[2:0] s;
reg out;
q7 q7_inst(
.clk(clk),
.in(in),
.s(s),
.out(out)
);
initial begin
#0 clk = 0;
in = 1'b0;
s = 3'd2;
#10 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;
end
always #5 clk = ~clk;
endmodule
Problem 177 T flip-flop
问题:提供一个T触发器的模块
module tff (
input clk,
input reset, // active-high synchronous reset
input t, // toggle
output q
);
编写testbench例化该tff模块,复位它然后切换到状态‘1’
解决:
`timescale 1ps/1ps
module top_module();
reg clk;
reg reset;
reg t;
reg q;
tff tff_inst(
.clk(clk),
.reset(reset),
.t(t),
.q(q)
);
initial begin
#0 clk = 0;
t = 1'b0;
reset = 1'b1;
#10 reset = 1'b0;
t = 1'b1;
end
always #5 clk = ~clk;
endmodule
呜~~~~
终于做完了,题目还是都比较基础的感觉,比较收获的就是状态机那部分了,三段式真的学到了很多,还有就是分模块设计电路那里,也体会到了分模块设计的好处。最后就是testbench的编写了,虽然感觉还算简单把,但是也是一直没有学习,现在也算了解了一点了
后面就准备着手小项目,先点个oled玩玩~~~
完结撒花~~~~
本文介绍了如何使用VHDL编写测试平台,包括产生时钟信号、输出信号的波形设计以及与门等基本逻辑门的测试。通过具体的例子展示了如何为不同模块创建testbench,例如tff触发器的测试,并强调了testbench在验证数字逻辑设计中的重要性。此外,还提及了对状态机和分模块设计的理解,以及对未来小项目如OLED显示的期待。
&spm=1001.2101.3001.5002&articleId=121521718&d=1&t=3&u=afd299b94bc144169351cc8b78e1eced)
499

被折叠的 条评论
为什么被折叠?



