




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、數字電路與邏輯設計綜合設計實驗報告實驗名稱:簡易音樂播放器姓名: 班級: 班班內序號:27一、 設計任務要求設計制作一個簡易樂曲播放器。1)播放器內預存3首樂曲;2)播放模式:順序播放、隨機播放,并用數碼管或LED顯示當前播放模式;3)順序播放:按內部給定的順序依次播放3首樂曲;4)隨機播放:隨機產生一個順序播放3首樂曲;5)用數碼管顯示當前播放樂曲的順序號;6)設置開始/暫停鍵,樂曲播放過程中按該鍵則暫停播放,再按則繼續播放;7)設置Next和Previous鍵,按Next鍵可以聽下 一首,按Previous鍵回到本首開始;8)選做:用戶可以自行設定播放順序,設置完成后,播放器按該順序依次播
2、放樂曲;9)選做:自擬其它功能。二、系統設計1)設計思路首先音樂有音高和節拍兩個因素。音高可以通過對時鐘信號不同的分頻得到不同頻率的信號進而發出不同的音,節拍可以定義一個音符計數器,計數器的每一個值對應一個音高。對播放的控制包括播放/暫停、復位、上一首、下一首、本首重放、順序播放/隨機播放,用一個狀態機,共播放和暫停兩個狀態,另外歌曲的切換以及暫停都是利用音符計數器賦不同的值或保持不變來實現。音高的顯示是通過不同的音符對應不同的點陣row和col的值來實現的。歌曲號是通過音符計數器的值來得出并送到數碼管顯示的。播放、暫停、順序、隨機這些的顯示是通過對狀態和模式變量的判別進而送到LED顯示的。2
3、)總體框圖div1div2div3keycontrolmelodyindexshownumberspeaker50M1M4hz2hzrand隨機數上、下、本首、復位、暫停鍵、順序隨機選擇暫停態的標志音符序號音符序號歌曲號音高對應的分頻數輸出聲音信號順序隨機暫停的LED顯示音高的點陣顯示 3)分塊設計 共分為9個模塊。Div1,div2,div3都是用來分頻的,分別是將50mhz變為1mhz,將1mhz變為4hz,將1mhz變為2hz。Rand模塊用來產生隨機數,用于隨機播放模式。Keycontrol是核心模塊,用來實現順序播放、隨機播放、播放/暫停、上一首、下一首、本首重放、復位、顯示順序或隨
4、機播放狀態、顯示播放/暫停態。Melody模塊是將音符計數器的每一個值與一個音高相對應,即記錄曲譜。Index模塊是用melody模塊傳來的音高信號通過查表得到它所對應的音高的分頻數,然后將這個分頻數送給speaker模塊,以發出不同的音,另外對應不同的音它還對點陣進行不同的輸出,進而顯示出音高。Speaker模塊接收index模塊送來的分頻數,利用分頻數對時鐘信號進行分頻,進而發出不同的音,另外它還接收keycontrol模塊送來的暫停態的標志,以保證在暫停態的時候不發出聲音。Shownumber模塊通過對音符計數器值的判斷確定現在播放的是哪首歌,進而輸出不同的歌曲號。3、 仿真波形及波形分
5、析1)div1模塊由仿真結果可看出,它將50mhz的時鐘信號變換為1mhz。Div2和div3模塊分別是將1mhz變為4hz,將1mhz變為2hz,原理相同,因而不再列出仿真結果。2) Rand模塊由仿真結果可以看出在每一個時鐘周期內,randnumber改變一次,randnumber可作為隨機數的產生信號。3)Keycontrol模塊:(時鐘用的是未經分頻的) 順序播放:可以看出,在mode=0,即順序播放模式下,在沒有按任何鍵時,音符計數器counter隨時鐘自動加1從而進入下一個音。Sequential表示順序播放,random表示隨機播放,由圖可見此時sequential為高電平,ra
6、ndom為低電平,可知此時為順序播放狀態。 counter由144自動變到145是第一首播完自動到第二首 下一首:當按一下一首鍵時,即nextone變為高電平,音符計數器counter由第一首歌的14變到了第二首歌開始音符所對應的數145,實現了切換到下一首的功能。 本首重放:當播放到第二首歌的152時,按下了本首重放鍵,即previous變為高電平,這時counter變為第二首歌起始音對應的數145,進而實現了本首重放的功能。 上一首:當播放到第二首對應counter為151時,按下了上一首鍵,即lastone變為高電平,counter變為第一首歌起始音符所對應的值1,從而實現了切換到上一首
7、的功能。 暫停:當按下暫停鍵后,即pp變為高電平,暫停狀態的標志ppsymbol就變為高電平,用于送給LED顯示播放/暫停態的ppout變為周期信號,實際中周期為1s,即LED會在1s內一亮一滅進行閃爍,表示進入了暫停狀態。 暫停后再按“播放/暫停”鍵:在暫停態再按一次播放/暫停鍵后,即pp再次變為高電平,ppout變為低電平,對應的LED會熄滅表示進入了播放狀態,ppsymbol也變為低電平。 暫停后按下一首:按了暫停鍵之后,即pp變為高電平之后,又按了下一首鍵,即nextone變為高電平,這時進入播放狀態,同時counter變成了下一首歌的第一個音符對應的值,實現了通過按下一首退出暫停狀態
8、,同時進行歌曲的切換。 暫停后按上一首:暫停后按上一首,即pp變為高電平后lastone也變為高電平,則進入播放狀態,并且開始播上一首。(信號counter中158對應的是第二首的音符,1對應的是第一首的音符) 暫停后按本首重放:暫停后按本首重放,即pp變為高電平后previous也變為高電平,這時進入播放狀態,另外counter變為本首歌第一個音對應的數,實現了本首重放。 復位:復位所要實現的是不管是在順序播放還是隨機播放狀態下,只要一按下復位鍵,就從第一首歌開始播放。如圖,counter等于272時reset變為高電平,counter變為1。 隨機播放:在隨機播放狀態,即mode=1時,在
9、第一首歌的最后一個音(counter為144時)時程序會檢測隨機數randnumber的值,查到是3,于是下一次counter就變為第三首歌第一個音對應的數213,從而實現了隨機播放。此時random為高電平,sequential為低電平,表示此時為隨機播放狀態。 隨機播放狀態下按上一首:按了上一首(lastone變為高電平)后,據隨機數randnumber的值3,于是轉入播放第三首。 按下一首:和按上一首是一樣的,也是根據當前randnumber值來確定下一首要播的是哪一首。Randnumber等于1、2、3、4分別對應第一、二、三、四首歌。 按本首重放:隨機播放模式下按本首重放,即prev
10、ious變為高電平,實現的功能與在順序播放模式是一樣的。由圖可見,播放到第一首的10時,counter變為1,即回到第一首的第一個音開始播。3) Melody模塊:根據不同的音符計數器counter的值,指示音高的值toneindex也在變化,其中1到7代表中音1到7,8代表高音1,9到13代表低音3到7。4) Index模塊:由仿真結果可看出,當音高toneindex為不同的值時,分頻數tonefreq的值也不同,將它送給speaker模塊對時鐘進行分頻,即可得到不同的音高。另外不同的toneindex值對應的點陣的row和col的值也不一樣,進而可以利用點陣顯示音高。5)Speaker模塊
11、: 根據分頻數tonefreq的不同,對時鐘產生的分頻也不同,如圖可見為tonefreq在0和2時輸出聲音信號sound的兩種頻率,進而會發出不同的音。 如下圖,分頻數tonefreq的值并沒有變,但表暫停的標志ppsymbol變為了高電平,暫停狀態不允許發聲,因而輸出的聲音信號sound變為低電平,當ppsymbol回到低電平時,sound才又變回tonefreq所對應頻率的信號。6)Shownumber模塊: 第一首:在音符計數器counter的值是第一首歌時,控制數碼管顯示歌曲號的段選碼number一直是01100000,于是在數碼管上顯示1。而位選碼則一直保持01111111不變,只讓
12、固定的一個數碼管來顯示。 第二首Counter現在對應的是第二首歌的音符,number的值為11011010,數碼管顯示2。四、主要部分源程序1)外圍模塊playerlibrary ieee;use ieee.std_logic_1164.all;entity player isPort -整個系統對外的輸入輸出端口 ( 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類似,不再重復)這個模塊將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
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) 產生隨機數的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序列發生器產生偽隨機序列 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; -狀態定義,有播放和暫停兩種狀態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 -復位 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 -為順序播放模式時 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=
27、2)then count=145; elsif(randnumber=3)then count=213; else count=345; end if; else countnull; end case; Else -當有鍵按下時 case state is when pause= -當為暫停態時 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 -隨機播放模式 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 -播放狀態 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 -隨機播放模式 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、) -根據模式不同(即mode值不同),顯示順序與隨機兩種播放模式,用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) -根據播放還是暫停狀態來給暫停態的標志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) 發聲模塊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; -暫停態不發聲 else if(t=tonefreq)then if(t=tonefreq)t
37、hen -產生與分頻數tonefreq相對應的頻率的聲音信號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) 顯示歌曲號的模塊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 -根據不同的音符計數器的值來確定數碼管的段選碼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等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 西安外國語大學《景觀設計基礎》2023-2024學年第一學期期末試卷
- 江蘇省南京玄武區2025屆初三3月聯合檢測試題(生物試題理)試題含解析
- 山西省晉中學市榆社縣2024-2025學年初三下學期期初自測化學試題含解析
- 重慶航天職業技術學院《能源動力測試技術》2023-2024學年第二學期期末試卷
- 江蘇省鹽城市東臺市2025年學生學業調研抽測試卷(第二次)化學試題含解析
- 吉林省梅河口五中2025年高中畢業班質量檢查(II)生物試題含解析
- 山西醫科大學《通風與空調工程課程設計》2023-2024學年第二學期期末試卷
- 西安美術學院《基礎藥理學》2023-2024學年第二學期期末試卷
- 江西工程學院《機械與電氣安全》2023-2024學年第二學期期末試卷
- 云南省楚雄北浦中學2025屆初三大練習(一)數學試題含解析
- 建筑技術質量考核評分表
- 機器學習-聚類分析
- 七年級心理健康期末考試試卷(含答案)
- 書香家庭申報表參考模板
- 短視頻編輯與制作全套教學課件
- 小學語文教學技能PPT完整全套教學課件
- 美國憲法全文(中、英文版)
- 初中歷史課件:中國古代科技發展史
- 安全閥管理臺賬
- 中國胃腸間質瘤診斷治療共識(完整版)
- 員工手冊(國企通用版員工手冊)
評論
0/150
提交評論