簡易音樂播放器數(shù)電實(shí)驗(yàn)_第1頁
簡易音樂播放器數(shù)電實(shí)驗(yàn)_第2頁
簡易音樂播放器數(shù)電實(shí)驗(yàn)_第3頁
簡易音樂播放器數(shù)電實(shí)驗(yàn)_第4頁
簡易音樂播放器數(shù)電實(shí)驗(yàn)_第5頁
已閱讀5頁,還剩12頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、數(shù)字電路與邏輯設(shè)計(jì)綜合設(shè)計(jì)實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)名稱:簡易音樂播放器姓名: 班級(jí): 班班內(nèi)序號(hào):27一、 設(shè)計(jì)任務(wù)要求設(shè)計(jì)制作一個(gè)簡易樂曲播放器。1)播放器內(nèi)預(yù)存3首樂曲;2)播放模式:順序播放、隨機(jī)播放,并用數(shù)碼管或LED顯示當(dāng)前播放模式;3)順序播放:按內(nèi)部給定的順序依次播放3首樂曲;4)隨機(jī)播放:隨機(jī)產(chǎn)生一個(gè)順序播放3首樂曲;5)用數(shù)碼管顯示當(dāng)前播放樂曲的順序號(hào);6)設(shè)置開始/暫停鍵,樂曲播放過程中按該鍵則暫停播放,再按則繼續(xù)播放;7)設(shè)置Next和Previous鍵,按Next鍵可以聽下 一首,按Previous鍵回到本首開始;8)選做:用戶可以自行設(shè)定播放順序,設(shè)置完成后,播放器按該順序依次播

2、放樂曲;9)選做:自擬其它功能。二、系統(tǒng)設(shè)計(jì)1)設(shè)計(jì)思路首先音樂有音高和節(jié)拍兩個(gè)因素。音高可以通過對(duì)時(shí)鐘信號(hào)不同的分頻得到不同頻率的信號(hào)進(jìn)而發(fā)出不同的音,節(jié)拍可以定義一個(gè)音符計(jì)數(shù)器,計(jì)數(shù)器的每一個(gè)值對(duì)應(yīng)一個(gè)音高。對(duì)播放的控制包括播放/暫停、復(fù)位、上一首、下一首、本首重放、順序播放/隨機(jī)播放,用一個(gè)狀態(tài)機(jī),共播放和暫停兩個(gè)狀態(tài),另外歌曲的切換以及暫停都是利用音符計(jì)數(shù)器賦不同的值或保持不變來實(shí)現(xiàn)。音高的顯示是通過不同的音符對(duì)應(yīng)不同的點(diǎn)陣row和col的值來實(shí)現(xiàn)的。歌曲號(hào)是通過音符計(jì)數(shù)器的值來得出并送到數(shù)碼管顯示的。播放、暫停、順序、隨機(jī)這些的顯示是通過對(duì)狀態(tài)和模式變量的判別進(jìn)而送到LED顯示的。2

3、)總體框圖div1div2div3keycontrolmelodyindexshownumberspeaker50M1M4hz2hzrand隨機(jī)數(shù)上、下、本首、復(fù)位、暫停鍵、順序隨機(jī)選擇暫停態(tài)的標(biāo)志音符序號(hào)音符序號(hào)歌曲號(hào)音高對(duì)應(yīng)的分頻數(shù)輸出聲音信號(hào)順序隨機(jī)暫停的LED顯示音高的點(diǎn)陣顯示 3)分塊設(shè)計(jì) 共分為9個(gè)模塊。Div1,div2,div3都是用來分頻的,分別是將50mhz變?yōu)?mhz,將1mhz變?yōu)?hz,將1mhz變?yōu)?hz。Rand模塊用來產(chǎn)生隨機(jī)數(shù),用于隨機(jī)播放模式。Keycontrol是核心模塊,用來實(shí)現(xiàn)順序播放、隨機(jī)播放、播放/暫停、上一首、下一首、本首重放、復(fù)位、顯示順序或隨

