




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
典型電路設(shè)計(jì)案例1、計(jì)數(shù)器設(shè)計(jì)LIBRARYieee;USEieee.std_logic_1164.ALL;USEieee.std_logic_unsigned.ALL;ENTITYcountISGeneric(n:integer:=3);PORT(clk:inSTD_LOGIC;q:outSTD_LOGIC_vector(n-1downto0));ENDcount;ARCHITECTUREaOFcountISsignaltmp:STD_LOGIC_vector(n-1downto0);BEGINprocess(clk)beginifclk'eventandclk='1'thentmp<=tmp+1;endif;endprocess;q<=tmp;ENDa;an位二進(jìn)制加法計(jì)數(shù)器24進(jìn)制計(jì)數(shù)器ENQAQBCLKLIBRARYieee;USEieee.std_logic_1164.ALL;USEieee.std_logic_unsigned.ALL;ENTITYcount24ISPORT(en,Reset,clk:inSTD_LOGIC;
qa:outSTD_LOGIC_VECTOR(3DOWNTO0);--個(gè)位數(shù)計(jì)數(shù)
qb:outSTD_LOGIC_VECTOR(1DOWNTO0));--十位數(shù)計(jì)數(shù)ENDcount24;ARCHITECTUREa1OFcount24ISBEGINprocess(clk)variabletma:STD_LOGIC_VECTOR(3DOWNTO0);variabletmb:STD_LOGIC_VECTOR(1DOWNTO0);ResetbeginIfReset=‘0‘thentma:="0000";tmb:="00";else
ifclk'eventandclk='1'thenifen='1'theniftma="1001"thentma:="0000";tmb:=tmb+1;--如果個(gè)位數(shù)為9,個(gè)位數(shù)清零,十位數(shù)加一
elsif
tmb="10"andtma="0011"then
tma:="0000";tmb:="00";--如果十位數(shù)為2,個(gè)位數(shù)為3,個(gè)位數(shù)十位數(shù)均清零
elsetma:=tma+1;--以上條件均不滿足,則個(gè)位數(shù)加一
endif;
endif;endif;endif;qa<=tma;qb<=tmb;將結(jié)果輸出endprocess;ENDa1;LIBRARYieee;USEieee.std_logic_1164.ALL;USEieee.std_logic_unsigned.ALL;ENTITYcount60ISPORT(en,Reset,clk:inSTD_LOGIC;
qa:outSTD_LOGIC_VECTOR(3DOWNTO0);--個(gè)位數(shù)計(jì)數(shù)
qb:outSTD_LOGIC_VECTOR(2DOWNTO0);--十位數(shù)計(jì)數(shù)
rco:OUTSTD_LOGIC);--計(jì)數(shù)進(jìn)位ENDcount60;ARCHITECTUREaOFcount60ISBEGINprocess(clk)variabletma:STD_LOGIC_VECTOR(3DOWNTO0);variabletmb:STD_LOGIC_VECTOR(2DOWNTO0);60進(jìn)制計(jì)數(shù)器ENQAQBCLKRCOResetbeginIfReset=‘0’thentma:="0000";
tmb:="0000";elseifclk'eventandclk='1'thenifen='1'thenrco<=tmb(2)andtmb(0)andtma(3)andtma(0);--計(jì)算是否有進(jìn)位,即是否計(jì)數(shù)超過59,超過則有進(jìn)位,否則無進(jìn)位
iftma="1001"thentma:="0000";--如果個(gè)位數(shù)為9,則個(gè)位數(shù)清零
iftmb="101"thentmb:="000";elsetmb:=tmb+1;endif;
--如果十位數(shù)為5,則十位數(shù)清零,否則十位數(shù)加一
elsetma:=tma+1;--如果個(gè)位數(shù)不為9,則個(gè)位數(shù)加一
endif;endif;
endif;endif;qa<=tma;qb<=tmb;將結(jié)果輸出endprocess;ENDa;2、分頻器設(shè)計(jì)
計(jì)數(shù)器就是對時(shí)鐘脈沖計(jì)數(shù),同時(shí)計(jì)數(shù)器還是一個(gè)分頻器。下圖為一個(gè)3位的計(jì)數(shù)器的仿真波形圖。<1>一個(gè)3bits的計(jì)數(shù)器,它所能計(jì)數(shù)的范圍為0~7(=23-1)。同理,nbits的計(jì)數(shù)器所能計(jì)數(shù)范圍為0~2n-1。<2>Q0、Q1、Q2的波形頻率分別為時(shí)鐘脈沖信號(hào)Clk的1/2、1/4、1/8,由此可以知道,nbits的計(jì)數(shù)器可獲得的最低分頻頻率為時(shí)鐘脈沖信號(hào)Clk的1/2n。<3>輸出信號(hào)Q(2downto0)的頻率等于信號(hào)Q2的頻率,信號(hào)Q(2downto1)的頻率也為信號(hào)Q2的頻率。由此可以知道,矢量信號(hào)的頻率為最高位信號(hào)的頻率。<4>對于4MHz頻率信號(hào),若得到1Hz時(shí)鐘脈沖信號(hào)Clk,通過公式f=1/2n可計(jì)算出n≈22,即應(yīng)設(shè)計(jì)一個(gè)22位的計(jì)數(shù)器。4MHz到1Hz的分頻器
LIBRARYieee;USEieee.std_logic_1164.ALL;USEieee.std_logic_unsigned.ALL;ENTITYcountISPORT(clk:inSTD_LOGIC;q:outSTD_LOGIC;ENDcount;ARCHITECTUREaOFcountISsignaltmp:STD_LOGIC_vector(21downto0);Beginprocess(clk)beginifclk'eventandclk='1'thentmp<=tmp+1;endif;endprocess;q<=tmp(21);ENDa;十進(jìn)制計(jì)數(shù)器
LIBRARYieee;USEieee.std_logic_1164.ALL;USEieee.std_logic_unsigned.ALL;ENTITYcount10ISPORT(clk:INSTD_LOGIC;
seg:OUTSTD_LOGIC_VECTOR(6DOWNTO0));ENDcount10;ARCHITECTUREa1OFcount10ISsignalsec:STD_LOGIC;signalq:STD_LOGIC_VECTOR(21DOWNTO0);signalnum:STD_LOGIC_VECTOR(3DOWNTO0);BEGINprocess(clk)----get1hzclockpulsebeginifclk'eventandclk='1'thenq<=q+1;endif;sec<=q(21);--get1hzclockpulseendprocess;timing:process(sec)beginifsec'eventandsec='1'thenifnum<9thennum<=num+1;elsenum<="0000";endif;endif;endprocess;B1:block--bcd-7segsBegin--gfedcbaseg<="0111111"whennum=0else"0000110"whennum=1else"1011011"whennum=2else"1001111"whennum=3else"1100110"whennum=4else"1101101"whennum=5else"1111101"whennum=6else"0000111"whennum=7else"1111111"whennum=8else"1101111"whennum=9else"0000000";endblock;ENDa1;3交通燈控制器的設(shè)計(jì)
設(shè)計(jì)一個(gè)十字路口交通燈控制器,東西、南北方向有紅燈、黃燈、綠燈,持續(xù)時(shí)間分別為45、5、40秒。東西方向b南北方向a十字路口東西方向b南北方向a十字路口交通燈控制器ClkRaYaGaYbRbGb電路框圖GA,RBT=40S?NoYesYA,RBT=5S?NoYesRA,GBT=40S?NoYesRA,YBT=5S?NoYes交通燈控制流程圖S0S1S2S3LIBRARYieee;USEieee.std_logic_1164.ALL;USEieee.std_logic_unsigned.ALL;ENTITYnclightISPort(clk:instd_logic;
ra,rb,ya,yb,ga,gb:outstd_logic);ENDnclight;Architectureaofnclightistypestateis(S0,S1,S2,S3);signalpresentstate,nextstate:state;signaltmp1,tmp2:integerrange0to40;signaltimeout1,timeout2:std_logic;signalq:std_logic_vector(21downto0);signalsec:std_logic;Begin----get1hzclockpulseprocess(clk)beginifclk'eventandclk='1'thenq<=q+1;endif;sec<=q(21);--get1hzclockpulseendprocess;timing:process(sec)beginifsec'eventandsec='1'then
iftmp1=39thentimeout1<='1';timeout2<='0';tmp1<=0;elseiftimeout1='1'then
iftmp2=4thentimeout2<='1';timeout1<='0';tmp2<=0;elsetmp2<=tmp2+1;endif;
elsetmp1<=tmp1+1;endif;endif;
endif;endprocess;changestate:process(presentstate)Begincasepresentstateis
whenS0=>iftimeout1='0'then
nextstate<=s0;
ra<='0';
ya<='0';ga<='1';
rb<='1';
yb<='0';gb<='0';elsenextstate<=s1;endif;whenS1=>iftimeout2='0'then
nextstate<=s1;
ra<='0';ya<='1';
ga<='0';
rb<='1';yb<='0';gb<='0';elsenextstate<=s2;endif;whenS2=>iftimeout1='0'then
nextstate<=s2;
ra<='1';
ya<='0';ga<=‘1';
rb<='0';yb<='0';gb<='1';
elsenextstate<=s3;endif;whenS3=>iftimeout2='0'then
nextstate<=s3;
ra<='1';
ya<='0';ga<='0';
rb<='0';yb<='1';
gb<='0';elsenextstate<=s0;endif;
whenothers=>nextstate<=s0;timeout1<='0';timeout2<='0';
endcase;endprocess;enda;4、數(shù)控分頻器設(shè)計(jì)
對于一個(gè)加法計(jì)數(shù)器,裝載不同的計(jì)數(shù)初始值時(shí),會(huì)有不同頻率的溢出輸出信號(hào)。計(jì)數(shù)器溢出時(shí),輸出‘1’電平,同時(shí)溢出時(shí)的‘1’電平反饋給計(jì)數(shù)器的輸入端作為裝載信號(hào);否則輸出‘0’電平。Libraryieee;Useieee.std_logic_1164.all;EntityspeakerisPort(
clk:instd_logic;
Freq_num:inintegerrange0to2047;--16#7FF#speaker:outstd_logic);Endspeaker;Architecturea1ofspeakerissignalpower_speaker:std_logic;beginProcess(clk)variablecount11bit:integerrange0to2047;Beginifclk'eventandclk='1'thenifcount11bit=2047thencount11bit:=Freq_num;
power_speaker<='1';Elsecount11bit:=count11bit+1;
power_speaker<='0';endif;endif;endprocess;--將輸出再進(jìn)行2分頻,將脈沖展寬,以使揚(yáng)聲器有足夠功率發(fā)音process(power_speaker)variablecount2bit:std_logic;Beginifpower_speaker'eventandpower_speaker='1'then
count2bit:=notcount2bit;ifcount2bit='1'thenspeaker<='1';elsespeaker<='0';endif;endif;endprocess;Enda1;C調(diào)音階頻率表
音階頻率/Hz音階頻率/Hz音階頻率/Hz1661.227830.61415.311479.986739.99370.001318.525659.33329.631174.664587.33293.671108.733554.37277.19987.762493.88246.94880.001440.00220.00參考代碼表clk=1MHz計(jì)數(shù)器的模為2048
音調(diào)音符1234567初始值高1730175017701790181518301930中1410149015601600162216501690低77391210361116119712901372次低100200300400500600700音樂演奏電路
35
635—65
312—設(shè)計(jì)框圖數(shù)控分頻器揚(yáng)聲器驅(qū)動(dòng)電路揚(yáng)聲器Freq_numClk1MHz分頻器4Hz16進(jìn)制計(jì)數(shù)器ROM模塊SpeakerIndexLibraryieee;Useieee.std_logic_1164.all;Useieee.std_logic_unsigned.all;EntitytoneisPort(index:inintegerrange0to16;tone:outintegerrange0to16#7FF#);Endtone;Architecturea1oftoneisBeginprocess(index)Begin35
635—65
312—caseindexiswhen0=>
tone<=1560;when1=>
tone<=1622;when2=>
tone<=1650;when3=>
tone<=1560;when4=>
tone<=1622;when5=>
tone<=1622;when6=>
tone<=1622;when7=>
tone<=1622;
when8=>
tone<=1650;when9=>
tone<=1622;when10=>tone<=1560;when11=>tone<=1410;when12=>tone<=1490;when13=>tone<=1490;when14=>tone<=1490;when15=>tone<=1490;
whenothers=>tone<=2047;Endcase;Endprocess;Enda1;35
635—65
312—音調(diào)音符1234567初始值高1730175017701790181518301930中1410149015601600162216501690低77391210361116119712901372次低100200300400500600700Libraryieee;Useieee.std_logic_1164.all;Useieee.std_logic_unsigned.all;EntitytopisPort(clk:instd_logic;spkout:outstd_logic);Endtop;Architecturea1oftopiscomponenttonePort(index:inintegerrange0to16;tone:outintegerrange0to16#7FF#);endcomponent;componentspeakerPort(clk:instd_logic;
Freq_in:inintegerrange0to16#7FF#;speaker:outstd_logic);endcomponent;signalindex1:integerrange0to16;signaltone2:integerrange0to16#7FF#;signalck4:std_logic;beginprocess(clk)variableq:std_logic_vector(17downto0);Beginifclk'eventandclk='1'thenq:=q+1;
endif;ck<=q(17);endprocess;process(ck)Beginifck'eventandck='1'thenifindex1=15thenindex1<=0;elseindex1<=index1+1;
endif;endif;endprocess;u1:toneportmap(index1,tone2);u2:speakerportmap(clk,tone2,spkout);Enda1;例2:用lpm_rom兆函數(shù)模塊實(shí)現(xiàn)七段碼顯示0-F。
IP核的使用(提高電路設(shè)計(jì)效率的有效方法)
LPM宏單元庫分為:
門單元函數(shù),如:lpm_and,lpm_mux…
算術(shù)運(yùn)算函數(shù),如:lpm_add_sub,
lpm_mult
存貯函數(shù),如:lpm_ff,lpm_rom…
七段顯示譯碼電路七段碼顯示:abcdefg1.七段譯碼關(guān)系表如下:
a[3..0] a,b,c,d,e,f,g 0 1,1,1,1,1,1,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 成都房產(chǎn)交易合同范本:房屋交易售后服務(wù)及保障措施
- 塔吊操作人員勞務(wù)派遣與權(quán)益保障合同
- 公共停車場車位租用及停車秩序管理合同
- 藏式風(fēng)格民宿客房裝修設(shè)計(jì)監(jiān)理合同
- 胎兒監(jiān)護(hù)考試題及答案
- 殘疾人勞動(dòng)合同簽訂與勞動(dòng)能力評估標(biāo)準(zhǔn)
- 鐵廠電工面試題及答案
- 文秘工作的面試題及答案
- 餐廳餐飲行業(yè)市場拓展合作合同
- 采購降本措施培訓(xùn)
- 急性上消化道出血Blatchford評分
- DB12-T368-2008鹵蟲池塘養(yǎng)殖技術(shù)規(guī)范
- TSG11-2020 鍋爐安全技術(shù)規(guī)程
- 航圖zbyn太原武宿-機(jī)場細(xì)則
- 浙江省城市體檢工作技術(shù)導(dǎo)則(試行)
- 義務(wù)教育歷史課程標(biāo)準(zhǔn)(2022年版)
- 防火封堵施工方案(新版)
- 真空度正壓和負(fù)壓關(guān)系及負(fù)壓中MPa和Pa對應(yīng)關(guān)系
- 大面積地面荷載作用附加沉降量計(jì)算
- 山東省普通初中小學(xué)音樂、美術(shù)、衛(wèi)生設(shè)備配備標(biāo)準(zhǔn)
評論
0/150
提交評論