




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、-作者xxxx-日期xxxx簡易音樂播放器數電實驗【精品文檔】數字電路與邏輯設計綜合設計實驗報告實驗名稱:簡易音樂播放器姓名: 班級: 班班內序號:27一、 設計任務要求設計制作一個簡易樂曲播放器。1)播放器內預存3首樂曲;2)播放模式:順序播放、隨機播放,并用數碼管或LED顯示當前播放模式;3)順序播放:按內部給定的順序依次播放3首樂曲;4)隨機播放:隨機產生一個順序播放3首樂曲;5)用數碼管顯示當前播放樂曲的順序號;6)設置開始/暫停鍵,樂曲播放過程中按該鍵則暫停播放,再按則繼續播放;7)設置Next和Previous鍵,按Next鍵可以聽下 一首,按Previous鍵回到本首開始;8)選
2、做:用戶可以自行設定播放順序,設置完成后,播放器按該順序依次播放樂曲;9)選做:自擬其它功能。二、系統設計1)設計思路首先音樂有音高和節拍兩個因素。音高可以通過對時鐘信號不同的分頻得到不同頻率的信號進而發出不同的音,節拍可以定義一個音符計數器,計數器的每一個值對應一個音高。對播放的控制包括播放/暫停、復位、上一首、下一首、本首重放、順序播放/隨機播放,用一個狀態機,共播放和暫停兩個狀態,另外歌曲的切換以及暫停都是利用音符計數器賦不同的值或保持不變來實現。音高的顯示是通過不同的音符對應不同的點陣row和col的值來實現的。歌曲號是通過音符計數器的值來得出并送到數碼管顯示的。播放、暫停、順序、隨機
3、這些的顯示是通過對狀態和模式變量的判別進而送到LED顯示的。2)總體框圖div1div2div3keycontrolmelodyindexshownumberspeaker50M1M4hz2hzrand隨機數上、下、本首、復位、暫停鍵、順序隨機選擇暫停態的標志音符序號音符序號歌曲號音高對應的分頻數輸出聲音信號順序隨機暫停的LED顯示音高的點陣顯示 3)分塊設計 共分為9個模塊。Div1,div2,div3都是用來分頻的,分別是將50mhz變為1mhz,將1mhz變為4hz,將1mhz變為2hz。Rand模塊用來產生隨機數,用于隨機播放模式。Keycontrol是核心模塊,用來實現順序播放、隨機
4、播放、播放/暫停、上一首、下一首、本首重放、復位、顯示順序或隨機播放狀態、顯示播放/暫停態。Melody模塊是將音符計數器的每一個值與一個音高相對應,即記錄曲譜。Index模塊是用melody模塊傳來的音高信號通過查表得到它所對應的音高的分頻數,然后將這個分頻數送給speaker模塊,以發出不同的音,另外對應不同的音它還對點陣進行不同的輸出,進而顯示出音高。Speaker模塊接收index模塊送來的分頻數,利用分頻數對時鐘信號進行分頻,進而發出不同的音,另外它還接收keycontrol模塊送來的暫停態的標志,以保證在暫停態的時候不發出聲音。Shownumber模塊通過對音符計數器值的判斷確定現
5、在播放的是哪首歌,進而輸出不同的歌曲號。3、 仿真波形及波形分析1)div1模塊由仿真結果可看出,它將50mhz的時鐘信號變換為1mhz。Div2和div3模塊分別是將1mhz變為4hz,將1mhz變為2hz,原理相同,因而不再列出仿真結果。2) Rand模塊由仿真結果可以看出在每一個時鐘周期內,randnumber改變一次,randnumber可作為隨機數的產生信號。3)Keycontrol模塊:(時鐘用的是未經分頻的)Ø 順序播放:可以看出,在mode=0,即順序播放模式下,在沒有按任何鍵時,音符計數器counter隨時鐘自動加1從而進入下一個音。Sequential表示順序播放
6、,random表示隨機播放,由圖可見此時sequential為高電平,random為低電平,可知此時為順序播放狀態。Ø counter由144自動變到145是第一首播完自動到第二首Ø 下一首:當按一下一首鍵時,即nextone變為高電平,音符計數器counter由第一首歌的14變到了第二首歌開始音符所對應的數145,實現了切換到下一首的功能。Ø 本首重放:當播放到第二首歌的152時,按下了本首重放鍵,即previous變為高電平,這時counter變為第二首歌起始音對應的數145,進而實現了本首重放的功能。Ø 上一首:當播放到第二首對應counter為1
7、51時,按下了上一首鍵,即lastone變為高電平,counter變為第一首歌起始音符所對應的值1,從而實現了切換到上一首的功能。Ø 暫停:當按下暫停鍵后,即pp變為高電平,暫停狀態的標志ppsymbol就變為高電平,用于送給LED顯示播放/暫停態的ppout變為周期信號,實際中周期為1s,即LED會在1s內一亮一滅進行閃爍,表示進入了暫停狀態。Ø 暫停后再按“播放/暫停”鍵:在暫停態再按一次播放/暫停鍵后,即pp再次變為高電平,ppout變為低電平,對應的LED會熄滅表示進入了播放狀態,ppsymbol也變為低電平。Ø 暫停后按下一首:按了暫停鍵之后,即pp變為
8、高電平之后,又按了下一首鍵,即nextone變為高電平,這時進入播放狀態,同時counter變成了下一首歌的第一個音符對應的值,實現了通過按下一首退出暫停狀態,同時進行歌曲的切換。Ø 暫停后按上一首:暫停后按上一首,即pp變為高電平后lastone也變為高電平,則進入播放狀態,并且開始播上一首。(信號counter中158對應的是第二首的音符,1對應的是第一首的音符)Ø 暫停后按本首重放:暫停后按本首重放,即pp變為高電平后previous也變為高電平,這時進入播放狀態,另外counter變為本首歌第一個音對應的數,實現了本首重放。Ø 復位:復位所要實現的是不管是
9、在順序播放還是隨機播放狀態下,只要一按下復位鍵,就從第一首歌開始播放。如圖,counter等于272時reset變為高電平,counter變為1。Ø 隨機播放:在隨機播放狀態,即mode=1時,在第一首歌的最后一個音(counter為144時)時程序會檢測隨機數randnumber的值,查到是3,于是下一次counter就變為第三首歌第一個音對應的數213,從而實現了隨機播放。此時random為高電平,sequential為低電平,表示此時為隨機播放狀態。Ø 隨機播放狀態下按上一首:按了上一首(lastone變為高電平)后,據隨機數randnumber的值3,于是轉入播放第
10、三首。Ø 按下一首:和按上一首是一樣的,也是根據當前randnumber值來確定下一首要播的是哪一首。Randnumber等于1、2、3、4分別對應第一、二、三、四首歌。Ø 按本首重放:隨機播放模式下按本首重放,即previous變為高電平,實現的功能與在順序播放模式是一樣的。由圖可見,播放到第一首的10時,counter變為1,即回到第一首的第一個音開始播。3) Melody模塊:根據不同的音符計數器counter的值,指示音高的值toneindex也在變化,其中1到7代表中音1到7,8代表高音1,9到13代表低音3到7。4) Index模塊:由仿真結果可看出,當音高to
11、neindex為不同的值時,分頻數tonefreq的值也不同,將它送給speaker模塊對時鐘進行分頻,即可得到不同的音高。另外不同的toneindex值對應的點陣的row和col的值也不一樣,進而可以利用點陣顯示音高。5)Speaker模塊:Ø 根據分頻數tonefreq的不同,對時鐘產生的分頻也不同,如圖可見為tonefreq在0和2時輸出聲音信號sound的兩種頻率,進而會發出不同的音。Ø 如下圖,分頻數tonefreq的值并沒有變,但表暫停的標志ppsymbol變為了高電平,暫停狀態不允許發聲,因而輸出的聲音信號sound變為低電平,當ppsymbol回到低電平時,
12、sound才又變回tonefreq所對應頻率的信號。6)Shownumber模塊:Ø 第一首:在音符計數器counter的值是第一首歌時,控制數碼管顯示歌曲號的段選碼number一直是01100000,于是在數碼管上顯示1。而位選碼則一直保持01111111不變,只讓固定的一個數碼管來顯示。Ø 第二首Counter現在對應的是第二首歌的音符,number的值為11011010,數碼管顯示2。四、主要部分源程序1)外圍模塊playerlibrary ieee;use ieee.std_logic_1164.all; entity player isPort -整個系統對外的輸
13、入輸出端口 ( clk50mhz,reset,lastone,previous,nextone,pp,mode:in std_logic; sequential,random,ppout,sound:out std_logic; col,row,number:out std_logic_vector(7 downto 0); enable:out std_logic_vector(5 downto 0) ); end player; architecture one of player is -子模塊定義component div1port(clk50mhz:in std_logic;clk1
14、mhz:out std_logic);end component;component div2port(clk1mhz:in std_logic;clk4hz:out std_logic);end component;component div3port(clk1mhz:in std_logic;clk2hz:out std_logic);end component;component randport(clk4hz:in std_logic;randnumber:out integer range 1 to 4);end component;component keycontrolport(
15、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);end component;component melodyport(counter:in integer range 1 to 400;toneindex:out integer range 0 to 13);end compon
16、ent;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_logic_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 c
17、omponent;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);end component;signal clk1mhz,clk4hz,clk2hz,ppsymbol:std_logic;signal randnumber:integer range 1 to 4;signal counter:integer range 1 to 400;signal tonein
18、dex:integer range 0 to 13;signal tonefreq:integer range 0 to 1516 ;Begin -各模塊間端口的連接u1:div1 port map(clk50mhz=>clk50mhz,clk1mhz=>clk1mhz);u2:div2 port map(clk1mhz=>clk1mhz,clk4hz=>clk4hz);u3:div3 port map(clk1mhz=>clk1mhz,clk2hz=>clk2hz);u4:rand port map(clk4hz=>clk4hz,randnumber
19、=>randnumber);u5:keycontrol port map(lastone=>lastone,previous=>previous,nextone=>nextone,pp=>pp,mode=>mode,reset=>reset,clk2hz=>clk2hz,clk4hz=>clk4hz,randnumber=>randnumber,sequential=>sequential,random=>random,ppout=>ppout,ppsymbol=>ppsymbol,counter=>co
20、unter);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 port map(counter=>coun
21、ter,enable=>enable,number=>number);end one;2) 分頻模塊div1(div2、div3與div1類似,不再重復)這個模塊將50mhz時鐘分頻成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
22、cess(clk50mhz)variable c:integer range 0 to 24; begin if(clk50mhz'event 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) 產生隨機數的rand模塊:library ieee;use ieee.std_logic_1164.all;entity rand isport(clk4hz:in std_logic;randnumber:out
23、 integer range 1 to 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(clk4hz'event and clk4hz='1')then -利用M序列發生器產生偽隨機序列 temp(0)<=temp(0)xor temp(3); temp(1)<
24、=temp(0); temp(2)<=temp(1); temp(3)<=temp(2); end if; if(temp="0001"or temp="0111"or temp="1011"or temp="0010")then randnumber<=1; elsif(temp="0011"or temp="1100"or temp="1001"or temp="1000")then randnumber<=
25、2; elsif(temp="1111"or temp="1101"or temp="0101"or temp="0110")then randnumber<=3; elsif(temp="1110"or temp="1010"or temp="0100")then randnumber<=4; end if; end process;end one;4) 核心模塊keycontrol:library ieee;use ieee.std_log
26、ic_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 istype statetype is(play,pause
27、,nothing);signal state:statetype:=play; -狀態定義,有播放和暫停兩種狀態signal count:integer range 1 to 400:=1; signal t:std_logic;begincounter<=count;ppout<=t;p1:process(clk4hz) begin if(clk4hz'event and clk4hz='1')then if(reset='1')then -復位 state<=play; count<=1; elsif(pp='1
28、9;)then -按下播放/暫停鍵 case state is when pause=> state<=play; when play=> state<=pause; count<=count; when nothing=>null; end case; else if(previous='0'and lastone='0'and nextone='0')then case state is when pause=>count<=count; -什么鍵也沒按,而當前處于暫停態 when play=&
29、gt; if(mode='0')then -為順序播放模式時 if(count=400)then count<=1; else count<=count+1; end if; Else -為隨機播放模式時 if(count=144 or count=212 or count=344 or count=400)then if(randnumber=1)then -據隨機數不同確定下一首歌曲 count<=1; elsif(randnumber=2)then count<=145; elsif(randnumber=3)then count<=213;
30、 else count<=345; end if; else count<=count+1; end if; end if; when others=>null; end case; Else -當有鍵按下時 case state is when pause=> -當為暫停態時 if(lastone='0'and previous='1'and nextone='0')then -按下了本首重放鍵 state<=play; if(count>=1 and count<=144)then count<
31、=1; elsif(count>=145 and count<=212)then count<=145; elsif(count>=213 and count<=344)then count<=213; else count<=345; end if; else if(mode='0')then -順序播放模式 if(lastone='1'and previous='0'and nextone='0')then -上一首 state<=play; if(count>=1 and
32、 count<=144)then count<=345; elsif(count>=145 and count<=212)then count<=1; elsif(count>=213 and count<=344)then count<=145; else count<=213; end if; elsif(lastone='0'and previous='0'and nextone='1')then -下一首 state<=play; if(count>=1 and count
33、<=144)then count<=145; elsif(count>=145 and count<=212)then count<=213; elsif(count>=213 and count<=344)then count<=345; else count<=1; end if; end if; Else -隨機播放模式 if(lastone='1'or nextone='1')then -按下了上一首或下一首 state<=play; if(randnumber=1)then count<
34、=1; elsif(randnumber=2)then count<=145; elsif(randnumber=3)then count<=213; else count<=345; end if; end if; end if; end if; when play=> -播放狀態 if(lastone='0'and previous='1'and nextone='0')then -本首重放 if(count>=1 and count<=144)then count<=1; elsif(count&g
35、t;=145 and count<=212)then count<=145; elsif(count>=213 and count<=344)then count<=213; else count<=345; end if; else if(mode='0')then -順序播放模式 if(lastone='1'and previous='0'and nextone='0')then -上一首 if(count>=1 and count<=144)then count<=345
36、; elsif(count>=145 and count<=212)then count<=1; elsif(count>=213 and count<=344)then count<=145; else count<=213; end if; elsif(lastone='0'and previous='0'and nextone='1')then -下一首 if(count>=1 and count<=144)then count<=145; elsif(count>=145
37、and count<=212)then count<=213; elsif(count>=213 and count<=344)then count<=345; else count<=1; end if; end if; Else -隨機播放模式 if(lastone='1'or nextone='1')then -按上一首或下一首 if(randnumber=1)then count<=1; elsif(randnumber=2)then count<=145; elsif(randnumber=3)then
38、count<=213; else count<=345; end if; end if; end if; end if; when others=>null; end case; end if; end if; end if;end process p1;p2:process(mode) -根據模式不同(即mode值不同),顯示順序與隨機兩種播放模式,用sequential和random來表示begin if(mode='0')then sequential<='1' random<='0' else sequent
39、ial<='0' random<='1' end if;end process p2;p3:process(state,clk2hz) -播放模式時該LED不亮,暫停狀態時閃爍begin if(clk2hz'event and clk2hz='1')then case state is when play=>t<='0' when pause=> t<=not t; when others=>null; end case; end if;end process p3;p4:proc
40、ess(state) -根據播放還是暫停狀態來給暫停態的標志ppsymbol賦值begin case state is when play=>ppsymbol<='0' when pause=>ppsymbol<='1' when others=>null; end case;end process p4;end one;5) 記錄曲譜的模塊melody:library ieee;use ieee.std_logic_1164.all;entity melody isport(counter:in integer range 1 t
41、o 400;toneindex:out integer range 0 to 13);end melody;architecture one of melody isbeginp1:process(counter)begin case counter is when 1=>toneindex<=9; -根據不同的音符計數器counter的值,對應不同的音高toneindex的值,其中1到7代表中音1到7,8代表高音1,9到13代表低音3到7。 when 2=>toneindex<=9; when 400=>toneindex<=1; when others=
42、>toneindex<=0; end case; end process p1;end one;6) 根據音高查找分頻數并用點陣進行音高顯示的index模塊:library ieee;use ieee.std_logic_1164.all;entity index isport(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_logic_vector(7 downto 0);end inde
43、x;architecture one of index isbeginp1:process(toneindex)begin case toneindex is -根據不同的音高toneindex,找出不同的分頻數tonefreq,另外給點陣row和col以不同的值,顯示出音高。 when 0=>tonefreq<=0; col<="00000000"row<="11111111" when 1=>tonefreq<=955; col<="10000000"row<="01111
44、111" when 2=>tonefreq<=850; col<="01000000"row<="00111111" when 3=>tonefreq<=757; col<="00100000"row<="00011111" when 4=>tonefreq<=715; col<="00010000"row<="00001111" when 5=>tonefreq<=637; col
45、<="00001000"row<="00000111" when 6=>tonefreq<=567; col<="00000100"row<="00000011" when 7=>tonefreq<=505; col<="00000010"row<="00000001" when 8=>tonefreq<=477; col<="00000001"row<="000
46、00000" when 9=>tonefreq<=1516; col<="00100000"row<="00011111" when 10=>tonefreq<=1431; col<="00010000"row<="00001111" when 11=>tonefreq<=1275; col<="00001000"row<="00000111" when 12=>tonefreq<=
47、1135; col<="00000100"row<="00000011" when 13=>tonefreq<=1011; col<="00000010"row<="00000001" when others=>tonefreq<=0;col<="00000000"row<="11111111" end case;end process p1;end one;7) 發聲模塊speaker:library ieee;u
48、se ieee.std_logic_1164.all;entity speaker isport(clk1mhz,ppsymbol:in std_logic;tonefreq:in integer range 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(clk1mhz'event and clk1mhz='1')then if(ppsymbol='1')then sound1<='0' -暫停態不發聲 else if(t<=tonefreq)then if(t=tonefreq)then -產生與分頻數tonefreq相對應的頻率的聲音信號sound t:=0; sound1<=not so
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 中國MicroLED 行業市場深度調查及發展前景研究預測報告
- 2025年 中式烹調師中級考試練習試題附答案
- 2025-2030年中國恒溫循環器項目投資可行性研究分析報告
- 郟縣君正商貿有限公司新建加油站安全設施施工情況報告-圖文
- 2025年中國LED驅動行業發展趨勢預測及投資戰略咨詢報告
- 中國玻璃儀器制造行業發展潛力分析及投資方向研究報告
- 2024-2030年中國彈簧床墊行業市場深度研究及投資規劃建議報告
- 丙酮項目風險分析和評估報告
- 2025年中國售飯車行業市場發展前景及發展趨勢與投資戰略研究報告
- 環境檢測儀器項目可行性研究報告
- 2024年河南省蘭考縣教育局公開招聘試題含答案分析
- 2025年北京市高考英語試卷真題(含答案解析)
- 2025年高考物理廣西卷試題真題及答案詳解(精校打印)
- 國家開放大學本科《商務英語4》一平臺機考真題及答案(第四套)
- 2024年湖北省中考地理生物試卷(含答案)
- 2024年甘肅省天水市中考生物·地理試題卷(含答案)
- GA 1016-2012槍支(彈藥)庫室風險等級劃分與安全防范要求
- 2022年小學六年級畢業監測科學素養測試題試卷 (含答題卡)
- 借款擔保人擔保承諾書
- 集團營銷管理辦法S
- 新編TSG D0001- 壓力管道安全技術監察規程——工業管道(高清晰版)
評論
0/150
提交評論