4、機(jī)播放狀態(tài)、顯示播放/暫停態(tài)。Melody模塊是將音符計(jì)數(shù)器的每一個(gè)值與一個(gè)音高相對(duì)應(yīng),即記錄曲譜。Index模塊是用melody模塊傳來的音高信號(hào)通過查表得到它所對(duì)應(yīng)的音高的分頻數(shù),然后將這個(gè)分頻數(shù)送給speaker模塊,以發(fā)出不同的音,另外對(duì)應(yīng)不同的音它還對(duì)點(diǎn)陣進(jìn)行不同的輸出,進(jìn)而顯示出音高。Speaker模塊接收index模塊送來的分頻數(shù),利用分頻數(shù)對(duì)時(shí)鐘信號(hào)進(jìn)行分頻,進(jìn)而發(fā)出不同的音,另外它還接收keycontrol模塊送來的暫停態(tài)的標(biāo)志,以保證在暫停態(tài)的時(shí)候不發(fā)出聲音。Shownumber模塊通過對(duì)音符計(jì)數(shù)器值的判斷確定現(xiàn)在播放的是哪首歌,進(jìn)而輸出不同的歌曲號(hào)。3、 仿真波形及波形分

5、析1)div1模塊由仿真結(jié)果可看出,它將50mhz的時(shí)鐘信號(hào)變換為1mhz。Div2和div3模塊分別是將1mhz變?yōu)?hz,將1mhz變?yōu)?hz,原理相同,因而不再列出仿真結(jié)果。2) Rand模塊由仿真結(jié)果可以看出在每一個(gè)時(shí)鐘周期內(nèi),randnumber改變一次,randnumber可作為隨機(jī)數(shù)的產(chǎn)生信號(hào)。3)Keycontrol模塊:(時(shí)鐘用的是未經(jīng)分頻的) 順序播放:可以看出,在mode=0,即順序播放模式下,在沒有按任何鍵時(shí),音符計(jì)數(shù)器counter隨時(shí)鐘自動(dòng)加1從而進(jìn)入下一個(gè)音。Sequential表示順序播放,random表示隨機(jī)播放,由圖可見此時(shí)sequential為高電平,ra

6、ndom為低電平,可知此時(shí)為順序播放狀態(tài)。 counter由144自動(dòng)變到145是第一首播完自動(dòng)到第二首 下一首:當(dāng)按一下一首鍵時(shí),即nextone變?yōu)楦唠娖?,音符?jì)數(shù)器counter由第一首歌的14變到了第二首歌開始音符所對(duì)應(yīng)的數(shù)145,實(shí)現(xiàn)了切換到下一首的功能。 本首重放:當(dāng)播放到第二首歌的152時(shí),按下了本首重放鍵,即previous變?yōu)楦唠娖?,這時(shí)counter變?yōu)榈诙赘杵鹗家魧?duì)應(yīng)的數(shù)145,進(jìn)而實(shí)現(xiàn)了本首重放的功能。 上一首:當(dāng)播放到第二首對(duì)應(yīng)counter為151時(shí),按下了上一首鍵,即lastone變?yōu)楦唠娖剑琧ounter變?yōu)榈谝皇赘杵鹗家舴鶎?duì)應(yīng)的值1,從而實(shí)現(xiàn)了切換到上一首

