




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
第六章VHDL基本邏輯電路的設計
哈爾濱工業大學(威海)信息工程學院電子工程系
第六章VHDL基本邏輯電路的設計
1.組合邏輯電路2.時序電路設計3.存儲器1組合邏輯電路設計1.1簡單門電路1.2三態門及總線緩沖器1.3編、譯碼器與選擇器1.4加法器、求補器1.1簡單門電路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;或非門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簡單門電路反相器y<=nota;ayifa='1'then y<='0';else y<='1';endif;1.1簡單門電路異或門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簡單門電路1.2三態門及總線緩沖器單元器件的三態輸出描述:引入中間信號,采用條件賦值語句;例:
4輸入與非門y<=not(a0anda1anda2anda3);改為:y1<=not(a0anda1anda2anda3);y<=y1whenen='1'else'Z';數據傳輸控制單元:三態控制單向總線控制1.2三態門及總線緩沖器數據傳輸控制單元:三態控制單向總線控制74x541architecturedofk74541issignalen:std_logic;beginen<=not(g1org2);y<=awhenen='1'else(others=>'Z');endd;1.2三態門及總線緩沖器雙向緩沖器緩沖器adrben
endr功能00a=b01b=a1X三態雙向總線緩沖器真值表1.2三態門及總線緩沖器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;數據傳輸控制單元:三態控制雙向總線控制1.2三態門及總線緩沖器數據傳輸控制單元:三態控制雙向總線控制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;數據傳輸控制單元:三態控制注意:雙向總線在功能仿真時的輸入設置a和b的輸入不要同時存在;設置a的輸入時,則b為輸出,應將b的輸入設置為高阻;反過來也是同樣;轉換傳輸方向時,應該以雙向阻塞作為間隔,避免出現沖突。1.2三態門及總線緩沖器數據傳輸控制單元:
MUX1.2三態門及總線緩沖器數據傳輸控制單元:
MUXMUX是電路中控制數據流動最為常用的手段;根據控制量的數值由多路數據中選擇一路輸出;采用選擇賦值能夠非常直觀地表達MUX的概念;1.3編、譯碼器與選擇器數據傳輸控制單元:
MUX4路8位數據選擇器architecturertlofmux4in8bisbeginwithsselecty<=awhen"00",bwhen"01",cwhen"10",dwhen"11",(others=>'U')whenothers;endrtl;1.3編、譯碼器與選擇器數據傳輸控制單元:
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;采用進程和case語句實現數據編碼轉換單元該類電路為多路輸入/多路輸出,將輸入的編碼轉換為對應的輸出的編碼;采用選擇賦值語句可以對各類碼制轉換電路進行設計。1.3編、譯碼器與選擇器數據編碼轉換單元:二進制譯碼器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編、譯碼器與選擇器數據編碼轉換單元:7段譯碼器輸入4位BCD碼,產生7個輸出,分別驅動相應顯示器件;考慮7段輸出與數字的對應關系,可以得出如下關系
abcdefg0:0000--11111101:0001--01100002:0010--11011013:0011--1111001
1.3編、譯碼器與選擇器數據編碼轉換單元: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;數據編碼轉換單元:優先編碼器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;數據檢測單元:奇偶校驗器奇偶校驗電路是實現數據錯誤檢驗的一種基本電路,其方式是檢測在輸入數據中‘1’的個數是奇數還是偶數;通常采用異或門的結構實現。1.3編、譯碼器與選擇器數據檢測單元:奇偶校驗器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編、譯碼器與選擇器半加器二進制輸入和輸出進位輸出basco0011010101100001半加器真值表半加器absco1.4加法器、求補器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;時序電路的結構與特點內部含有存儲器件(觸發器、鎖存器);信號變化受時鐘控制;通常采用狀態變化進行描述;采用進程進行設計;2.時序電路設計同步時序電路的信號變化特點同步時序電路以時鐘信號為驅動;電路內部信號的變化(或輸出信號的變化)只發生在特定的時鐘邊沿;設計要點:時鐘邊沿的檢測;輸出賦值的控制:是否改變、如何改變。2.時序電路設計同步時序電路的時鐘控制采用進程描述可以有效控制執行條件,進程中的條件控制可以將時鐘信號(clk)做為控制信號,只有當時鐘信號變化時,進程才執行;在時鐘條件不滿足時,任何輸入信號的變化對電路(進程)不起作用;2.時序電路設計VHDL中的時鐘檢測方式VHDL通常采用屬性語句檢測時鐘邊沿;與時鐘有關的屬性語句:clk'event:boolean,clk有變化時為true;clk‘last_value:bit,clk在變化之前的值;注意:上述屬性語句只能在子結構中應用(作為局部量)。2.時序電路設計VHDL中的時鐘檢測方式例:上升沿的檢測:
clk'eventandclk='1';clk'eventandclk'last_value='0';在由上升沿導致的進程執行時,上述兩個表達式的值都為true;而在由其他輸入變化導致的進程執行時,上述表達式的值就是faith;2.時序電路設計時序電路的基本單元設計Latch:輸出受時鐘電平控制,在一段時間內可受輸入變化影響發生而變化;(電平控制)flip-flop:輸出只在時鐘邊沿時刻發生變化,輸入信號變化不能直接導致輸出變化;(邊沿控制)2.時序電路設計時序電路的基本單元設計例:Dlatch的設計process(clk,d)
begin
ifclk='1'thenq<=d;
endif;endprocess;d和clk的任何變化都會導致進程執行;僅當clk為1時,d的變化才會導致q的變化;2.時序電路設計時序電路的基本單元設計例:Dflip-flop的設計:process(clk,d)
begin
ifclk'eventandclk='1'thenq<=d;
endif;endprocess;d和clk的任何變化都會導致進程執行;只有在clk上升沿引發的進程執行中,d的變化才會導致q的變化;觸發沿選擇與清零設置問題:process(clk,clr)
begin
ifclr='1'thenq<='0';
elsifclk'eventandclk='1'thenq<=d;
endif;endprocess;異步清零,上升沿觸發;2.時序電路設計觸發沿選擇與清零設置問題:process(clk,clr)begin
ifclk'eventandclk='0'
ifclr='0'thenq<='0';
elseq<=d;
endif;
endif;endprocess;下降沿觸發,同步清零;2.時序電路設計時序電路的基本單元設計采用wait語句進行時鐘檢測:processbeginwaitonclk; ifclk='1'then
q<=d;
endif;endprocess;2.時序電路設計時序電路的基本單元設計采用wait語句進行時鐘檢測:processbegin
waituntilclk='0';q<=d;endprocess;2.時序電路設計關于寄存器生成的控制問題寄存器的作用是在輸入信號變化時,保持輸出信號不變;當程序設計中隱含這一要求時,就會在綜合時引入寄存器;寄存器只在滿足一定條件時才允許改變輸出值,因此只能通過條件判斷語句才會引入寄存器;2.時序電路設計關于寄存器生成的控制問題例1:寄存器的引入process(clk,d)begin
ifclk='1'thenq<=d;elseq<='0';
endif;endprocess;2.時序電路設計關于寄存器生成的控制問題例1:寄存器的引入process(clk,d)begin
ifclk='1'thenq<=d;
endif;endprocess;2.時序電路設計關于寄存器生成的控制問題例2:雙輸出D觸發器的設計比較1:process(clk)beginif(clk'eventandclk='1')then qi<=d;q<=qi;qn<=notqi;endif;endprocess;2.時序電路設計關于寄存器生成的控制問題例2:雙輸出D觸發器的設計比較2:process(clk)beginif(clk'eventandclk='1')thenqi<=d;q<=d;qn<=notqi;endif;endprocess;2.時序電路設計關于寄存器生成的控制問題例2:雙輸出D觸發器的設計比較3:process(clk)beginif(clk'eventandclk='1')thenq<=d;qn<=notd;endif;endprocess;關于寄存器生成的控制問題例2:雙輸出D觸發器的設計比較4:process(clk)beginif(clk'eventandclk='1')thenqi<=d;endif;q<=qi;qn<=notqi;endprocess;關于寄存器的設計準則(1)一個進程中只引入一個寄存器(組);只含有一條時間測試語句;只對時間的一個邊沿進行測試;(2)引入寄存器的優選語句應該是IF/THEN語句,因為該語句更容易控制寄存器的引入;在該語句中只應設置一條邊沿測試描述分句;關于寄存器的設計準則(3)嚴格控制帶時間測試語句的IF/THEN語句中賦值語句的數量,將不必要的語句放到該語句以外;(4)在各類條件控制語句中,注意控制條件的完整性,避免因漏掉條件而生成寄存器;(5)在過程中不能設計寄存器。寄存器的設計實例16位鎖存寄存器設計
帶有時鐘使能控制和輸出三態控制;libraryieee;useieee.std_logic_1164.all;
entitykreg16isport(clk,clken,oe,clr:instd_logic;d:instd_logic_vector(1to16);q:outstd_logic_vector(1to16));endkreg16;寄存器的設計實例architecturebehofkreg16is
signaliq:std_logic_vector(1to16);begin
process(clk,clr,oe,iq)begin
ifclr='1'theniq<=(others=>'0');
寄存器的設計實例
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.時序電路設計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;同步計數器所謂同步計數器,就是在時鐘脈沖的控制下,構成計數器的各觸發器狀態同時發生變化的那一類計數器可逆計數器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.時序電路設計異步計數器異步計數器又稱行波計數器,它的下一位計數器的輸出作為上一位計數器的始終信號。clkcount3dclkqdclkqdclkqdclkqcount0count1count2dclkqqnqnqnqn2.時序電路設計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;計數器(counter)設計計數器也稱為分頻器,是數字電路中的基本時序模塊;計數器通常以clk信號為基本輸入,對輸入信號進行計數,在clk每個周期中改變一次計數器狀態,狀態可以輸出;經過n次計數后,計數器將回到初始狀態,并給出進位輸出信號;2.時序電路設計計數器的VHDL設計可以采用兩種方式:1采用二進制串設置狀態,指定循環的起點和終點,在時鐘觸發條件下對狀態進行加1或減1運算,使狀態順序變化;2采用結構設計方式,先形成小型計數器,再擴展形成大型的計數器。計數器(counter)設計2.時序電路設計4位二進制加法計數器74163有同步復位,同步置數和進位控制功能;采用unsigned數據類型進行設計;libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;2.時序電路設計entityk74163isport(clk,clrl,ldl,enp,ent:instd_logic;d:inunsigned(3downto0);q:outunsigned(3downto0);rco:outstd_logic);endk74163;architecturebehofk74163issignaliq:unsigned(3downto0);begin計數器的行為設計:741632.時序電路設計process(clk,ent,iq)beginifclk‘eventandclk=’1‘then
--時鐘沿檢測
ifclrl='0'theniq<=(others=>'0');
--同步復位
elsifldl=‘0’theniq<=d;--同步置數
elsif(entandenp)='1'theniq<=iq+1;
--狀態按順序改變endif;endif;計數器的行為設計:741632.時序電路設計
if(iq=15)and(ent='1')thenrco<='1';
elserco<='0';
endif;
q<=iq;
endprocess;endbeh;對于usigned類型,在位數固定的條件下,加1或減1的運算可以自動產生循環,不需要考慮起點和終點設置問題。計數器的行為設計:741632.時序電路設計計數器的行為設計電路的綜合與仿真結果:在狀態12時輸出進位信號;對上述程序只需要改變兩句:elseif(entandenp)='1'and(iq=12)then
iq<=“0011”;--現態為終態時,次態為初態if(iq=12)and(ent=‘1’)thenrco<='1‘
--在終態輸出1計數器的行為設計:BCD碼計數器計數器的結構設計利用4個k74163連接成16位加法二進制計數器(模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;計數器的結構設計architecturestrofkcount16iscomponentk74163port(clk,clrl,ldl,enp,ent:instd_logic;d:inunsigned(3downto0);q:outunsigned(3downto0);rco:outstd_logic);endcomponent;signalco0,co1,co2:std_logic;begin2.時序電路設計計數器的結構設計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;關于正負邊沿同時觸發的問題在一些特殊的電路中,需要同時使用時鐘的正負邊沿進行觸發。在VHDL設計中,可以采用兩個進程分別處理正邊沿觸發和負邊沿觸發,形成兩個不同的信號,然后再考慮怎么將兩個信號合成最終輸出。關于正負邊沿同時觸發的問題例1:時鐘邊沿計數器要求對時鐘信號的正負邊沿同時進行計數;libraryieee;useieee.std_logic_1164.all;useieee.std_logic_arith.all;entityclkcountisport(clk:instd_logic;
y:outunsigned(7downto0));endclkcount;關于正負邊沿同時觸發的問題architecturebehofclkcountissignalc1,c2:unsigned(7downto0);begin
process(clk)
variableid:unsigned(7downto0):="00000000";beginif(clk'eventandclk='1')thenid:=id+1;--上升沿計數
endif;c1<=id;endprocess;關于正負邊沿同時觸發的問題process(clk)
variableid:unsigned(7downto0):="00000000";beginif(clk'eventandclk='0')thenid:=id+1;--下降沿計數
endif;c2<=id;endprocess;y<=c1+c2;--將兩個計數相加endbeh;2.時序電路設計關于正負邊沿同時觸發的問題電路綜合及仿真結果:2.時序電路設計關于正負邊沿同時觸發的問題有時將運算得到的信號與時鐘信號進行“與”運算,也能使輸出信號在時鐘的兩個邊沿都發生變化;這對于某些特殊的信號發生器設計具有意義。例2:將模3計數器的輸出與時鐘信號進行運算,可以得到以下結果:2.時序電路設計關于正負邊沿同時觸發的問題y1<=yiandclk;y2<=yiandnotclk;y3<=yixorclk;考察y3信號的上升沿,可以認為該信號是對時鐘信號的1.5分頻(半整數分頻)!2.時序電路設計Shift-Register移位寄存器設計移位寄存器可以寄存n位二進制數(可以將其視為串行排列的數組),在每個時鐘周期,內部寄存數據移動1位(向右或向左),同時有1位數據移入或移出;利用進程中簡單的賦值語句可以很方便地設計移位寄存器;2.時序電路設計移位寄存器設計:簡單4位右移libraryieee;useieee.std_logic_1164.all;
entitykshfreg1isport(clk,d:instd_logic;y:outstd_logic);endkshfreg1;
architecturebehofkshfreg1issignalq0,q1,q2:std_logic;--中間信號begin2.時序電路設計移位寄存器設計:簡單4位右移process(clk)beginif(clk'eventandclk='1')thenq0<=d;q1<=q0;q2<=q1;y<=q2;
--注意信號賦值的意義
endif;endprocess;endbeh;2.時序電路設計移位寄存器設計:簡單4位右移利用連接運算符號&,也可以將上述程序改為如下形式:architecturebehofkshfreg1issignalq:std_logic_vector(0to2);beginprocess(clk)beginif(clk'eventandclk='1')thenq<=d&q(0to1);y<=q(2);--&實現數據q右移endif;endprocess;endbeh;移位寄存器設計:8位多功能器件可實現異步復位、同步置數(并行輸入)、狀態輸出(并行輸出)、串入串出的左/右移控制;
2.時序電路設計移位寄存器設計:8位多功能器件libraryieee;useieee.std_logic_1164.all;entitykshfreg2isport(clk:instd_logic;--時鐘
dir,clr,ld,dr,dl:instd_logic;--各種控制信號
d:instd_logic_vector(7downto0);--并行輸入
q:outstd_logic_vector(7downto0));--并行輸出endkshfreg2;移位寄存器設計:8位多功能器件architecturebehofkshfreg2issignalqi:std_logic_vector(7downto0);
--內部傳遞信號beginprocess(clk,clr)beginifclr=‘1’thenqi<=(others=>‘0’);
--異步置零
elsif(clk'eventandclk='1')then
--時鐘控制
ifld=‘1’thenqi<=d;--并入控制2.時序電路設計移位寄存器設計:8位多功能器件
elsifdir=‘0’then--右移控制
qi<=qi(6downto0)&dr;else
--左移控制
qi<=dl&qi(7downto1);endif;endif;q<=qi;--并行輸出endprocess;endbeh;2.時序電路設計移位寄存器設計:8位多功能器件電路綜合結果:2.時序電路設計典型的存儲器模塊有:尋址存儲器:ROMRAM順序存儲器:FIFO
Stack
(LIFO)
存儲器模塊的VHDL設計3.存儲器ROM和RAM屬于通用大規模器件,一般不需要自行設計;但是在數字系統中,有時也需要設計一些小型的存儲器件,用于特定的用途:l例如臨時存放數據,構成查表運算等。此類器件的特點為地址與存儲內容直接對應,設計時將輸入地址作為給出輸出內容的條件,采用條件賦值方式進行設計。尋址存儲器的VHDL設計3.存儲器設計思想:將每個8位數組作為一個字(word);總共存儲16個字;將ram作為由16個字構成的數組,以地址為下標;通過讀寫控制模式實現對特定地址上字的讀出或寫入;尋址存儲器設計:16x8位RAM3.存儲器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;尋址存儲器設計:16x8位RAM3.存儲器architecturebehofkramissubtypewordisstd_logic_vector(7downto0);typememoryisarray(0to15)ofword;signaladr_in:integerrange0to15;signalsram:memory;beginadr_in<=conv_integer(adr);--將地址轉換為數組下標process(clk)begin尋址存儲器設計:16x8位RAM3.存儲器if(clk'eventandclk='1')thenif(cs='1'andwr='1')then--片選、寫
sram(adr_in)<=d;endif;if(cs='1'andwr='0')then--片選、讀
d<=sram(adr_in);endif;endif;endprocess;endbeh;尋址存儲器設計:16x8位RAM3.存儲器ROM的內容是初始設計電路時就寫入到內部的,通常采用電路的固定結構來實現存儲;ROM只需設置數據輸出端口和地址輸入端口;設計思想:采用二進制譯碼器的設計方式,將每個輸入組態對應的輸出與一組存儲數據對應起來;尋址存儲器設計:16x8位ROM3.存儲器libraryieee;useieee.std_logic_1164.all;
entityromisport(dataout:outstd_logic_vector(7downto0);addr:instd_logic_vector(3downto0);ce:instd_logic);endrom;尋址存儲器設計:16x8位ROM3.存儲器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尋址存儲器設計: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;尋址存儲器設計:16x8位ROM順序存儲器的特點是不設置地址,所有數據的寫入和讀出都按順序進行;數據寫入或讀出時通常采用移位操作設計;在設計時必須考慮各存儲單元的存儲狀態;順序存儲器(堆棧和FIFO)的設計3.存儲器設計要求:存入數據按順序排放;存儲器全滿時給出信號并拒絕繼續存入;數據讀出時按后進先出原則;存儲數據一旦讀出就從存儲器中消失;堆棧(后進先出存儲器)的設計3.存儲器設計思想:將每個存儲單元設置為字(word);存儲器整體作為由字構成的數組;為每個字設置一個標記(flag),用以表達該存儲單元是否已經存放了數據;每寫入或讀出一個數據時,字的數組內容進行相應的移動,標記也做相應的變化;堆棧(后進先出存儲器)的設計3.存儲器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;堆棧設計:移位寄存器方式3.存儲器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;堆棧設計:移位寄存器方式3.存儲器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;堆棧設計:移位寄存器方式when"01"=>dataout<=data(15);stackflag<=stackflag(14downto0)&'0';foriin15downto1loopdata(i)<=data(i-1);endloop;whenothers=>null;endcase;endif;endprocess;endb;堆棧設計:移位寄存器方式3.存儲器architecturebofstackistypearraylogicisarray(15downto0)ofstd_logic_vector(7downto0);signaldata:arraylogic;beginprocess(clk,reset,pop,push)variablep:naturalrange0to15;variableselfunction:std_logic_vector(1downto0);variables:std_logic;begin堆棧設計:地址指針方式3.存儲器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;
堆棧設計:地址指針方式3.存儲器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;堆棧設計:地址指針方式3.存儲器設計要求:存入數據按順序排放;存儲器全滿時給出信號并拒絕繼續存入;全空時也給出信號并拒絕讀出;讀出時按先進先出原則;存儲數據一旦讀出就從存儲器中消失;FIFO(先進先出存儲器)的設計3.存儲器設計思想:結合堆棧指針的設計思想,采用環行寄存器方式進行設計;分別設置寫入指針wp和讀出指針rp,標記下一個寫入地址和讀出地址;地址隨寫入或讀出過程順序變動;設計時需要注意處理好從地址最高位到地址最地位的變化;FIFO(先進先出存儲器)的設計3.存儲器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設計:地址指針方式3.存儲器architecturebofkfifoistypearraylogicisar
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權】 IEC 60601-1:1988/AMD1:1991 EN-D Amendment 1 - Medical electrical equipment - Part 1: General requirements for safety
- 小學生防金融詐騙教育
- 2025年鄉鎮年度精神文明建設工作方案
- 企業商業規劃方案
- 2025年幼兒園大班上學期工作方案
- 壓力性損傷的護理及預防
- 急性心梗的護理
- 網絡主題班會教育教案
- 現代商務展示模板
- 汽車音響培訓
- 山東省人工智能融合創新職業技能競賽(人工智能訓練師)試題及答案
- 2024年山東省青島市中考語文試卷(含答案解析)
- 抗凝劑皮下注射技術臨床實踐指南與臨床應用
- 2022新教材蘇教版科學5五年級下冊全冊教學設計
- 干部履歷表填寫范本(中共中央組織部1999年)
- 小兒闌尾炎概要
- 13J933-2體育場地與設施(二)
- 2024年(學習強國)思想政治理論知識考試題庫與答案
- 2024年海南省國有資本運營有限公司招聘筆試沖刺題(帶答案解析)
- 2024提高治療前腫瘤TNM評估率工作方案(修改版)
- 《阿Q正傳》(課件)2023-2024高二語文選擇性必修下冊
評論
0/150
提交評論