VHDL基本邏輯電路的設(shè)計(jì)_第1頁(yè)
VHDL基本邏輯電路的設(shè)計(jì)_第2頁(yè)
VHDL基本邏輯電路的設(shè)計(jì)_第3頁(yè)
VHDL基本邏輯電路的設(shè)計(jì)_第4頁(yè)
VHDL基本邏輯電路的設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩113頁(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)介

第六章VHDL基本邏輯電路的設(shè)計(jì)

哈爾濱工業(yè)大學(xué)(威海)信息工程學(xué)院電子工程系

第六章VHDL基本邏輯電路的設(shè)計(jì)

1.組合邏輯電路2.時(shí)序電路設(shè)計(jì)3.存儲(chǔ)器1組合邏輯電路設(shè)計(jì)1.1簡(jiǎn)單門(mén)電路1.2三態(tài)門(mén)及總線緩沖器1.3編、譯碼器與選擇器1.4加法器、求補(bǔ)器1.1簡(jiǎn)單門(mén)電路libraryIEEE;useIEEE.STD_LOGIC_1164.all;entitynand2is port( a:inSTD_LOGIC; b:inSTD_LOGIC; y:outSTD_LOGIC );endnand2;architecturenand2ofnand2isbeginy<=anandb; endnand2;&abyarchitecturenand2ofnand2isbegin process(a,b) variablecomb:std_logic_vector(1downto0); comb:=a&b; casecombis when"00"=>y<='1'; when"01"=>y<='1'; when“10"=>y<='1'; when“11"=>y<='0'; whenothers=>y<='Z'; endcase;endprocess;endnand2;或非門(mén)y<=anorb;+abycasecombis when"00"=>y<='1'; when"01"=>y<='1'; when“10"=>y<='1'; when“11"=>y<='0'; whenothers=>y<='Z';endcase;1.1簡(jiǎn)單門(mén)電路反相器y<=nota;ayifa='1'then y<='0';else y<='1';endif;1.1簡(jiǎn)單門(mén)電路異或門(mén)y<=axorb;+abycasecombis when"00"=>y<=‘0'; when"01"=>y<='1'; when“10"=>y<='1'; when“11"=>y<='0'; whenothers=>y<='Z';endcase;1.1簡(jiǎn)單門(mén)電路1.2三態(tài)門(mén)及總線緩沖器單元器件的三態(tài)輸出描述:引入中間信號(hào),采用條件賦值語(yǔ)句;例:

4輸入與非門(mén)y<=not(a0anda1anda2anda3);改為:y1<=not(a0anda1anda2anda3);y<=y1whenen='1'else'Z';數(shù)據(jù)傳輸控制單元:三態(tài)控制單向總線控制1.2三態(tài)門(mén)及總線緩沖器數(shù)據(jù)傳輸控制單元:三態(tài)控制單向總線控制74x541architecturedofk74541issignalen:std_logic;beginen<=not(g1org2);y<=awhenen='1'else(others=>'Z');endd;1.2三態(tài)門(mén)及總線緩沖器雙向緩沖器緩沖器adrben

endr功能00a=b01b=a1X三態(tài)雙向總線緩沖器真值表1.2三態(tài)門(mén)及總線緩沖器process(a,dr,en)beginifen='0'anddr='1'then bout<=a;else bout<="ZZZZZZZZ";endif;b<=bout;endprocess;process(a,dr,en)beginifen='0'anddr='0'then aout<=b;else aout<="ZZZZZZZZ";endif;a<=aout;endprocess;數(shù)據(jù)傳輸控制單元:三態(tài)控制雙向總線控制1.2三態(tài)門(mén)及總線緩沖器數(shù)據(jù)傳輸控制單元:三態(tài)控制雙向總線控制entityk74245isport(a,b:inoutstd_logic_vector(7downto0);dir,g:instd_logic);

endk74245;architecturedflofk74245isbeginb<=awhen(g='0')and(dir='0')else"ZZZZZZZZ";a<=bwhen(g='0')and(dir='1')else(others=>'Z');enddfl;數(shù)據(jù)傳輸控制單元:三態(tài)控制注意:雙向總線在功能仿真時(shí)的輸入設(shè)置a和b的輸入不要同時(shí)存在;設(shè)置a的輸入時(shí),則b為輸出,應(yīng)將b的輸入設(shè)置為高阻;反過(guò)來(lái)也是同樣;轉(zhuǎn)換傳輸方向時(shí),應(yīng)該以雙向阻塞作為間隔,避免出現(xiàn)沖突。1.2三態(tài)門(mén)及總線緩沖器數(shù)據(jù)傳輸控制單元:

MUX1.2三態(tài)門(mén)及總線緩沖器數(shù)據(jù)傳輸控制單元:

MUXMUX是電路中控制數(shù)據(jù)流動(dòng)最為常用的手段;根據(jù)控制量的數(shù)值由多路數(shù)據(jù)中選擇一路輸出;采用選擇賦值能夠非常直觀地表達(dá)MUX的概念;1.3編、譯碼器與選擇器數(shù)據(jù)傳輸控制單元:

MUX4路8位數(shù)據(jù)選擇器architecturertlofmux4in8bisbeginwithsselecty<=awhen"00",bwhen"01",cwhen"10",dwhen"11",(others=>'U')whenothers;endrtl;1.3編、譯碼器與選擇器數(shù)據(jù)傳輸控制單元:

