版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、數(shù)字集成電路設(shè)計入門-從HDL到版圖于敦山 北大微電子學(xué)系第五章 Verilog的詞匯約定(Lexical convention)理解Verilog中使用的詞匯約定認識語言專用標記(tokens)學(xué)習(xí)timescale學(xué)習(xí)內(nèi)容:術(shù)語及定義空白符:空格、tabs及換行Identifier: 標志符,Verilog中對象(如模塊或端口)的名字Lexical: 語言中的字或詞匯,或與其相關(guān)。由其文法(grammar)或語法(syntax)區(qū)分。LSB:最低有效位(Lease significant bit)MSB:最高有效位(Most significant bit)空白符和注釋module MUX
2、2_1 (out, a, b, sel); / Port declarations output out; input sel, / control input b, /* data inputs */ a;/* The netlist logic selects input ”a” when sel = 0 and it selects ”b” when sel = 1.*/ not (sel_, sel); and (a1, a, sel_), (b1, b, sel); / What does this line do? or (out, a1, b1);endmodule格式自由使用空
3、白符提高可讀性及代碼組織。Verilog忽略空白符除非用于分開其它的語言標記。多行注釋,在/* */內(nèi)單行注釋到行末結(jié)束整數(shù)常量和實數(shù)常量整數(shù)的大小可以定義也可以不定義。整數(shù)表示為: 其中 size :大小,由十進制數(shù)表示的位數(shù)(bit)表示。缺省為32位 base:數(shù)基,可為2(b)、8(o)、10(d)、16(h)進制。缺省為10進制 value:是所選數(shù)基內(nèi)任意有效數(shù)字,包括X、Z。實數(shù)常量可以用十進制或科學(xué)表示法表示。 Verilog中,常量(literals)可是整數(shù)也可以是實數(shù)12 unsized decimal (zero-extended to 32 bits)H83a uns
4、ized hexadecimal (zero- extended to 32 bits)8b1100_ 0001 8-bit binary64hff01 64-bit hexadecimal (zero- extended to 64 bits)9O17 9-bit octal32bz01x Z-extended to 32 bits3b1010_ 1101 3-bit number, truncated to 3b1016.3 decimal notation32e- 4 scientific notation for 0.00324.1E3 scientific notation for
5、4100整數(shù)常量和實數(shù)常量整數(shù)的大小可以定義也可以不定義。整數(shù)表示為:數(shù)字中(_)忽略,便于查看沒有定義大小(size)整數(shù)缺省為32位缺省數(shù)基為十進制數(shù)基(base)和數(shù)字(16進制)中的字母無大小寫之分當(dāng)數(shù)值value大于指定的大小時,截去高位。如 2b1101表示的是2b01實數(shù)常量實數(shù)可用科學(xué)表示法或十進制表示科學(xué)表示法表示方式: , 表示: 尾數(shù)10指數(shù)字符串(string)字符串要在一行中用雙引號括起來,也就是不能跨行。字符串中可以使用一些C語言轉(zhuǎn)義(escape)符,如t n可以使用一些C語言格式符(如%b)在仿真時產(chǎn)生格式化輸出: ”This is a normal strin
6、g” ”This string has a t tab and ends with a new linen” ”This string formats a value: val = %b”Verilog中,字符串大多用于顯示信息的命令中。Verilog沒有字符串?dāng)?shù)據(jù)類型字符串(string)轉(zhuǎn)義符及格式符將在驗證支持部分討論 格式符%h%o%d%b%c%s%v%m%thexoctdecbinACSIIstringstrengthmoduletime轉(zhuǎn)義符tn”tab換行反斜杠雙引號ASCII representation of above格式符%0d表示沒有前導(dǎo)0的十進制數(shù)標識符(identi
7、fiers)標識符是用戶在描述時給Verilog對象起的名字標識符必須以字母(a-z, A-Z)或( _ )開頭,后面可以是字母、數(shù)字、( $ )或( _ )。最長可以是1023個字符標識符區(qū)分大小寫,sel和SEL是不同的標識符模塊、端口和實例的名字都是標識符module MUX2_1 (out, a, b, sel);output out;input a, b, sel; not not1 (sel_, sel); and and1 (a1, a, sel_); and and2 (b1, b, sel); or or1 (out, a1, b1);endmoduleVerilog標識符標
8、識符(identifiers)有效標識符舉例: shift_reg_a busa_index _bus3無效標識符舉例: 34net / 開頭不是字母或“_” a*b_net / 包含了非字母或數(shù)字, “$” “_” n238 /包含了非字母或數(shù)字, “$” “_”Verilog區(qū)分大小寫,所有Verilog關(guān)鍵詞使用小寫字母。轉(zhuǎn)義標識符( Escaped identifiers)可以包含任何可打印字符反斜杠及空白符不是標識符的一部分module 2:1MUX (out, a, b, sel);output out;input a, b, sel; not not1(sel ,sel); an
9、d and1( a1, a, sel ); and and2( b1, b, sel); or or1( out, a1, b1);endmodule使用轉(zhuǎn)義符可能會產(chǎn)生一些問題,并且不是所有工具都支持。有時用轉(zhuǎn)義符完成一些轉(zhuǎn)換,如產(chǎn)生邏輯圖的Verilog網(wǎng)表。綜合工具輸出綜合網(wǎng)表時也使用轉(zhuǎn)義符。不建議使用轉(zhuǎn)義符。轉(zhuǎn)義標識符由反斜杠“”開始,空白符結(jié)束Escaped Identifiers轉(zhuǎn)義標識符( Escaped identifiers)轉(zhuǎn)義標識符允許用戶在標識符中使用非法字符。如: #sel busa+ index A,B top. 3inst .net1 / 在層次化名字中轉(zhuǎn)義符 轉(zhuǎn)
10、義標識符必須以空格結(jié)束語言專用標記( tokens)系統(tǒng)任務(wù)及函數(shù) $符號指示這是系統(tǒng)任務(wù)和函數(shù)系統(tǒng)函數(shù)有很多,如:返回當(dāng)前仿真時間$time顯示/監(jiān)視信號值($display, $monitor)停止仿真$stop結(jié)束仿真$finish $monitor($time, “a = %b, b = %h”, a, b); 當(dāng)信號a或b的值發(fā)生變化時,系統(tǒng)任務(wù)$monitor顯示當(dāng)前仿真時間,信號a值(二進制格式), 信號b值(16進制格式)。語言專用標記( tokens)延時說明“#”用于說明過程(procedural)語句和門的實例的延時,但不能用于模塊的實例化。module MUX2_ 1
11、(out, a, b, sel) ;output out ;input a, b, sel ;not #1 not1( sel_, sel);and #2 and1( a1, a, sel_);and #2 and2( b1, b, sel);or #1 or1( out, a1, b1);endmodule門延時有很多類名字:門延時(gate delay),傳輸延時(propagation delay),固有延時(intrinsic delay),對象內(nèi)在延時(intra-object delay)編譯指導(dǎo)(Compiler Directives)( )符號說明一個編譯指導(dǎo)這些編譯指導(dǎo)使仿真
12、編譯器進行一些特殊的操作編譯指導(dǎo)一直保持有效直到被覆蓋或解除resetall 復(fù)位所有的編譯指導(dǎo)為缺省值,應(yīng)該在其它編譯指導(dǎo)之前使用文本替換(substitution) - define編譯指導(dǎo)define提供了一種簡單的文本替換的功能 define 在編譯時替換??商岣呙枋龅目勺x性。define not_delay #1define and_delay #2define or_delay #1module MUX2_1 (out, a, b, sel);output out;input a, b, sel;not not_delay not1( sel_, sel);and and_dela
13、y and1( a1, a, sel_);and and_delay and2( b1, b, sel);or or_delay or1( out, a1, b1);endmodule定義not_delay使用not_delay文本替換(substitution)解除定義的宏,使用 undef macro_name使用編譯指導(dǎo)define,可以提高描述的可讀性定義全局設(shè)計參數(shù),如延時和矢量的位數(shù)。這些參數(shù)可以定義在同一位置。這樣,當(dāng)要修改設(shè)計配置時,只需要在一個地方修改。定義Verilog命令的簡寫形式 define vectors_ file /usr1/chrisz/library/vec
14、tors define results_ file / usr1/chrisz/library/results可以將define放在一個文件中,與其它文件一起編譯。文本包含(inclusion) - include編譯指導(dǎo)include在當(dāng)前內(nèi)容中插入一個文件 格式: include “”如include global.vinclude parts/count. vinclude ././library/mux. v”include可用于:include保存在文件中的全局的或經(jīng)常用到的一些定義,如文本宏在模塊內(nèi)部include一些任務(wù)(tasks),提高代碼的可維護性??梢允窍鄬β窂交蚪^對路徑
15、Timescaletimescale 說明時間單位及精度格式:timescale / 如:timescale 1 ns / 100 ps time_unit: 延時或時間的測量單位time_precision: 延時值超出精度要先舍入后使用timescale必須在模塊之前出現(xiàn)timescale 1 ns / 10 ps/ All time units are in multiples of 1 nanosecondmodule MUX2_1 (out, a, b, sel);output out;input a, b, sel;not #1 not1( sel_, sel);and #2 an
16、d1( a1, a, sel_);and #2 and2( b1, b, sel);or #1 or1( out, a1, b1);endmoduleTimescaletime_precision不能大于time_unittime_precision和time_unit的表示方法:integer unit_stringinteger : 可以是1, 10, 100unit_string: 可以是s(second), ms(millisecond), us(microsecond), ns(nanosecond), ps(picosecond), fs(femtosecond)以上integer
17、和unit_string可任意組合precision的時間單位應(yīng)盡量與設(shè)計的實際精度相同。precision是仿真器的仿真時間步。若time_unit與precision_unit差別很大將嚴重影響仿真速度。如說明一個timescale 1s / 1ps,則仿真器在1秒內(nèi)要掃描其事件序列1012次;而timescale 1s/1ms則只需掃描103次。如果沒有timescale說明將使用缺省值,一般是ns。Timescale所有timescale中的最小值決定仿真時的最小時間單位。這是因為仿真器必須對整個設(shè)計進行精確仿真 在下面的例子中,仿真時間單位(STU)為100fstimescale 1ns/ 10psmodule1 (. . .);not #1.23 (. . .) / 1.23ns or 12300 STUs. . .endmoduletimescale 100ns/ 1nsmodule2 (. . .);not #1.23 (. . .) / 123ns or 1230000 STUs. . .endmoduletimescale 1ps/ 100fsmodule3 (. . .);not #1.23 (. . .) / 1.23ps or 12 STUs (rounded off). . .endmodule復(fù)習(xí)Verilog中的空白符總是忽
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 贛州江理至善服務(wù)管理有限公司招聘勞務(wù)派遣制工作人員 備考題庫必考題
- 陜西選調(diào)生2026年崗位在哪兒看參考題庫附答案
- 2025廣西防城港市東興海關(guān)緝私分局招聘緝私警務(wù)輔助人員4人考試備考題庫必考題
- 吉安市新廬陵大數(shù)據(jù)有限公司2026年面向社會招聘派遣員工的備考題庫附答案
- 2026湖北省定向北京師范大學(xué)選調(diào)生招錄參考題庫必考題
- 2026江西九江市贛北勞動保障事務(wù)代理所招聘勞務(wù)派遣制員工22人參考題庫附答案
- 阿壩師范學(xué)院2025年下半年公開選調(diào)工作人員(1人)參考題庫附答案
- 2025年陵川縣事業(yè)單位考試真題
- 2025年撫州市臨川區(qū)事業(yè)單位真題
- 門診部護理科研與創(chuàng)新實踐
- GB/T 16895.6-2014低壓電氣裝置第5-52部分:電氣設(shè)備的選擇和安裝布線系統(tǒng)
- GB/T 11018.1-2008絲包銅繞組線第1部分:絲包單線
- GB 31633-2014食品安全國家標準食品添加劑氫氣
- 麻風(fēng)病防治知識課件整理
- 手術(shù)室物品清點護理質(zhì)量控制考核標準
- 消防工程監(jiān)理實施細則
- 雙排樁支護設(shè)計計算書
- 權(quán)利的游戲雙語劇本-第Ⅰ季
- 衛(wèi)生部《臭氧消毒技術(shù)規(guī)范》
- 早期復(fù)極綜合征的再認識
- 山西某2×150MW循環(huán)流化床空冷機組施工組織設(shè)計方案
評論
0/150
提交評論