VHDL存儲器的設(shè)計_第1頁
VHDL存儲器的設(shè)計_第2頁
VHDL存儲器的設(shè)計_第3頁
已閱讀5頁,還剩10頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

存儲器的設(shè)計尋址存儲器(RAM和ROM)ROM和RAM屬于通用大規(guī)模器件,一般不需要自行設(shè)計,特別是采用 PLD器件進行設(shè)計時;但是在數(shù)字系統(tǒng)中,有時也需要設(shè)計一些小型的存儲器件,用于特定的用途:臨時存放數(shù)據(jù),構(gòu)成查表運算等。此類器件的特點為地址與存儲內(nèi)容直接對應(yīng),設(shè)計時將輸入地址作為給出輸出內(nèi)容的條件;RAM隨機存儲器RAM的用途是存儲數(shù)據(jù),其指標(biāo)為存儲容量和字長; RAM的內(nèi)部可以分為地址譯碼和存儲單元兩部分; 外部端口為:wr寫讀控制cs片選d數(shù)據(jù)端口adr地址端口例16x8位RAM的設(shè)計設(shè)計思想:將每個8位數(shù)組作為一個字(word);總共存儲16個字;將ram作為由16個字構(gòu)成的數(shù)組,以地址為下標(biāo);通過讀寫控制模式實現(xiàn)對特定地址上字的讀出或?qū)懭耄籰ibraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entitykramisport(clk,wr,cs:instd_logic;inoutstd_logic_vector(7downto0;adr:instd_logic_vector(3downto0;endkram;architecturebehofkramissubtypewordisstd_logic_vector(7downto0;typememoryisarray(0to15ofword;signaladr_in:integerrange0to15;signalsram:memory;beginadr_in<=conv_integer(adr;process(clkbeginif(clk'eventandclk='1'thenif(cs='1'andwr='1'thensram(adr_in<=d;endif;if(cs='1'andwr='0'thend<=sram(adr_in;endif;endif;endprocess;endbeh;RAM的數(shù)據(jù)端口通常為 inout模式,設(shè)置仿真輸入時只能在寫入時將信號加到該輸入端口上,在其他時候輸入應(yīng)設(shè)置為高阻態(tài);RAM設(shè)計時需要注意器件的大小,一個 16x8位的RAM大約占用200個門,而256x16的RAM則需要6200門以上,因此大規(guī)模RAM不適合于采用PLD設(shè)計,最好采用通用器件;ROM只讀存儲器ROM的內(nèi)容是初始設(shè)計電路時就寫入到內(nèi)部的,通常采用電路的固定結(jié)構(gòu)來實現(xiàn)存儲;ROM只需設(shè)置數(shù)據(jù)輸出端口和地址輸入端口;例1簡單ROM的設(shè)計(16x8位ROM)設(shè)計思想:采用二進制譯碼器的設(shè)計方式,但將每個輸入組態(tài)對應(yīng)的輸出與一組存儲數(shù)據(jù)對應(yīng)起來;libraryieee;useieee.std_logic_1164.all;entityromisport(dataout:outstd_logic_vector(7downto0;addr:instd_logic_vector(3downto0;ce:instd_logic;endrom;architecturedofromisbegindataout<="00001111"whenaddr="0000"andce='0'else"11110000"whenaddr="0001"andce='0'else"11001100"whenaddr="0010"andce='0'else"00110011"whenaddr="0011"andce='0'else"10101010"whenaddr="0100"andce='0'else"01010101"whenaddr="0101"andce='0'else"10011001"whenaddr="0110"andce='0'else"01100110"whenaddr="0111"andce='0'else"00000000"whenaddr="1000"andce='0'else"11111111"whenaddr="1001"andce='0'else"00010001"whenaddr="1010"andce='0'else"10001000"whenaddr="1011"andce='0'else"10011001"whenaddr="1100"andce='0'else"01100110"whenaddr="1101"andce='0'else"10100110"whenaddr="1110"andce='0'else"01100111"whenaddr="1111"andce='0'else"XXXXXXXX";endd;對于較大的ROM,可以采用結(jié)構(gòu)設(shè)計的方法,直接調(diào)用 參數(shù)化模塊進行設(shè)計;例ROM的LPM設(shè)計(256x8位ROM)libraryieee;useieee.std_logic_1164.all;librarylpm;uselpm.lpm_components.all;entityromlpmisport(address:instd_logic_vector(7downto0;inclock:instd_logic;outstd_logic_vector(7downto0;endromlpm;architecturestrofromlpmissignalsub_wire0:std_logic_vector(7downto0;beginq<=sub_wire0(7downto0;lpm_rom_component:lpm_romgenericmap(lpm_width=>8,lpm_widthad=>8,lpm_address_control=>"registered",lpm_outdata=>"unregistered",lpm_file=>"krom2.mif"portmap(address=>address,inclock=>inclock,q=>sub_wire0;endstr;ROM的初始化在ROM的設(shè)計中,必須要預(yù)先設(shè)置好數(shù)據(jù)存儲文件,這是一種以 .mif為后綴的文本文件,在任何文本編輯器中,按如下文件格式寫入:DEPTH=16;字線數(shù)量WIDTH=4;位線數(shù)量ADDRESS_RADIX=HEX;地址與數(shù)據(jù)的表達類型DATA_RADIX=HEX; 可以選擇:HEXOCTDECBINCONTENT 存儲內(nèi)容地址:數(shù)據(jù);BEGIN[0..F]:3;2:4567;8:FE5;END;文件寫完后,保存為.mif即可。例:4位查表式乘法器設(shè)計功能:將兩個4位二進制數(shù)A和B相乘,輸出乘積結(jié)果C(8位二進制數(shù));設(shè)計方案:采用256x8位ROM實現(xiàn),8位地址輸入(高4位為A,低4位為B),256個存儲字;8位數(shù)據(jù)輸出;數(shù)據(jù)存儲文件(krom2.mif):填寫相應(yīng)的乘法表即可depth=256;width=8;address_radix=hex;data_radix=hex;contentbegin[00..0f]:00;10:000102030405060708090a0b0c0d0e0f;20:00020406080a0c0e10121416181a1c1e;30:000306090c0f1215181b1e2124272a2d;40:0004080c1014181c2024282c3034383c;50:00050a0f14191d23282d32373c41464b;60:00060c12181e242a30363c42484e545a;70:00070e151c232a31383f464d545b6269;80:00081018202830384048505860687078;90:0009121b242d363f48515a636c757e87;a0:000a141e28323c46505a646e78828c96;b0:000b16212c37424d58636e79848f9aa5;c0:000c1824303c4854606c7884909ca8b4;d0:000d1a2734414e5b6875828f9ca9b6c3;e0:000e1c2a38465462707e8c9aa8b6c4d2;f0:000f1e2d3c4b5a66788796a5b4c3d2e1;end;該乘法器

ROM

設(shè)計完畢后,將其設(shè)置為符號文件,將來就可以在

VHDL

程序中用component語句調(diào)用了。在maxplus2的仿真器窗口內(nèi),也可以直接生成ROM的初始化文件,其步驟如下:選擇Initialize/InitializeMemory ;按ROM地址輸入數(shù)據(jù);存盤即可生成指定的 mif文件(文件名已經(jīng)在結(jié)構(gòu)體內(nèi)指明);順序存儲器(堆棧和 FIFO)順序存儲器的特點是不設(shè)置地址,所有數(shù)據(jù)的寫入和讀出都按順序進行;數(shù)據(jù)寫入或讀出時通常會進行移位操作;在設(shè)計時必須考慮各存儲單元的存儲狀態(tài);堆棧(后進先出存儲器)要求:存入數(shù)據(jù)按順序排放,存儲器全滿時給出信號并拒絕繼續(xù)存入;讀出時按后進先出原則;存儲數(shù)據(jù)一旦讀出就從存儲器中消失;設(shè)計思想:將每個存儲單元設(shè)置為字(word);存儲器整體作為由字構(gòu)成的數(shù)組;為每個字設(shè)置一個標(biāo)記(flag),用以表達該存儲單元是否已經(jīng)存放了數(shù)據(jù);每寫入或讀出一個數(shù)據(jù)時,字的數(shù)組內(nèi)容進行相應(yīng)的移動,標(biāo)記也做相應(yīng)的變化; 程序示例: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;architecturebofstackistypearraylogicisarray(15downto0ofstd_logic_vector(7downto0;signaldata:arraylogic;signalstackflag:std_logic_vector(15downto0;beginstackfull<=stackflag(0;process(clk,reset,pop,pushvariableselfunction:std_logic_vector(1downto0;beginselfunction:=push&pop;ifreset='1'thenstackflag<=(others=>'0';dataout<=(others=>'0';foriin0to15loopdata(i<="00000000";endloop;elsifclk'eventandclk='1'thencaseselfunctioniswhen"10"=>ifstackflag(0= then’0’data(15<=datain;stackflag<='1'&stackflag(15downto1;foriin0to14loopdata(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;以上程序是基于移位寄存器的設(shè)計思想;若基于存儲器的設(shè)計思想,則可以設(shè)置一個指針(point),表示出當(dāng)前寫入或讀出單元的地址,使這種地址進行順序變化,就可以實現(xiàn)數(shù)據(jù)的順序讀出或?qū)懭耄怀绦蚴纠齦ibrary說明和entity設(shè)計與上面程序完全相同;architecturebofstackistypearraylogicisarray(15downto0ofstd_logic_vector(7downto0;signaldata:arraylogic;beginprocess(clk,reset,pop,pushvariablep:naturalrange0to15;variableselfunction:std_logic_vector(1downto0;variables:std_logic;beginstackfull<=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;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;FIFO(先進先出存儲器)要求:存入數(shù)據(jù)按順序排放,存儲器全滿時給出信號并拒絕繼續(xù)存入,全空時也給出信號并拒絕讀出;讀出時按先進先出原則;存儲數(shù)據(jù)一旦讀出就從存儲器中消失;設(shè)計思想:結(jié)合堆棧指針的設(shè)計思想,采用環(huán)行寄存器方式進行設(shè)計;分別設(shè)置寫入指針wp和讀出指針rp,標(biāo)記下一個寫入地址和讀出地址;地址隨寫入或讀出過程順序變動;設(shè)置全空標(biāo)記和全滿標(biāo)記以避免讀出或?qū)懭氲腻e誤;設(shè)計時需要注意處理好從地址最高位到地址最地位的變化;程序示例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;architecturebofkfifoistypearraylogicisarray(15downto0ofstd_logic_vector(7downto0;signaldata:arraylogic;signalfi,ei:std_logic;--為全滿全空設(shè)置內(nèi)部信號,以便內(nèi)部調(diào)用;signalwp,rp:naturalrange0to15;--指針;beginprocess(clk,reset,pop,pushvariableselfunction:std_logic_vector(1downto0;beginfull<=fi;empty<=ei;selfunction:=push&pop;ifreset='1'thenwp<=0;rp<=0;fi<='0';ei<='1';--初始指針處于0位;dataout<=(others=>'0';foriin0to15loopdata(i<="00000000";endloop;elsifclk'eventandclk='1'then--write;iffi='0'andselfunction="10"andwp<15thendata(wp<=datain;wp<=wp+1;ifwp=rpthenfi<='1';endif;ifei='1'thenei<='0';endif;endif;iffi='0'andselfunction="10"andwp=15thendata(wp<=datain;wp<=0;ifwp=rpthenfi<='1';endif;ifei='1'thenei<='0';endif;endif;--read;ifei='0'andselfunction="01"andrp<15thendataout<=data(rp;rp<=rp+1;ifwp=rpthenei<='1';endif;iffi='1'thenfi<='0';endif;endif;ifei='0'andselfunction="01"andrp=15thendataout<=data(rp;rp<=0;ifwp=rpthenei<='1';endif;iffi='1'thenfi<='0';endif;endif;endif;endprocess;endb;采用參數(shù)化模塊直接形成FIFO的設(shè)計由于各類存儲器通常都會占用較多的硬件資源,直

溫馨提示

  • 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. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論