收藏 分销(赏)

基于verilog语言简易电子琴设计-数字电子技术课程设计报告.docx

上传人:人****来 文档编号:4883107 上传时间:2024-10-17 格式:DOCX 页数:30 大小:1.16MB 下载积分:12 金币
下载 相关 举报
基于verilog语言简易电子琴设计-数字电子技术课程设计报告.docx_第1页
第1页 / 共30页
基于verilog语言简易电子琴设计-数字电子技术课程设计报告.docx_第2页
第2页 / 共30页


点击查看更多>>
资源描述
数字电子技术课程设计报告 基于verilog HDL语言的简易电子琴设计 学 院:__信息与控制工程学院________ 专业班级:___电气11级四班______________ 姓 名:___商玉玺________________________ 学 号:___11053421_____________________ 指导教师:___________________________________ 一、实验目的 1、学习verilogHDL语言的基本运用,能够利用其进行简单编程; 2、学习使用Quartus Ⅱ7.0的基本操作,能够利用其进行简单的设计; 3、结合实践加深对理论知识的理解。 二、设计题目 用verilogHDl语言设计简易电子琴。 三、题目要求 (1)单独从左至右按下S1-S7每个按键后能够各自对应发出 “哆来咪发唆啦西”的音乐声; (2)按下最右边按键(S8),同时再配合按下S1-S7键后,发高八度的对应音; (3)按键需要进行“消抖”处理; (4)外部输入脉冲信号频率为1mhz; (5)扩展要求:自主设计(增加低8度功能,自动播放一段音乐)。 四、设计原理 (1)喇叭的振动频率不同,导致产生不同的声音;振动频率越低,声音越低沉,振动频率越高,声音越尖锐。题目中音乐基本音的 “哆”对应频率为523Hz 、“来”对应频率为587Hz 、“咪”对应频率为659Hz 、“发”对应频率为698Hz 、“唆”对应频率为784Hz 、“啦”对应频率为880Hz 、“西”对应频率为998Hz。 低8度音:基本音频率/2,例如低音1的频率为523/2=261.5Hz。 高8度音:基本音频率×2,例如高音1的频率为523×2=1046Hz.。 不同的频率产生利用给定的时钟脉冲来进行分频实现。 (2)消抖的原理:按键默认输入逻辑‘1’,当有按键按下时对应的输入为逻辑‘0’(但会存在抖动),当FPGA开始检测到该引脚从‘1’变为‘0’后开始定时(按键抖动时间大约10ms),定时时间结束后若该引脚仍然为‘0’则表示确实发生按键按下,否则视为抖动而不予以理会;按键松开过程的消抖处理和按下时原理一样。 (3)原理框图 四、管脚对应表 信号名称 对应FPGA管脚名 说明 1MHz L2 基准时钟 OU F3 音频输出 S1 F8 基本功能按键 S2 A14 S3 F10 S4 B16 S5 F12 S6 B17 S7 F15 S8 B18 BT1 M1 扩展功能按键 BT2 M2 BT3 U12 BT4 U11 五、实验过程 1、设计按键防抖模块 (1)设计程序 module xiaodou(rst,clk_1M,out); input clk_1M; input rst; output out; wire rst; reg out; reg[24:0]cnt; reg[2:0]state; parameter state0=3'b000, state1=3'b001, state2=3'b010, state3=3'b011, state4=3'b100, state5=3'b101; always@(posedge clk_1M) begin cnt<=24'd0; case(state) state0:if(!rst) begin out=0; state<=state1; end else state<=state0; state1:begin out=0; cnt<=cnt+1; if(cnt==10000) state<=state2; else begin //out=1; state<=state1; end end state2:if(!rst) state<=state3; else state<=state0; state3:if(!rst) begin out=1; cnt<=0; //state<=state3; end else state<=state4; state4:begin cnt<=cnt+1; if(cnt==200000) begin out=1; state<=state5; end else begin out=1; state<=state4; end end state5:if(rst) begin out=0; state<=state0; end else state<=state3; endcase end endmodule (2)原理图及仿真波形 2、按键识别模块设计 (1)程序设计 module xkey(a,b,c,d,e,f,g,h,l,qout); input a,b,c,d,e,f,g,h,l; output qout; reg [8:0] qin; reg [4:0] qout; always@(a or b or c or d or e or f or g or h or l) begin qin[8]=a; qin[7]=b; qin[6]=c; qin[5]=d; qin[4]=e; qin[3]=f; qin[2]=g; qin[1]=h; qin[0]=l; end always@(qin) begin case(qin) 9'b100000000:qout<=5'b00001; 9'b010000000:qout<=5'b00010; 9'b001000000:qout<=5'b00011; 9'b000100000:qout<=5'b00100; 9'b000010000:qout<=5'b00101; 9'b000001000:qout<=5'b00110; 9'b000000100:qout<=5'b00111; 9'b100000010:qout<=5'b01000; 9'b010000010:qout<=5'b01001; 9'b001000010:qout<=5'b01010; 9'b000100010:qout<=5'b01011; 9'b000010010:qout<=5'b01100; 9'b000001010:qout<=5'b01101; 9'b000000110:qout<=5'b01110; 9'b100000001:qout<=5'b01111; 9'b010000001:qout<=5'b10000; 9'b001000001:qout<=5'b10001; 9'b000100001:qout<=5'b10010; 9'b000010001:qout<=5'b10011; 9'b000001001:qout<=5'b10100; 9'b000000101:qout<=5'b10101; 9'b000000000:qout<=5'b00000; 9'b000000010:qout<=5'b00000; 9'b000000001:qout<=5'b00000; default:qout<=0; endcase end endmodule (2)原理图及仿真波形 3、分频器模块的设计 (1)程序设计 module fenpin(in,clk_1M,out); input in; input clk_1M; output out; wire[4:0]in; reg out; reg[11:0]count; reg[4:0]state; initial count<=12'd0; parameter state0=5'b00000, state1=5'b00001, state2=5'b00010, state3=5'b00011, state4=5'b00100, state5=5'b00101, state6=5'b00110, state7=5'b00111, state8=5'b01000, state9=5'b01001, state10=5'b01010, state11=5'b01011, state12=5'b01100, state13=5'b01101, state14=5'b01110, state15=5'b01111, state16=5'b10000, state17=5'b10001, state18=5'b10010, state19=5'b10011, state20=5'b10100, state21=5'b10101, state22=5'b10110; always@(posedge clk_1M) begin case(state) state0: begin //if(allin==5'b10110) //state<=state0; if(in==5'b00001) state<=state1; else if(in==5'b00010) state<=state2; else if(in==5'b00011) state<=state3; else if(in==5'b00100) state<=state4; else if(in==5'b00101) state<=state5; else if(in==5'b00110) state<=state6; else if(in==5'b00111) state<=state7; else if(in==5'b01000) state<=state8; else if(in==5'b01001) state<=state9; else if(in==5'b01010) state<=state10; else if(in==5'b01011) state<=state11; else if(in==5'b01100) state<=state12; else if(in==5'b01101) state<=state13; else if(in==5'b01110) state<=state14; else if(in==5'b01111) state<=state15; else if(in==5'b10000) state<=state16; else if(in==5'b10001) state<=state17; else if(in==5'b10010) state<=state18; else if(in==5'b10011) state<=state19; else if(in==5'b10100) state<=state20; else if(in==5'b10101) state<=state21; else if(in==5'b00000) state<=state22; else state<=state0; end state1: begin if(count<=956) begin begin count=count+12'd1; end if(in==5'b00001) state<=state1; else begin out=0; state<=state0; end end else begin begin out=~out; count=0; end if(in==5'b00001) state<=state1; else begin out=0; state<=state0; end end end state2:begin if(count<=852)begin begin count=count+12'd1;end if(in==5'b00010)state<=state2;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b00010)state<=state2;else begin out=0;state<=state0;end end end state3:begin if(count<=759)begin begin count=count+12'd1;end if(in==5'b00011)state<=state3;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b00011)state<=state3;else begin out=0;state<=state0;end end end state4:begin if(count<=716)begin begin count=count+12'd1;end if(in==5'b00100)state<=state4;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b00100)state<=state4;else begin out=0;state<=state0;end end end state5:begin if(count<=638)begin begin count=count+12'd1;end if(in==5'b00101)state<=state5;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b00101)state<=state5;else begin out=0;state<=state0;end end end state6:begin if(count<=568)begin begin count=count+12'd1;end if(in==5'b00110)state<=state6;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b00110)state<=state6;else begin out=0;state<=state0;end end end state7:begin if(count<=501)begin begin count=count+12'd1;end if(in==5'b00111)state<=state7;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b00111)state<=state7;else begin out=0;state<=state0;end end end state8:begin if(count<=478)begin begin count=count+12'd1;end if(in==5'b01000)state<=state8;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b01000)state<=state8;else begin out=0;state<=state0;end end end state9:begin if(count<=426)begin begin count=count+12'd1;end if(in==5'b01001)state<=state9;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b01001)state<=state9;else begin out=0;state<=state0;end end end state10:begin if(count<=380)begin begin count=count+12'd1;end if(in==5'b01010)state<=state10;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b01010)state<=state10;else begin out=0;state<=state0;end end end state11:begin if(count<=358)begin begin count=count+12'd1;end if(in==5'b01011)state<=state11;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b01011)state<=state11;else begin out=0;state<=state0;end end end state12:begin if(count<=319)begin begin count=count+12'd1;end if(in==5'b01100)state<=state12;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b01100)state<=state12;else begin out=0;state<=state0;end end end state13:begin if(count<=284)begin begin count=count+12'd1;end if(in==5'b01101)state<=state13;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b01101)state<=state13;else begin out=0;state<=state0;end end end state14:begin if(count<=251)begin begin count=count+12'd1;end if(in==5'b01110)state<=state14;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b01110)state<=state14;else begin out=0;state<=state0;end end end state15:begin if(count<=1912)begin begin count=count+12'd1;end if(in==5'b01111)state<=state15;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b01111)state<=state15;else begin out=0;state<=state0;end end end state16:begin if(count<=1704)begin begin count=count+12'd1;end if(in==5'b10000)state<=state16;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b10000)state<=state16;else begin out=0;state<=state0;end end end state17:begin if(count<=1518)begin begin count=count+12'd1;end if(in==5'b10001)state<=state17;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b10001)state<=state17;else begin out=0;state<=state0;end end end state18:begin if(count<=1432)begin begin count=count+12'd1;end if(in==5'b10010)state<=state18;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b10010)state<=state18;else begin out=0;state<=state0;end end end state19:begin if(count<=1276)begin begin count=count+12'd1;end if(in==5'b10011)state<=state19;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b10011)state<=state19;else begin out=0;state<=state0;end end end state20:begin if(count<=1136)begin begin count=count+12'd1;end if(in==5'b10100)state<=state20;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b10100)state<=state20;else begin out=0;state<=state0;end end end state21:begin if(count<=1002)begin begin count=count+12'd1;end if(in==5'b10101)state<=state21;else begin out=0;state<=state0;end end else begin begin out=~out;count=0;end if(in==5'b10101)state<=state21;else begin out=0;state<=state0;end end end state22:begin out=0;state<=state0;end endcase end endmodule (2)原理图及仿真波形 4、自动播放模块 (1)程序设计 module huanlesong(in,clk_1M,o1,o2,o3,o4,o5,o6,o7,o8,o9); input in,clk_1M; output o1,o2,o3,o4,o5,o6,o7,o8,o9; reg o1,o2,o3,o4,o5,o6,o7,o8,o9; reg[18:0]q; reg[6:0]n; always@(posedge clk_1M) if(in==0) begin o1=0;o2=0;o3=0;o4=0;o5=0;o6=0;o7=0;o8=0;o9=0; q=q+1;if(q=='d200000)begin q='b0;n=n+1;end case(n) 'd1:o3=1; 'd2:o3=1; 'd3:o4=1; 'd4:o5=1; 'd5:o5=1; 'd6:o4=1; 'd7:o3=1; 'd8:o2=1; 'd9:o1=1; 'd10:o1=1; 'd11:o2=1; 'd12:o3=1; 'd13:o3=1; 'd14:o2=1; 'd15:o2=1; 'd16:begin o1=0;o2=0;o3=0;o4=0;o5=0;o6=0;o7=0;o8=0;o9=0;end 'd17:o3=1; 'd18:o3=1; 'd19:o4=1; 'd20:o5=1; 'd21:o5=1; 'd22:o4=1; 'd23:o3=1; 'd24:o2=1; 'd25:o1=1; 'd26:o1=1; 'd27:o2=1; 'd28:o3=1; 'd29:o2=1; 'd30:o1=1; 'd31:o1=1; 'd32:begin o1=0;o2=0;o3=0;o4=0;o5=0;o6=0;o7=0;o8=0;o9=0;end 'd33:o2=1; 'd34:o2=1; 'd35:o3=1; 'd36:o1=1; 'd37:o2=1; 'd38:o3=1; 'd39:o3=1; 'd40:o1=1; 'd41:o2=1; 'd42:o3=1; 'd43:o3=1; 'd44:o2=1; 'd45:o1=1; 'd46:o2=1; 'd47:begin o9=1;o5=1;end 'd48:o1=1; 'd49:o3=1; 'd50:o3=1; 'd51:o4=1; 'd52:o5=1; 'd53:o5=1; 'd54:o4=1; 'd55:o3=1; 'd56:o2=1; 'd57:o1=1; 'd58:o1=1; 'd59:o2=1; 'd60:o3=1; 'd61:o2=1; 'd62:o1=1; 'd63:o1=1; 'd64:begin o1=0;o2=0;o3=0;o4=0;o5=0;o6=0;o7=0;o8=0;o9=0;end 'd65:n=0; endcase end endmodule (2)原理图及仿真波形 5、二选一模块设计 (1)程序设计 module xza(in,k1,k2,clk_1M,out); input in,k1,k2,clk_1M; output out; reg out; /*initial begin k1=1;k2=1;out=0; end*/ always@(posedge clk_1M) begin if(in==0) out<=k2; else out<=k1; end endmodule (2)原理图及仿真波形 6、电子琴设计 原理图 六、心得体会 虽然只有短短五天的课程设计,但是在解决各种困难的过程中也有所收获。首先,在课程设计之前应该做好预习,最少知道要做什么,怎么做,做到有一个大致的思路,只有知己知彼方能百战百胜;而后在课程设计一开始就应该积极调整心态,端正态度,认真听老师的讲解和要求,积极思考,不能因为在机房就分心; 接着在课程设计的时候就应该集中精力,理清思路,认真编写程序,在编写的过程中难免遇到许多错误,不管是verilogHDl语法的问题还是QuartusⅡ7.0软件的使用问题,积极询问老师,达到站在巨人的肩膀上的效果,同时可以积极和周围同学交流一些心得体会,切忌闭门造车,事倍功半。在设计过程中更应该排除杂念,不要抱侥幸心理,要实事求是脚踏实地的一步一步做下去,因为整个工程包含的模块至少有两个,哪一个模块出问题都会导致得不到结果,所以出现问题,结果不理想必须要及时解决,不能向后拖,而且在测试的时候尽量接近真实情况,不能因为仿真花费的时间长,就简单测试这也会为后来的工作埋下隐患,比如我在设计分频器的过程中一味求快,在测试的时候只加了让他输出中音“哆”的音,结果是正确的,但是后来在组合电路后结果无论加什么条件只是输出“哆”的音,只能再改程序,一步一步从头开始;另外设计最好是自己完成,不要照抄照搬别人的,自己的能力的不到提升也是不尊重别人的劳动成果,更是对课程涉及的亵渎。在别人早早就完成设计后,我们应该寻求技术上的帮助而不是寻求结果。设计过程中要平心静气,戒骄戒躁,有时候可能就是没有思路,要学调整自己。课程设计过程中一次又一次的建工程,建verilog文件,bdf原理图文件,和vwf仿真波形图文件,一遍遍地仿真,基本能够熟练掌握Quartus的基本操作,对verilog语言从认识到使用虽然历经坎坷,但是只有这样才会有深刻的记忆,虽然仍旧有许多问题依旧是自己不了解和不能解决的,但会在以后的学习中继续努力;本次课程设计的各个模块中,分频模块和自动谱曲模块依旧不能让人满意,分频模块由于在计数延时分频过程中夹杂着判断,所以不能很好的通过所设的数字达到理想的频率,而自动谱曲模块本来就是参考的别人的程序,在拿来自己使用的时候依旧不能实现长短音,而且在自己用的时候由于计数太小以至于不发不发的频率太快,难以分辨。但总体来说,课程设计还是取得了一定成果。最后谢谢老师的帮助和指导 1. 基于C8051F单片机直流电动机反馈控制系统的设计与研究 2. 基于单片机的嵌入式Web服务器的研究 3. MOTOROLA单片机MC68HC(8)05PV8/A内嵌EEPROM的工艺和制程方法及对良率的影响研究 4. 基于模糊控制的电阻钎焊单片机温度控制系统的研制 5. 基于MCS-51系列单片机的通用控制模块的研究 6. 基于单片机实现的供暖系统最佳启停自校正(STR)调节器 7. 单片机控制的二级倒立摆系统的研究 8. 基于增强型51系列单片机的TCP/IP协议栈的实现 9. 基于单片机的蓄电池自动监测系统 10. 基于32位嵌入式单片机系统的图像采集与处理技术的研究 11. 基于单片机的作物营养诊断专家系统的研究 12. 基于单片机的交流伺服电机运动控制系统研究与开发 13. 基于单片机的泵管内壁硬度测试仪的研制 14. 基于单片机的自动找平控制系统研究 15. 基于C8051F040单片机的嵌入式系统开发 16. 基于单片机的液压动力系统状态监测仪开发 17. 模糊Smith智能控制方法的研究及其单片机实现 18. 一种基于单片机的轴快流CO〈,2〉激光器的手持控制面板的研制 19. 基于双单片机冲床数控系统的研究 20. 基于CYGNAL单片机的在线间歇式浊度仪的研制 21. 基于单片机的喷油泵试验台控制器的研制 22. 基于单片机的软起动器的研究和设计 23. 基于单片机控制的高速快走丝电火花线切割机床短循环走丝方式研究 24. 基于单片机的机电产品控制系统开发 25. 基于PIC单片机的智能手机充电器 26. 基于单片机的实时内核设计及其应用研究 27. 基于单片机的远程抄表系统的设计与研究 28. 基于单片机的烟气二氧化硫浓度检测仪的研制 29. 基于微型光谱仪的单片机系统 30. 单片机系
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服