MUXarchitecturebehofmux4in8pisbeginprocess(s,a,b,c,d)begincasesiswhen"00"=>y<=a;when"01"=>y<=b;when"10"=>y<=c;when"11"=>y<=d;whenothers=>y<=(others=>'U');endcase;endprocess;endbeh;采用進(jìn)程和case語(yǔ)句實(shí)現(xiàn)數(shù)據(jù)編碼轉(zhuǎn)換單元該類電路為多路輸入/多路輸出,將輸入的編碼轉(zhuǎn)換為對(duì)應(yīng)的輸出的編碼;采用選擇賦值語(yǔ)句可以對(duì)各類碼制轉(zhuǎn)換電路進(jìn)行設(shè)計(jì)。1.3編、譯碼器與選擇器數(shù)據(jù)編碼轉(zhuǎn)換單元:二進(jìn)制譯碼器architecturertlofv74x138issignalyli:std_logic_vector(0to7);beginwithaselectyli<="01111111"when"000","10111111"when"001","11011111"when"010","11101111"when"011","11110111"when"100","11111011"when"101","11111101"when"110","11111110"when"111","11111111"whenothers;yl<=yLiwhen(g1andnotg2alandnotg2bl)=‘1’else“11111111”;

endrtl;1.3編、譯碼器與選擇器數(shù)據(jù)編碼轉(zhuǎn)換單元:7段譯碼器輸入4位BCD碼,產(chǎn)生7個(gè)輸出,分別驅(qū)動(dòng)相應(yīng)顯示器件;考慮7段輸出與數(shù)字的對(duì)應(yīng)關(guān)系,可以得出如下關(guān)系

abcdefg0:0000--11111101:0001--01100002:0010--11011013:0011--1111001

1.3編、譯碼器與選擇器數(shù)據(jù)編碼轉(zhuǎn)換單元:7段譯碼器architecturedofbcdseg7isbeginy<="1111110"whendata="0000"else"0110000"whendata="0001"else"1101101"whendata="0010"else"1111001"whendata="0011"else"0110011"whendata="0100"else"1011011"whendata="0101"else"0011111"whendata="0110"else"1110000"whendata="0111"else"1111111"whendata="1000"else"1110011"whendata="1001"else“0000000”;

endd;數(shù)據(jù)編碼轉(zhuǎn)換單元:優(yōu)先編碼器architecturertlofkencoderissignala1:std_logic_vector(2downto0);begina1<="000"wheni(7)='0'else"001"wheni(7downto6)="10"else"010"wheni(7downto5)="110"else"011"wheni(7downto4)="1110"else"100"wheni(7downto3)="11110"else"101"wheni(7downto2)="111110"else"110"wheni(7downto1)="1111110"else"111";a<=a1whenel='0'else"111";endrtl;數(shù)據(jù)檢測(cè)單元:奇偶校驗(yàn)器奇偶校驗(yàn)電路是實(shí)現(xiàn)數(shù)據(jù)錯(cuò)誤檢驗(yàn)的一種基本電路,其方式是檢測(cè)在輸入數(shù)據(jù)中‘1’的個(gè)數(shù)是奇數(shù)還是偶數(shù);通常采用異或門(mén)的結(jié)構(gòu)實(shí)現(xiàn)。1.3編、譯碼器與選擇器數(shù)據(jù)檢測(cè)單元:奇偶校驗(yàn)器architecturertlofkparity9issignaly1,y2,y3,y:std_logic;beginy1<=i(1)xori(2)xori(3);y2<=i(4)xori(5)xori(6);y3<=i(7)xori(8)xori(9);y<=y1xory2xory3;odd<=y;even<=noty;endrtl;1.3編、譯碼器與選擇器半加器二進(jìn)制輸入和輸出進(jìn)位輸出basco0011010101100001半加器真值表半加器absco1.4加法器、求補(bǔ)器libraryIEEE;useIEEE.STD_LOGIC_1164.all;entityhalf_adderis port( a:inSTD_LOGIC; b:inSTD_LOGIC; s:outSTD_LOGIC; co:outSTD_LOGIC );endhalf_adder;architecturehalf_adderofhalf_adderissignalc,d:std_logic;beginc<=aorb;d<=anandb;co<=notd;s<=candd;endhalf_adder;全加器半加器ab+co半加器cinsU0_su1u2U0_co1.3編、譯碼器與選擇器libraryIEEE;useIEEE.STD_LOGIC_1164.all;entityfull_adderis port( a,b,cin:inSTD_LOGIC; co,s:outSTD_LOGIC);endfull_adder;architecturefull_adderoffull_adderiscomponenthalf_adder port( a,b:inSTD_LOGIC; s,co:outSTD_LOGIC);endcomponent;signalu0_co,u0_s,u1_co:std_logic;beginu0:half_adderportmap(a,b,u0_s,u0_co);u1:half_adderportmap(u0_s,b,cin,s,u1_co);co<=u0_cooru1_co;endfull_adder;時(shí)序電路的結(jié)構(gòu)與特點(diǎn)內(nèi)部含有存儲(chǔ)器件(觸發(fā)器、鎖存器);信號(hào)變化受時(shí)鐘控制;通常采用狀態(tài)變化進(jìn)行描述;采用進(jìn)程進(jìn)行設(shè)計(jì);2.時(shí)序電路設(shè)計(jì)同步時(shí)序電路的信號(hào)變化特點(diǎn)同步時(shí)序電路以時(shí)鐘信號(hào)為驅(qū)動(dòng);電路內(nèi)部信號(hào)的變化(或輸出信號(hào)的變化)只發(fā)生在特定的時(shí)鐘邊沿;設(shè)計(jì)要點(diǎn):時(shí)鐘邊沿的檢測(cè);輸出賦值的控制:是否改變、如何改變。2.時(shí)序電路設(shè)計(jì)同步時(shí)序電路的時(shí)鐘控制采用進(jìn)程描述可以有效控制執(zhí)行條件,進(jìn)程中的條件控制可以將時(shí)鐘信號(hào)(clk)做為控制信號(hào),只有當(dāng)時(shí)鐘信號(hào)變化時(shí),進(jìn)程才執(zhí)行;在時(shí)鐘條件不滿足時(shí),任何輸入信號(hào)的變化對(duì)電路(進(jìn)程)不起作用;2.時(shí)序電路設(shè)計(jì)VHDL中的時(shí)鐘檢測(cè)方式VHDL通常采用屬性語(yǔ)句檢測(cè)時(shí)鐘邊沿;與時(shí)鐘有關(guān)的屬性語(yǔ)句:clk'event:boolean,clk有變化時(shí)為true;clk‘last_value:bit,clk在變化之前的值;注意:上述屬性語(yǔ)句只能在子結(jié)構(gòu)中應(yīng)用(作為局部量)。2.時(shí)序電路設(shè)計(jì)VHDL中的時(shí)鐘檢測(cè)方式例:上升沿的檢測(cè):

