【HDLBits 刷题 15】Verification Writing Testbenches
15 刷题 Writing verification
2023-09-14 09:16:20 时间
目录
Verification Writing Testbenches
写在前面
以下的解题方法不一定为最佳解决方案,有更好的方法欢迎提出,共同学习,共同进步!
终于完成了 HDLBits 刷题,虽然说难度不大,但是有些题目题目还是有锻炼价值的,值得一刷。
Verification Writing Testbenches
clock
提供一个具有以下声明的模块:
module dut ( input clk ) ;
编写一个测试平台,创建一个模块 dut 实例(具有任何实例名称),并创建一个时钟信号来驱动模块的 clk 输入。时钟的周期为 10 ps。时钟应初始化为零,其第一个转换为 0 到 1。
module top_module();
reg clk;
initial begin
clk = 'd0;
end
always #5 clk = ~clk;
dut dut_inst(
clk
);
endmodule
Tb/tb1
创建一个 Verilog 测试平台,该测试平台将为输出 A 和 B 生成以下波形:
module top_module ( output reg A, output reg B );//
// generate input patterns here
initial begin
A = 'd0;
B = 'd0;
#10
A = 'd1;
#5
B = 'd1;
#5
A = 'd0;
#20
B = 'd0;
end
endmodule
Tb/and
您将获得以下要测试的 AND 门:
module andgate (
input [1:0] in,
output out
);
通过生成以下时序图,编写一个实例化此 AND 门并测试所有 4 种输入组合的测试平台:
module top_module();
reg [1:0] in;
wire out;
initial begin
in = 'd0;
#10
in = 'd1;
#10
in = 'd2;
#10
in = 'd3;
end
andgate andgate_inst(in, out);
endmodule
Tb/tb2
下面的波形设置 clk、in 和 s:
模块 q7 具有以下声明:
module q7 (
input clk,
input in,
input [2:0] s,
output out
);
编写一个测试平台,实例化模块 q7 并完全按照上述波形所示生成这些输入信号。
module top_module();
reg clk;
reg in;
reg [2:0] s;
wire out;
initial begin
clk = 'd0;
in = 'd0;
s = 'd2;
#10
s = 'd6;
#10
in = 'd1;
s = 'd2;
#10
in = 'd0;
s = 'd7;
#10
in = 'd1;
s = 'd0;
#30
in = 'd0;
end
always #5 clk = ~clk;
q7 q7_inst (clk, in, s, out);
endmodule
Tb/tff
您将获得一个具有以下声明的 T 触发器模块:
module tff (
input clk,
input reset, // active-high synchronous reset
input t, // toggle
output q
);
编写一个测试平台,该测试平台实例化一个tff,并将重置T触发器,然后将其切换到“1”状态。
module top_module ();
reg clk;
reg reset;
reg t;
wire q;
initial begin
clk = 'd0;
reset = 'd1;
#10
reset = 'd0;
end
always #5 clk = ~clk;
always @(posedge clk) begin
if (reset) begin
t <= 'd0;
end
else begin
t <= 'd1;
end
end
tff tff_inst(clk, reset, t, q);
endmodule
相关文章
- 15-基于Nginx构建Tomcat集群
- 超低功耗(VKL系列) 15*4点 LCD液晶显示驱动控制电路(IC)-VKL060,用于仪器仪表/水电表/温湿度表等,超低工作电流
- 竞赛好题暑假练习15
- 力扣刷题笔记--剑指 Offer 15. 二进制中1的个数
- react源码解析15.scheduler&Lane_2023-03-15
- vue的几个提效技巧_2023-03-15
- 用机器学习解码一颗“失声”15年的大脑,让它“开口说话”
- B站入股汉堡公司 持股约15%为第二大股东
- MySQL更新下月15号新版本发布(mysql 下月15号)
- Oracle15分钟的改变(oracle 15分钟前)
- 新版 iOS/iPadOS 15 开发工具优先考虑 5G 而非 Wi-Fi
- iOS 15/watchOS 8 正式版发布后,微软 Outlook 就会放弃支持 iOS 13/watchOS 6