可編程邏輯器件及EDA技術實驗報告.doc_第1頁
可編程邏輯器件及EDA技術實驗報告.doc_第2頁
可編程邏輯器件及EDA技術實驗報告.doc_第3頁
可編程邏輯器件及EDA技術實驗報告.doc_第4頁
可編程邏輯器件及EDA技術實驗報告.doc_第5頁
已閱讀5頁,還剩20頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

可編程邏輯器件及EDA技術實驗報告一、組合邏輯電路設計 數(shù)字邏輯電路按照邏輯功能的特點分為兩類,一類是組合邏輯電路,簡稱為組合電路;另一類是時序邏輯電路,簡稱為時序電路。組合電路的特點是電路任意時刻輸出狀態(tài)只取決該時刻的輸入狀態(tài),而與該時刻錢的電路狀態(tài)無關。1、邏輯門電路設計實驗原理:邏輯門電路包括基本邏輯門電路和符合邏輯門電路。VHDL語言可以直接支持的邏輯運算符共有七種邏輯運算,它們是: NOT 邏輯非 AND 邏輯與 NAND 邏輯與非 OR 邏輯或 NOR 或非 XOR 異或 XNOR 異或非實驗內容:例3-2的參考程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee. std_logic_unsigned.all;entity example3_2 is port(a,b,c,d:in std_logic; f:out std_logic_vector(3 downto 0);end example3_2;architecture behavioral of example3_2 isbeginf(0)=(a and b)or(b and c)or(not b and not c);f(1)=(a and b and c)or not(not a or not b or not c);f(2)=(a xor b xor c)or(not(d)and(a or c);f(3)=not (a and b)xor (c and d)or(a and b and d)xor(b and c and d);end behavioral;實驗分析:用邏輯運算符是實現(xiàn)了相對較為復雜的邏輯運算。參考程序中使用括號來強制控制邏輯運算的優(yōu)先級,對于用VHDL設計,這種寫法是必修的。用這種方法可以簡單、快捷地完成邏輯電路設計。電路結構圖:實驗波形仿真如下圖:2、常用編碼器設計編碼是指用文字、符號和數(shù)碼等來表示某種信息的過程。在數(shù)字系統(tǒng)中,由于采用二進制運算來處理數(shù)據(jù),因此通常是將信息編成若干位二進制代碼,而在邏輯電路中,信號都是以高、低電平的形式給出的。實現(xiàn)編碼的數(shù)字電路稱作編碼器(encoder),編碼器的邏輯功能就是把輸入的每一個高低電平信號編成一組對應的二進制代碼。實驗原理:根據(jù)8線-3線優(yōu)先編碼器的真值表可得,優(yōu)先編碼器的編碼輸入、編碼輸出均為低電平有效,且有使能輸入和使能輸出功能。實驗內容:例3.4試用VHDL設計一個8線-3線優(yōu)先編碼器,編碼器輸出為反碼輸出。它的程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity example3_4 is port(sin:in std_logic; i:in std_logic_vector(7 downto 0); a:out std_logic_vector(2 downto 0); e,s:out std_logic);end example3_4;architecture behavioral of example3_4 isbegin process(sin,i) begin if sin=1 then a=111;e=1;s=1; else if i(7)=0 then a=000;e=0;s=1; elsif i(6)=0 then a=001;e=0;s=1; elsif i(5)=0 then a=010;e=0;s=1; elsif i(4)=0 then a=011;e=0;s=1; elsif i(3)=0 then a=100;e=0;s=1; elsif i(2)=0 then a=101;e=0;s=1; elsif i(1)=0 then a=110;e=0;s=1; elsif i(0)=0 then a=111;e=0;s=1; else a=111;e=1;s segment segment segment segment segment segment segment segment segment segment segment segment segment segment segment segment NULL ; END CASE ; END PROCESS ; END ;實驗分析:當共陰極數(shù)碼管的某一陽極接高電平時,相應的二極管發(fā)光,若要顯示某字形,則使相應幾段的二極管發(fā)光即可,所以共陰極數(shù)碼管需要有輸出高電平有效的譯碼器去驅動,而共陰極數(shù)碼管則需要輸出低電平有效的譯碼器去驅動。上面程序是一個能驅動共陽極數(shù)碼管的7段譯碼器的VHDL程序。實驗波形仿真如下:4、數(shù)據(jù)選擇器設計 數(shù)據(jù)選擇器(multiplexer)是在地址選擇信號的控制下,從多路輸入數(shù)據(jù)中選擇一路作為輸出的邏輯電路,叫做多路開關,簡稱MUX。實驗原理:在可編程邏輯器件的設計中經常用數(shù)據(jù)選擇器來實現(xiàn)課編程邏輯器件內部數(shù)據(jù)總線的連接。實驗內容:例3.7試用VHDL設計4選1數(shù)據(jù)選擇器。參考程序:Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_arith.all;Use ieee.std_logic_unsigned.all;Entity example3_7 is Port(d:in std_logic_vector(3 downto 0); a:in std_logic_vector(1 downto 0); e:in std_logic; f:out std_logic);end example3_7;architecture behavioral of example3_7 isbegin process(e,a,d) begin if e=0then case a is when 00 =ffff=d(3); end case; end if;end process;end behavioral;實驗分析:一個4選1數(shù)據(jù)選擇器,D3D0為4個數(shù)據(jù)輸入,F(xiàn)為數(shù)據(jù)輸出,A1、A0是地址選擇輸入。當A1、A0為不同代碼時,D3D0中不同輸入通道數(shù)據(jù)送至輸出端F。E為使能端,當E=0時,數(shù)據(jù)選擇器正常工作,否則禁止工作。實驗波形仿真:5、數(shù)據(jù)分配器設計 在數(shù)字信號的傳輸過程中,常常需要將一路數(shù)據(jù)分配到多路通道中去。實現(xiàn)這種功能的邏輯電路,叫做數(shù)據(jù)分配器(Demultiplexer),簡稱DEMUX,其電路為單輸入、多輸出形式。實驗內容:例3.10試用VHDL設計兩總線數(shù)據(jù)分配器。它的參考程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity example3_10 is port(sel:in std_logic; a,b:in std_logic_vector(7 downto 0); mux_out: out std_logic_vector(7 downto 0);end example3_10;architecture behavioral of example3_10 isbegin process(sel,a,b) begin if sel=1 then mux_out=a; else mux_out=b; end if; end process;end behavioral;實驗分析:D為被傳輸?shù)臄?shù)據(jù)輸入,A、B是(地址)選擇輸入,Q0Q3為數(shù)據(jù)輸出。電路結構圖:實驗波形仿真圖:6、數(shù)值比較器設計數(shù)值比較器是用來比較兩個數(shù)據(jù)之間市值關系的電路。按照比較的數(shù)據(jù)類型劃分,數(shù)值比較器可分為無符號數(shù)二進制比較器和有符號數(shù)二進制比較器。實驗內容:例3.12試用VHDL設計兩個8位有符號數(shù)的數(shù)值比較器,比較分別輸出大于、小于和相等的結果。它的程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity example3_12 is port(a,b:in std_logic_vector(7 downto 0); gt,eq,lt:out std_logic);end example3_12;architecture behavioral of example3_12 issignal sab:std_logic_vector(1 downto 0);begin sab if a(6 downto 0)b(6 downto 0) then gt=1;eq=0;lt=0; elsif a(6 downto 0)=b(6 downto 0)then gt=0;eq=1;lt=0; else gt=0;eq=0;lt gt=1;eq=0;lt gt=1;eq=0;lt if a(6 downto 0)b(6 downto 0) then gt=0;eq=0;lt=1; elsif a(6 downto 0)=b(6 downto 0)then gt=0;eq=1;lt=0; else gt=1;eq=0;lt gt=0;eq=1;lt=0; end case; end process; end behavioral;實驗分析:從程序可以看到,利用并置的方法從輸入數(shù)據(jù)中分離出符號位,然后用case語句將符號位的四種組態(tài)分開,分別處理。實驗波形仿真圖: 7、算術運算單元電路設計實驗原理:算術運算單元電路是構成處理器CPU的算術邏輯單元(ALU)的一個重要組成部分。實驗內容:例3.13試用VHDL設計一個8位二進制數(shù)的加法器。它的程序如下: library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity fulladder is port(ai,bi,cin:in std_logic; si,cio:out std_logic);end fulladder;architecture behavioral of fulladder isbeginsi=(ai xor bi)xor cin;cio=(ai and bi)or(cin and ai)or(cin and bi);end behavioral;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity example3_13 is port(a,b:in std_logic_vector(7 downto 0); ci:in std_logic; co:out std_logic; s:out std_logic_vector(7 downto 0);end example3_13;architecture behavioral of example3_13 is component fulladderport(ai,bi,cin:in std_logic; si,cio:out std_logic);end component;signal carry:std_logic_vector(8 downto 0);begincarry(0)=ci;coa(i), bi=b(i), cin=carry(i), si=s(i), cio=carry(i+1);end generate gen;end behavioral;實驗分析:8位二進制加法器可以由8個全加器通過級聯(lián)的方式構成。實驗波形仿真圖如下:二、時序邏輯電路設計根據(jù)邏輯電路功能,邏輯電路可分為組合邏輯電路和時序邏輯電路兩大類。其特點是電路任意時刻的穩(wěn)態(tài)輸出僅取決于該時刻的輸入信號,而與電路原來的狀態(tài)無關。1、 常用觸發(fā)器設計實驗原理:觸發(fā)器(flip-flop)是能存儲一位二進制數(shù)的邏輯電路,是時序邏輯電路的基本單元電路。觸發(fā)器具有兩個穩(wěn)定狀態(tài),用來表示邏輯狀態(tài)或二進制數(shù)的0和1。實驗內容:例3.14試用VHDL設計一個D觸發(fā)器。它參考程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all; ENTITY example3_14 IS PORT (CLK : IN STD_LOGIC ; D : IN STD_LOGIC ; Q : OUT STD_LOGIC ); END ; ARCHITECTURE behavioral OF example3_14 IS BEGIN PROCESS (CLK) BEGIN IF CLKEVENT AND CLK = 1 THEN Q = D ; END IF; END PROCESS ; END;電路結構圖:實驗波形仿真圖:實驗原理:對于時序電路的控制,通??梢詣澐譃橥椒绞胶彤惒椒绞?。同步方式是指控制信號只有在時鐘有效時才起作用,簡稱同步控制;異步方式是指控制系統(tǒng)起作用不需要時鐘信號有效,簡稱異步控制。實驗內容:例3.15試用VHDL設計一個具有異步復位和同步置位的D觸發(fā)器。它的參考程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity example3_15 is port(d: in std_logic; clk: in std_logic; clr,set: in std_logic; q: out std_logic);end example3_15;architecture behavioral of example3_15 isbegin process(clk,clr,set) begin if clr=1 then q=0; elsif rising_edge(clk) then if set=1 then q=1; else q=d; end if; end if; end process;end behavioral;電路結構圖:實驗波形仿真圖:2、常用數(shù)碼寄存器設計 數(shù)碼寄存器用于寄存數(shù)據(jù),不能進行數(shù)據(jù)移位。它被廣泛地應用于各類數(shù)字計算機和數(shù)字系統(tǒng)中。一般來說,寄存器是借助時鐘脈沖的作用把數(shù)據(jù)寄存在觸發(fā)器內,寄存數(shù)據(jù)的位數(shù)和所用觸發(fā)器的個數(shù)是相等的,因為一個觸發(fā)器能儲存1位二進制碼,所以用N觸發(fā)器組成的寄存器能儲存一組N二進制碼。按照數(shù)碼寄存器的功能,可以把數(shù)碼寄存器的功能劃分為寄存器、鎖存器和移位寄存器等。實驗內容:例3.17試用VHDL設計一個8位鎖存器。它的參考程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity example3_17 is port(d: in std_logic_vector(7 downto 0); le: in std_logic; q: out std_logic_vector(7 downto 0);end example3_17;architecture behavioral of example3_17 issignal qin: std_logic_vector(7 downto 0);begin p1: process(d) begin if le=1then qin=d; end if; end process p1; p2: process(le) begin if falling_edge(le) then q= qin; end if; end process p2;end behavioral;實驗波形仿真圖:3、常用計數(shù)器設計 計數(shù)的功能就是累計輸入脈沖的個數(shù)。實現(xiàn)計數(shù)功能的數(shù)字電路就稱為計數(shù)器(counter)。被計數(shù)的脈沖(簡稱計數(shù)脈沖)可以是周期性脈沖,也可以是非周期性脈沖,它通常加載計數(shù)器的時鐘輸入端,作為計數(shù)器的時鐘脈沖。 計數(shù)器在循環(huán)中的狀態(tài)個數(shù)叫做計數(shù)器的模(modulus)。在循環(huán)中有m個狀態(tài)的計數(shù)器稱為模m計數(shù)器,或稱m分頻計數(shù)器。 實驗內容:例3.21試用VHDL設計一個十進制計數(shù)器。它的參考程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity example3_21 is port(en,clk: in std_logic; q: out std_logic_vector(3 downto 0); qcc: out std_logic);end example3_21;architecture behavioral of example3_21 issignal qtemp: std_logic_vector(3 downto 0);begin process(clk,en) begin if clkevent and clk=1then if en=1then if qtemp=1001then qtemp=0000; else qtemp=qtemp+1; end if; end if; end if; end process;q=qtemp;qcc=qtemp(3) and qtemp(2) and qtemp(0) and qtemp(0);end behavioral;電路結構圖:實驗波形仿真圖:三、有限狀態(tài)機(finite state machine)是由寄存器和組合邏輯構成的硬件時序電路。同步有限狀態(tài)機的狀態(tài)只能在同一時鐘跳變沿的情況下才能從一個狀態(tài)轉向另一個狀態(tài)。有限狀態(tài)機按照結構劃分為mealy型和moore型。1、 Mealy型狀態(tài)機設計實驗原理:Mealy型狀態(tài)機的輸出信號是當前狀態(tài)和所有輸入信號的函數(shù)。Mealy型狀態(tài)機的輸出是在輸入變化后立即發(fā)生變化,且輸入變化可能出現(xiàn)在時鐘周期內的任何時候,因而mealy型狀態(tài)機隊輸入的響應比Moore型狀態(tài)機對輸入的響應早一個時鐘周期。實驗內容:例3.23試用VHDL設計實現(xiàn)交通燈控制器的mealy型狀態(tài)機,其中T1,T2,T3分別代表三個定時器的溢出信號,三個定時器代表紅燈、綠燈和黃燈點亮時間;reset信號代表復位信號。它的參考程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity example3_23 is port (reset,clk: in std_logic; t1,t2,t3: in std_logic; r,g,y: out std_logic);end example3_23;architecture behavioral of example3_23 is type state_type is (red,green,yellow); signal state,next_state:state_type;beginsync_ptoc: process(clk) begin if (clkevent and clk =1)then if(reset =1)then state = red; else state = next_state; end if; end if;end process;-mealy state machine-outputs based on state and inputsoutput_decode: process(state,t1,t2,t3)begin if(state =red and t1 =0)then r=1; g=0; y=0; elsif (state = green and t2 = 0)then r=0; g=1; y=0; elsif (state = yellow and t3 = 0)then r=0; g=0; y=1; end if;end process;next_state_decode: process(state,t1,t2,t3)begin next_state if t1 =1 then next_state if t2 =1 then next_state next_state next_state= red; end case; end process;end behavioral;實驗波形仿真圖:2、 Moore型狀態(tài)機設計實驗原理:Moore型狀態(tài)機的輸出只與當前狀態(tài)有關,而與當前輸入無關。Moore型狀態(tài)機在時鐘跳變后的有限個門延遲之后,輸出達到穩(wěn)定值。輸出會在一個完整的時鐘周期內保持穩(wěn)定,即使在該時鐘周期內輸入信號有變化,輸出也不會變化。輸入對輸出的影響要到下一個時鐘周期才能反映出來。把輸入和輸出隔離開來是Moore型狀態(tài)機的一個重要特點。 實驗內容:例3.24試用VHDL設計如實現(xiàn)空調系統(tǒng)的控制器的Moore型狀態(tài)機,其中high和low信號是來自室內溫度傳感器的輸出信號,分別表示室內溫度過高和過低,當兩者輸出均無效時代表室內溫度適中。如果溫度過高或者過低,則制冷控制信號cold或者制冷控制信號heat輸出有效。它的程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity example3_24 is port (reset,clk: in std_logic; high,low: in std_logic; cold,heat: out std_logic);end example3_24;architecture behavioral of example3_24 istype state_type is(too_high, too_low,well_situated);signal state, next_state: state_type;beginsync_proc:process(clk) begin if(clkevent and clk=1)then if(reset=1)then state= well_situated; else state= next_state; end if; end if; end process;-moore state machineoutput_decode: process(state) begin if state = too_high then cold=1; heat=0; elsif state = too_low then cold=0; heat=1; elsif state = well_situated then cold=0; heat=0; end if ; end process;next_state_decode: process(state,high,low) begin next_state if high=1then next_state = too_high; end if; if low=1then next_state if high=1then next_state= too_high; else next_state if low=1then next_state = too_low; else next_state next_state = well_situated; end case; end process;end behavioral;電路結構圖:實驗波形仿真圖:四、存儲器設計 存儲器按其類型可分為只讀存儲器、隨機存儲器和順序存儲器。用可編程邏輯器件的邏輯資源和其內部的嵌入式存儲器資源可以設計實現(xiàn)各種類型的存儲器。1、 只讀存儲器(ROM)的設計實驗原理:只讀存儲器(ROM)是一個非易失的存儲器。在FPGA中嵌入式存儲模塊的隨機存儲器(RAM)結構,用RAM結構實現(xiàn)ROM是通過FPGA的配置過程實現(xiàn)的。FPGA的綜合系統(tǒng)設計的ROM中數(shù)據(jù)文件直接綜合到配置數(shù)據(jù)文件中,每次FPGA在唄重新配置的同時也對FPGA內部編程為ROM的存儲器資源進行初始化,這樣就形成了實際意義上的ROM。實驗內容:例3.25試用VHDL設計一個8*8的ROM。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;use std.textio.all;entity example3_25 is port(clk: in std_logic; rd: in std_logic; data: out std_logic_vector(7 downto 0); address: in std_logic_vector(3 downto 0);end example3_25;architecture behavioral of example3_25 is type romtype is array(0 to 15)of bit_vector(7 downto 0); impure function rom_function_name(rom_file_name: in string) return romtype is file rom_file: text is in rom_file_name; variable line_name: line; variable rom_name: romtype; begin for i in romtyperange loop readline (rom_file, line_name); read (line_name, rom_name(i); end loop; return rom_name; end function;signal rom_name: romtype:=rom_function_name(file_name.men)

溫馨提示

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

評論

0/150

提交評論