數字邏輯設計及應用教學課件:5-1 verilog HDL-CHENYU_第1頁
數字邏輯設計及應用教學課件:5-1 verilog HDL-CHENYU_第2頁
數字邏輯設計及應用教學課件:5-1 verilog HDL-CHENYU_第3頁
數字邏輯設計及應用教學課件:5-1 verilog HDL-CHENYU_第4頁
數字邏輯設計及應用教學課件:5-1 verilog HDL-CHENYU_第5頁
已閱讀5頁,還剩57頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、Chapter 5 Hardware Description Language Verilog HDL structure Signal and operations Structure description Behavioral decriptionAbout the HDL?What is the HDL?Hardware Description Language Sofe Core Hard CoreWhy we used the HDL?Verilog HDLIEEE std1364-2001Verilog HDL and C LanguaueVerilog HDL and VHDL

2、Verilog HDL structureHardware module: Name、port and structure;Verilog HDL structuremodule majority (a,b,c,f);input a,b,c;output f;structure description;endmodule;Verilog HDL structuremodule inhibit (a,b,s);input 3.0 a,b;output 8.0 s;structure description;endmoduleSignal and operationsTwo kinds of si

3、gnal : port : input and output; wire : any connect nets in module;The value of signals: 0 1 z (高阻) x(未知)Verilog HDL structuremodule majority (a,b,c,f);input a,b,c;output f;wire w1,w2,w3;structure description;endmodule;Logic operators for bit data:y = a & b;y = a | b;y = a;y = a b;Signal and operatio

4、nsOperators for bus datas:y = a & b;y = a | b;y = ! a;y = a + b;y = a - b;y = a * b;Signal and operationsVerilog HDL structuremodule majority (a,b,c,f);input a,b,c;output f;wire w1,w2,w3;assign w1=a&b;assign w2=b&c;assign w3=a&c;assign f=w1|w2|w3;endmoduleVerilog HDL structuremodule majority (a,b,c,

5、f);input a,b,c;output f;assign f=(a&b)|(b&c)|(a&c);endmoduleUse built_in gates for designVerilog HDL structuremodule majority (a,b,c,f);input a,b,c;output f;wire w1,w2,w3;and u1(w1,a,b);and u2(w2,b,c);and u3(w3,a,c);or u4(f,w1,w2,w3); endmoduleexamplem o d u l e m o d u l e _ n a m e (p o r t _ l i

6、s t) ;D e c l a r a t i o n s :reg, wire, parameter,input, output, inout,function, task, . . .S t a t e m e n t s :Initial statementAlways statementModule instantiationGate instantiationUDP instantiationContinuous assignmente n d m o d u l eHalf Adderm o d u l e H a l f A d d e r (A, B, Sum, Carry)

7、; i n p u t A, B; o u t p u t Sum, Carry; a s s i g n #2 Sum = A B; a s s i g n #5 Carry = A & B;e n d m o d u l e模塊的名字是H a l f A d d e r。模塊有4個端口: 兩個輸入端口A和B,兩個輸出端口S u m和C a rry。由于沒有定義端口的位數, 所有端口大小都為1位;同時, 由于沒有各端口的數據類型說明, 這四個端口都是線網數據類型。模塊包含兩條描述半加器數據流行為的連續賦值語句。從這種意義上講,這些語句在模塊中出現的順序無關緊要,這些語句是并發的。每條語句的執

8、行順序依賴于發生在變量A和B上的事件。Half Adderm o d u l e H a l f A d d e r (A, B, Sum, Carry) ; i n p u t A, B; o u t p u t Sum, Carry; a s s i g n #2 Sum = A B; a s s i g n #5 Carry = A & B;e n d m o d u l e# 2指2個時間單位。使用編譯指令將時間單位與物理時間相關聯。這樣的編譯器指令需在模塊描述前定義,如下所示: timescale 1ns /100ps,此語句說明時延時間單位為1 n s并且時間精度為100ps (時

9、間精度是指所有的時延必須被限定在0 . 1 n s內)。如果此編譯器指令所在的模塊包含上面的連續賦值語句, #2 代表2 n s。時延舉例 t i m e s c a l e 1ns/ 1nsm o d u l e D e c o d e r 2 x 4 (A, B, EN, Z) ; i n p u t A, B, EN; o u t p u t 0 :3 Z; wire Abar, Bbar; assign #1 Abar = A; / 語/ 句1。 assign #1 Bbar = B; / 語/ 句2。 assign #2 Z0 = (Abar & Bbar & EN ) ; / /

10、語句3。 assign #2 Z1 = (Abar & B & EN) ; / / 語句4。 assign #2 Z2 = (A & Bbar & EN) ; / / 語句5。 assign #2 Z3 = ( A & B & EN) ; / / 語句6。e n d m o d u l e以反引號“ ”開始的第一條語句是編譯器指令, 編譯器指令 t i m e s c a l e 將模塊中所有時延的單位設置為1 n s,時間精度為1 ns。例如,在連續賦值語句中時延值# 1和# 2分別對應時延1 ns 和2 ns。Verilog HDL設計的行為功能使用下述過程語句結構描述:1) initia

