1 / 47

Chapter 5 Verilog 硬體描述語言

Chapter 5 Verilog 硬體描述語言. Verilog 硬體描述語言的基本架構 Verilog 模組描述的基本格式 Verilog 的描述格式 Verilog 的資料型態 Verilog 的事件基礎時間控制 Verilog 的輸入輸出埠描述 Verilog 的行為描述語法. Chapter 5 Verilog 硬體描述語言. Verilog 硬體描述語言的基本架構 Verilog 模組描述的基本格式 如何開啟進入 Verilog 硬體描述語言編輯器 Verilog 的描述格式 Verilog 的資料型態 Verilog 的事件基礎時間控制

jaime-boyle
Download Presentation

Chapter 5 Verilog 硬體描述語言

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 5 Verilog 硬體描述語言 • Verilog硬體描述語言的基本架構 • Verilog模組描述的基本格式 • Verilog的描述格式 • Verilog的資料型態 • Verilog的事件基礎時間控制 • Verilog的輸入輸出埠描述 • Verilog的行為描述語法

  2. Chapter 5 Verilog硬體描述語言 • Verilog硬體描述語言的基本架構 • Verilog模組描述的基本格式 • 如何開啟進入Verilog硬體描述語言編輯器 • Verilog的描述格式 • Verilog的資料型態 • Verilog的事件基礎時間控制 • Verilog的輸入輸出埠描述 • Verilog的行為描述語法

  3. Verilog硬體描述語言的基本架構 module Switch-level Gate-level Dataflow-level Behavioral-level endmodule

  4. 模組內之四種層次描述電路 • 開關層次(Switch-Level):描述元件開關及儲存點組合而成 • 邏輯層次(Gate-Level):描述邏輯閘的連接形式 • 資料流層次(Data-Level):描述電路的資料如何在暫存器中儲存與傳送 • 行為層次(Behavioral-Level):描述模組之功能

  5. 暫存器轉移層次(Register-Transfer-Level, RTL) • 資料流層次(Data-Level) + 行為層次(Behavioral-Level)經合成而形成暫存器轉移層次(Register-Transfer-Level, RTL)

  6. Chapter 5 Verilog硬體描述語言 • Verilog硬體描述語言的基本架構 • Verilog模組描述的基本格式 • Verilog的描述格式 • Verilog的資料型態 • Verilog的事件基礎時間控制 • Verilog的輸入輸出埠描述 • Verilog的行為描述語法

  7. Verilog模組描述的基本格式 module <模組名稱><模組輸入輸出埠宣告> 模組四個層次的描述; endmodule

  8. 以開關層次描述一NOT閘之模組 module inv (ina, out); input ina; output out; supply1 vcc; supply0 gnd; pmos (out, vcc, ina); nmos (gnd, out, ina); endmodule

  9. 以邏輯閘層次描述一OR閘之模組 module ORGATE (A, B, F); input A; input B; output F; or u1(F, A, B); endmodule

  10. 以資料流層次描述一AND閘之模組 module ANDGATE (A, B, F); input A; input B; output F; wire F; assign F=A&B; endmodule

  11. 以行為層次描述一NAND閘之模組 module NANDGATE (A, B, F); input A; input B; output F; reg F; always @(A or B) begin F=~(A & B); end endmodule

  12. Chapter 5 Verilog硬體描述語言 • Verilog硬體描述語言的基本架構 • Verilog模組描述的基本格式 • Verilog的描述格式 • Verilog的資料型態 • Verilog的事件基礎時間控制 • Verilog的輸入輸出埠描述 • Verilog的行為描述語法

  13. Verilog 的基本語法規定 • 關鍵字如module, endmodule, assign, wire, always, input, output, begin, end…等必須使用小寫 • 識別字的大小寫是有差別的,第一個字必須是使用英文字母 • 單行註解用//; 多行註解用 /* … */ • 字串以雙引號表示,如 “This is a string”

  14. Verilog 的數字格式(1) • 有規定長度的數字(sized numbers) • <size>’<base format><number> • <size>:位元數 • <base format>:d10進位,h16進位, o 8進位,b 2進位 • Example: F=4’b0101; A=16’h6FA3

  15. Verilog 的數字格式(2) • 不規定長度的數字(unsized numbers) • ’<base format><number> • <base format>:d10進位,h16進位, o 8進位,b 2進位 • 位元數之大小由模擬器或硬體機定值來決定 • Example: b=’ha5; b=a5(32位元之16進位數)

  16. Verilog的運算子

  17. Chapter 5 Verilog硬體描述語言 • Verilog硬體描述語言的基本架構 • Verilog模組描述的基本格式 • Verilog的描述格式 • Verilog的資料型態 • Verilog的事件基礎時間控制 • Verilog的輸入輸出埠描述 • Verilog的行為描述語法

  18. (1)、數值組集(Value Set) • Verilog有四種表示數值,即 0、1、x、z以及八種信號強度

  19. (2) 、接線(net) • 接線(net)表示在硬體元件的接點連接線 • 關鍵字可以分為下列六種 • wire: 內定為一個位元的值,機定值為高阻抗 • wand: Wired-AND型接線 • waor: Wired-OR型接線 • tri • trior • trireg

  20. (3) 、暫存器(reg) • Verilog中reg相當於一個變數,其機定值為x • Example: reg out; 宣告一個out變數, reg所宣告的變數必須在always的區塊描述內使用 reg F; always @(A or B) begin F=~(A & B); end endmodule module NANDGATE (A, B, F); input A; input B; output F;

  21. (4) 、向量(Vectors) • 向量(Vectors)表示多位元的元件,wire及reg都可定義為向量格式 • Examples: • wire A[7:0]; //宣告有一8位元的BUS • reg [0:15] out; //宣告有一16位元寬度的向量暫存器變數out

  22. (5) 、整數(Integer) • 整數之關鍵字為integer,最少要32位元,integer宣告可帶正負號 • Example: integer count; initial count = 0;

  23. (6) 、實數(Real) • 實數之關鍵字為real,可用十進制或帶有指數表示 • Example: real w, x; initial begin w = 5.2; x = 25e6;

  24. (7) 、時間(Time) • 時間之關鍵字為time,主要功能在描述儲存模擬的時間,也就是取得目前的模擬時間,最少為64位元的資料 • Example: time storage_time; initial storage_time=$time

  25. (8) 、陣列(Arrays) • Verilog所提供陣列的儲存內容可以是整數、暫存資料、時間及向量,但不能為實數而且只適用於一維陣列 • 表示格式為<array_name>[<subscript>] • integer A[0:15];16個變數A的陣列 • reg [3:0] B[0:15];16個變數B的陣列,每一個B的位元寬度為4位元

  26. (9) 、記憶體(Memories) • 記憶體是一個暫存器的陣列,而陣列中的每一個物件都視為一個word,每一個word可以是1個位元或是多個位元所組成 • reg [15:0] memory1 [0:1023]/*宣告記憶體memory1為16位元1K word的大小*/ • reg memory2 [0:1023]/*宣告記憶體memory2為1位元1K word的大小*/

  27. (10) 、參數(Parameters) • 主要作用在設定一個固定常數,此常數可在每一次編譯時更改其值 • parameter LGG=100;//宣告一常數LGG等於100

  28. (11) 、字串(Strings) • 字串的作用在指定給暫存器,若長度大於reg的長度,則其左邊的位元會被刪掉,若長度小於reg的長度,則其左邊的位元會以零補之 • Reg [8*16:1] string_value; initial string_value=“good morning”

  29. Chapter 5 Verilog硬體描述語言 • Verilog硬體描述語言的基本架構 • Verilog模組描述的基本格式 • Verilog的描述格式 • Verilog的資料型態 • Verilog的事件基礎時間控制 • Verilog的輸入輸出埠描述 • Verilog的行為描述語法

  30. 事件基礎時間控制(Event-based timing control) • Event就是一個wire • 當暫存器改變時就是事件,此事件可用來觸發一個敘述或包含多個敘述的區塊,且模組的輸入埠接收到一個新值也算是一個事件 • Event-based timing control可包含(1) Regular event control (2) Named event control (3) Event OR control (4) Level-sensitive timing control

  31. Regular event control • 代表符號為@,它是表示當信號產生正緣(posedge),負緣(negedge),轉換(transition)或數值改變時,其相關敘述才會被執行 • always @(clock) Q=J; 當clock信號值改變時就執行 Q=J 敘述 • always @(posedge clock) Q=J; 當clock信號正緣觸發時就執行 Q=J 敘述

  32. Event OR control • 指使用多個信號或事件去觸發一個敘述或含有多個敘述的區塊來執行,因此將這些多個信號或事件以or(或)來表示 • always @(reset or clock or A or B) begin if (reset) F=1’b0; else if (clock) F=A+B; end

  33. Chapter 5 Verilog硬體描述語言 • Verilog硬體描述語言的基本架構 • Verilog模組描述的基本格式 • Verilog的描述格式 • Verilog的資料型態 • Verilog的事件基礎時間控制 • Verilog的輸入輸出埠描述 • Verilog的行為描述語法

  34. Verilog的輸入輸出埠描述 • 輸入埠(input) • 輸出埠(output) • 雙向埠(inout) • Examples module Addr(F1, F2, D, SUM, C0) input [3:0] F1, F2; output [3:0] SUM; output C0; input D;

  35. Chapter 5 Verilog硬體描述語言 • Verilog硬體描述語言的基本架構 • Verilog模組描述的基本格式 • Verilog的描述格式 • Verilog的資料型態 • Verilog的事件基礎時間控制 • Verilog的輸入輸出埠描述 • Verilog的行為描述語法

  36. Always • Always是屬於並行迴圈,其事件一旦被觸發,其區塊中的敘述將會被執行,觸發一次執行一次行程無窮迴圈 always@(事件1 or 事件2 or … or 事件n) begin <敘述區> end

  37. 「 Begin … end 」 • 主要是將不同敘述同時集中,做法與C語言的“{”與“}”一樣,當敘述址為一行時,則Begin … end可以拿掉 begin:<方塊名稱> <資料型態宣告>; . . . end 各種敘述

  38. 「 If 」「 else if 」「 else 」 • If 跟 else if 為條件判斷式,只要達成If 或是 else if 的判斷條件,則執行內部的敘述區塊,否則執行else內部的敘述區塊 • If (判斷條件1) begin <敘述區塊> end else if (判斷條件2) begin <敘述區塊> end else if (判斷條件3) begin <敘述區塊> end . . . else begin <敘述區塊> end

  39. 「 If 」「 else if 」「 else 」 cont’ • 通常if else if else會出現在Always迴圈底下,因為Always屬於並行迴圈,若再搭配條件判斷便可以進行串列(下面程式藍色部分) 與並列(下面程式綠色部分)處理。 Always@(判斷條件1 or 判斷條件2 or … or 判斷條件n) begin if (判斷條件1) begin <敘述區塊> end if (判斷條件2) begin <敘述區塊> end else begin <敘述區塊> end end Always@(判斷條件1 or 判斷條件2 or … or 判斷條件n) begin if (判斷條件1) begin <敘述區塊> end else if (判斷條件2) begin <敘述區塊> end else begin <敘述區塊> end end 二個if會同時判斷

  40. EX. • Always @(posedge CLK or negedge CLR) //如果CLK在正緣觸發或是CLR在負緣觸發時便執行 //下面的敘述 begin //如同C語法的{ if (!CLR) //如果觸發的是CLR且為0則執行以下敘述 q=1’b0; //如果觸發的是CLR且為0則q清除為0,一行故if敘述式可加可不加begin end else //否則,如果不是CLR的觸發(也就是CLK時) begin //因為else裡面敘述事不只一個,故要加begin end q=d; //若不是CLR則q輸出d(輸入端)的資料 cont = cont +1; end //因為else裡面敘述事不只一個,故要加begin end end //如同C語法的}

  41. 「 Case … endcase 」 • Case 類似if else的寫法,依照case後面的條件狀況判斷式,來判斷要進入哪一個狀況執行裡面的敘述式,否則執行default(類似else)裡面的敘述式。 case (條件狀況判斷式) 狀況1: begin <敘述式1> end 狀況2: begin <敘述式2> end . . . default: begin <敘述式n> end endcase

  42. EX. • Case (s) //若S的狀態改變時便進入case敘述式 2’b00: //若S的狀態式2bit 00的話便進入以下敘述式 begin //敘述式開始 y = i[0]; cont = cont+1; end //敘述式結束 2’b01: //若S的狀態式2bit 01的話便進入以下敘述式 begin //敘述式開始 y = i[1]; cont = cont+1; end //敘述式結束 2’b10: //若S的狀態式2bit 10的話便進入以下敘述式 begin //敘述式開始 y = i[3]; cont = cont+1; end //敘述式結束 default: //否則進入以下敘述式 begin //敘述式開始 y = i[4]; cont = cont+1; end //敘述式結束 endcase //本case敘述式結束

  43. 「 While 」 • 在While語法中,後面所接的條件判斷式如果為“真”則一直執行While內部的敘述式,直到該判斷式為“假”才停止執行。 while (條件判斷式) begin <敘述式> end

  44. EX. Parameter i=10; //設定 i = 10 while (i>0) //如果i >0的話就執行內部敘述式,一直到i <0結束 begin //敘述式開始 $display(“i=%d”,i); //把i的值用十進制的方式顯示出來 i= i-1; //目的是要把i減到停止執行while迴圈(即i<0) end //敘述式結束

  45. Question & Answer

More Related