7、的功能。 暫停:當(dāng)按下暫停鍵后,即pp變?yōu)楦唠娖?,暫停狀態(tài)的標(biāo)志ppsymbol就變?yōu)楦唠娖?,用于送給LED顯示播放/暫停態(tài)的ppout變?yōu)橹芷谛盘?hào),實(shí)際中周期為1s,即LED會(huì)在1s內(nèi)一亮一滅進(jìn)行閃爍,表示進(jìn)入了暫停狀態(tài)。 暫停后再按“播放/暫?!辨I:在暫停態(tài)再按一次播放/暫停鍵后,即pp再次變?yōu)楦唠娖?,ppout變?yōu)榈碗娖?,?duì)應(yīng)的LED會(huì)熄滅表示進(jìn)入了播放狀態(tài),ppsymbol也變?yōu)榈碗娖健?暫停后按下一首:按了暫停鍵之后,即pp變?yōu)楦唠娖街螅职戳讼乱皇祖I,即nextone變?yōu)楦唠娖剑@時(shí)進(jìn)入播放狀態(tài),同時(shí)counter變成了下一首歌的第一個(gè)音符對(duì)應(yīng)的值,實(shí)現(xiàn)了通過按下一首退出暫停狀態(tài)

8、,同時(shí)進(jìn)行歌曲的切換。 暫停后按上一首:暫停后按上一首,即pp變?yōu)楦唠娖胶髄astone也變?yōu)楦唠娖剑瑒t進(jìn)入播放狀態(tài),并且開始播上一首。(信號(hào)counter中158對(duì)應(yīng)的是第二首的音符,1對(duì)應(yīng)的是第一首的音符) 暫停后按本首重放:暫停后按本首重放,即pp變?yōu)楦唠娖胶髉revious也變?yōu)楦唠娖?,這時(shí)進(jìn)入播放狀態(tài),另外counter變?yōu)楸臼赘璧谝粋€(gè)音對(duì)應(yīng)的數(shù),實(shí)現(xiàn)了本首重放。 復(fù)位:復(fù)位所要實(shí)現(xiàn)的是不管是在順序播放還是隨機(jī)播放狀態(tài)下,只要一按下復(fù)位鍵,就從第一首歌開始播放。如圖,counter等于272時(shí)reset變?yōu)楦唠娖?,counter變?yōu)?。 隨機(jī)播放:在隨機(jī)播放狀態(tài),即mode=1時(shí),在

9、第一首歌的最后一個(gè)音(counter為144時(shí))時(shí)程序會(huì)檢測(cè)隨機(jī)數(shù)randnumber的值,查到是3,于是下一次counter就變?yōu)榈谌赘璧谝粋€(gè)音對(duì)應(yīng)的數(shù)213,從而實(shí)現(xiàn)了隨機(jī)播放。此時(shí)random為高電平,sequential為低電平,表示此時(shí)為隨機(jī)播放狀態(tài)。 隨機(jī)播放狀態(tài)下按上一首:按了上一首(lastone變?yōu)楦唠娖剑┖?,?jù)隨機(jī)數(shù)randnumber的值3,于是轉(zhuǎn)入播放第三首。 按下一首:和按上一首是一樣的,也是根據(jù)當(dāng)前randnumber值來確定下一首要播的是哪一首。Randnumber等于1、2、3、4分別對(duì)應(yīng)第一、二、三、四首歌。 按本首重放:隨機(jī)播放模式下按本首重放,即prev

10、ious變?yōu)楦唠娖?,?shí)現(xiàn)的功能與在順序播放模式是一樣的。由圖可見,播放到第一首的10時(shí),counter變?yōu)?,即回到第一首的第一個(gè)音開始播。3) Melody模塊:根據(jù)不同的音符計(jì)數(shù)器counter的值,指示音高的值toneindex也在變化,其中1到7代表中音1到7,8代表高音1,9到13代表低音3到7。4) Index模塊:由仿真結(jié)果可看出,當(dāng)音高toneindex為不同的值時(shí),分頻數(shù)tonefreq的值也不同,將它送給speaker模塊對(duì)時(shí)鐘進(jìn)行分頻,即可得到不同的音高。另外不同的toneindex值對(duì)應(yīng)的點(diǎn)陣的row和col的值也不一樣,進(jìn)而可以利用點(diǎn)陣顯示音高。5)Speaker模塊

