Verilog初级教程(1)认识 Verilog HDL
【摘要】
文章目录
背景正文介绍Verilog有什么用途?如何验证Verilog设计的功能?Verilog设计模板 参考资料汇总
背景
集成电路的设计经历了从原理图绘制(工程师在纸上绘制晶体管及其连接,以便对其设计,使其可以在硅上制造)到硬件描述语言的转变,这是因为大型的设计,如果使用原理图的方式进行设计会耗费大量的人力、时间和资源等,这催生着硬件描述语言的诞...
背景
集成电路的设计经历了从原理图绘制(工程师在纸上绘制晶体管及其连接,以便对其设计,使其可以在硅上制造)到硬件描述语言的转变,这是因为大型的设计,如果使用原理图的方式进行设计会耗费大量的人力、时间和资源等,这催生着硬件描述语言的诞生!
硬件描述语言最开始出现的VHDL,它是1983年,应美国国防部要求开发的,目的是记录供应商公司将其包括在设备中的ASIC的行为。
硬件描述语言允许工程师描述所需硬件的功能,并使得EDA工具将该行为转换为组合逻辑以及时序逻辑之类的实际硬件单元,VHDL很快得到了发展!
Verilog的开发旨在简化开发流程,并使得硬件描述语言(HDL)更加的健壮和灵活。如果,Verilog已经成为全球使用地区最多的硬件描述语言。
如下图,来自于参考资料2,显示了使用Verilog以及VHDL的地域区别,
正文介绍
Verilog有什么用途?
Verilog创建了一种抽象级别,以帮助隐藏电路实现及其细节,让我们能关注于电路的行为。
举个例子:
module ctr ( input up_down, input clk, input rstn, output reg [2:0] out ); always @ (posedge clk) if (!rstn) out <= 0; else begin if (up_down) out <= out + 1; else out <= out - 1; end
endmodule
这段设计描述的电路是一种计数器,输入信号up_down有效时候,计数递增,否则递减!
这很清晰地让我们知道Verilog长什么样子,我们不需要描述电路的实现细节,而只需要描述电路的行为或者功能即可,这大大提高了开发效率!
如何验证Verilog设计的功能?
打个不恰当的比喻,也许能帮助理解,如果将Verilog描述的电路比作一个灯泡,那么验证的方式就是给灯泡通电,测试灯泡亮或不亮,以此达到验证的目的。
通过不同的方法对设计进行检查,统称为验证。验证的最普遍和广泛实践的方法是电路仿真。有一些软件工具可以了解Verilog中描述的硬件应如何工作并为设计模型提供各种输入刺激。然后对照预期值检查设计的输出,以查看设计在功能上是否正确。
所有仿真均由EDA(电子设计自动化)软件工具执行,并且Verilog设计RTL放置在称为testbench的平台内。在测试平台内,各种测试为设计提供了不同的刺激。下图显示了这样的测试平台。
Verilog设计模板
module [design_name] ( [port_list] ); [list_of_input_ports]
[list_of_output_ports] [declaration_of_other_signals] [other_module_instantiations_if_required] [behavioral_code_for_this_module]
endmodule
- 模块定义和端口列表声明
- 输入和输出端口列表
- 使用允许的Verilog数据类型声明其他信号
- 设计可能依赖于其他Verilog模块,因此它们的实例是通过模块实例化创建的
- 描述该模块行为的此模块的实际Verilog设计
例如下面的verilog设计显示了一个D触发器的行为:
// "dff" is the name of this module module dff ( input d, // Inputs to the design should start with "input" input rstn, input clk, output reg q); // Outputs of the design should start with "output" always @ (posedge clk) begin // This block is executed at the positive edge of clk 0->1 if (!rstn) // At the posedge, if rstn is 0 then q should get 0 q <= 0; else q <= d; // At the posedge, if rstn is 1 then q should get d
end
endmodule // End of module
对这段设计进行测试的仿真文件:
module tb; // 1. Declare input/output variables to drive to the design
reg tb_clk;
reg tb_d;
reg tb_rstn;
wire tb_q; // 2. Create an instance of the design
// This is called design instantiation
dff dff0 ( .clk (tb_clk), // Connect clock input with TB signal .d (tb_d), // Connect data input with TB signal .rstn (tb_rstn), // Connect reset input with TB signal .q (tb_q)); // Connect output q with TB signal // 3. The following is an example of a stimulus
// Here we drive the signals tb_* with certain values
// Since these tb_* signals are connected to the design inputs,
// the design will be driven with the values in tb_*
initial begin tb_rsnt <= 1'b0; tb_clk <= 1'b0; tb_d <= 1'b0;
end
endmodule
参考资料汇总
文章来源: reborn.blog.csdn.net,作者:李锐博恩,版权归原作者所有,如需转载,请联系作者。
原文链接:reborn.blog.csdn.net/article/details/106960243
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)