版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、可編程邏輯電路設(shè)計,Digital Design Using PLD,可編程邏輯電路設(shè)計教學(xué)組,二○○七年,PLD設(shè)計的VHDL語言實現(xiàn),(概述及組合邏輯部分),Hardware Description Language (HDL),數(shù)字系統(tǒng)的描述方式HDL語言既包含一些高級程序設(shè)計語言的結(jié)構(gòu)形式,也兼顧描述硬件線路連接的構(gòu)件,可以支持從系統(tǒng)級到門級的各個層次的行為描述和結(jié)構(gòu)描述。HDL語言基本特征是并發(fā)的(硬件的基本特
2、征),但也提供順序功能的描述手段。HDL語言特點:文本輸入適于設(shè)計大系統(tǒng)——表達(dá)功能,隱藏細(xì)節(jié)高表達(dá)效率易修改、開發(fā)周期短通用語言,模塊可重用性好常用HDL語言:VHDL、Verilog-HDL、AHDL,VHDL語言,Very high speed integrated circuit HDLIEEE工業(yè)標(biāo)準(zhǔn)HDL語言可支持仿真與綜合兩個版本:1076-19871076-1993,VHDL程序結(jié)構(gòu),1、USE定
3、義區(qū)Library——定義所使用的元件庫Package——定義所使用的元件庫中的包2、Entity定義區(qū):定義電路實體的I/O接口規(guī)格3、Architecture定義區(qū):描述電路內(nèi)部具體功能Component定義區(qū)信號定義行為描述/數(shù)據(jù)流描述/結(jié)構(gòu)描述4、Configuration定義區(qū):決定使用哪一個architecture(非必須),Use定義區(qū),Library IEEE;--庫定義Use IEEE.
4、std_logic_1164.all;--包引用Use IEEE.std_logic_arith.all;--包引用引用語句的用法:Library ,;Use lib_name.pack_name.object;,Packages,Package isConstant DecclarationsType DeclarationsSignal DeclarationsSubprogram
5、 DeclarationsComponent DeclarationsOther DeclarationsEnd ;(1076-1987)End Package ;(1076-1993)Package Body isConstant DeclarationsType DeclarationsSubprogram BodyEnd Package ;(1076-1987)
6、End Package Body (1076-1993),Package Example,package package_example istype life is (sleeping, working, eating, entertaiment, otheractions);subtype uint4 is integer range 0 to 15;subtype uint5 is integer range
7、0 to 31;function compare(a, b: integer) return boolean;end package_example;package body package_example isfunction compare(a,b: integer) return boolean isvariable temp:boolean;beginif a<b thentemp:=
8、true;elsetemp:=false;end if;return temp;end compare;end package_example;,Libraries,包括一系列的packages隱含Libraries: 不用聲明,自動引用STD:Standard:定義bit, Boolean, integer, real和time以及支持它們的運(yùn)算符。Textio:定義文件操作。Work: I
9、EEE:Std_logic_1164Std_logic_arithStd_logic_signedStd_logic_unsigned其它庫: Altera的元件庫用戶自定義庫,Entity(實體),Entity定義語法Entity isgeneric declarationsport declarationsEnd ;Entity ExampleEntity adder isgeneri
10、c(data_width:integer:=4 );port( add_a, add_b: in std_logic_vector(data_width-1 downto 0);sum: out std_logic_vector(data_width downto 0) );End adder;,Generic & Port Declarations,Generic Declarations用于將參數(shù)傳入En
11、tity。例如:數(shù)據(jù)線寬度,器件的延時參數(shù)、負(fù)載電容電阻、驅(qū)動能力、功耗等等。Port Declarations: port_name: : :管腳的模式In (輸入)- Out (輸出)Buffer (輸出帶內(nèi)部反饋)- Inout (雙向): 數(shù)據(jù)類型Boolean: False, TrueBit: ’0’, ‘1’Std_logic: ‘X’, ‘0’, ‘1’, ‘Z’, ‘-’, ‘W
12、’, ‘L’, ‘H’,支持多信號判決Std_ulogic: 與Std_logic類型一樣,不支持多信號判決Bit_vector & std_logic_vector: Integer: NaturalPositiveReal: time自定義數(shù)據(jù)類型:如數(shù)組等,Architecture(結(jié)構(gòu)體),描述設(shè)計的功能或者結(jié)構(gòu)必須與某個entity相聯(lián)系一個entity可以對應(yīng)多個architecture(編譯時通過
13、configuration來指定)Architecture中的各個語句是并發(fā)執(zhí)行的,對應(yīng)于電路硬件中的不同部件Architecture的描述風(fēng)格行為描述——描述實體的功能,RTL級算法描述數(shù)據(jù)流描述結(jié)構(gòu)描述——描述實體的結(jié)構(gòu),門級混合描述,Architecture組成,Architecture定義ARCHITECTURE arch_name OF entity_name ISsignal declarations;
14、constant declarations;type & subtype declarations;component declarations;subprogram declarations;BEGINProcess Statements;Concurrent Procedure Calls;Concurrent Signal Assignment;Conditional Signal As
15、signment;Selected Signal Assignment;Component Instantiation Statements;Generate Statements;END arch_name;,結(jié)構(gòu)描述例子——半加器,Architecture struct_ha of half_adder iscomponent and_gate port( a1,a2: in std_logic;
16、 a3: out std_logic);end component;component xor_gate port( a1,a2: in std_logic; a3: out std_logic);end component;Beging1: and_gate port map(a,b,c);g2: xor_gate port map(a,b,s);End struct
17、_ha;,行為描述例子——半加器,算法描述Architecture behave_ha of half_adder isBegin g1:process(a,b)begin if a=‘1’ and b=‘1’ thenc<=‘1’; elsec<=‘0’; end if;end process; g2:process(a,b)begin
18、 if a=‘1’ and b=‘0’ thenc<=‘1’; elsif a=‘0’ and b=‘1’c<=‘1’; elsec<=‘0’; end if;end process;End struct_ha;,數(shù)據(jù)流描述Architecture behave_ha of half_adder isBeginc<= a and b;s
19、<=a xor b;End struct_ha;,Configuration,用于將entity和architecture聯(lián)系起來廣泛應(yīng)用于仿真環(huán)境被綜合器有限支持或者不支持語法:Configuration of isfor end for;End;,數(shù)據(jù)對象,Constant(常數(shù))定義語法: Constant : := 用符號代表常數(shù),增加程序的可讀性和可維護(hù)性一經(jīng)定義,不得更改Signa
20、l(信號)定義語法: Signal : := 對應(yīng)于電路中的某一節(jié)點通常定義于entity、architecture或者package中,全局使用可再賦值 : “ : :=不對應(yīng)于具體電路中的節(jié)點,一般用于計算用途只局限于進(jìn)程和子程序中定義并使用可再賦值: “:=”對變量的賦值立即生效,信號和變量的區(qū)別——例1,一段程序:a, b: in std_logic;x, y: out std_logic;
21、signal temp: std_logic;process (a, b, temp)begintemp<=a;x<=temp;temp<=b;y<=temp;end process;等價電路圖:,另一段程序:a, b: in std_logic;x, y: out std_logic;process (a, b, temp) variable t
22、emp: std_logic;begintemp:=a;x<=temp;temp:=b;y<=temp;end process;等價電路圖:,信號和變量的區(qū)別——例2,一段程序:D, clk: in std_logic;x: out std_logic;signal temp: std_logic;process (clk)begin if (clk
23、’event and clk=‘1’) thentemp<=D;x<=temp; end if;end process;等價電路圖:,另一段程序:D, clk: in std_logic;x: out std_logic;process (clk) variable temp: std_logic; begin if (clk’event and
24、clk=‘1’) thentemp:=D;x<=temp; end if;end process;等價電路圖:,數(shù)據(jù)類型,基本數(shù)據(jù)類型邏輯類型: bit, boolean, std_logic, std_ulogic, std_logic_vector, bit_vector整數(shù)類型: Integer(及其子類如Natural, Positive), unsigned, signed實數(shù)類型:
25、 Real高級數(shù)據(jù)類型枚舉類型:定義語法:TYPE IS (, , )使程序易讀,例如在定義狀態(tài)機(jī)時數(shù)組類型:定義語法:TYPE IS ARRAY (integer1 DOWNTO integer2) OF 多用于定義ROM、RAM等,運(yùn)算符,關(guān)系運(yùn)算符:> = <= = /=邏輯運(yùn)算符:and, or, not, nand, nor, xor算術(shù)運(yùn)算符:+
26、 - * / MOD REM ** ABS其他運(yùn)算符:+(正號) -(負(fù)號) &(連接) 運(yùn)算符重載對于不同的數(shù)據(jù)類型定義同樣一個運(yùn)算,其實際操作可能不同。例如+(加)運(yùn)算,可以對整數(shù)使用,也可以對std_loigc_vector等類型用(在std_logic_arith包中定義)。通常定義與package中。IEEE的package中定義了大量的重
27、載運(yùn)算符,Vector信號的分解與合并,Architecture rtl of test issignal a: std_logic_vector(3 downto 0);signal b: std_logic_vector(0 to 3);signal c: std_logic_vector(0 to 1);signal d: std_logic_vector(1 downto 0);Beginc<=a(2
28、 downto 1);b<=A(3) & D & ‘1’End rtl;,并發(fā)語句,VHDL程序的結(jié)構(gòu)體中的各個語句是并發(fā)的,代表電路的不同節(jié)點,它們是同時運(yùn)作的并發(fā)語句的順序不影響其執(zhí)行結(jié)果并發(fā)語句列表:直接信號賦值: <=條件信號賦值:when--else選擇信號賦值:select—when進(jìn)程:process斷言:assert——面向仿真的語句,不能綜合塊語句:BlockComp
29、onent語句For-Generate,When--else,語法: when else when else……….. when else ;特點:各個條件可以不互斥主要用于譯碼器、多路復(fù)接器和解復(fù)接器例子: q <= a when sel=“00” elseb when sel=“01” elsec when sel=“10” else
30、d;,Select--when,語法:with select when , when ,……….. when others;特點:各個條件必須互斥主要用于譯碼器、多路復(fù)接器和解復(fù)接器范例: with sel selectq <= a when “00”,b when “01”,c when “10”,d when others;,Blo
31、ck,用于將電路劃分成幾個模塊,增加程序的可讀性語法: blockBeginEnd block ;范例:Library ieee;Use ieee.std_logic_1164.all;Entity half_addsub isport(a,b: in std_logic;sum, carry: out std_logic;diff, borrow: out std_logic);End h
32、alf_addsub;,Architecture rtl of half_addsub isBeginHalf_adder: blocksum<=a xor b;carry<=a and b;End block half_adder;Half_sub: blockdiff<=a xor b;borrow<=(not a) and b;End block half_sub;End
33、rtl;,Component,Component定義語句:與entity類似 Component generic ( generic_declarations );port ( port_declarations);End component;Component例化語句:: generic map ( generic_mapping)port map (port_mapping);Port ma
34、p語句兩種格式:Port map ( =>, =>, …);Port map ( , , …);,Component范例——4位全加器,Library ieee;Use ieee.std_logic_1164.all;Entity full_adder_4 isport( A, B: in std_logic_vector(3 downto 0); ci: in std_logic;
35、 C: out std_logic_vector(3 downto 0); co: out std_logic);End full_adder_4;Architecture rtl of full_adder_4 iscomponent full_adder_1port(a,b: in std_logic;ci: in std_logic;c: out std_logic;co:
36、out std_logic);end component;signal t: std_logic_vector(2 downto 0);Begin,U0: full_adder_1port map(A(0),B(0),ci,C(0),t(0));U1: full_adder_1port map(A(1),B(1),t(0),C(1),t(1));U2: full_adder_1port map
37、(A(2),B(2),t(1),C(2),t(2));U3: full_adder_1port map(A(3),B(3),t(2),C(3),co);End rtl;,For-Generate,例化多個相同的Component語法:: For i in to generatecomponent例化語句;End generate ;范例: 4位全加器Architecture rtl of full_ad
38、der_4 is;signal t: std_logic_vector(4 downto 0);Begingen: for I in 0 to 3 generateadd1: full_adder_1 port map(A(i),B(i),t(i),C(i),t(i+1));end generate gen;t(0)<=ci;co<=t(4);End rtl;If-Generate語句可以
39、條件生成。生成語句可以嵌套。,順序語句,可用于進(jìn)程、函數(shù)和子程序中依次執(zhí)行,語句順序影響其執(zhí)行結(jié)果順序語句的執(zhí)行需要被激活順序語句列表:變量和信號賦值::= <=If語句:if--then--elsif--elseCase語句:case--whenLoop語句Wait語句,Process,特點:Process語句本身是一個并發(fā)式語句,但其內(nèi)部包含的是順序語句僅當(dāng)進(jìn)程的某個敏感信號發(fā)生變化時,進(jìn)程內(nèi)部
40、的順序語句塊才被激活依次執(zhí)行;否則進(jìn)程處于被掛起的狀態(tài)。進(jìn)程內(nèi)的變量在進(jìn)程被掛起和再次激活時,保持原值??梢酝ㄟ^兩種方式定義敏感信息:用敏感信息表或者用wait語句。但這兩者不能同時出現(xiàn)在一個進(jìn)程中(wait語句可以有多個)。定義語法:Process()constant declaration;type declarations;variable declarations;Beginsequential sta
41、tement #1;sequential statement #2; …….sequential statement #n;End process;,Process范例,Process(clk)Beginif (clk‘event and clk=‘1’) thenq<=d;end if;End process;ProcessBeginwait on clk;i
42、f clk’event and clk=‘1’ thennq<=not d;end if;End process;,Process——敏感列表,(1)正常的代碼Process (ck, d)Beginif ck=‘1’ thenq<=d;end if;End process;Max+plus II綜合結(jié)果:LatchFPGA Express綜合結(jié)果: Latch,(2)危險的代碼Pro
43、cess (ck)Beginif ck=‘1’ thenq<=d;end if;End process;Max+plus II綜合結(jié)果: D觸發(fā)器FPGA Express綜合結(jié)果: Latch,If語句,語法:If thensequential statements;Elsif thensequential statements; ……..Elsesequenti
44、al statements;End if;對應(yīng)于when-else語句,范例:if sel=“00” thenq<=a;elsif sel=“01” thenq<=b;elsif sel=“10” thenq<=c;elseq<=d;end if;,Case語句,語法:case is when =>sequential statements;
45、 when =>sequential statements; ……. when others=>sequential statements;end case;對應(yīng)于select-when語句,范例:case sel is when “00” =>q q q q<=d;end case;,Loop語句,無限循環(huán):使用Exit退出循環(huán)語法:: Loopsequ
46、ential statements;exit Loop_lable [when ];End loop;While循環(huán):根據(jù)條件結(jié)束循環(huán)While Loopsequential statements;End loop;For循環(huán):FOR IN Loopsequential statements;End loop;,Loop語句范例,例1Signal a: std_logic_vector(7 downt
47、o 0)Process (a)variable temp: std_logic;Begintemp:=‘1’;for I in 0 to 7 loop temp:=temp and a(i);end loop;b<=temp;End process;,,例2Signal a: std_logic_vector(7 downto 0)Process (a)variable cnt:
48、integer;variable temp: std_logic;Begintemp:=‘1’;cnt=0;while cnt<8 loop temp:=temp and a(cnt); cnt:=cnt+1;end loop;b<=temp;End process;,Subprogram,Package body of example is procedure p(A:
49、 in integer, B:inout integer) is begin B:=A+B; end; function inc(A: in integer) return integer is beginreturn (A+1) end;End example; 子程序調(diào)用范例:p(a,b);x<=inc(a);,用于描述一定的算法內(nèi)部是串行執(zhí)行—類似process可
50、以在程序中任何地方被調(diào)用調(diào)用方法類似于Component例化綜合結(jié)果是組合邏輯電路包括function和procedureFunction: 有返回值Procedure: 無返回值子程序定義范例:Package example is procedure p(A: in integer, B:inout integer); function inc(A: in integer) return integer;
51、Package example;,設(shè)計中應(yīng)注意的問題,Process的敏感列表應(yīng)完全I(xiàn)f, case-when語句應(yīng)注意條件的完備性盡量避免采用可能有歧義的語法使用IEEE提供的數(shù)據(jù)包中的函數(shù),IF語句對比,a,b: in std_logic;q: out std_logic;Process(a,b)beginIf a=‘1’ thenq<=b;End if;End process;Proce
52、ss(a,b)beginIf a=‘1’ thenq<=b;Elseq<=‘0’;End if;End process;,,,,,,a,b,q,,Library IEEE,定義了許多運(yùn)算符的重載函數(shù),方便實現(xiàn)各種組合邏輯和算術(shù)功能定義了各種數(shù)據(jù)類型的相互轉(zhuǎn)換函數(shù),如conv_signed()將其他類型如integer, unsigned在\maxplus2\vhdl93\ieee\目錄下可以看
53、這些庫文件的源代碼,例如arith.vhd是std_logic_arith包的聲明文件,而arithb.vhd是該包的body。,例:減法器,輸入:A: 二進(jìn)制無符號整數(shù),8位B: 二進(jìn)制無符號整數(shù),8位輸出C: 二進(jìn)制補(bǔ)碼表是整數(shù),9位功能:C=A-B要求:輸入輸出都是std_logic_vector類型。,Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_l
54、ogic_arith.all;Entity sub_8 isport( A,B: in std_logic_vector(7 downto 0);C: out std_logic_vector(8 downto 0));End sub_8;Architecture rtl of sub_8 issignal t1,t2: integer range 0 to 255;signal t3: integer
溫馨提示
- 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. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 組合邏輯電路和多態(tài)邏輯電路設(shè)計算法研究.pdf
- 基于憶阻器的可編程模擬電路設(shè)計.pdf
- 可編程邏輯器件設(shè)計技巧
- 實驗七 組合邏輯電路設(shè)計
- 試驗六 組合邏輯電路設(shè)計
- 基于fpga的時序邏輯電路設(shè)計
- 組合邏輯電路設(shè)計實驗報告
- 低功耗混合邏輯電路設(shè)計.pdf
- 組合邏輯電路設(shè)計實驗報告
- 可編程邏輯控制器plc
- 現(xiàn)場可編程邏輯系統(tǒng)的設(shè)計技巧
- 基于matlab的邏輯電路設(shè)計與仿真
- 簡易交通燈控制邏輯電路設(shè)計
- 課程設(shè)計---交通燈邏輯電路設(shè)計
- 可編程邏輯器件加密設(shè)計與實現(xiàn).pdf
- 0.18umfpga可編程邏輯單元設(shè)計與實現(xiàn)
- 外文翻譯---可編程邏輯控制器
- 可編程邏輯控制器 外文翻譯
- 外文翻譯--可編程邏輯控制器
- 外文翻譯--可編程邏輯控制器
評論
0/150
提交評論