当前位置: 首页 > news >正文

HDLBits中文版,标准参考答案 | 5 Verification: Writing Testbenches | 验证:编写测试平台

关注 望森FPGA  查看更多FPGA资讯

这是望森的第 24 期分享

作者 | 望森
来源 | 望森FPGA

目录

1 Clock

2 Testbench1

3 AND gate

4 Testbench2

5 T flip-fop


本文中的代码都能够正常运行,请放心食用😋~

练习的官方网站是:https://hdlbits.01xz.net/

注:作者将每个练习的知识点都放在了题目和答案之后


1 Clock

题目:

您将获得一个具有以下声明的模块:

module dut ( input clk ) ;

编写一个测试平台,创建一个 module dut 实例(可命名为任何实例名称),并创建一个时钟信号来驱动模块的 clk 输入。时钟周期为 10 ps。时钟应初始化为零,其第一次转换应为 0 到 1。

答案:

`timescale 1ps/1ps
module top_module ( );//时钟reg clk;parameter period = 10/2;initial beginclk = 0;endalways #period clk <= ~clk;//实例化dut        inst1(.clk        (clk)
);endmodule

2 Testbench1

题目:

创建一个 Verilog 测试台,它将为输出 A 和 B 产生以下波形:

答案:

module top_module ( output reg A, output reg B );//// generate input patterns hereinitial beginA <= 0;B <= 0;#10 A <= 1;#5  B <= 1;#5  A <= 0;#20 B <= 0;endendmodule

3 AND gate

题目:

您将获得以下要测试的与门:

module andgate (

input [1:0] in,

output out

);

编写一个测试平台,实例化此与门并测试所有 4 个输入组合,通过生成以下时序图:

答案:

module top_module();reg [1:0] in;wire out;initial beginin <= 2'b00;#10 in <= 2'b01;#10 in <= 2'b10;#10 in <= 2'b11;endandgate inst1(.in(in),.out(out));endmodule

4 Testbench2

题目:

下面的波形设置了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 beginclk = 0;endalways #5 clk <= ~clk;//数据产生initial beginin <= 0;#20 in <= 1;#10 in <= 0;#10 in <= 1;#30 in <= 0;endinitial begins <= 3'h2;#10 s <= 3'h6;#10 s <= 3'h2;#10 s <= 3'h7;#10 s <= 3'h0;end//模块实例化q7 inst1(.clk(clk),.in(in),.s(s),.out(out));endmodule

5 T flip-fop

题目:

给你一个 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;//时钟parameter period = 10/2;initial beginclk = 0;endalways #period clk <= ~clk;//复位initial beginreset <= 0;#10 reset <= 1;#10 reset <= 0;end//输入信号initial begint <= 0;#20 t <= 1;end//实例化tff tff_inst1(.clk(clk),.reset(reset),   // active-high synchronous reset.t(t),       // toggle.q(q));endmodule

- END -

公z号/CSDN/知乎搜索【望森FPGA】,查看更多FPGA资讯~

相关推荐文章,点击跳转:

望森FPGA的HDLBits合集


http://www.mrgr.cn/news/52754.html

相关文章:

  • 【C++贪心】1775. 通过最少操作次数使数组的和相等|1850
  • 架构师之路-学渣到学霸历程-20
  • 《ESP32调试异常集锦》之移植I2C程序时i2c_master_cmd_begin返回-1
  • fiddler抓包23_重放请求(Replay)
  • 对比长安链、FISCO BCOS、蚂蚁链
  • OpenAI推出Swarm框架:简化多AI智能体系统交互
  • Python | Leetcode Python题解之第491题非递减子序列
  • 【JavaEE】【多线程】volatile,wait/notify
  • 【Qunar风控安全产品的探索之路】
  • 【算法】力扣:K个一组反转链表
  • R01 vue+springboot 高考志愿推荐AI问答大数据平台
  • LabVIEW提高开发效率技巧----VI继承与重载
  • 【RoadRunner】自动驾驶模拟3D场景构建 | 软件简介与视角控制
  • AI学习指南深度学习篇-预训练模型的实践
  • Nodemon 深入解析与使用
  • 【MySQL】聚合函数和分组查询
  • 【ShuQiHere】 机器学习中的网格搜索(Grid Search)超参数调优
  • 手机数据恢复技巧:适用于手机的恢复应用程序
  • 面对配分函数 - 去噪得分匹配篇
  • 在FastAPI网站学python:环境变量 Python Environment Variables