clk'eventandclk='1';clk'eventandclk'last_value='0';在由上升沿導(dǎo)致的進(jìn)程執(zhí)行時(shí),上述兩個(gè)表達(dá)式的值都為true;而在由其他輸入變化導(dǎo)致的進(jìn)程執(zhí)行時(shí),上述表達(dá)式的值就是faith;2.時(shí)序電路設(shè)計(jì)時(shí)序電路的基本單元設(shè)計(jì)Latch:輸出受時(shí)鐘電平控制,在一段時(shí)間內(nèi)可受輸入變化影響發(fā)生而變化;(電平控制)flip-flop:輸出只在時(shí)鐘邊沿時(shí)刻發(fā)生變化,輸入信號(hào)變化不能直接導(dǎo)致輸出變化;(邊沿控制)2.時(shí)序電路設(shè)計(jì)時(shí)序電路的基本單元設(shè)計(jì)例:Dlatch的設(shè)計(jì)process(clk,d)

begin

ifclk='1'thenq<=d;

endif;endprocess;d和clk的任何變化都會(huì)導(dǎo)致進(jìn)程執(zhí)行;僅當(dāng)clk為1時(shí),d的變化才會(huì)導(dǎo)致q的變化;2.時(shí)序電路設(shè)計(jì)時(shí)序電路的基本單元設(shè)計(jì)例:Dflip-flop的設(shè)計(jì):process(clk,d)

begin

ifclk'eventandclk='1'thenq<=d;

endif;endprocess;d和clk的任何變化都會(huì)導(dǎo)致進(jìn)程執(zhí)行;只有在clk上升沿引發(fā)的進(jìn)程執(zhí)行中,d的變化才會(huì)導(dǎo)致q的變化;觸發(fā)沿選擇與清零設(shè)置問(wèn)題:process(clk,clr)

begin

ifclr='1'thenq<='0';

elsifclk'eventandclk='1'thenq<=d;

endif;endprocess;異步清零,上升沿觸發(fā);2.時(shí)序電路設(shè)計(jì)觸發(fā)沿選擇與清零設(shè)置問(wèn)題:process(clk,clr)begin

ifclk'eventandclk='0'

ifclr='0'thenq<='0';

elseq<=d;

endif;

endif;endprocess;下降沿觸發(fā),同步清零;2.時(shí)序電路設(shè)計(jì)時(shí)序電路的基本單元設(shè)計(jì)采用wait語(yǔ)句進(jìn)行時(shí)鐘檢測(cè):processbeginwaitonclk; ifclk='1'then

q<=d;

endif;endprocess;2.時(shí)序電路設(shè)計(jì)時(shí)序電路的基本單元設(shè)計(jì)采用wait語(yǔ)句進(jìn)行時(shí)鐘檢測(cè):processbegin

waituntilclk='0';q<=d;endprocess;2.時(shí)序電路設(shè)計(jì)關(guān)于寄存器生成的控制問(wèn)題寄存器的作用是在輸入信號(hào)變化時(shí),保持輸出信號(hào)不變;當(dāng)程序設(shè)計(jì)中隱含這一要求時(shí),就會(huì)在綜合時(shí)引入寄存器;寄存器只在滿足一定條件時(shí)才允許改變輸出值,因此只能通過(guò)條件判斷語(yǔ)句才會(huì)引入寄存器;2.時(shí)序電路設(shè)計(jì)關(guān)于寄存器生成的控制問(wèn)題例1:寄存器的引入process(clk,d)begin

ifclk='1'thenq<=d;elseq<='0';

endif;endprocess;2.時(shí)序電路設(shè)計(jì)關(guān)于寄存器生成的控制問(wèn)題例1:寄存器的引入process(clk,d)begin