11、l語句:此語句只執行一次。2) always語句:此語句總是循環執行, 或者說此語句重復執行。initial語句 t i m e s c a l e 1ns / 1nsm o d u l e Test (Pop, Pid) ; o u t p u t Pop, Pid; r e g Pop, Pid; i n i t i a l b e g i n P o p = 0; / 語句1。 P i d = 0; / 語句2。 P o p = #5 1; / 語句3。 P i d = #3 1; / 語句4。 Pop = #6 0; / 語句5。 P i d = #2 0; / 語句6。 e n de

12、 n d m o d u l ei n i t i a l語句包含一個順序過程。這一順序過程在0 ns時開始執行,并且在順序過程中所有語句全部執行完畢后, initial語句永遠掛起。這一順序過程包含帶有定義語句內時延的分組過程賦值的實例。語句1和2在0 ns時執行。第三條語句也在0時刻執行,導致P o p 在第5 ns時被賦值。語句4在第5 ns 執行,并且P i d 在第8 ns被賦值。同樣,P o p在14 ns被賦值0,P i d在第16 ns被賦值0。第6條語句執行后, i n i t i a l語句永遠被掛起。2) always語句a l w a y s ( A o r B o r

13、 C i n ) b e g i n Sum = (A B) Cin ; T1 = A & Cin; T2 = B & Cin; T3 = A & B; C o u t = (T 1| T 2) | T 3;e n dalways 語句中有一個與事件控制(緊跟在字符 后面的表達式)。相關聯的順序過程( b e g i n - e n d對)。這意味著只要A、B或C i n 上發生事件,即A、B或C i n之一的值發生變化,順序過程就執行。在順序過程中的語句順序執行,并且在順序過程執行結束后被掛起。順序過程執行完成后,always 語句再次等待A、B或C i n上發生的事件。To realize

14、 it in Quartus What is quartus Nothing is more important than practice!Build your first project!Any way, programs must belong to a project. A project include one or more verilog HDL files and other files,such as waveform file to simulate and diagram? files which also work as verilog files. The first

15、 practice1.Open quartus 2.Create a new project with project WIZARD3.Create our first verilog file4.Edit it5.Build it6.Create our first waveform fileThe first practice7.config the waveform file8.simulate our work9.view the conclusion10.How to write your code into FPGATipBy this way,You can write a CP

16、U in FPGA!Its Nothing but digital circuit!A door to hardware engineer opened!Congradulations!After your first projectYou can use Quartus to practice what you learn!If you try every example in our book, you can master digital logic and will be a good engineer!Lets go on to learn basic knowledge of ve

17、rilog!Assign連續賦值語句將值賦給線網(連續賦值不能為寄存器賦值),它的格式如下(簡單形式):a s s i g n LHS_target = RHS_expressio;n例如,w i r e 3:0 Z, Preset, Clear; /線網說明 a s s i g n Z = Preset & Clear; /連續賦值語句連續賦值的目標為Z,表達式右端為“ Preset & Clear”。注意連續賦值語句中的關鍵詞a s s i g n。連續賦值語句在什么時候執行呢? 只要在右端表達式的操作數上有事件(事件為值的變化)發生時,表達式即被計算;如果結果值有變化,新結果就賦給左邊的

18、線網。在上面的例子中,如果P re s e t或C l e a r變化,就計算右邊的整個表達式。如果結果變化,那么結果即賦值到線網Z。Conditional operators :Verilog HDL中的操作符可以分為下述類型:1) 算術操作符2) 關系操作符3) 相等操作符4) 邏輯操作符5) 按位操作符6) 歸約操作符7) 移位操作符8) 條件操作符9) 連接和復制操作符Conditional operators :8) 條件操作符除條件操作符從右向左關聯外,其余所有操作符自左向右關聯。下面的表達式:A + B - C 等價于: (A + B ) - C / /自左向右而表達式:A ?

19、B : C ? D : F等價于: A ? B : (C ? D : F) /從右向左圓擴號能夠用于改變優先級的順序,如以下表達式: (A ? B : C) ? D : FConditional operators :8) 條件操作符條件操作符根據條件表達式的值選擇表達式,形式如下:c o n d_e x p r ? e x p r 1 : e x p r 2如果c o n d _ e x p r 為真(即值為1 ),選擇e x p r 1;如果c o n d _ e x p r為假(值為0 ),選擇e x p r 2。如 果c o n d _ e x p r 為x或z,結果將是按以下邏輯e

20、x p r 1和e x p r 2按位操作的值: 0與0得0,1與1得1, 其余情況為x。Conditional operators :a = ba != ba ba = ba ba = bassign y = (s ? a:b);assign y = (s=1 ? a|b:a&b);conditional operations and comparatorsFull adder module fa (x,y,cin,s,cout);input x,y,cin;output s,cout;assign s = (xy)cin;assign cout=(x&y)|(x&cin)|(y&cin);endmodulemodule fa (x,y,cin,s,cout);input x,y,cin;output s,cout;wire p,g;assign p=xy;assign g=x&y;assign s = pcin;assign cout=g|(p&cin);endmoduleFull adder Full addermodule adder_4(a,b,ci,sum,co);input 3:0a,b;input ci;output3:0sum;output co;assign co,sum=a+b+ci;endmodul

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論