




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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個(gè)端口: 兩個(gè)輸入端口A和B,兩個(gè)輸出端口S u m和C a rry。由于沒有定義端口的位數(shù), 所有端口大小都為1位;同時(shí), 由于沒有各端口的數(shù)據(jù)類型說明, 這四個(gè)端口都是線網(wǎng)數(shù)據(jù)類型。模塊包含兩條描述半加器數(shù)據(jù)流行為的連續(xù)賦值語(yǔ)句。從這種意義上講,這些語(yǔ)句在模塊中出現(xiàn)的順序無(wú)關(guān)緊要,這些語(yǔ)句是并發(fā)的。每條語(yǔ)句的執(zhí)
8、行順序依賴于發(fā)生在變量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個(gè)時(shí)間單位。使用編譯指令將時(shí)間單位與物理時(shí)間相關(guān)聯(lián)。這樣的編譯器指令需在模塊描述前定義,如下所示: timescale 1ns /100ps,此語(yǔ)句說明時(shí)延時(shí)間單位為1 n s并且時(shí)間精度為100ps (時(shí)
9、間精度是指所有的時(shí)延必須被限定在0 . 1 n s內(nèi))。如果此編譯器指令所在的模塊包含上面的連續(xù)賦值語(yǔ)句, #2 代表2 n s。時(shí)延舉例 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; / 語(yǔ)/ 句1。 assign #1 Bbar = B; / 語(yǔ)/ 句2。 assign #2 Z0 = (Abar & Bbar & EN ) ; / /
10、語(yǔ)句3。 assign #2 Z1 = (Abar & B & EN) ; / / 語(yǔ)句4。 assign #2 Z2 = (A & Bbar & EN) ; / / 語(yǔ)句5。 assign #2 Z3 = ( A & B & EN) ; / / 語(yǔ)句6。e n d m o d u l e以反引號(hào)“ ”開始的第一條語(yǔ)句是編譯器指令, 編譯器指令 t i m e s c a l e 將模塊中所有時(shí)延的單位設(shè)置為1 n s,時(shí)間精度為1 ns。例如,在連續(xù)賦值語(yǔ)句中時(shí)延值# 1和# 2分別對(duì)應(yīng)時(shí)延1 ns 和2 ns。Verilog HDL設(shè)計(jì)的行為功能使用下述過程語(yǔ)句結(jié)構(gòu)描述:1) initia
11、l語(yǔ)句:此語(yǔ)句只執(zhí)行一次。2) always語(yǔ)句:此語(yǔ)句總是循環(huán)執(zhí)行, 或者說此語(yǔ)句重復(fù)執(zhí)行。initial語(yǔ)句 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; / 語(yǔ)句1。 P i d = 0; / 語(yǔ)句2。 P o p = #5 1; / 語(yǔ)句3。 P i d = #3 1; / 語(yǔ)句4。 Pop = #6 0; / 語(yǔ)句5。 P i d = #2 0; / 語(yǔ)句6。 e n de
12、 n d m o d u l ei n i t i a l語(yǔ)句包含一個(gè)順序過程。這一順序過程在0 ns時(shí)開始執(zhí)行,并且在順序過程中所有語(yǔ)句全部執(zhí)行完畢后, initial語(yǔ)句永遠(yuǎn)掛起。這一順序過程包含帶有定義語(yǔ)句內(nèi)時(shí)延的分組過程賦值的實(shí)例。語(yǔ)句1和2在0 ns時(shí)執(zhí)行。第三條語(yǔ)句也在0時(shí)刻執(zhí)行,導(dǎo)致P o p 在第5 ns時(shí)被賦值。語(yǔ)句4在第5 ns 執(zhí)行,并且P i d 在第8 ns被賦值。同樣,P o p在14 ns被賦值0,P i d在第16 ns被賦值0。第6條語(yǔ)句執(zhí)行后, i n i t i a l語(yǔ)句永遠(yuǎn)被掛起。2) always語(yǔ)句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 語(yǔ)句中有一個(gè)與事件控制(緊跟在字符 后面的表達(dá)式)。相關(guān)聯(lián)的順序過程( b e g i n - e n d對(duì))。這意味著只要A、B或C i n 上發(fā)生事件,即A、B或C i n之一的值發(fā)生變化,順序過程就執(zhí)行。在順序過程中的語(yǔ)句順序執(zhí)行,并且在順序過程執(zhí)行結(jié)束后被掛起。順序過程執(zhí)行完成后,always 語(yǔ)句再次等待A、B或C i n上發(fā)生的事件。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連續(xù)賦值語(yǔ)句將值賦給線網(wǎng)(連續(xù)賦值不能為寄存器賦值),它的格式如下(簡(jiǎn)單形式):a s s i g n LHS_target = RHS_expressio;n例如,w i r e 3:0 Z, Preset, Clear; /線網(wǎng)說明 a s s i g n Z = Preset & Clear; /連續(xù)賦值語(yǔ)句連續(xù)賦值的目標(biāo)為Z,表達(dá)式右端為“ Preset & Clear”。注意連續(xù)賦值語(yǔ)句中的關(guān)鍵詞a s s i g n。連續(xù)賦值語(yǔ)句在什么時(shí)候執(zhí)行呢? 只要在右端表達(dá)式的操作數(shù)上有事件(事件為值的變化)發(fā)生時(shí),表達(dá)式即被計(jì)算;如果結(jié)果值有變化,新結(jié)果就賦給左邊的
18、線網(wǎng)。在上面的例子中,如果P re s e t或C l e a r變化,就計(jì)算右邊的整個(gè)表達(dá)式。如果結(jié)果變化,那么結(jié)果即賦值到線網(wǎng)Z。Conditional operators :Verilog HDL中的操作符可以分為下述類型:1) 算術(shù)操作符2) 關(guān)系操作符3) 相等操作符4) 邏輯操作符5) 按位操作符6) 歸約操作符7) 移位操作符8) 條件操作符9) 連接和復(fù)制操作符Conditional operators :8) 條件操作符除條件操作符從右向左關(guān)聯(lián)外,其余所有操作符自左向右關(guān)聯(lián)。下面的表達(dá)式:A + B - C 等價(jià)于: (A + B ) - C / /自左向右而表達(dá)式:A ?
19、B : C ? D : F等價(jià)于: A ? B : (C ? D : F) /從右向左圓擴(kuò)號(hào)能夠用于改變優(yōu)先級(jí)的順序,如以下表達(dá)式: (A ? B : C) ? D : FConditional operators :8) 條件操作符條件操作符根據(jù)條件表達(dá)式的值選擇表達(dá)式,形式如下: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,結(jié)果將是按以下邏輯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. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 辦理許可證合同標(biāo)準(zhǔn)文本
- 倉(cāng)庫(kù)租賃安全合同樣本
- 辦會(huì)運(yùn)營(yíng)合同標(biāo)準(zhǔn)文本
- 離子色譜儀企業(yè)縣域市場(chǎng)拓展與下沉戰(zhàn)略研究報(bào)告
- 合金鎳粉企業(yè)數(shù)字化轉(zhuǎn)型與智慧升級(jí)戰(zhàn)略研究報(bào)告
- 包干價(jià)浮動(dòng)合同樣本
- 個(gè)人旅游包車合同樣本
- 個(gè)人代理業(yè)務(wù)轉(zhuǎn)讓合同樣本
- 勞務(wù)時(shí)間合同標(biāo)準(zhǔn)文本
- 勞務(wù)派合同樣本
- 北京市消防條例解讀
- 醫(yī)院檢驗(yàn)科實(shí)驗(yàn)室生物安全程序文件SOP
- JTG D70-2-2014 公路隧道設(shè)計(jì)規(guī)范 第二冊(cè) 交通工程與附屬設(shè)施
- 必修二英語(yǔ)單詞默寫
- 新人教版四年級(jí)數(shù)學(xué)下冊(cè)總復(fù)習(xí)專題一《四則運(yùn)算及運(yùn)算定律》課件
- 宋詞欣賞《虞美人·聽雨》課件
- 封條模板A4直接打印版
- 混合痔病歷范文
- 110kV線路光纜施工方案及安全管控
- 35KV高壓開關(guān)柜買賣合同
- 典雅中國(guó)風(fēng)工筆畫PPT模板
評(píng)論
0/150
提交評(píng)論