小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

例說Verilog HDL和VHDL區(qū)別,助你選擇適合自己的硬件描述語言

 比特波特 2021-07-04

如果你搜索Verilog和VHDL的區(qū)別,你會看到很多討論這場HDL語言戰(zhàn)爭的區(qū)別頁面,但大多數(shù)都很簡短,沒有很好地舉例說明,不方便初學(xué)者或?qū)W生理解。

VerilogVHDL之間的區(qū)別將在本文中通過示例進行詳細說明。優(yōu)點和缺點的VerilogVHDL進行了討論。

HDL 建模能力:VerilogVHDL

首先,讓我們討論一下 Verilog 和 VHDL 的硬件建模能力,因為它們都是用于建模硬件的硬件描述語言。

下圖顯示了 Verilog 和 VHDL 在硬件抽象行為級別方面的 HDL 建模能力。 

圖形來源:Douglas J. Smith,“VHDL 和 Verilog 比較和對比加上 用 VHDL、Verilog 和 C 編寫的建模示例”

低級建模 

如上圖所示,Verilog 和 VHDL 都能夠?qū)τ布M行建模。但是,在底層硬件建模方面,Verilog優(yōu)于VHDL。這是合理的,因為 Verilog 最初是為建模和模擬邏輯門而創(chuàng)建的。事實上,Verilog 具有內(nèi)置原語或低級邏輯門,因此設(shè)計人員可以在 Verilog 代碼中實例化原語,而 VHDL 沒有。

Verilog 的門基元:and、nand、or、nor、xor、xnor、buf、not、bufif0、notif0、bufif1、notif1、pullup、pulldown。
Verilog 的開關(guān)原語:pmos、nmos、rpmos、rnmos、cmos、rcmos、tran、rtran、tranif0、rtranif0、tranif1、rtranif1

更重要的是,Verilog 支持用戶定義基元 (UDP),因此設(shè)計人員可以定義自己的單元基元。此功能對于 ASIC 設(shè)計人員來說尤其必要。

以下是有關(guān)如何在 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 中一些低級內(nèi)置門基元的 VHDL 等效項可以通過使用邏輯運算符如 NOT、AND、NAND、OR、NOR、XOR、XNOR 來實現(xiàn)。 

下面是 Verilog 門基元的 VHDL 等效代碼示例:

or u1(x,y,z); in Verilog <=> x <=< span=""> y OR z; in VHDLand u2(i1,i2,i3); (Verilog) <=> i3 <=< span=""> i2 AND i3; in VHDL

為了支持 Verilog 中的 UDP 功能,VITAL(VHDL Initiative Towards ASIC Libraries-VHDL 面向 ASIC 庫的倡議)問世,使 ASIC 設(shè)計人員能夠在符合 VITAL 的 VHDL 中創(chuàng)建自己的單元基元或 ASIC 庫,如上圖所示。盡管如此,VHDL 仍然可能無法實現(xiàn) Verilog 對低級硬件建模的支持。因此,如果我是 ASIC 設(shè)計師,我會更喜歡 Verilog 而不是 VHDL。

高級建模

另一方面,如上述圖表所示,VHDL 在高級硬件建模方面優(yōu)于 Verilog。與 Verilog 相比,VHDL 為高級硬件建模提供了更多功能和構(gòu)造。以下是在比較 VHDL 和 Verilog 時支持高級硬件建模的主要不同功能:

?VHDL 中的用戶定義數(shù)據(jù)類型

Verilog 的數(shù)據(jù)類型非常簡單,都是用 Verilog 語言定義的(用戶不能在 Verilog 中定義自己的數(shù)據(jù)類型)。Verilog 有兩種主要的數(shù)據(jù)類型,包括 net 數(shù)據(jù)類型(用于將組件連接在一起,例如wire(最流行)、wor、wand、tri、trior 等)和變量數(shù)據(jù)類型(用于臨時存儲,例如reg(最流行),整數(shù)、時間、實數(shù)和實時)。 

