例说Verilog HDL和VHDL区别

verilog和vhdl之间的区别将在本文中通过示例进行详细说明。对优点和缺点的verilog和vhdl进行了讨论。
hdl 建模能力:verilog与vhdl
首先,让我们讨论一下 verilog 和 vhdl 的硬件建模能力,因为它们都是用于建模硬件的硬件描述语言。
下图显示了 verilog 和 vhdl 在硬件抽象行为级别方面的 hdl 建模能力。
图形来源:douglas j. smith,“vhdl 和 verilog 比较和对比加上 用 vhdl、verilog 和 c 编写的建模示例”
低级建模 
如上图所示,verilog 和 vhdl 都能够对硬件进行建模。但是,在底层硬件建模方面,verilog优于vhdl。这是合理的,因为 verilog 最初是为建模和模拟逻辑门而创建的。事实上,verilog 具有内置原语或低级逻辑门,因此设计人员可以在 verilog 代码中实例化原语,而 vhdl 则没有。
verilog 的门基元:and、nand、or、nor、xor、xnor、buf、not、bufif0、notif0、bufif1、notif1、pullup、pulldown。
verilog 的开关原语:pmos、nmos、rpmos、rnmos、cmos、rcmos、tran、rtran、tranif0、rtranif0、tranif1、rtranif1。
更重要的是,verilog 支持用户定义基元 (udp),因此设计人员可以定义自己的单元基元。此功能对于 asic 设计人员来说尤其必要。
以下是有关如何在 verilog 代码中实例化门基元的 verilog 示例:
or #5 u1(x,y,z);and #10 u2(i1,i2,i3);adc_circuit u3(in1,out1,out2,clock); // adc_circuit is an user-defined primitive for // analog to digital converter for example.  
verilog 中一些低级内置门基元的 vhdl 等效项可以通过使用逻辑运算符如 not、and、nand、or、nor、xor、xnor 来实现。 
下面是 verilog 门基元的 vhdl 等效代码示例:
or u1(x,y,z); in verilog x <= y or z; in vhdland u2(i1,i2,i3); (verilog) i3 <= i2 and i3; in vhdl  
为了支持 verilog 中的 udp 功能,vital(vhdl initiative towards asic libraries-vhdl 面向 asic 库的倡议)问世,使 asic 设计人员能够在符合 vital 的 vhdl 中创建自己的单元基元或 asic 库,如上图所示。尽管如此,vhdl 仍然可能无法实现 verilog 对低级硬件建模的支持。因此,如果我是 asic 设计师,我会更喜欢 verilog 而不是 vhdl。
高级建模
另一方面,如上述图表所示,vhdl 在高级硬件建模方面优于 verilog。与 verilog 相比,vhdl 为高级硬件建模提供了更多功能和构造。以下是在比较 vhdl 和 verilog 时支持高级硬件建模的主要不同功能:
vhdl 中的用户定义数据类型
verilog 的数据类型非常简单,都是用 verilog 语言定义的(用户不能在 verilog 中定义自己的数据类型)。verilog 有两种主要的数据类型,包括 net 数据类型(用于将组件连接在一起,例如wire(最流行)、wor、wand、tri、trior 等)和变量数据类型(用于临时存储,例如reg(最流行),整数、时间、实数和实时)。 
vhdl支持许多不同的数据类型,包括预定义的 vhdl 数据类型和用户定义的数据类型。预定义的 vhdl 数据类型包括位、位向量、字符串、时间、布尔值、字符和数字(实数或整数)。vhdl 允许设计人员根据预定义的 vhdl 数据类型定义不同的类型;对于可能使用许多不同数据类型的复杂和高级系统来说,这是一个很好的功能。以下是用于定义新数据类型的示例 vhdl 代码:
type int_8bit is range 0 to 255 -- define 8-bit unsigned numberssignal i : int_8bit;type state_fsm is (idle, start, calculate , finish, delay) -- define symbolic states to represent fsm states.signal current_state, next_state: state_fsm;  
vhdl 中的设计重用包
vhdl 中的包通常用于数据类型和子程序的声明。vhdl 包中声明的子程序或数据类型可用于许多不同的实体或体系结构。例如:
package fsm_type is type fsm_states is (idle, transmit, receive, stop);end package-- to use the fsm_states type in an entity or architecture-- use the following statement on top of the entityuse work.fsm_type.allentity example is  
verilog 中没有包定义。与 vhdl 包最接近的 verilog 等效项是`include verilog 编译器指令。函数或定义可以单独保存在另一个文件中,然后通过使用`include指令在模块中使用它。下面是一个 verilog 示例代码:
// below is the content of verilogvsvhdl.h file`define input_verilog ./test_verilogvsvhdl.hex // input file name `define output_vhdl vhdl.bmp // output file name `define verilog_vhdl_difference// then call it in every single module that you want to use the definition above`include verilogvsvhdl.h  
vhdl 中的配置语句
一个 vhdl 设计可以为一个实体获得许多具有不同体系结构的设计实体。配置语句将确切的设计实体与设计中的组件实例相关联。当实体中有多个架构时,配置语句会继续指定所需的设计架构分配给实体以进行综合或仿真。当 vhdl 设计人员需要管理大型高级设计时,此功能非常有用。 
以下是配置语句的 vhdl 示例代码:
entity buf is generic (delay : time := 10 ns); port ( buf_in : in bit; buf_out : out bit);end buf;-- the first design architecture for buf architecture struct_buf1 of buf issignal temp: bit;begin buf_out <= not temp after delay; temp <= not buf_in after delay;end struct_buf1;-- the second design architecture for buf architecture struct_buf2 of buf isbegin buf_out time_delay) port map (buf_in => in1, buf_out => out1); end for;end for ;end config_buf;  
verilog-2001 中还添加了配置块。
vhdl 中的库管理
同时查看 verilog 和 vhdl 代码时,最明显的区别是 verilog 没有库管理,而 vhdl 在代码顶部包含设计库。vhdl 库包含已编译的架构、实体、包和配置。此功能在管理大型设计结构时非常有用。上面已经给出了 vhdl 中的包和配置示例。以下是 vhdl 中库管理的 vhdl 示例代码:
-- library management in vhdllibrary ieee;use ieee.std_logic_1164.all;use ieee.numeric_std.all;use work.clock_div.all;  
简而言之,vhdl 在高级硬件建模方面比 verilog 更好。由于 fpga 设计流程不需要低级硬件建模,如果我是 fpga 设计师,我更喜欢 vhdl 而不是 verilog。 
值得一提的是,systemverilog 的创建是为了通过将 vhdl 中的高级功能和结构添加到 verilog 中进行验证来增强 verilog 语言在高级建模中的弱点。systemverilog 现在广泛用于 ic 验证。
冗长(verboseness:):verilog 与 vhdl
vhdl 是强类型的vs verilog 是松散类型的
vhdl 是一种非常强类型的硬件描述语言,因此必须使用匹配和定义的数据类型正确编写 vhdl 代码。这意味着如果在 vhdl 中分配时混合数据类型或不匹配信号,将会出现编译错误。另一方面,verilog 是一种松散类型的语言。在 verilog 中,您可以在分配时混合数据类型或不匹配信号。下面是不匹配信号的 vhdl 示例代码:
signal test_reg1: std_logic_vector(3 downto 0); signal test_reg2: std_logic_vector(7 downto 0); test_reg2 <= test_reg1;-- you cannot assign a 4-bit signal to an 8-bit signal -- in vhdl, it will introduce a syntax error below:-- width mismatch. expected width 8, actual width is 4 -- for dimension 1 of test_reg1.  
编译上面的vhdl代码时,会出现语法错误“ width mismatch. expected width 8, actual width is 4 ”。如果将vhdl代码改为“ test_reg2 <= 0000&test_reg1; 匹配位宽,则不会出现语法错误。 
如果在 verilog 中将 4 位信号分配给 8 位信号会怎样?
wire [3:0] test1; wire [7:0] test2; // in verilog, you can assign 4-bit signal to 8-bit signal. assign test2 = test1; // there will be no syntax error during synthesis  
当您将 4 位信号分配给 8 位信号时,verilog 编译器不会引入语法错误。在 verilog 中,不同位宽的信号可以相互分配。verilog 编译器将使源信号的宽度适应目标信号的宽度。未使用的位将在综合期间进行优化。
下面是在分配信号时混合数据类型的另一个 vhdl 示例:
signal test1: std_logic_vector(7 downto 0);signal test2: integer;test2 <= test1;-- syntax error: type of test2 is incompatile with type of test1  
上面的 vhdl 代码会引入一个语法错误“ (type of test2 is incompatible with type of test1)test2 的类型与 test1 的类型不兼容”。你必须转换test1的 分配之前整数数据类型test1到test2如下:
library ieee;use ieee.numeric_std.all;signal test1: std_logic_vector(3 downto 0);signal test2: integer;-- use ieee.numberic_std.all library for this conversiontest2 aluout aluout aluout aluout clk, clk_1s => clk_1s); end  
或者在包中声明组件以供重用:
library ieee;use ieee.std_logic_1164.all;package clock_div_pack is component clk_div is port ( clk_50: in std_logic; clk_1s : out std_logic );end component clk_div;end package;-- declare the component in a separate package and -- reuse by using the following statement:use work.clock_div_pack.all;entity clock isend clock;architecture behavioral of clock issignal clk, clk_1s: std_logic;begincreate_1s_clock: clk_div port map (clk_50 => clk, clk_1s => clk_1s); end
在 vhdl-93 中直接实例化实体的示例代码:
create_1s_clock: entity work.clk_div port map (clk_50 => clk, clk_1s => clk_1s);  
verilog 具有编译器指令,例如`timescale  (声明时间单位和延迟精度)、`define  (将文本字符串声明为宏名称)、`ifdef、ifndef `else `elseif `endif(条件编译)、`include(包括一个可以包含函数或其他声明的文件)等。vhdl 没有编译器指令。 
vhdl 支持枚举和记录数据类型,允许用户为一种数据类型定义多个信号。verilog 不支持枚举和记录类型。下面是枚举和记录类型的 vhdl 代码:
type fsm is (idle, test, verilogvsvhdl, stop, fpga4student);-- enumerated typetype int_4 is range 0 to 15;-- record tye in vhdltype record_example is record data1: integer; data2: int_4; data3: fsm;end record;
等等。
尽管 verilog 和 vhdl 之间存在差异,但它们是两种最流行的硬件描述语言。如果可以,最好同时学习它们。重要的是要记住,在编码时始终考虑逻辑门或硬件以开发硬件编码思维,而在使用 verilog 和 vhdl 编码时忘记软件编程思维,这一点非常重要。


简略的讲什么是误码率
分享三种不同的电压采样电路
由浅入深的图解机器学习和GPT原理
闹钟的ESD整改案例
趋势科技发布的一项有关互联汽车安全性的重大新研究,评估出29种实际攻击场景
例说Verilog HDL和VHDL区别
磁阻传感器及其制造方法
压缩空气流量计旋涡频率的检测方法
现场总线控制系统的特点及对计算机控制系统造成哪些影响
计量仪器仪表的标定、检定、校准与校验的含义是怎样的有什么区别
热继电器的选择方法_热继电器的安装_热继电器的日常维护
矢量网络分析仪测到的 S 参变换成时域时的测试结果
变压器容量计算的方法
一个典型的输出为12 V/500 mA的非隔离开关电源芯片-TB1211
电池编号是从哪里来的?常见的干电池型号
Altium Designer导出3D STEP模型的方法
500kV变压器的运行维护
工业CT断层扫描仪的精度
食品重金属快速测定仪的功能
手机电池的性能一般会受到哪些因素的影响