第4章 VHDL設(shè)計(jì)提高_(dá)第1頁(yè)
第4章 VHDL設(shè)計(jì)提高_(dá)第2頁(yè)
第4章 VHDL設(shè)計(jì)提高_(dá)第3頁(yè)
第4章 VHDL設(shè)計(jì)提高_(dá)第4頁(yè)
第4章 VHDL設(shè)計(jì)提高_(dá)第5頁(yè)
已閱讀5頁(yè),還剩45頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

4.2常用邏輯電路的VHDL實(shí)現(xiàn)4.1VHDL設(shè)計(jì)邏輯電路的基本思想和方法第4章VHDL設(shè)計(jì)提高4.1

VHDL設(shè)計(jì)邏輯電路的基本思想和方法4.1.1邏輯函數(shù)表達(dá)式方法4.1.2真值表方法4.1.3電路連接描述方法4.1.4不完整條件語(yǔ)句方法4.1.5層次化設(shè)計(jì)方法利用VHDL中的邏輯運(yùn)算就可以實(shí)現(xiàn)任何組合邏輯電路的設(shè)計(jì)。4.1.1邏輯函數(shù)表達(dá)式方法在數(shù)字邏輯電路設(shè)計(jì)中,利用真值表來(lái)表達(dá)組合電路是非常常用的手段,其特點(diǎn)是直觀、明了,將真值表用VHDL描述出來(lái)也是硬件語(yǔ)言常用的方法之一。4.1.2真值表方法所謂電路連接描述方法,就是將給定的電路原理圖用portmap語(yǔ)句來(lái)實(shí)現(xiàn)。在電路中,某些元件不是基本元件,無(wú)法用邏輯函數(shù)表達(dá)式來(lái)表示,也就是說(shuō),無(wú)法用邏輯運(yùn)算來(lái)實(shí)現(xiàn)。4.1.3電路連接描述方法圖4.1電路連接描述法的圖例libraryieee;useieee.std_logic_1164.all;entitydff1isport(clk:instd_logic;d:instd_logic;q:outstd_lgoic);end;architecturebhvofdff1issignalq1:std_logic;beginprocess(clk,q1)beginifclk'eventandclk='1'thenq1<=d;endif;endprocess;q<=q1;endbhv;4.1.4不完整條件語(yǔ)句方法圖4.2QuartsII綜合后的RTL電路圖層次化設(shè)計(jì)方法是自頂向下設(shè)計(jì)方法的最好體現(xiàn)。自頂向下的設(shè)計(jì)方法將系統(tǒng)分解為各個(gè)模塊的集合后,可以對(duì)設(shè)計(jì)的每個(gè)獨(dú)立模塊分別設(shè)計(jì),最后將不同的模塊集成為最終的系統(tǒng),并對(duì)其進(jìn)行綜合測(cè)試和評(píng)價(jià)。4.1.5層次化設(shè)計(jì)方法圖4.312位全加器電路原理圖1.子模塊設(shè)計(jì)libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityadder4bisport(clr,cin:instd_logic;a,b:instd_logic_vector(3downto0);s:outstd_logic_vector(3downto0);cout:outstd_logic);endadder4b;architectureartofadder4bissignalsint:std_logic_vector(4downto0);signalaa,bb:std_logic_vector(4downto0);beginprocess(clr)beginifclr='1'thensint<="00000";elseaa<='0'&a;bb<='0'&b;sint<=aa+bb+cin;endif;s<=sint(3downto0);cout<=sint(4);endprocess;endart;a2.頂層模塊設(shè)計(jì)libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityadder12bisport(clr,cin:instd_logic;a,b:instd_logic_vector(11downto0);s:outstd_logic_vector(11downto0);cout:outstd_logic);endadder12b;architectureartofadder12biscomponentadder4bisport(clr,cin:instd_logic;a,b:instd_logic_vector(3downto0);s:outstd_logic_vector(3downto0);cout:outstd_logic);endcomponent;signalcarry_out0,carry_out1:std_logic; beginu1:adder4bportmap(clr=>clr,cin=>cin,a=>a(3downto0),b=>b(3downto0),s=>s(3downto0),cout=>carry_out0);u2:adder4bportmap(clr=>clr,cin=>carry_out,a=>a(7downto4),b=>b(7downto4),s=>s(7downto4),cout=>carry_out1);u3:adder4bportmap(clr=>clr,cin=>carry_out,a=>a(11downto8),b=>b(11downto8),s=>s(11downto8),cout=>cout);endart;4.2常用邏輯電路的VHDL實(shí)現(xiàn)4.2.1基本組合邏輯電路設(shè)計(jì)4.2.2基本時(shí)序邏輯電路設(shè)計(jì)4.2.3狀態(tài)機(jī)的設(shè)計(jì)4.2.1基本組合邏輯電路設(shè)計(jì)1.基本邏輯門圖4.4基本邏輯門2.三態(tài)門圖4.58位三態(tài)控制門電路3.?dāng)?shù)據(jù)選擇器

