文章目錄
-
- 背景
- 正文介紹
- Verilog有什麼用途?
- 如何驗證Verilog設計的功能?
- Verilog設計模闆
內建電路的設計經曆了從原理圖繪制(工程師在紙上繪制半導體及其連接配接,以便對其設計,使其可以在矽上制造)到硬體描述語言的轉變,這是因為大型的設計,如果使用原理圖的方式進行設計會耗費大量的人力、時間和資源等,這催生着硬體描述語言的誕生!
硬體描述語言最開始出現的VHDL,它是1983年,應美國國防部要求開發的,目的是記錄供應商公司将其包括在裝置中的ASIC的行為。
硬體描述語言允許工程師描述所需硬體的功能,并使得EDA工具将該行為轉換為組合邏輯以及時序邏輯之類的實際硬體單元,VHDL很快得到了發展!
Verilog的開發旨在簡化開發流程,并使得硬體描述語言(HDL)更加的健壯和靈活。如果,Verilog已經成為全球使用地區最多的硬體描述語言。
如下圖,來自于參考資料2,顯示了使用Verilog以及VHDL的地域差別,
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中描述的硬體應如何工作并為設計模型提供各種輸入刺激。然後對照預期值檢查設計的輸出,以檢視設計在功能上是否正确。
所有仿真均由EDA(電子設計自動化)軟體工具執行,并且Verilog設計RTL放置在稱為testbench的平台内。在測試平台内,各種測試為設計提供了不同的刺激。下圖顯示了這樣的測試平台。
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