11、: 根據(jù)分頻數(shù)tonefreq的不同,對(duì)時(shí)鐘產(chǎn)生的分頻也不同,如圖可見為tonefreq在0和2時(shí)輸出聲音信號(hào)sound的兩種頻率,進(jìn)而會(huì)發(fā)出不同的音。 如下圖,分頻數(shù)tonefreq的值并沒有變,但表暫停的標(biāo)志ppsymbol變?yōu)榱烁唠娖剑瑫和顟B(tài)不允許發(fā)聲,因而輸出的聲音信號(hào)sound變?yōu)榈碗娖?,?dāng)ppsymbol回到低電平時(shí),sound才又變回tonefreq所對(duì)應(yīng)頻率的信號(hào)。6)Shownumber模塊: 第一首:在音符計(jì)數(shù)器counter的值是第一首歌時(shí),控制數(shù)碼管顯示歌曲號(hào)的段選碼number一直是01100000,于是在數(shù)碼管上顯示1。而位選碼則一直保持01111111不變,只讓

12、固定的一個(gè)數(shù)碼管來顯示。 第二首Counter現(xiàn)在對(duì)應(yīng)的是第二首歌的音符,number的值為11011010,數(shù)碼管顯示2。四、主要部分源程序1)外圍模塊playerlibrary ieee;use ieee.std_logic_1164.all;entity player isPort -整個(gè)系統(tǒng)對(duì)外的輸入輸出端口 ( clk50mhz,reset,lastone,previous,nextone,pp,mode:in std_logic; sequential,random,ppout,sound:out std_logic; col,row,number:out std_logic_ve

13、ctor(7 downto 0); enable:out std_logic_vector(5 downto 0) ); end player;architecture one of player is -子模塊定義component div1port(clk50mhz:in std_logic;clk1mhz:out std_logic);end component;component div2port(clk1mhz:in std_logic;clk4hz:out std_logic);end component;component div3port(clk1mhz:in std_logi

14、c;clk2hz:out std_logic);end component;component randport(clk4hz:in std_logic;randnumber:out integer range 1 to 4);end component;component keycontrolport(lastone,previous,nextone,pp,mode,reset,clk2hz,clk4hz:in std_logic;randnumber:in integer range 1 to 4;sequential,random,ppout,ppsymbol:out std_logic

15、;counter:out integer range 1 to 400);end component;component melodyport(counter:in integer range 1 to 400;toneindex:out integer range 0 to 13);end component;component indexport(toneindex:in integer range 0 to 13;tonefreq:out integer range 0 to 1516 ;row:out std_logic_vector(7 downto 0);col:out std_l

16、ogic_vector(7 downto 0);end component;component speakerport(clk1mhz,ppsymbol:in std_logic;tonefreq:in integer range 0 to 1516 ;sound:out std_logic);end component;component shownumberport(counter:in integer range 1 to 400;enable:out std_logic_vector(5 downto 0);number:out std_logic_vector(7 downto 0)

17、;end component;signal clk1mhz,clk4hz,clk2hz,ppsymbol:std_logic;signal randnumber:integer range 1 to 4;signal counter:integer range 1 to 400;signal toneindex:integer range 0 to 13;signal tonefreq:integer range 0 to 1516 ;Begin -各模塊間端口的連接u1:div1 port map(clk50mhz=clk50mhz,clk1mhz=clk1mhz);u2:div2 port

18、 map(clk1mhz=clk1mhz,clk4hz=clk4hz);u3:div3 port map(clk1mhz=clk1mhz,clk2hz=clk2hz);u4:rand port map(clk4hz=clk4hz,randnumber=randnumber);u5:keycontrol port map(lastone=lastone,previous=previous,nextone=nextone,pp=pp,mode=mode,reset=reset,clk2hz=clk2hz,clk4hz=clk4hz,randnumber=randnumber,sequential=

19、sequential,random=random,ppout=ppout,ppsymbol=ppsymbol,counter=counter);u6:melody port map(counter=counter,toneindex=toneindex);u7:index port map(toneindex=toneindex,tonefreq=tonefreq,row=row,col=col);u8:speaker port map(clk1mhz=clk1mhz,tonefreq=tonefreq,sound=sound,ppsymbol=ppsymbol);u9:shownumber

20、port map(counter=counter,enable=enable,number=number);end one;2) 分頻模塊div1(div2、div3與div1類似,不再重復(fù))這個(gè)模塊將50mhz時(shí)鐘分頻成1mhzlibrary ieee;use ieee.std_logic_1164.all;entity div1 isport(clk50mhz:in std_logic;clk1mhz:out std_logic);end div1;architecture one of div1 issignal t:std_logic:=0;begin clk1mhz=t;p1:pro

21、cess(clk50mhz)variable c:integer range 0 to 24; begin if(clk50mhzevent and clk50mhz=1) then if(c=24)then c:=0; t=not t; else c:=c+1; end if; end if;end process p1;end one;3) 產(chǎn)生隨機(jī)數(shù)的rand模塊:library ieee;use ieee.std_logic_1164.all;entity rand isport(clk4hz:in std_logic;randnumber:out integer range 1 to

22、 4);end rand;architecture one of rand issignal temp:std_logic_vector(3 downto 0);begin process(clk4hz,temp) begin if(temp=0000)then temp=0001; elsif(clk4hzevent and clk4hz=1)then -利用M序列發(fā)生器產(chǎn)生偽隨機(jī)序列 temp(0)=temp(0)xor temp(3); temp(1)=temp(0); temp(2)=temp(1); temp(3)=temp(2); end if; if(temp=0001or te

23、mp=0111or temp=1011or temp=0010)then randnumber=1; elsif(temp=0011or temp=1100or temp=1001or temp=1000)then randnumber=2; elsif(temp=1111or temp=1101or temp=0101or temp=0110)then randnumber=3; elsif(temp=1110or temp=1010or temp=0100)then randnumber=4; end if; end process;end one;4) 核心模塊keycontrol:li