4.3線-8線譯碼器圖4.63線-8譯碼器端口圖下面用VHDL語(yǔ)言分別以兩種方法描述3線-8線譯碼器,其源程序如下。方法一:用case語(yǔ)句描述,利用真值表輔助,很容易編寫程序。libraryieee;useieee.std_logic_1164.all;entitydecoder3_8isport(a,b,c,g1,g2a,g2b:instd_logic;y:outstd_logic_vector(7downto0));end;architectureaofdecoder3_8issignaldz:std_logic_vector(2downto0);begindz<=c&b&a;process(dz,g1,g2a,g2b)beginif(g1='1'andg2a='0'andg2b='0')thencasedziswhen"000"=>y<="11111110";when"001"=>y<="11111101";when"010"=>y<="11111011";when"011"=>y<="11110111";when"100"=>y<="11101111";when"101"=>y<="11011111";when"110"=>y<="10111111";when"111"=>y<="01111111";whenothers=>y<="××××××××";endcase;elsey<="11111111";endif;endprocess;end;方法二:利用移位操作符SLL和程序包std_logic_unsigned中的數(shù)據(jù)類型轉(zhuǎn)換函數(shù)conv_integer可以十分簡(jiǎn)潔地完成3線-8線譯碼器的設(shè)計(jì)。(略去實(shí)體部分)architectureaofdecoder3_8isbeginoutput<="00000001"SLLCONV_INTEGER(input);end;方法三:也是利用移位操作符SLL,只不過(guò)是每次進(jìn)程的啟動(dòng)只改變一個(gè)端口的輸出。architecturebehaveofdecoder3_8isbeginprocess(input)beginoutput<=(others=>'0');output(conv_integer(input))<='1';endprocess;endbehave;5.優(yōu)先編碼器表4.2 8-3優(yōu)先編碼器的真值表輸入輸出din0din1din2din3din4din5din6din7output0output1output2×××××××0000××××××01100×××××011010××××0111011×××01111100××011111101×011111111001111111111libraryieee;useieee.std_logic_1164.allentitycoderisport(din:instd_logic_vector(0to7);output:outstd_logic_vector(0to2));end;architecturebehaveofcoderissignalsint:std_logic_vevtor(4downto0);beginprocess(din)beginif(din(7)='0')thenoutput<="000";elsif(din(6)='0')thenoutput<="100";elsif(din(5)='0')thenoutput<="010";elsif(din(4)='0')thenoutput<="110";elsif(din(3)='0')thenoutput<="001";elsif(din(2)='0')thenoutput<="101";elsif(din(1)='0')thenoutput<="011";elseoutput<="111";endif;endprocess;endbehav;6.七段碼譯碼器七段碼的輸出去驅(qū)動(dòng)七段碼顯示器,才能顯示正常的數(shù)字。圖4.7共陰極數(shù)碼管顯示器電路示意圖libraryieee;useieee.std_logic_1164.allentitydecl7sisport(a:instd_logic_vector(3downto0);led7s:outstd_logic_vector(6downto0));end;architecturebehaveofdecl7sisbegin圖4.7共陰極數(shù)碼管顯示器電路示意圖

process(a)begincaseaiswhen"0000"=>led7s<="0111111";when"0001"=>led7s<="0000110";when"0010"=>led7s<="1011011";when"0011"=>led7s<="1001111";when"0100"=>led7s<="1100110";when"0101"=>led7s<="1101101";when"0110"=>led7s<="1111101";when"0111"=>led7s<="0000111";when"1000"=>led7s<="1111111";when"1001"=>led7s<="1101111";when"1010"=>led7s<="1110111";when"1011"=>led7s<="1111100";when"1100"=>led7s<="0111001";when"1101"=>led7s<="1011110";when"1110"=>led7s<="1111001";when"1111"=>led7s<="1110001";whenothers=>null;endcase;endprocess;end;7.二-十進(jìn)制BCD譯碼器BCD譯碼器在電路設(shè)計(jì)中也經(jīng)常用到,尤其在計(jì)數(shù)、顯示、譯碼電路中。圖4.8BCD譯碼器端口圖libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;entitybcdymqisport(din:inintegerrange15downto0;a,b:outintegerrange9downto0);end;architecturefpq1ofbcdymqisbeginp1:process(din)beginifdin<10thena<=din;b<=0;elsea<=din-10;b<=1;endif;endprocessp1;end;8.多位加(減)法器下面以4位全減器為例來(lái)說(shuō)明,加法器可以用相似的方法實(shí)現(xiàn)。libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;entityjianfaqiisport(a,b:instd_logic_vector(0to3);c0:instd_logic;c1:outstd_logic;d:outstd_logic_vector(0to3));end;architectureaofjianfaqiisbeginprocessbeginifa>b+c0thend<=a-(b+c0);c1<='0';elsec1<='1';d<=("10000")-(b+c0-a);endif;endprocess;end;4.2.2基本時(shí)序邏輯電路設(shè)計(jì)T觸發(fā)器的動(dòng)作特點(diǎn)是翻轉(zhuǎn),我們以上升沿觸發(fā)的T觸發(fā)器設(shè)計(jì)為例進(jìn)行講解。1.觸發(fā)器

libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;entitytff1isport(t,clk:instd_logic;q:outstd_logic);end;architectureaoftff1issignalq_temp:std_logic;beginp1:process(clk)beginifrising_edge(clk)thenift='1'then--當(dāng)T=1時(shí)T觸發(fā)器具有2分頻的功能

q_temp<=notq_temp;elseq_temp<=q_temp;endif;endif;q<=q_temp;endprocess;q<=q_temp;end;2.計(jì)數(shù)器計(jì)數(shù)器是邏輯電路中使用最廣泛的電路,在復(fù)雜電路的設(shè)計(jì)中幾乎離不開(kāi)計(jì)數(shù)器。(1)n位二進(jìn)制計(jì)數(shù)器設(shè)計(jì)一般把計(jì)數(shù)器的模值M=2n、狀態(tài)編碼為自然二進(jìn)制數(shù)的計(jì)數(shù)器簡(jiǎn)稱為n位二進(jìn)制計(jì)數(shù)器。為了使設(shè)計(jì)的信號(hào)更具有工程實(shí)際的意義,下面的例子使用了一般情況下的in、out端口模式。libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entitycnt4IS port(clk :in std_logic;q :out std_logic_vector(3downto0) ); endcnt4;architecturebehaveofcnt4issignalq1:std_logic_vector(3downto0);beginprocess(clk)beginif(clk'eventandclk='1')thenq1<=q1+1;endif;endprocess;q<=q1;endbehave;圖4.94位二進(jìn)制計(jì)數(shù)器的仿真波形圖(2)一般計(jì)數(shù)器設(shè)計(jì)libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entitycnt10is port(clk,rst,en,updown:instd_logic;cq:outstd_logic_vector(3downto0)); endcnt10;architecturebehaveofcnt10isbeginprocess(clk,rst,en,updown)variablecqi:std_logic_vector(3downto0);beginifrst='1'thencqi:=(others=>'0'); --計(jì)數(shù)器異步復(fù)位

elsif(clk'eventandclk='1')then --檢測(cè)時(shí)鐘上升沿

ifen='1'then --檢測(cè)是否允許計(jì)數(shù)(同步使能)

ifupdown='0'thenifcqi<9thencqi:=cqi+1; --允許計(jì)數(shù),檢測(cè)是否小于9elsecqi:=(others=>'0'); --大于9,計(jì)數(shù)值清零

endif;elseifcqi>0thencqi:=cqi-1; --檢測(cè)是否大于0elsecqi:=(others=>'1'); --否則,計(jì)數(shù)值置1endif;endif;endif;endif;cq<=cqi; --將計(jì)數(shù)值向端口輸出endprocess;endbehave;圖4.10一般計(jì)數(shù)器的仿真波形圖3.分頻器分頻器電路的實(shí)質(zhì)其實(shí)還是計(jì)數(shù)器的設(shè)計(jì)。

下面介紹兩種任意分頻的方法。

方法一:利用計(jì)數(shù)器的進(jìn)位輸出端分頻。

要設(shè)計(jì)n分頻的分頻器,我們就設(shè)計(jì)一個(gè)N進(jìn)制計(jì)數(shù)器,將計(jì)數(shù)器的進(jìn)位作為分頻器的輸出。方法二:數(shù)控分頻器(通過(guò)改變并行置數(shù)值分頻)。

數(shù)控分頻器是利用計(jì)數(shù)值可并行預(yù)置的加法計(jì)數(shù)器設(shè)計(jì)完成的。方法是將計(jì)數(shù)器溢出位與預(yù)置數(shù)加載輸入信號(hào)相減。圖4.11數(shù)控分頻器的仿真波形圖4.移位寄存器方法一:利用信號(hào)的傳輸延遲性。圖4.12一般移位寄存器的仿真波形圖方法二:帶模式控制的移位寄存器。圖4.13帶模式控制的移位寄存器的仿真波形圖4.2.3狀態(tài)機(jī)的設(shè)計(jì)

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論