当前位置:网站首页>[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
边栏推荐
- "Digital Economy Panorama White Paper" Financial Digital User Chapter released!
- php microtime 封装工具类,计算接口运行时间(打断点)
- 肝完Alibaba这份面试通关宝典,我成功拿下今年第15个Offer
- 面试突击71:GET 和 POST 有什么区别?
- 微信小程序获取手机号
- 数据库系统原理与应用教程(074)—— MySQL 练习题:操作题 141-150(十八):综合练习
- 如何免费获得一个市全年的气象数据?降雨量气温湿度太阳辐射等等数据
- C language advanced article: memory function
- AMS simulation
- LeetCode-142. 环形链表 II
猜你喜欢
随机推荐
漫谈缺陷管理的自动化实践方案
随机森林项目实战---气温预测
App自动化测试怎么做?实战分享App自动化测试全流程
我在母胎SOLO20年
nacos应用
如何免费获得一个市全年的气象数据?降雨量气温湿度太阳辐射等等数据
基于SSM和Web实现的农作物生长监控系统
字符串本地化和消息字典(二)
pandas连接oracle数据库并拉取表中数据到dataframe中、筛选当前时间(sysdate)到一天之前的所有数据(筛选一天范围数据)
基于Sikuli GUI图像识别框架的PC客户端自动化测试实践
dataset数据集有哪些_数据集类型
后台图库上传功能
LyScript implements memory stack scanning
第3章 搭建短视频App基础架构
【一起学Rust】Rust学习前准备——注释和格式化输出
After completing the interview and clearance collection of Alibaba, I successfully won the 15th Offer this year
详解虚拟机!京东大佬出品HotSpot VM源码剖析笔记(附完整源码)
Go 语言快速入门指南: 介绍及安装
距LiveVideoStackCon 2022 上海站开幕还有3天!
肝完Alibaba这份面试通关宝典,我成功拿下今年第15个Offer









