数电实验报告-音乐播放器.doc_第1页
数电实验报告-音乐播放器.doc_第2页
数电实验报告-音乐播放器.doc_第3页
数电实验报告-音乐播放器.doc_第4页
数电实验报告-音乐播放器.doc_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验课题:简易乐曲播放器学院:班级:姓名: 学号:班内序号:一、设计课题要求.2二、设计思路和总体框图.2三、分块电路设计 .4四、仿真波形.6五、源程序.7六、功能说明.20七、所用元器件情况.20八、故障及问题分析.21九、总结和结论.22十、参考文献.22一 设计课题的任务要求设计制作一个简易乐曲播放器:1. 播放器内预存3 首乐曲;2. 播放模式:顺序播放、随机播放,并用数码管或LED 显示当前播放模式;顺序播放:按内部给定的顺序依次播放3 首乐曲;随机播放:随机产生一个顺序播放3 首乐曲;3. 用数码管显示当前播放乐曲的顺序号;4. 设置开始/暂停键,乐曲播放过程中按该键则暂停播放,再按则继续播放;5. 设置Next 和Previous 键,按Next 键可以听下一首,按Previous 键回到本首开始;6. 选做:用户可以自行设定播放顺序,设置完成后,播放器按该顺序依次播放乐曲;7. 选做:自拟其它功能。二 设计思路和总体框图设计思路:组成乐曲的每个音符的发音频率值及其持续的时间是乐曲能连续演奏所需的2个基本要素。乐曲的12平均律规定:每2个八度音之间的频率相差1倍。在2个八度音之间,又可分为12个半音,每两个半音的频率比为2开12次方。另外,音符A(简谱中的低音6)的频率为440Hz,音符B到C之间、E到F之间为半音,其余为全音。由此可以计算出简谱中从低音1至高音1之间每个音符的频率,如下表所示。产生各音符所需的频率可用分频器实现。本次实验使用的是MAX实验板,时钟频率为50MHz,计算出各个音符对应的分频系数,进行50%占空比的分频,即可得到各音符对应的频率。对于节拍,如果将一拍的长度定为1秒,则1/4拍的时间为1/4秒,为其提供一个4Hz的时钟频率即可产生出1/4拍的效果了。若需要半拍,只需将该音符记录两次就可以了。产生节拍时钟也用分频器实现,本次实验中时钟频率为5Hz。总体框图:音乐播放音调分频器50MHz时钟顺序播放节拍分频器随机播放暂停/播放状态判断本首重放下一首单曲循环上一首图1:简易乐曲播放器总体结构框图seq pau =10MDS图: 随机播放顺序播放0000010110暂停图2:状态转移图1在顺序播放和随机播放模式下,有四种功能,如下图:ne pre pr rep=0001上一首单曲循环0100010000011000001001000001100000101000回到本首开始下一首0010图3:状态转移图2流程图:开始顺序播放数码管显示曲目序号N是否随机播放?Y随机播放判断按键previouspresentnextrepeatpause上一首单曲循环下一首回到本首开始暂停or播放图4:简易音乐播放器流程图三 分块电路设计二分频高1四分频中1tune1八分频低1二分频高2四分频中2tune2八分频低2二分频高3四分频中3tune3八分频低3二分频高4分频四分频50MHz中4tune4八分频低4二分频高5四分频中5tune5八分频低5二分频高6四分频中6tune6八分频低6二分频高7四分频中7tune7八分频低7图3音调分频器四 仿真波形分频部分:上图为分频部分程序的波形图,从图中可看出高中低音的频率分别呈2倍关系,例如高1的频率为中1频率的2倍,中1频率的2倍为低1的二倍。整个程序:presentpreviouspauserepeatpausenextpreviousnextrepeat顺序播放随机播放present如上图:1 顺序播放时,light1点亮,light2熄灭,三首曲子1-2-3顺序播放;随机播放时,light2点亮,light1,熄灭,由波形图看出,此次随机播放,乐曲3后接着的是乐曲1;2 在顺序播放和随机播放两种情况下,当ne为1时,表示要播放下一曲,但蜂鸣器继续播放,当ne又回到0时,开始播放下一曲,数码管显示下一曲的序号;3 在顺序播放和随机播放两种情况下,当pau为1时,表示暂停,蜂鸣器停止发声,数码管的显示保持不变,当pau回到0时,蜂鸣器继续发声,继续播放曲目;4 在顺序播放和随机播放两种情况下,当pre为1时,表示要播放下一曲,但蜂鸣器继续播放,当ne又回到0时,开始播放下一曲,数码管显示下一曲序号;5 在顺序播放和随机播放两种情况下,当rep保持为1时,进行单曲循环播放,数码管显示保持不变,当rep回到0时,取消单曲循环播放,本首乐曲播放完即播放下一曲;6 在顺序播放和随机播放两种情况下,当pr为1时,表示回到本曲的开始,从头播放正在播放的曲子,数码管的显示保持不变。备注:上述仿真图有些小,最后我附了一张仿真波形大图。五 源程序整个程序只有一个文件,分多个进程完成不同的功能。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity music_player is port (clk: in std_logic; -主频50MHz seq,ne,pre,pr,pau,rep:in std_logic; -按键:随机,下一首,上一首,本首,开始,暂停,单曲循环 index0: out std_logic; -音频输出 seg: out std_logic_vector (6 downto 0);-数码管显示序号 cat0: out std_logic_vector (5 downto 0);-数码管位选 light1,light2: out std_logic); -LED灯end music_player;architecture a of music_player is signal clk0: std_logic; -节拍时钟 signal count0:integer range 0 to 198; -计数器 signal temp1, temp2, temp3, temp4, temp5, temp6, temp7 :integer range 0 to 23871; -分频系数 signal temp01,temp02,temp03,temp04,temp05,temp06,temp07:std_logic_vector(3 downto 0); -占空比50%分频 signal tune1, tune2, tune3, tune4, tune5, tune6, tune7 :std_logic; -初始频率(占空比不是50%) signal tmp,qout:std_logic_vector(2 downto 0); -随机序列 begin fre:process(clk) -初始分频:高音部分,占空比非50% begin if (clkevent and clk=1) then if temp1=23871 then temp1=0; else temp1=temp1+1; end if; if temp1=23871 then tune1=1; else tune1=0; end if; if temp2=21311 then temp2=0; else temp2=temp2+1; end if; if temp2=21311 then tune2=1; else tune2=0; end if; if temp3=18943 then temp3=0; else temp3=temp3+1; end if; if temp3=18943 then tune3=1; else tune3=0; end if; if temp4=17919 then temp4=0; else temp4=temp4+1; end if; if temp4=17919 then tune4=1; else tune4=0; end if; if temp5=15935 then temp5=0; else temp5=temp5+1; end if; if temp5=15935 then tune5=1; else tune5=0; end if; if temp6=14207 then temp6=0; else temp6=temp6+1; end if; if temp6=14207 then tune6=1; else tune6=0; end if; if temp7=12671 then temp7=0; else temp7=temp7+1; end if; if temp7=12671 then tune7=1; else tune7=0; end if; end if; end process fre; fre1:process(tune1, tune2, tune3, tune4, tune5, tune6, tune7) begin if (tune1event and tune1=1) then temp01=temp01+1; end if; - temp01(1)为高1,temp01(2)为中1, temp01(3)为低1 if (tune2event and tune2=1) then temp02=temp02+1; end if; - temp02(1)为高2,temp02(2)为中2, temp02(3)为低2 if (tune3event and tune3=1) then temp03=temp03+1; end if; - temp03(1)为高3,temp03(2)为中3, temp03(3)为低3 if (tune4event and tune4=1) then temp04=temp04+1; end if; - temp04(1)为高4,temp04(2)为中4, temp04(3)为低4 if (tune5event and tune5=1) then temp05=temp05+1; end if; - temp05(1)为高5,temp05(2)为中5, temp05(3)为低5 if (tune6event and tune6=1) then temp06=temp06+1; end if; - temp06(1)为高6,temp06(2)为中6, temp06(3)为低6 if (tune7event and tune7=1) then temp07=temp07+1; end if; - temp07(1)为高7,temp07(2)为中7, temp07(3)为低7 end process fre1;- tuneh1=temp01(1); -高1- tunem1=temp01(2); -中1- tunel1=temp01(3); -低1 fre0:process(clk) -节拍分频,频率为5Hz variable count:integer range 0 to 10000000; begin if (clkevent and clk=1) then count:=count+1; if count=5000000 then clk0=1; elsif count=10000000 then clk0tmptmptmptmptmptmp=001; end case; end if; qout=tmp; end process p1; add:process(seq,clk0,pau,ne,pre,pr,count0,qout) -检测按键,修改计数器的值 variable mem:integer range 0 to 198; begin if (clk0event and clk0=1) then if(seq=0 and ne=0 and pr=0 and rep=0 and pau=0 and pre=0) then -顺序,play if mem=0 then if count0=198 then count0=0; else count0=count0+1; end if; else count0=mem; mem:=0; if count0=198 then count0=0; else count0=count0+1; end if; end if; elsif(seq=1 and ne=0 and pr=0 and rep=0 and pau=0 and pre=0) then -随机,play if qout=001 then if count0=62 then count0=63; elsif count0=128 then count0=129; elsif count0=198 then count0=0; else count0=count0+1; end if; elsif qout=011 then if count0=62 then count0=129; elsif count0=198 then count0=63; elsif count0=128 then count0=0; else count0=count0+1; end if; elsif qout=010 then if count0=128 then count0=0; elsif count0=62 then count0=129; elsif count0=198 then count0=63; else count0=count0+1; end if; elsif qout=110 then if count0=128 then count0=129; elsif count0=198 then count0=0; elsif count0=62 then count0=63; else count0=count0+1; end if; elsif qout=100 then if count0=198 then count0=0; elsif count0=62 then count0=63; elsif count0=128 then count0=129; else count0=count0+1; end if; elsif qout=101 then if count0=198 then count0=63; elsif count0=128 then count0=0; elsif count0=62 then count0=129; else count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0count0=129; end case; elsif(ne=0 and pr=0 and rep=1 and pau=0 and pre=0) then -单曲循环 if count0=62 then count0=0; elsif count0=128 then count0=63; elsif count0=198 then count0=129; else count0=count0+1; end if; elsif(ne=0 and pr=0 and rep=0 and pau=1 and pre=0) then -暂停 mem:=count0; end if; end if; end process add; speak:process(count0,pau,temp01,temp02,temp03,temp04,temp05,temp06,temp07) -音调输出 begin if pau=1 then index0index0index0ind

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论