ifclk='1'thenq<=d;

endif;endprocess;2.時(shí)序電路設(shè)計(jì)關(guān)于寄存器生成的控制問(wèn)題例2:雙輸出D觸發(fā)器的設(shè)計(jì)比較1:process(clk)beginif(clk'eventandclk='1')then qi<=d;q<=qi;qn<=notqi;endif;endprocess;2.時(shí)序電路設(shè)計(jì)關(guān)于寄存器生成的控制問(wèn)題例2:雙輸出D觸發(fā)器的設(shè)計(jì)比較2:process(clk)beginif(clk'eventandclk='1')thenqi<=d;q<=d;qn<=notqi;endif;endprocess;2.時(shí)序電路設(shè)計(jì)關(guān)于寄存器生成的控制問(wèn)題例2:雙輸出D觸發(fā)器的設(shè)計(jì)比較3:process(clk)beginif(clk'eventandclk='1')thenq<=d;qn<=notd;endif;endprocess;關(guān)于寄存器生成的控制問(wèn)題例2:雙輸出D觸發(fā)器的設(shè)計(jì)比較4:process(clk)beginif(clk'eventandclk='1')thenqi<=d;endif;q<=qi;qn<=notqi;endprocess;關(guān)于寄存器的設(shè)計(jì)準(zhǔn)則(1)一個(gè)進(jìn)程中只引入一個(gè)寄存器(組);只含有一條時(shí)間測(cè)試語(yǔ)句;只對(duì)時(shí)間的一個(gè)邊沿進(jìn)行測(cè)試;(2)引入寄存器的優(yōu)選語(yǔ)句應(yīng)該是IF/THEN語(yǔ)句,因?yàn)樵撜Z(yǔ)句更容易控制寄存器的引入;在該語(yǔ)句中只應(yīng)設(shè)置一條邊沿測(cè)試描述分句;關(guān)于寄存器的設(shè)計(jì)準(zhǔn)則(3)嚴(yán)格控制帶時(shí)間測(cè)試語(yǔ)句的IF/THEN語(yǔ)句中賦值語(yǔ)句的數(shù)量,將不必要的語(yǔ)句放到該語(yǔ)句以外;(4)在各類條件控制語(yǔ)句中,注意控制條件的完整性,避免因漏掉條件而生成寄存器;(5)在過(guò)程中不能設(shè)計(jì)寄存器。寄存器的設(shè)計(jì)實(shí)例16位鎖存寄存器設(shè)計(jì)

帶有時(shí)鐘使能控制和輸出三態(tài)控制;libraryieee;useieee.std_logic_1164.all;

entitykreg16isport(clk,clken,oe,clr:instd_logic;d:instd_logic_vector(1to16);q:outstd_logic_vector(1to16));endkreg16;寄存器的設(shè)計(jì)實(shí)例architecturebehofkreg16is

signaliq:std_logic_vector(1to16);begin

process(clk,clr,oe,iq)begin

ifclr='1'theniq<=(others=>'0');

寄存器的設(shè)計(jì)實(shí)例

elsifclk'eventandclk='1'then

ifclken='1'theniq<=d;endif;

endif;

ifoe='1'thenq<=iq;

elseq<=(others=>'Z');endif;endprocess;endbeh;寄存器dclkqdclkqdclkqdclkqdffx(0)dffx(1)dffx(2)dffx(3)aclkb2.時(shí)序電路設(shè)計(jì)architectureshiftofshiftisbegincomponentdff port(d,clk:instd_logic; q:outstd_logic);endcomponent;signalz:std_logic_vector(0to4);begin z(0)<=a; g1:foriin0to3generate dffx:dffportmap(z(i),clk,z(i+1)); endgenerate; b<=z(4);endshift;同步計(jì)數(shù)器所謂同步計(jì)數(shù)器,就是在時(shí)鐘脈沖的控制下,構(gòu)成計(jì)數(shù)器的各觸發(fā)器狀態(tài)同時(shí)發(fā)生變化的那一類計(jì)數(shù)器可逆計(jì)數(shù)器process(clk,rst)begin ifrst='1'then count<=(others=>'0');elsifclk'eventandclk='1'then ifupdn='1'then count<=count+1; else count<=count-1; endif; endif;endprocess;2.時(shí)序電路設(shè)計(jì)異步計(jì)數(shù)器異步計(jì)數(shù)器又稱行波計(jì)數(shù)器,它的下一位計(jì)數(shù)器的輸出作為上一位計(jì)數(shù)器的始終信號(hào)。clkcount3dclkqdclkqdclkqdclkqcount0count1count2dclkqqnqnqnqn2.時(shí)序電路設(shè)計(jì)libraryIEEE;useIEEE.STD_LOGIC_1164.all;entityrplcontis port( clk:inSTD_LOGIC; count:outSTD_LOGIC_VECTOR(7downto0));endrplcont;architecturerplcontofrplcontissignalcount_in_bar:std_logic_vector(7downto0);componentdff port(clk,d:instd_logic;q,qb:outstd_logic);endcomponent;begincount_in_bar(0)<=clk;gen1:foriin0to7generate U:dffportmap(clk=>count_in_bar(i), d=>count_in_bar(i+1), q=>count(i),qb=>count_in_bar(i+1));endgenerate;endrplcont;計(jì)數(shù)器(counter)設(shè)計(jì)計(jì)數(shù)器也稱為分頻器,是數(shù)字電路中的基本時(shí)序模塊;計(jì)數(shù)器通常以clk信號(hào)為基本輸入,對(duì)輸入信號(hào)進(jìn)行計(jì)數(shù),在clk每個(gè)周期中改變一次計(jì)數(shù)器狀態(tài),狀態(tài)可以輸出;經(jīng)過(guò)n次計(jì)數(shù)后,計(jì)數(shù)器將回到初始狀態(tài),并給出進(jìn)位輸出信號(hào);2.時(shí)序電路設(shè)計(jì)計(jì)數(shù)器的VHDL設(shè)計(jì)可以采用兩種方式:1采用二進(jìn)制串設(shè)置狀態(tài),指定循環(huán)的起點(diǎn)和終點(diǎn),在時(shí)鐘觸發(fā)條件下對(duì)狀態(tài)進(jìn)行加1或減1運(yùn)算,使?fàn)顟B(tài)順序變化;2采用結(jié)構(gòu)設(shè)計(jì)方式,先形成小型計(jì)數(shù)器,再擴(kuò)展形成大型的計(jì)數(shù)器。計(jì)數(shù)器(counter)設(shè)計(jì)2.時(shí)序電路設(shè)計(jì)4位二進(jìn)制加法計(jì)數(shù)器74163有同步復(fù)位,同步置數(shù)和進(jìn)位控制功能;采用unsigned數(shù)據(jù)類型進(jìn)行設(shè)計(jì);libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;2.時(shí)序電路設(shè)計(jì)entityk74163isport(clk,clrl,ldl,enp,ent:instd_logic;d:inunsigned(3downto0);q:outunsigned(3downto0);rco:outstd_logic);endk74163;architecturebehofk74163issignaliq:unsigned(3downto0);begin計(jì)數(shù)器的行為設(shè)計(jì):741632.時(shí)序電路設(shè)計(jì)process(clk,ent,iq)beginifclk‘eventandclk=’1‘then