24、brary ieee;use ieee.std_logic_1164.all;entity keycontrol isport(lastone,previous,nextone,pp,mode,reset,clk2hz,clk4hz:in std_logic;randnumber:in integer range 1 to 4;sequential,random,ppout,ppsymbol:out std_logic;counter:out integer range 1 to 400:=1);end keycontrol;architecture one of keycontrol ist

25、ype statetype is(play,pause,nothing);signal state:statetype:=play; -狀態(tài)定義,有播放和暫停兩種狀態(tài)signal count:integer range 1 to 400:=1; signal t:std_logic;begincounter=count;ppout=t;p1:process(clk4hz) begin if(clk4hzevent and clk4hz=1)then if(reset=1)then -復(fù)位 state=play; count state state=pause; countnull; end c

26、ase; else if(previous=0and lastone=0and nextone=0)then case state is when pause=count if(mode=0)then -為順序播放模式時(shí) if(count=400)then count=1; else count=count+1; end if; Else -為隨機(jī)播放模式時(shí) if(count=144 or count=212 or count=344 or count=400)then if(randnumber=1)then -據(jù)隨機(jī)數(shù)不同確定下一首歌曲 count=1; elsif(randnumber=

27、2)then count=145; elsif(randnumber=3)then count=213; else count=345; end if; else countnull; end case; Else -當(dāng)有鍵按下時(shí) case state is when pause= -當(dāng)為暫停態(tài)時(shí) if(lastone=0and previous=1and nextone=0)then -按下了本首重放鍵 state=1 and count=144)then count=145 and count=212)then count=213 and count=344)then count=213;

28、 else count=345; end if; else if(mode=0)then -順序播放模式 if(lastone=1and previous=0and nextone=0)then -上一首 state=1 and count=144)then count=145 and count=212)then count=213 and count=344)then count=145; else count=213; end if; elsif(lastone=0and previous=0and nextone=1)then -下一首 state=1 and count=144)th