VHDL支持許多不同的數(shù)據(jù)類型,包括預(yù)定義的 VHDL 數(shù)據(jù)類型和用戶定義的數(shù)據(jù)類型。預(yù)定義的 VHDL 數(shù)據(jù)類型包括位、位向量、字符串、時間、布爾值、字符和數(shù)字(實數(shù)或整數(shù))。VHDL 允許設(shè)計人員根據(jù)預(yù)定義的 VHDL 數(shù)據(jù)類型定義不同的類型;對于可能使用許多不同數(shù)據(jù)類型的復(fù)雜和高級系統(tǒng)來說,這是一個很好的功能。以下是用于定義新數(shù)據(jù)類型的示例 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 中的設(shè)計重用包

VHDL 中的包通常用于數(shù)據(jù)類型和子程序的聲明。VHDL 包中聲明的子程序或數(shù)據(jù)類型可用于許多不同的實體或體系結(jié)構(gòu)。例如:

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 編譯器指令。函數(shù)或定義可以單獨保存在另一個文件中,然后通過使用`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 設(shè)計可以為一個實體獲得許多具有不同體系結(jié)構(gòu)的設(shè)計實體。配置語句將確切的設(shè)計實體與設(shè)計中的組件實例相關(guān)聯(lián)。當(dāng)實體中有多個架構(gòu)時,配置語句會繼續(xù)指定所需的設(shè)計架構(gòu)分配給實體以進行綜合或仿真。當(dāng) VHDL 設(shè)計人員需要管理大型高級設(shè)計時,此功能非常有用。 

以下是配置語句的 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 <=< span=""> not temp after DELAY; temp <=< span=""> not BUF_IN after DELAY;end STRUCT_BUF1;-- The second design architecture for BUF architecture STRUCT_BUF2 of BUF isbegin BUF_OUT <=< span=""> BUF_IN after 2*DELAY;;end STRUCT_BUF2;-- Testbench to simulate BUF entity entity BUF_TESTBENCH is end BUF_TESTBENCH;architecture STRUCT_BUF_TEST of BUF_TESTBENCH issignal TEST1, TEST2 : BIT := '1';-- BUF_COMP component declaration:component BUF_COMP is generic (TIME_DELAY : TIME); port ( IN1 : in BIT; OUT1 : out BIT );end component;begin -- instantiation of BUF_COMP component: DUT:BUF_COMP generic map (10 ns) port map (TEST1,TEST2);end STRUCT_BUF_TEST;-- Configuration specify the design entity and architecture-- for the DUT component instance in the testbench aboveconfiguration CONFIG_BUF of TEST_BUF is-- Associate BUF_COMP component instance to BUF design entity-- and STRUCT_BUF1 design architecture for simulation for STRUCT_BUF_TEST for DUT : BUF_COMP use entity WORK.BUF (STRUCT_BUF1) generic map (DELAY => TIME_DELAY) port map (BUF_IN => IN1, BUF_OUT => OUT1); end for;end for ;end CONFIG_BUF;

Verilog-2001 中還添加了配置塊。

?VHDL 中的庫管理

同時查看 Verilog 和 VHDL 代碼時,最明顯的區(qū)別是 Verilog 沒有庫管理,而 VHDL 在代碼頂部包含設(shè)計庫。VHDL 庫包含已編譯的架構(gòu)、實體、包和配置。此功能在管理大型設(shè)計結(jié)構(gòu)時非常有用。上面已經(jīng)給出了 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 設(shè)計流程不需要低級硬件建模,如果我是 FPGA 設(shè)計師,我更喜歡 VHDL 而不是 Verilog。 

值得一提的是,SystemVerilog 的創(chuàng)建是為了通過將 VHDL 中的高級功能和結(jié)構(gòu)添加到 Verilog 中進行驗證來增強 Verilog 語言在高級建模中的弱點。SystemVerilog 現(xiàn)在廣泛用于 IC 驗證。

冗長Verboseness::Verilog 與 VHDL

?VHDL 是強類型的vs Verilog 是松散類型的

VHDL 是一種非常強類型的硬件描述語言,因此必須使用匹配和定義的數(shù)據(jù)類型正確編寫 VHDL 代碼。這意味著如果在 VHDL 中分配時混合數(shù)據(jù)類型或不匹配信號,將會出現(xiàn)編譯錯誤。另一方面,Verilog 是一種松散類型的語言。在 Verilog 中,您可以在分配時混合數(shù)據(jù)類型或不匹配信號。下面是不匹配信號的 VHDL 示例代碼: 

signal test_reg1: std_logic_vector(3 downto 0); signal test_reg2: std_logic_vector(7 downto 0); test_reg2 <=< span=""> 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代碼時,會出現(xiàn)語法錯誤“ Width mismatch. Expected width 8, Actual width is 4 ”。如果將VHDL代碼改為“ test_reg2 <= "0000"&test_reg1; "匹配位寬,則不會出現(xiàn)語法錯誤。 
如果在 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

當(dāng)您將 4 位信號分配給 8 位信號時,Verilog 編譯器不會引入語法錯誤。在 Verilog 中,不同位寬的信號可以相互分配。Verilog 編譯器將使源信號的寬度適應(yīng)目標(biāo)信號的寬度。未使用的位將在綜合期間進行優(yōu)化。
下面是在分配信號時混合數(shù)據(jù)類型的另一個 VHDL 示例:

signal test1: std_logic_vector(7 downto 0);signal test2: integer;test2 <=< span=""> test1;-- Syntax Error: type of test2 is incompatile with type of test1

上面的 VHDL 代碼會引入一個語法錯誤“ type of test2 is incompatible with type of test1test2 的類型與 test1 的類型不兼容”。你必須轉(zhuǎn)換test1的 分配之前整數(shù)數(shù)據(jù)類型TEST1TEST2如下:

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 <=< span=""> to_integer(unsigned(test1));-- No syntax errors this time

另一方面,Verilog 在分配時混合數(shù)據(jù)類型時沒有問題。以下是一個 Verilog 示例:

reg [3:0] test1; integer test2; always @(test1) begin test2 = test1; end // NO syntax errors when compiling

當(dāng)您將具有reg數(shù)據(jù)類型的信號分配給具有不同數(shù)據(jù)類型(如integer )的另一個信號時,  Verilog 編譯器不會像在 VHDL 中那樣引入語法錯誤。 

?VHDL 復(fù)雜數(shù)據(jù)類型與 Verilog 簡單數(shù)據(jù)類型

如上所述,VHDL 有許多不同的復(fù)雜數(shù)據(jù)類型,用戶還可以定義許多其他復(fù)雜數(shù)據(jù)類型。這也使得 VHDL 比 Verilog 更冗長,因為 Verilog 只有 2 種主要數(shù)據(jù)類型,并且 Verilog 中不允許用戶定義的數(shù)據(jù)類型。

換句話說,為了對同一電路建模,VHDL 代碼通常比 Verilog 代碼更冗長、更長,因為 VHDL 的強類型,我們需要在不同的復(fù)雜數(shù)據(jù)類型之間執(zhí)行轉(zhuǎn)換。它可以是優(yōu)點也可以是缺點。事實上,當(dāng)您在 VHDL 代碼中分配錯誤的內(nèi)容時,VHDL 編譯器更有可能引入語法錯誤。當(dāng)您成功編譯 VHDL 代碼時,與 Verilog 相比,您的 VHDL 代碼更有可能正常工作。另一方面,Verilog 是松散類型的,更簡潔,更簡單。但是編譯成功后,很有可能你的Verilog代碼中仍然存在錯誤。 

下面是另一個使 VHDL 比 Verilog 更冗長的示例代碼:

-- VHDL code for ALU process(SEL,ABUS,BBUS,tmp1,tmp2)begin case(SEL) is when "0000" => ALUOUT <=< span=""> tmp1; -- ADD when "0001" => ALUOUT <=< span=""> tmp2;-- SUB when "0010" => ALUOUT <=< span=""> BBUS; -- AND when others => ALUOUT <=< span=""> ABUS; end case;end process;// Verilog equivalent to VHDL ALU assign ALUOUT=(SEL==0)?tmp1:((SEL==1)?tmp2:((SEL==2)?BBUS:ABUS));

VHDL 中的 if else、when/else、with/select 語句可以在 Verilog 中使用條件運算符 (?) 表達得更簡潔,如上例所示。 

Verilog 和 VHDL 之間的其他區(qū)別:

?Verilog 類似于C 編程語言,而 VHDL 類似于Ada或 Pascal 編程語言

?Verilog 區(qū)分大小寫,而 VHDL 不區(qū)分大小寫。這意味著DAta1和Data1在Verilog中是兩個不同的信號,但在VHDL中是相同的信號。

?在 Verilog 中,要在模塊中使用組件實例,您只需在模塊中使用正確的端口映射對其進行實例化。在VHDL中,在實例化實例之前,如果您使用舊的實例化語句作為以下示例,則通常需要將組件聲明為架構(gòu)或包中。在 VHDL-93 中,您可以像這樣直接實例化實體:“ Label_name: entity work.component_name port map (port list) ;”。

例如,要在 VHDL 中實例化實體 clk_div,將在體系結(jié)構(gòu)代碼中添加一個組件聲明,如下所示:

architecture Behavioral of digital_clock is-- component declaration before instantiation belowcomponent clk_divport ( clk_50: in std_logic; clk_1s : out std_logic );end component;signal clk, clk_1s: std_logic;begin-- component instantiationcreate_1s_clock: clk_div port map (clk_50 => 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(包括一個可以包含函數(shù)或其他聲明的文件)等。VHDL 沒有編譯器指令。 

?VHDL 支持枚舉和記錄數(shù)據(jù)類型,允許用戶為一種數(shù)據(jù)類型定義多個信號。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 之間存在差異,但它們是兩種最流行的硬件描述語言。如果可以,最好同時學(xué)習(xí)它們。重要的是要記住,在編碼時始終考慮邏輯門或硬件以開發(fā)硬件編碼思維,而在使用 Verilog 和 VHDL 編碼時忘記軟件編程思維,這一點非常重要。 

詳細對比

VHDL 與 VerilogHDL 的不同點

詳下一篇文章

序號

區(qū)別之處

VHDL

Verilog

1

文件的擴展名不一樣

.vhd

.v

2

結(jié)構(gòu)不一樣

包含庫、實體、結(jié)構(gòu)體。
ENTITY 實體名 IS
PORT(端口說明)
END 實體名 ;

ARCHITECTURE 結(jié)構(gòu)體名 OF 實體名 IS
說明部分
BEGIN
賦值語句/ 元件語句/ 進程語句
END 結(jié)構(gòu)體名 ;

模塊結(jié)構(gòu) (module… endmodule)
module 模塊名 (端口列表) ;
輸入/輸出端口說明; 變量類型說明;
assign 語句 (連續(xù)賦值語句) ;
元件例化語句;
always@(敏感列表)
begin

end
endmodule

其中assign語句、元件例化語句、always語句的順序可以更換

NOW現(xiàn)!

—— END ——
有你想看的精彩




聽大神聊FPGA設(shè)計:豁然開朗
ADC/DAC設(shè)計經(jīng)典問答
基于FPGA的快速傅立葉變換
Google版「鴻蒙」,F(xiàn)uchsia悄悄地來了
日本斷供光刻膠,國產(chǎn)迎頭趕上!100頁國產(chǎn)光刻膠研究框架PPT!
Arm推出首批Armv9架構(gòu)CPU和GPU,包括Cortex-X2,Cortex-A710和Mali-G710
耗時兩年,19歲小伙采用230片純74邏輯芯片搭建出32位Risc-V處理器!可玩貪吃蛇
SPI怎么玩?搞懂時序,運用自如
談?wù)刋ilinx FPGA設(shè)計的實現(xiàn)過程
Verilog_實現(xiàn)任意占空比、任意分頻的方法
【FPGA】幾種時序問題的常見解決方法
開源DIY墨水屏手表!外觀可鹽可甜,無線藍牙計步鬧鐘一應(yīng)俱全!
Verilog 版本:Verilog-95、Verilog-2001與System Verilog區(qū)別簡談
1202年了,還在使用虛擬機嗎?Win10安裝Ubuntu子系統(tǒng)及圖形化界面詳細教程



點個在看你最好看

    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多