--時(shí)鐘沿檢測(cè)

ifclrl='0'theniq<=(others=>'0');

--同步復(fù)位

elsifldl=‘0’theniq<=d;--同步置數(shù)

elsif(entandenp)='1'theniq<=iq+1;

--狀態(tài)按順序改變endif;endif;計(jì)數(shù)器的行為設(shè)計(jì):741632.時(shí)序電路設(shè)計(jì)

if(iq=15)and(ent='1')thenrco<='1';

elserco<='0';

endif;

q<=iq;

endprocess;endbeh;對(duì)于usigned類型,在位數(shù)固定的條件下,加1或減1的運(yùn)算可以自動(dòng)產(chǎn)生循環(huán),不需要考慮起點(diǎn)和終點(diǎn)設(shè)置問(wèn)題。計(jì)數(shù)器的行為設(shè)計(jì):741632.時(shí)序電路設(shè)計(jì)計(jì)數(shù)器的行為設(shè)計(jì)電路的綜合與仿真結(jié)果:在狀態(tài)12時(shí)輸出進(jìn)位信號(hào);對(duì)上述程序只需要改變兩句:elseif(entandenp)='1'and(iq=12)then

iq<=“0011”;--現(xiàn)態(tài)為終態(tài)時(shí),次態(tài)為初態(tài)if(iq=12)and(ent=‘1’)thenrco<='1‘

--在終態(tài)輸出1計(jì)數(shù)器的行為設(shè)計(jì):BCD碼計(jì)數(shù)器計(jì)數(shù)器的結(jié)構(gòu)設(shè)計(jì)利用4個(gè)k74163連接成16位加法二進(jìn)制計(jì)數(shù)器(模65536)libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;entitykcount16isport(clk,clrl,ldl,en:instd_logic;d:inunsigned(15downto0);q:outunsigned(15downto0);rco:outstd_logic);endkcount16;計(jì)數(shù)器的結(jié)構(gòu)設(shè)計(jì)architecturestrofkcount16iscomponentk74163port(clk,clrl,ldl,enp,ent:instd_logic;d:inunsigned(3downto0);q:outunsigned(3downto0);rco:outstd_logic);endcomponent;signalco0,co1,co2:std_logic;begin2.時(shí)序電路設(shè)計(jì)計(jì)數(shù)器的結(jié)構(gòu)設(shè)計(jì)u1:k74163portmap

(clk,clrl,ldl,en,en,d(3downto0),

q(3downto0),co0);u2:k74163portmap

(clk,clrl,ldl,co0,co0,d(7downto4),

q(7downto4),co1);u3:k74163portmap

(clk,clrl,ldl,co1,co1,d(11downto8),

q(11downto8),co2);u4:k74163portmap

(clk,clrl,ldl,co2,co2,d(15downto12),

q(15downto12),rco);endstr;關(guān)于正負(fù)邊沿同時(shí)觸發(fā)的問(wèn)題在一些特殊的電路中,需要同時(shí)使用時(shí)鐘的正負(fù)邊沿進(jìn)行觸發(fā)。在VHDL設(shè)計(jì)中,可以采用兩個(gè)進(jìn)程分別處理正邊沿觸發(fā)和負(fù)邊沿觸發(fā),形成兩個(gè)不同的信號(hào),然后再考慮怎么將兩個(gè)信號(hào)合成最終輸出。關(guān)于正負(fù)邊沿同時(shí)觸發(fā)的問(wèn)題例1:時(shí)鐘邊沿計(jì)數(shù)器要求對(duì)時(shí)鐘信號(hào)的正負(fù)邊沿同時(shí)進(jìn)行計(jì)數(shù);libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;entityclkcountisport(clk:instd_logic;

y:outunsigned(7downto0));endclkcount;關(guān)于正負(fù)邊沿同時(shí)觸發(fā)的問(wèn)題architecturebehofclkcountissignalc1,c2:unsigned(7downto0);begin