29、en count=145 and count=212)then count=213 and count=344)then count=345; else count=1; end if; end if; Else -隨機(jī)播放模式 if(lastone=1or nextone=1)then -按下了上一首或下一首 state=play; if(randnumber=1)then count=1; elsif(randnumber=2)then count=145; elsif(randnumber=3)then count=213; else count -播放狀態(tài) if(lastone=0an

30、d previous=1and nextone=0)then -本首重放 if(count=1 and count=144)then count=145 and count=212)then count=213 and count=344)then count=213; else count=1 and count=144)then count=145 and count=212)then count=213 and count=344)then count=145; else count=1 and count=144)then count=145 and count=212)then co

31、unt=213 and count=344)then count=345; else count=1; end if; end if; Else -隨機(jī)播放模式 if(lastone=1or nextone=1)then -按上一首或下一首 if(randnumber=1)then count=1; elsif(randnumber=2)then count=145; elsif(randnumber=3)then count=213; else countnull; end case; end if; end if; end if;end process p1;p2:process(mode

32、) -根據(jù)模式不同(即mode值不同),顯示順序與隨機(jī)兩種播放模式,用sequential和random來表示begin if(mode=0)then sequential=1; random=0; else sequential=0; randomt tnull; end case; end if;end process p3;p4:process(state) -根據(jù)播放還是暫停狀態(tài)來給暫停態(tài)的標(biāo)志ppsymbol賦值begin case state is when play=ppsymbolppsymbolnull; end case;end process p4;end one;5)

33、記錄曲譜的模塊melody:library ieee;use ieee.std_logic_1164.all;entity melody isport(counter:in integer range 1 to 400;toneindex:out integer range 0 to 13);end melody;architecture one of melody isbeginp1:process(counter)begin case counter is when 1=toneindextoneindextoneindextoneindextonefreq=0; col=00000000

34、;rowtonefreq=955; col=10000000;rowtonefreq=850; col=01000000;rowtonefreq=757; col=00100000;rowtonefreq=715; col=00010000;rowtonefreq=637; col=00001000;rowtonefreq=567; col=00000100;rowtonefreq=505; col=00000010;rowtonefreq=477; col=00000001;rowtonefreq=1516; col=00100000;rowtonefreq=1431; col=000100

35、00;rowtonefreq=1275; col=00001000;rowtonefreq=1135; col=00000100;rowtonefreq=1011; col=00000010;rowtonefreq=0;col=00000000;row=11111111; end case;end process p1;end one;7) 發(fā)聲模塊speaker:library ieee;use ieee.std_logic_1164.all;entity speaker isport(clk1mhz,ppsymbol:in std_logic;tonefreq:in integer ran

36、ge 0 to 1516;sound:out std_logic);end speaker;architecture one of speaker issignal sound1:std_logic;beginsound=sound1;p1:process(clk1mhz,tonefreq) variable t:integer range 0 to 1516; begin if(clk1mhzevent and clk1mhz=1)then if(ppsymbol=1)then sound1=0; -暫停態(tài)不發(fā)聲 else if(t=tonefreq)then if(t=tonefreq)t

37、hen -產(chǎn)生與分頻數(shù)tonefreq相對(duì)應(yīng)的頻率的聲音信號(hào)sound t:=0; sound1=not sound1; else t:=t+1; end if; else t:=0; end if; end if; end if;end process p1;end one;8) 顯示歌曲號(hào)的模塊shownumber:library ieee;use ieee.std_logic_1164.all;entity shownumber isport(counter:in integer range 1 to 400;enable:out std_logic_vector(5 downto 0);number:out std_logic_vector(7 downto 0);end shownumber;architecture one of shownumber isbegin enable=1 and counter=144)then -根據(jù)不同的音符計(jì)數(shù)器的值來確定數(shù)碼管的段選碼number number=145 and counter=212)then number=213 and counter=344)then number=11110010; -輸出3 else number=01100110; -輸出4 end if; end process

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(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ǔ)空間,僅對(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)論