数字电子技术综合实验报告——简易电子琴(共40页).docx
-
资源ID:14052024
资源大小:367.93KB
全文页数:40页
- 资源格式: DOCX
下载积分:20金币
快捷下载
会员登录下载
微信登录下载
三方登录下载:
微信扫一扫登录
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
|
数字电子技术综合实验报告——简易电子琴(共40页).docx
精选优质文档-倾情为你奉上数字电子技术综合实验报告2012-2013学年第二学期姓名:学号:班级: 实验时间:实验指导老师: 专心-专注-专业目录一、设计任务·········································································2二、设计方案·········································································2三、系统框图·········································································3四、方案实现·········································································31.乐曲演奏的原理······································································32.总体方案·················································································4五、实验结果·········································································6六、方案优化·········································································7七、心得体会·········································································7附录·························································································71. VHDL源程序·····································································72. 各层次原理图·································································353.编译报告··········································································40题目: 简易电子琴设计摘要 电子琴的设计大规模可编程逻辑器件(FPGA)作为系统的核心控制部分通过软件的设计编写然后进行软硬件的调试运行最终达到设计电路的乐器演奏、选歌及显示功能。设计中采用计数原理控制演奏器发声,对音乐发生所必须确定的音符和节拍分别用程序语言实现。可以用它来弹奏和播放乐曲。特点是设计思路简单、清晰。关键字:电子琴 CPLD一、设计任务1. 基本要求(1) 具有一般弹奏功能;(2) 自动播放功能;(3) 数码显示音符功能。2发挥部分 (1)能通过选择键在多首歌曲中选择播放; (2)输出增加功率放大电路,增加歌曲容量;(3)增加音效或节拍可调;(4)无线弹奏。二、设计方案采用大规模可编程逻辑器件(FPGA),利用quartusII,通过verilog代码实现简易电子琴演奏电路。三、系统框图四、方案实现1.乐曲演奏的原理:乐曲演奏的原理:组成乐曲的每个音符的频率值(音调)以及持续时间(音长)是乐曲能持续演奏所需的两个基本数据,因此只要控制输出到扬声器的激励信号的频率的高低和持续的时间,就可以使扬声器发出持续的乐曲声。l 音调的控制 频率的高低决定了音调的高低。音乐的十二平均率规定:每两个八度音(如简谱中的中音1与高音1)之间的频率相差一倍。在两个八度音之间,又可分为十二个半音,每半个音的频率比为。另外,音名A(简谱中的低音6)的频率为440HZ,音名B到C之间,E到F之间为半音,其余为全音。由此可以计算出简谱中从低音1至高音1之间的每个音名对应的频率如图所示:音名频率(HZ)音名频率(HZ)音名频率(HZ)低音1261.6中音1523.3高音11046.5低音2293.7中音2587.3高音21174.7低音3329.6中音3659.3高音31318.5低音4349.2中音4698.5高音41396.9低音5392中音5784高音51568低音6440中音6880高音61760低音7493.9中音7987.8高音71975.5 所有不同频率均从同一基准频率分频得到。将分频数四舍五入进行取整,并尽量减小误差。在本设计中选取6MHZ作为基准频率。从下表中可以看出最大分频系数为11468,采用14位二进制计数器分频可满足要求。此外还应给出预置数,对应不同的预置数,只需加载不同的预置数即可。采用加载预置数实现分频的方法比采用反馈复零法节省资源,实现起来更加容易。音名分频比预置数音名分频比预置数音名分频比预置数低音1114684915中音1573610647高音1286713516低音2102156168中音2511111272高音2255413829低音391027281中音3455211831高音3227414109低音485917792中音4428912094高音4214814235低音576538730中音5382712556高音5191314470低音668189565中音6340912947高音6170514678低音7607310310中音7303713346高音7151914864l 音长的控制音符的持续时间须根据音乐的速度及每个音符的节拍数来确定。如果设定全音符的持续时间为1S的话,假设产生4分音符,则产生四分频即可实现四分音符的时长,并提供4HZ分频器。如图为乐曲演奏的原理图,其中,乐谱产生电路用来控制音乐的音调和时长。控制音调通过设置计数器的预置数来实现,预置不同的数值会可以使计数器产生不同频率的信号,从而产生不同的音调。控制音长是通过控制计数器预置数的停留时间来实现的,预置数的停留时间越长,则该音符的演奏时间越长,如2分音符,在记谱时将该音符记录两次即可。2.总体方案 系统设计运用了自上而下的模块化设计思想,整个系统可分为分频,播放,弹奏,显示四个部分。1. 分频部分分频部分为一个可预置数的加计数器、二分频器和预置数选择器。预置数选择器选择来自播放和弹奏部分的不同的预置数。从预置数起循环作加计数,计到16383时产生一个高电平,否则得到低电平,将信号再进行二分频便可得到方波信号。预制数不同,产生的方波信号频率也不同。因此,只要改变加计数器的预置数,便可由6MHz的时钟信号分频得到不同频率的方波。将方波信号输出到扬声器,便可发出不同音调的声音。2. 播放部分播放部分为一个节拍发生器、预置数获得器和一个存储器。节拍发生器将一个64Hz的时钟信号分为32Hz,16Hz,8Hz和4Hz的信号,以适应不同歌曲的播放速度。预置数获得器将音阶信号转换为对应的预置数。存储器将歌曲的预置数传送给分频器,实现曲目的不同音调和音长。3. 弹奏部分弹奏部分有十四个按键,每个按键对应一个音阶,及对应一个预置数,将预置数传递给分频部分便可得到不同频率的方波,从而产生不同的音调。4. 显示部分在进行音乐播放或弹奏时,将产生的预置数传递给此模块。根据不同的预置数,产生不同的信号,输出到数码管,便可显示出音阶数字。5. 功能仿真(1) 综合仿真结果:设置输入信号key1为高电平,此时设置key=8192,即key2=1,key3key15=0。功能为播放第一首歌,在仿真结束后,如图示,fout为蜂鸣器的输出,led为数码管显示。如图示也正确,所以本设计经过仿真证明正确可行。(2) 总电路原理图(3)引脚分配输入信号:1个6MHz时钟信号,1个64Hz时钟信号,1个功能选择按键,14个弹奏(选择)按键;输出信号:3个数码管输出,一个蜂鸣器输出声音。五、实验结果在编译并仿真后下载,通过硬件测试,实验达到预期效果,当key1=0时,通过key2key15这14个按键的键入蜂鸣器可以发出中音及高音的doxi十四个音阶的音,即表示了电子琴的弹奏功能;当key1=1时,key2=1时播放了第一首歌;key3=1时,播放了第二首歌;key4=1时,播放第三首歌;key5=1时,播放了第四首歌。发出声音的同时,数码管可以显示不同的代表音符的数字。通过硬件的测试,所有的设计目标均实现。六、方案优化若采用正弦波代替方波来驱动扬声器将会有更好的效果。七、心得体会本次设计要用quartusII软件,由于之前对此软件不是太熟悉所以导致了一些错误和问题的发生,所以这次课程设计中认真学习了quartusII软件的具体使用步骤和操作流程,对所有可能出现的问题进行逐一攻破。通过这次实验,我不但熟悉了quartusII软件,也了解了开发的最基本流程和方法,也进一步加深了对Verilog编程语言的理解,最重要的是锻炼了我独立思考和分析的逻辑能力,通过从顶向下的设计方法,一步步实现,然后将整个设计串套起来,是我对设计的流程以及编程有了很大的提高。附录:1.VHDL源程序module change_fenpinbi(clk_6m,prenum,tofout);/通过预置数改变分频比;input clk_6m;input 13:0prenum;output tofout;wire clk_6m;reg 13:0divider;reg tofout;always(posedge clk_6m)beginif(divider=16383)begintofout=1'b1;divider=prenum;endelsebegintofout=1'b0;divider=divider+14'd1;endendendmodule module er_fen_pin(tofout,fout); /二分频模块;input tofout;output fout;reg fout;always(posedge tofout)beginfout=fout;endendmodulemodule fenpin(clk_64,clk_16,clk_8,clk_4); /获得适应不同曲目不同的时钟信号;input clk_64;output clk_16,clk_8,clk_4;wire clk_64;reg clk_32,clk_16,clk_8,clk_4;reg counter2;reg 1:0counter4;always(posedge clk_64)beginclk_32=clk_32;endalways(posedge clk_32)begin clk_16=clk_16;if(counter2=1'b1)beginclk_8=clk_8;counter2=1'b0;endelsecounter2=counter2+1'b1;if(counter4=2'd3)beginclk_4=clk_4;counter4=2'd0;endelsecounter4=counter4+2'd1;endendmodulemodule get_prenum(clk_sing,scale,prenum_s);/将音阶信号转换为预置数;input clk_sing;input 4:0scale;output 13:0prenum_s;wire clk_sing;wire 4:0scale;reg 13:0prenum_s;always(posedge clk_sing)begincase(scale)5'd0:prenum_s=14'd16383;5'd1:prenum_s=14'd4915;5'd2:prenum_s=14'd6168;5'd3:prenum_s=14'd7281;5'd4:prenum_s=14'd7792;5'd5:prenum_s=14'd8730;5'd6:prenum_s=14'd9565;5'd7:prenum_s=14'd10301;5'd8:prenum_s=14'd10647;5'd9:prenum_s=14'd11272;5'd10:prenum_s=14'd11831;5'd11:prenum_s=14'd12074;5'd12:prenum_s=14'd12556;5'd13:prenum_s=14'd12974;5'd14:prenum_s=14'd13346;5'd15:prenum_s=14'd13516;5'd16:prenum_s=14'd13829;5'd17:prenum_s=14'd14109;5'd18:prenum_s=14'd14235;5'd19:prenum_s=14'd14470;5'd20:prenum_s=14'd14678;5'd21:prenum_s=14'd14846;endcaseend endmodulemodule premusic(clk_16,clk_8,clk_4,key,clk_sing,scale); /预置曲目模块;input clk_16,clk_8,clk_4;input 13:0key;output 4:0scale;output clk_sing;reg clk_sing;reg 4:0scale;reg 4:0scale1;reg 4:0scale2;reg 4:0scale3;reg 4:0scale4;reg 7:0counter8_1;reg 7:0counter8;reg 8:0counter9;reg 8:0counter9_1;always(key)/选择曲目;begincase(key)14'd8192:begin scale=scale1;clk_sing=clk_4;end14'd4096:Beginscale=scale2;clk_sing=clk_4;end14'd512: begin scale=scale3;clk_sing=clk_8;end14'd1024: Beginscale=scale4;clk_sing=clk_8;enddefault:begin scale=5'd0;clk_sing=clk_4;endendcaseendalways(posedge clk_4)/梁祝;beginif(counter8=8'd134)counter8=8'd0;elsecounter8=counter8+8'd1;case(counter8)8'd0: scale1=5'd3;8'd1: scale1=5'd3;8'd2: scale1=5'd3;8'd3: scale1=5'd3;8'd4: scale1=5'd5;8'd5: scale1=5'd5;8'd6: scale1=5'd5;8'd7: scale1=5'd6;8'd8: scale1=5'd8;8'd9: scale1=5'd8;8'd10: scale1=5'd8;8'd11: scale1=5'd9;8'd12: scale1=5'd6;8'd13: scale1=5'd8;8'd14: scale1=5'd5;8'd15: scale1=5'd5;8'd16: scale1=5'd12;8'd17: scale1=5'd12;8'd18: scale1=5'd12;8'd19: scale1=5'd15;8'd20: scale1=5'd13;8'd21: scale1=5'd12;8'd22: scale1=5'd10;8'd23: scale1=5'd12;8'd24: scale1=5'd9;8'd25: scale1=5'd9;8'd26: scale1=5'd9;8'd27: scale1=5'd9;8'd28: scale1=5'd9;8'd29: scale1=5'd9;8'd30: scale1=5'd0;8'd31: scale1=5'd0;8'd32: scale1=5'd9;8'd33: scale1=5'd9;8'd34: scale1=5'd9;8'd35: scale1=5'd10;8'd36: scale1=5'd7;8'd37: scale1=5'd7;8'd38: scale1=5'd6;8'd39: scale1=5'd6;8'd40: scale1=5'd5;8'd41: scale1=5'd5;8'd42: scale1=5'd5;8'd43: scale1=5'd6;8'd44: scale1=5'd8;8'd45: scale1=5'd8;8'd46: scale1=5'd9;8'd47: scale1=5'd9;8'd48: scale1=5'd3;8'd49: scale1=5'd3;8'd50: scale1=5'd8;8'd51: scale1=5'd8;8'd52: scale1=5'd6;8'd53: scale1=5'd5;8'd54: scale1=5'd6;8'd55: scale1=5'd8;8'd56: scale1=5'd5;8'd57: scale1=5'd5;8'd58: scale1=5'd5;8'd59: scale1=5'd5;8'd60: scale1=5'd5;8'd61: scale1=5'd5;8'd62: scale1=5'd5;8'd63: scale1=5'd5;8'd64: scale1=5'd10;8'd65: scale1=5'd10;8'd66: scale1=5'd10;8'd67: scale1=5'd12;8'd68: scale1=5'd7;8'd69: scale1=5'd7;8'd70: scale1=5'd9;8'd71: scale1=5'd9;8'd72: scale1=5'd6;8'd73: scale1=5'd8;8'd74: scale1=5'd5;8'd75: scale1=5'd5;8'd76: scale1=5'd5;8'd77: scale1=5'd5;8'd78: scale1=5'd0;8'd79: scale1=5'd0;8'd80: scale1=5'd3;8'd81: scale1=5'd5;8'd82: scale1=5'd5;8'd83: scale1=5'd3;8'd84: scale1=5'd5;8'd85: scale1=5'd6;8'd86: scale1=5'd7;8'd87: scale1=5'd9;8'd88: scale1=5'd6;8'd89: scale1=5'd6;8'd90: scale1=5'd6;8'd91: scale1=5'd6;8'd92: scale1=5'd6;8'd93: scale1=5'd6;8'd94: scale1=5'd5;8'd95: scale1=5'd6;8'd96: scale1=5'd8;8'd97: scale1=5'd8;8'd98: scale1=5'd8;8'd99: scale1=5'd9;8'd100: scale1=5'd12;8'd101: scale1=5'd12;8'd102: scale1=5'd10;8'd103: scale1=5'd10;8'd104: scale1=5'd9;8'd105: scale1=5'd9;8'd106: scale1=5'd10;8'd107: scale1=5'd9;8'd108: scale1=5'd8;8'd109: scale1=5'd8;8'd110: scale1=5'd6;8'd111: scale1=5'd5;8'd112: scale1=5'd3;8'd113: scale1=5'd3;8'd114: scale1=5'd3;8'd115: scale1=5'd3;8'd116: scale1=5'd8;8'd117: scale1=5'd8;8'd118: scale1=5'd8;8'd119: scale1=5'd8;8'd120: scale1=5'd6;8'd121: scale1=5'd8;8'd122: scale1=5'd6;8'd123: scale1=5'd5;8'd124: scale1=5'd3;8'd125: scale1=5'd5;8'd126: scale1=5'd6;8'd127: scale1=5'd8;8'd128: scale1=5'd5;8'd129: scale1=5'd5;8'd130: scale1=5'd5;8'd131: scale1=5'd5;8'd132: scale1=5'd5;8'd133: scale1=5'd5;8'd134: scale1=5'd0;8'd135: scale1=5'd0;default:scale1=5'd0;endcaseendalways(posedge clk_4) /小情歌;begin if(counter9=9'd334)counter9=9'd0;elsecounter9=counter9+9'd1;case(counter9)9'd0: scale2=5'd0;9'd1: scale2=5'd0;9'd2: scale2=5'd15;9'd3: scale2=5'd14;9'd4: scale2=5'd15;9'd5: scale2=5'd15;9'd6: scale2=5'd14;9'd7: scale2=5'd14;9'd8: scale2=5'd15;9'd9: scale2=5'd15;9'd10: scale2=5'd14;9'd11: scale2=5'd14;9'd12: scale2=5'd12;9'd13: scale2=5'd12;9'd14: scale2=5'd10;9'd15: scale2=5'd10;9'd16: scale2=5'd12;9'd17: scale2=5'd12;9'd18: scale2=5'd12;9'd19: scale2=5'd12;9'd20: scale2=5'd14;9'd21: scale2=5'd14;9'd22: scale2=5'd14;9'd23: scale2=5'd14;9'd24: scale2=5'd13;9'd25: scale2=5'd13;9'd26: scale2=5'd13;9'd27: scale2=5'd13;9'd28: scale2=5'd13;9'd29: scale2=5'd13;9'd30: scale2=5'd13;9'd31: scale2=5'd13;9'd32: scale2=5'd0;9'd33: scale2=5'd0;9'd34: scale2=5'd15;9'd35: scale2=5'd14;9'd36: scale2=5'd15;9'd37: scale2=5'd15;9'd38: scale2=5'd14;9'd39: scale2=5'd14;9'd40: scale2=5'd15;9'd41: scale2=5'd15;9'd42: scale2=5'd14;9'd43: scale2=5'd14;9'd44: scale2=5'd15;9'd45: scale2=5'd15;9'd46: scale2=5'd17;9'd47: scale2=5'd0;9'd48: scale2=5'd17;9'd49: scale2=5'd17;9'd50: scale2=5'd17;9'd51: scale2=5'd17;9'd52: scale2=5'd17;9'd53: scale2=5'd17;9'd54: scale2=5'd17;9'd55: scale2=5'd17;9'd56: scale2=5'd0;9'd57: scale2=5'd0;9'd58: scale2=5'd0;9'd59: scale2=5'd0;9'd60: scale2=5'd0;9'd61: scale2=5'd13;9'd62: scale2=5'd15;9'd63: scale2=5'd13;9'd64: scale2=5'd15;9'd65: scale2=5'd15;9'd66: scale2=5'd15;9'd67: scale2=5'd15;9'd68: scale2=5'd15;9'd69: scale2=5'd15;9'd70: scale2=5'd16;9'd71: scale2=5'd17;9'd72: scale2=5'd16;9'd73: scale2=5'd16;9'd74: scale2=5'd16;9'd75: scale2=5'd16;9'd76: scale2=5'd0;9'd77: scale2=5'd12;9'd78: scale2=5'd14;9'd79: scale2=5'd12;9'd80: scale2=5'd14;9'd81: scale2=5'd14;9'd82: scale2=5'd14;9'd83: scale2=5'd14;9'd84: scale2=5'd16;9'd85: scale2=5'd16;9'd86: scale2=5'd15;9'd87: scale2=5'd0;9'd88: scale2=5'd15;9'd89: scale2=5'd15;9'd90: scale2=5'd15;9'd91: scale2=5'd15;9'd92: scale2=5'd15;9'd93: scale2=5'd15;9'd94: scale2=5'd15;9'd95: scale2=5'd15;9'd96: scale2=5'd17;9'd97: scale2=5'd17;9'd98: scale2=5'd17;9'd99: scale2=5'd16;9'd100: scale2=5'd16;9'd101: scale2=5'd16;9'd102: scale2=5'd15;9'd103: scale2=5'd15;9'd104: scale2=5'd16;9'd105: scale2=5'd16;9'd106: scale2=5'd16;9'd107: scale2=5'd15;9'd108: scale2=5'd15;9'd109: scale2=5'd15;9'd110: scale2=5'd12;9'd111: scale2=5'd12;9'd112: scale2=5'd12;9'd113: scale2=5'd12;9'd114: scale2=5'd12;9'd115: scale2=5'd12;9'd116: scale2=5'd12;9'd117: scale2=5'd15;9'd118: scale2=5'd14;9'd119: scale2=5'd13;9'd120: scale2=5'd12;9'd121: scale2=5'd12;9'd122: scale2=5'd12;9'd123: scale2=5'd12;9'd124: scale2=5'd12;9'd125: scale2=5'd12;9'd126: scale2=5'd12;9'd127: scale2=5'd12;9'd128: scale2=5'd0;9'd129: scale2=5'd0;9'd130: scale2=5'd15;9'd131: scale2=5'd14;9'd132: scale2=5'd15;9'd133: scale2=5'd15;9'd134: scale2=5'd14;9'd135: scale2=5'd14;9'd136: scale2=5'd15;9'd137: scale2=5'd15;9'd138: scale2=5'd14;9'd139: scale2=5'd14;9'd140: scale2=5'd12;9'd141: scale2=5'd12;9'd142: scale2=5'd10;9'd143: scale2=5'd10;9'd144: scale2=5'd12;9'd145: scale2=5'd12;9'd146: scale2=5'd12;9'd147: scale2=5'd12;9'd148: scale2=5'd14;9'd149: scale2=5'd14;9'd150: scale2=5'd14;9'd151: scale2=5'd14;9'd152: scale2=5'd15;9'd153: scale2=5'd15;9'd154: scale2=5'd15;9'd155: scale2=5'd15;9'd156: scale2=5'd15;9'd157: scale2=5'd15;9'd158: scale2=5'd15;9'd159: scale2=5'd15;9'd159: scale2=5'd0;9'd160: scale2=5'd0;9'd161: scale2=5'd15;9'd162: scale2=5'd14;9'd163: scale2=5'd15;9'd164: scale2=5'd15;9'd165: scale2=5'd14;9'd166: scale2=5'd14;9'd167: scale2=5'd15;9'd168: scale2=5'd15;9'd169: scale2=5'd14;9'd170: scale2=5'd14;9'd171: scale2=5'd15;9'd172: scale2=5'd15;9'd173: scale2=5'd17;9'd174: scale2=5'd20;9'd175: scale2=5'd19;9'd176: scale2=5'd19;9'd177: scale2=5'd19;9'd178: scale2=5'd19;9'd179: scale2=5'd19;9'd180: scale2=5'd19;9'd181: scale2=5'd19;9'd182: scale2=5'd19;9'd183: scale2=5'd19;9'd184: scale2=5'd19;9'd185: scale2=5'd19;9'd186: scale2=5'd19;9'd187: scale2=5'd0;9'd188: scale2=5'd19;9'd189: scale2=5'd18;9'd190: scale2=5'd17;9'd191: scale2=5'd18;9'd192: scale2=5'd18;9'd193: scale2=5'd18;9'd194: scale2=5'd18;9'd195: scale2=5'd18;9'd196: scale2=5'd18;9'd197: scale2=5'd19;9'd198: scale2=5'd19;9'd199: scale2=5'd16;9'd200: scale2=5'd16;9'd201: scale2=5'd16;9'd202: scale2=5'd16;9'd203: scale2=5'd0;9'd204: scale2=5'd18;9'd205: scale2=5'd17;9'd206: scale2=5'd16;9'd207: scale2=5'd17;9'd208: scale2=5'd17;9'd209: scale2=5'd17;9'd210: scale2=5'd17;9'd211: scale2=5'd16;9'd212: scale2=5'd16;9'd213: scale2=5'd16;9'd214: scale2=5'd15;9'd215: scale2=5'd15;9'd216: scale2=5'd15;9'd217: scale2=5'd15;9'd218: scale2=5'd15;9'd219: scale2=5'd15;9'd220: scale