process(clk)

variableid:unsigned(7downto0):="00000000";beginif(clk'eventandclk='1')thenid:=id+1;--上升沿計(jì)數(shù)

endif;c1<=id;endprocess;關(guān)于正負(fù)邊沿同時(shí)觸發(fā)的問(wèn)題process(clk)

variableid:unsigned(7downto0):="00000000";beginif(clk'eventandclk='0')thenid:=id+1;--下降沿計(jì)數(shù)

endif;c2<=id;endprocess;y<=c1+c2;--將兩個(gè)計(jì)數(shù)相加endbeh;2.時(shí)序電路設(shè)計(jì)關(guān)于正負(fù)邊沿同時(shí)觸發(fā)的問(wèn)題電路綜合及仿真結(jié)果:2.時(shí)序電路設(shè)計(jì)關(guān)于正負(fù)邊沿同時(shí)觸發(fā)的問(wèn)題有時(shí)將運(yùn)算得到的信號(hào)與時(shí)鐘信號(hào)進(jìn)行“與”運(yùn)算,也能使輸出信號(hào)在時(shí)鐘的兩個(gè)邊沿都發(fā)生變化;這對(duì)于某些特殊的信號(hào)發(fā)生器設(shè)計(jì)具有意義。例2:將模3計(jì)數(shù)器的輸出與時(shí)鐘信號(hào)進(jìn)行運(yùn)算,可以得到以下結(jié)果:2.時(shí)序電路設(shè)計(jì)關(guān)于正負(fù)邊沿同時(shí)觸發(fā)的問(wèn)題y1<=yiandclk;y2<=yiandnotclk;y3<=yixorclk;考察y3信號(hào)的上升沿,可以認(rèn)為該信號(hào)是對(duì)時(shí)鐘信號(hào)的1.5分頻(半整數(shù)分頻)!2.時(shí)序電路設(shè)計(jì)Shift-Register移位寄存器設(shè)計(jì)移位寄存器可以寄存n位二進(jìn)制數(shù)(可以將其視為串行排列的數(shù)組),在每個(gè)時(shí)鐘周期,內(nèi)部寄存數(shù)據(jù)移動(dòng)1位(向右或向左),同時(shí)有1位數(shù)據(jù)移入或移出;利用進(jìn)程中簡(jiǎn)單的賦值語(yǔ)句可以很方便地設(shè)計(jì)移位寄存器;2.時(shí)序電路設(shè)計(jì)移位寄存器設(shè)計(jì):簡(jiǎn)單4位右移libraryieee;useieee.std_logic_1164.all;

entitykshfreg1isport(clk,d:instd_logic;y:outstd_logic);endkshfreg1;

architecturebehofkshfreg1issignalq0,q1,q2:std_logic;--中間信號(hào)begin2.時(shí)序電路設(shè)計(jì)移位寄存器設(shè)計(jì):簡(jiǎn)單4位右移process(clk)beginif(clk'eventandclk='1')thenq0<=d;q1<=q0;q2<=q1;y<=q2;

--注意信號(hào)賦值的意義

endif;endprocess;endbeh;2.時(shí)序電路設(shè)計(jì)移位寄存器設(shè)計(jì):簡(jiǎn)單4位右移利用連接運(yùn)算符號(hào)&,也可以將上述程序改為如下形式:architecturebehofkshfreg1issignalq:std_logic_vector(0to2);beginprocess(clk)beginif(clk'eventandclk='1')thenq<=d&q(0to1);y<=q(2);--&實(shí)現(xiàn)數(shù)據(jù)q右移endif;endprocess;endbeh;移位寄存器設(shè)計(jì):8位多功能器件可實(shí)現(xiàn)異步復(fù)位、同步置數(shù)(并行輸入)、狀態(tài)輸出(并行輸出)、串入串出的左/右移控制;

2.時(shí)序電路設(shè)計(jì)移位寄存器設(shè)計(jì):8位多功能器件libraryieee;useieee.std_logic_1164.all;entitykshfreg2isport(clk:instd_logic;--時(shí)鐘

dir,clr,ld,dr,dl:instd_logic;--各種控制信號(hào)

d:instd_logic_vector(7downto0);--并行輸入

q:outstd_logic_vector(7downto0));--并行輸出endkshfreg2;移位寄存器設(shè)計(jì):8位多功能器件architecturebehofkshfreg2issignalqi:std_logic_vector(7downto0);

--內(nèi)部傳遞信號(hào)beginprocess(clk,clr)beginifclr=‘1’thenqi<=(others=>‘0’);

--異步置零

elsif(clk'eventandclk='1')then

--時(shí)鐘控制

ifld=‘1’thenqi<=d;--并入控制2.時(shí)序電路設(shè)計(jì)移位寄存器設(shè)計(jì):8位多功能器件

elsifdir=‘0’then--右移控制

qi<=qi(6downto0)&dr;else

--左移控制

qi<=dl&qi(7downto1);endif;endif;q<=qi;--并行輸出endprocess;endbeh;2.時(shí)序電路設(shè)計(jì)移位寄存器設(shè)計(jì):8位多功能器件電路綜合結(jié)果:2.時(shí)序電路設(shè)計(jì)典型的存儲(chǔ)器模塊有:尋址存儲(chǔ)器:ROMRAM順序存儲(chǔ)器:FIFO

Stack

(LIFO)

存儲(chǔ)器模塊的VHDL設(shè)計(jì)3.存儲(chǔ)器ROM和RAM屬于通用大規(guī)模器件,一般不需要自行設(shè)計(jì);但是在數(shù)字系統(tǒng)中,有時(shí)也需要設(shè)計(jì)一些小型的存儲(chǔ)器件,用于特定的用途:l例如臨時(shí)存放數(shù)據(jù),構(gòu)成查表運(yùn)算等。此類器件的特點(diǎn)為地址與存儲(chǔ)內(nèi)容直接對(duì)應(yīng),設(shè)計(jì)時(shí)將輸入地址作為給出輸出內(nèi)容的條件,采用條件賦值方式進(jìn)行設(shè)計(jì)。尋址存儲(chǔ)器的VHDL設(shè)計(jì)3.存儲(chǔ)器設(shè)計(jì)思想:將每個(gè)8位數(shù)組作為一個(gè)字(word);總共存儲(chǔ)16個(gè)字;將ram作為由16個(gè)字構(gòu)成的數(shù)組,以地址為下標(biāo);通過(guò)讀寫(xiě)控制模式實(shí)現(xiàn)對(duì)特定地址上字的讀出或?qū)懭?;尋址存?chǔ)器設(shè)計(jì):16x8位RAM3.存儲(chǔ)器libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;

entitykramisport(clk,wr,cs:instd_logic;d:inoutstd_logic_vector(7downto0);adr:instd_logic_vector(3downto0));endkram;尋址存儲(chǔ)器設(shè)計(jì):16x8位RAM3.存儲(chǔ)器architecturebehofkramissubtypewordisstd_logic_vector(7downto0);typememoryisarray(0to15)ofword;signaladr_in:integerrange0to15;signalsram:memory;beginadr_in<=conv_integer(adr);--將地址轉(zhuǎn)換為數(shù)組下標(biāo)process(clk)begin尋址存儲(chǔ)器設(shè)計(jì):16x8位RAM3.存儲(chǔ)器if(clk'eventandclk='1')thenif(cs='1'andwr='1')then--片選、寫(xiě)

sram(adr_in)<=d;endif;if(cs='1'andwr='0')then--片選、讀

d<=sram(adr_in);endif;endif;endprocess;endbeh;尋址存儲(chǔ)器設(shè)計(jì):16x8位RAM3.存儲(chǔ)器ROM的內(nèi)容是初始設(shè)計(jì)電路時(shí)就寫(xiě)入到內(nèi)部的,通常采用電路的固定結(jié)構(gòu)來(lái)實(shí)現(xiàn)存儲(chǔ);ROM只需設(shè)置數(shù)據(jù)輸出端口和地址輸入端口;設(shè)計(jì)思想:采用二進(jìn)制譯碼器的設(shè)計(jì)方式,將每個(gè)輸入組態(tài)對(duì)應(yīng)的輸出與一組存儲(chǔ)數(shù)據(jù)對(duì)應(yīng)起來(lái);尋址存儲(chǔ)器設(shè)計(jì):16x8位ROM3.存儲(chǔ)器libraryieee;useieee.std_logic_1164.all;

entityromisport(dataout:outstd_logic_vector(7downto0);addr:instd_logic_vector(3downto0);ce:instd_logic);endrom;尋址存儲(chǔ)器設(shè)計(jì):16x8位ROM3.存儲(chǔ)器architecturedofromissignalid:std_logic_vector(4downto0);beginid<=addr&ce;dataout<="00001111"whenid="00000"else"11110000"whenid="00010"else"11001100"whenid="00100"else"00110011"whenid="00110"else"10101010"whenid="01000"else"01010101"whenid="01010"else"10011001"whenid="01100"else尋址存儲(chǔ)器設(shè)計(jì):16x8位ROM

"01100110"whenid="01110"else"00000000"whenid="10000"else"11111111"whenid="10010"else"00010001"whenid="10100"else"10001000"whenid="10110"else"10011001"whenid="11000"else"01100110"whenid="11010"else"10100110"whenid="11100"else"01100111"whenid="11110"else"XXXXXXXX";endd;尋址存儲(chǔ)器設(shè)計(jì):16x8位ROM順序存儲(chǔ)器的特點(diǎn)是不設(shè)置地址,所有數(shù)據(jù)的寫(xiě)入和讀出都按順序進(jìn)行;數(shù)據(jù)寫(xiě)入或讀出時(shí)通常采用移位操作設(shè)計(jì);在設(shè)計(jì)時(shí)必須考慮各存儲(chǔ)單元的存儲(chǔ)狀態(tài);順序存儲(chǔ)器(堆棧和FIFO)的設(shè)計(jì)3.存儲(chǔ)器設(shè)計(jì)要求:存入數(shù)據(jù)按順序排放;存儲(chǔ)器全滿時(shí)給出信號(hào)并拒絕繼續(xù)存入;數(shù)據(jù)讀出時(shí)按后進(jìn)先出原則;存儲(chǔ)數(shù)據(jù)一旦讀出就從存儲(chǔ)器中消失;堆棧(后進(jìn)先出存儲(chǔ)器)的設(shè)計(jì)3.存儲(chǔ)器設(shè)計(jì)思想:將每個(gè)存儲(chǔ)單元設(shè)置為字(word);存儲(chǔ)器整體作為由字構(gòu)成的數(shù)組;為每個(gè)字設(shè)置一個(gè)標(biāo)記(flag),用以表達(dá)該存儲(chǔ)單元是否已經(jīng)存放了數(shù)據(jù);每寫(xiě)入或讀出一個(gè)數(shù)據(jù)時(shí),字的數(shù)組內(nèi)容進(jìn)行相應(yīng)的移動(dòng),標(biāo)記也做相應(yīng)的變化;堆棧(后進(jìn)先出存儲(chǔ)器)的設(shè)計(jì)3.存儲(chǔ)器libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_signed.all;

entitystackisport(datain:instd_logic_vector(7downto0);push,pop,reset,clk:instd_logic;stackfull:outstd_logic;dataout:bufferstd_logic_vector(7downto0));endstack;堆棧設(shè)計(jì):移位寄存器方式3.存儲(chǔ)器architecturebofstackistypearraylogicisarray(15downto0)ofstd_logic_vector(7downto0);signaldata:arraylogic;signalstackflag:std_logic_vector(15downto0);beginstackfull<=stackflag(0);

process(clk,reset,pop,push)variableselfunction:std_logic_vector(1downto0);begin

selfunction:=push&pop;堆棧設(shè)計(jì):移位寄存器方式3.存儲(chǔ)器ifreset='1'thenstackflag<=(others=>'0');dataout<=(others=>'0');foriin0to15loopdata(i)<="00000000“;endloop;elsifclk'eventandclk='1'thencaseselfunctioniswhen"10"=>ifstackflag(0)=’0’then

data(15)<=datain;

stackflag<='1'&stackflag(15downto1);

foriin0to14loop

data(i)<=data(i+1);endloop;endif;堆棧設(shè)計(jì):移位寄存器方式when"01"=>dataout<=data(15);stackflag<=stackflag(14downto0)&'0';foriin15downto1loopdata(i)<=data(i-1);endloop;whenothers=>null;endcase;endif;endprocess;endb;堆棧設(shè)計(jì):移位寄存器方式3.存儲(chǔ)器architecturebofstackistypearraylogicisarray(15downto0)ofstd_logic_vector(7downto0);signaldata:arraylogic;beginprocess(clk,reset,pop,push)variablep:naturalrange0to15;variableselfunction:std_logic_vector(1downto0);variables:std_logic;begin堆棧設(shè)計(jì):地址指針?lè)绞?.存儲(chǔ)器stackfull<=s;selfunction:=push&pop;ifreset='1'thenp:=0;dataout<=(others=>'0');s:='0';foriin0to15loopdata(i)<="00000000";endloop;elsifclk'eventandclk='1'thenifp<15andselfunction="10"thendata(p)<=datain;p:=p+1;endif;

堆棧設(shè)計(jì):地址指針?lè)绞?.存儲(chǔ)器ifp=15andselfunction="10"ands='0'thendata(p)<=datain;s:='1';endif;ifp>0andselfunction="01"ands='0'thenp:=p-1;dataout<=data(p);endif;ifp=15andselfunction="01"ands='1'thendataout<=data(p);s:='0';endif;endif;endprocess;endb;堆棧設(shè)計(jì):地址指針?lè)绞?.存儲(chǔ)器設(shè)計(jì)要求:存入數(shù)據(jù)按順序排放;存儲(chǔ)器全滿時(shí)給出信號(hào)并拒絕繼續(xù)存入;全空時(shí)也給出信號(hào)并拒絕讀出;讀出時(shí)按先進(jìn)先出原則;存儲(chǔ)數(shù)據(jù)一旦讀出就從存儲(chǔ)器中消失;FIFO(先進(jìn)先出存儲(chǔ)器)的設(shè)計(jì)3.存儲(chǔ)器設(shè)計(jì)思想:結(jié)合堆棧指針的設(shè)計(jì)思想,采用環(huán)行寄存器方式進(jìn)行設(shè)計(jì);分別設(shè)置寫(xiě)入指針wp和讀出指針rp,標(biāo)記下一個(gè)寫(xiě)入地址和讀出地址;地址隨寫(xiě)入或讀出過(guò)程順序變動(dòng);設(shè)計(jì)時(shí)需要注意處理好從地址最高位到地址最地位的變化;FIFO(先進(jìn)先出存儲(chǔ)器)的設(shè)計(jì)3.存儲(chǔ)器libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;useieee.std_logic_signed.all;

entitykfifoisport(datain:instd_logic_vector(7downto0);push,pop,reset,clk:instd_logic;full,empty:outstd_logic;dataout:outstd_logic_vector(7downto0));endkfifo;

FIFO設(shè)計(jì):地址指針?lè)绞?.存儲(chǔ)器architecturebofkfifoistypearraylogicisar

溫馨提示

  • 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)論