当前位置:网站首页>[Verilog] HDLBits Problem Solution - Verification: Writing Testbenches
[Verilog] HDLBits Problem Solution - Verification: Writing Testbenches
2022-08-03 12:11:00 【wjh776a68】
Clock
module top_module ( );
reg clk;
initial begin
clk = 0;
forever #5 clk = ~clk;
end
dut dut_inst(.clk(clk)) ;
endmodule
Testbench1
module top_module ( output reg A, output reg B );//
// generate input patterns here
initial begin
A = 0;
B = 0;
#10
A = 1;
#5
B = 1;
#5
A = 0;
#20
B = 0;
end
endmodule
AND gate
module top_module();
reg [1:0] in;
wire out;
initial begin
in = 'b0;
#10;
in = 'b01;
#10;
in = 'b10;
#10;
in = 'b11;
#10;
//$finish;
end
andgate andgate_inst (
.in(in),
.out(out)
);
endmodule
Testbench2
module top_module();
reg clk;
reg in;
reg [2:0] s;
reg [5:0] STAT;
wire out;
initial begin
STAT = 0;
clk = 0;
in = 0;
s = 'h2;
forever #5 clk = ~clk;
end
always @ (negedge clk) begin
case (STAT)
0: begin
s <= 'h6;
end
1: begin
s <= 'h2;
in <= 1;
end
2: begin
s <= 'h7;
in <= 0;
end
3: begin
s <= 'h0;
in <= 1;
end
6: begin
s <= 'h0;
in <= 0;
end
default: begin
end
endcase
if (STAT < 6) begin
STAT <= STAT + 1;
end
end
q7 q7_inst(
.clk(clk),
.in(in),
.s(s),
.out(out)
);
endmodule
T flip-flop
module top_module ();
reg clk, reset, t;
reg [5:0] STAT;
wire q;
initial begin
clk = 0;
reset = 0;
t = 0;
STAT = 0;
forever #1 clk = ~clk;
end
always @ (posedge clk) begin
case (STAT)
0: begin
reset <= 1;
STAT <= 1;
end
1: begin
reset <= 0;
t <= 1;
STAT <= 2;
end
2: begin
t <= 0;
end
endcase
end
tff tff_inst(
.clk(clk),
.reset(reset), // active-high synchronous reset
.t(t), // toggle
.q(q)
);
endmodule
边栏推荐
- 3年软件测试经验,不懂自动化基础...不知道我这种测试人员是不是要被淘汰了?
- LeetCode-142. 环形链表 II
- 码率vs.分辨率,哪一个更重要?
- 【云原生 · Kubernetes】部署Kubernetes集群
- 深度学习中数据到底要不要归一化?实测数据来说明!
- 数据库系统原理与应用教程(073)—— MySQL 练习题:操作题 131-140(十七):综合练习
- 基于Sikuli GUI图像识别框架的PC客户端自动化测试实践
- Explain the virtual machine in detail!JD.com produced HotSpot VM source code analysis notes (with complete source code)
- fastposter v2.9.0 程序员必备海报生成器
- 微信小程序获取手机号
猜你喜欢
随机推荐
4500字归纳总结,一名软件测试工程师需要掌握的技能大全
常用lambda表达式
第5章 实现首页Tab数据展示
从零开始Blazor Server(6)--基于策略的权限验证
OFDM 十六讲 4 -What is a Cyclic Prefix in OFDM
bash case用法
零信任架构分析【扬帆】
nacos应用
基于SSM和Web实现的农作物生长监控系统
opencv学习—VideoCapture 类基础知识「建议收藏」
面试官:SOA 和微服务的区别?这回终于搞清楚了!
零信任的基本概念【新航海】
广州番禺:暑期防溺水,安全不放假
分享一款实用的太阳能充电电路(室内光照可用)
mysql advanced (twenty-four) method summary of defense against SQL injection
一次内存泄露排查小结
"Digital Economy Panorama White Paper" Financial Digital User Chapter released!
-找树根-
【HCIP持续更新】STP协议相关保护机制
Matlab学习10-图像处理之傅里叶变换