FPGA课程设计报告--简易电子琴的设计
FPGA设计简易电子琴

简易电子琴电路设计一、设计要求:(1) 设计一个简易电子琴。
(2) 利用实验箱的脉冲源产生1,2,3,……共7 个或14 个音阶信号。
(3) 用指示灯显示节拍。
(4) 能产生颤音效果。
二、原理说明:简易电子琴实现自动播放和手动弹奏两种模式,由一个开头选择。
自动播放功能可以预置多首乐曲,可以通过手动选择,本设计预置了两首乐曲《梁祝》和《两只老虎》。
手动弹奏设置了7个按键做琴键,分别对应7个音阶。
系统由8个模块组成,图1是顶层设计文件,其内部有7个功能模块:Speakera.v(例2) 和ToneTaba.v (例3),NoteTabs.v (例4),div_27.v,div-50.v,Keyboard.v,Dir.v。
模块ToneTaba音阶发生器,当4位发声控制输入Index中某一位为高电平时,则对应某一音阶的数值将从端口Tone输出,作为获得该音阶的分频预置值;同时由Code输出对应该音阶简谱的LED显示,音阶越高,LED亮的数目越多。
模块Speakera中的主要电路是一个数控分频器,它由一个初值可预置的加法计数器构成,当模块Speakera由端口Tone获得一个2进制数后,将以此值为计数器的预置数,对端口Clk12MHZ输入的频率进行分频,之后由Spkout 向扬声器输出发声。
模块NoteTabs用于产生节拍控制(Index数据存留时间)和音阶选择信号,即在NoteTabs模块放置两个乐曲曲谱真值表,通过song来选择播放的音乐,00代表复位,01选乐曲《梁祝》,10选《两只老虎》,由一个计数器的计数值来控制此真值表的输出,而由此计数器的计数时钟信号作为乐曲节拍控制信号,从而可以设计出一个纯硬件的乐曲自动演奏电路。
模块div-27和div_50是分频模块,通过计数的方式进行分频。
div_27是由板上27M时钟分频产生4Hz的频率用于节拍控制,div_50是板上50M时钟产生12.5MHz用于Sperkera模块。
基于FPGA的多功能电子琴设计与实现

西南科技大学电子专业综合设计报告设计名称:基于FPGA的多功能电子琴的设计与实现姓名:学号:班级:指导教师:起止日期: 2013年11月22日-2013年12月10 日西南科技大学信息工程学院制综合设计任务书学生班级:电子1001 学生姓名:学号:设计名称:基于FPGA的多功能电子琴的设计与实现起止日期:2013.11.22-2013.12.10 指导教师:综合设计学生日志基于FPGA的多功能电子琴的设计与实现摘要:随着科学技术的日新月异,人们的生活也在发生在变化,电子产品也随之增多,比如现在流行的电子琴,已经逐渐代替了曾经的手动风琴了。
文章中所介绍的多功能电子琴的设计在Quartus II平台上,采用Verilog HDL 语言和模块化的设计方法,设计出一个能够通过按键控制不同的音符,同时也可以通过按键进行演奏已经存储的曲子的多功能电子琴。
本系统主要由五个个模块组成:顶层模块,曲目1模块,曲目2模块,按键模块,曲目循环播放模块。
关键词: FPGA;电子琴; Verilog HDL;音符FPGA-based design and implementation of multi-organAbstract:With the development of science and technology, also occurs in people's lives change, electronic products also increase, such as the now popular organ, has replaced the former manual organ. Multifunction keyboard design as described in the article on the Quartus II platform, using Verilog HDL language and modular design method, design a button control through different note, you can also play music already stored by keys multifunction keyboard. The system consists of five modules: the top-level module, a module tracks, track 2 modules, key module, track loop module.Key words: FPGA, Keyboard, Verilog HDL, Note一、设计目的和意义目的:1.1、在掌握计算机组成原理理论相关的基础上,了解 EDA技术,掌握 Verilog HDL 硬件描述语言的设计方法和思想;1.2、培养综合运用知识和独立开展实践创新的能力;1.3、深入学习Verilog HDL,了解其编程环境;1.4、学会运用Quartus II等编程仿真软件;1.5将硬件语言编程与硬件实物功能演示相结合,加深理解Verilog HDL的学习。
基于FPGA的电子琴设计课程设计

课程设计摘要乐曲演奏广泛用于自动答录装置、手机铃声、集团电话、及智能仪器仪表设备。
实现方法有许多种。
现用可编程逻辑器件(PLD)来完成该设计。
核心是一数控分频器,对输入的脉冲进行分频,得到每个音阶对应的频率,由此实现简易电子琴的发音功能。
电子琴可演奏由键盘输入的音阶,同时在数码管上显示对应音节的频率。
本设计基于超高速硬件描述语言VHDL在Altera公司的CycloneⅡ系列的EP2C5T144C8芯片上编程实现;经仿真,调试基本能够达到技术指标,仿真结果基本正确。
关键词音乐译码电路模块,VHDL,数控分频,电子琴基于FPGA的电子琴设计AbstractMusic performances are widely used in automatic answering devices, cell phone ring tones, the Group phones, smart instrumentation and equipment。
The design is accomplished using a programmable logic device (PLD). The core is a numerical control frequency divider, the input pulse frequency, the frequency of each scale corresponding to the frequency, thus achieving the function of simple electronic piano. The electronic piano can be played by the keyboard input of the scale, while in the digital tube display the corresponding syllable frequency. The design based on ultra high speed hardware description language VHDL on Altera's cyclone II Series ep2c5t144c8 chip programming; the simulation and debugging can basically meet the technical indicators, and the result of simulation is correct.Keywords Music decoder circuit module,VHDL,Numerical control pointing frequency modules,electronic organ沈阳工程学院课程设计目录摘要 (I)Abstract ................................................................................................................................................................ I I1 引言 (1)2 VHDL简述及应用 (2)2.1VHDL简述 (2)2.2 VHDL的应用 (2)3 FPGA的简述 (3)3.1 FPGA的介绍 (3)3.2 FPGA的整体结构 (3)3.3 Altera公司的FPGA (3)4 电子琴演奏系统设计原理分析 (4)4.1电子琴演奏设计的基本要求 (4)4.2电子琴演奏原理 (4)4.3音名与频率的关系 (5)4.4控制音长的节拍发生器 (6)5 电子琴硬件演奏电路的层次化设计方案 (8)5.1按键控制模块 (8)5.2自动演奏模块 (8)5.3自动播放控制模块 (9)5.4数控分频模块设计 (9)5.5数码管译码显示 (10)5.6音频驱动模块 (10)结论 (12)致谢 (13)参考文献 (14)附录1 (15)附录2 (16)基于FPGA的电子琴设计1 引言我们生活在一个信息高速发达的时代,各种各样电子产品层出不穷。
基于FPGA的简易电子琴设计

简易电子琴的设计学生姓名:王春指导老师:郑大腾摘要本系统是采用EDA技术设计的一个简易的八音符电子琴,该系统基于计算机中时钟分频器的原理,采用自顶向下的设计方法来实现,它可以通过按键输入来控制音响。
多功能电子琴的设计是在原有普通电子琴的基础上进行扩充的一个设计。
该电子琴的设计大体可以由三个模块构成,分别是电子琴发声模块、存储器模块和选择控制模块。
用超高速硬件描述语言VHDL编程可以实现各个模块的功能。
不仅能实现弹琴和演奏的功能,它还能实现“复读”的功能,就是可以存储任意一段音乐,并且可以即时的播放出来。
系统实现是用硬件描述语言VHDL 按照模块化方式进行设计,然后进行编程、时序仿真、总体整合。
本系统的功能比较齐全,有一定的现实使用的价值。
本文中介绍了电子琴系统的整体的设计,并基于超高速硬件描述语言VHDL在相关的芯片上编程实现的。
关键字电子琴;EDA;VHDL;音调发生;现场可编程逻辑器件FPGA;超高速硬件描述语言VHDL;电子琴系统;AbstractThis system is designed using EDA technology a simple eight-note keyboard, the system clock divider based on the principle of the computer, using top-down design methodology to implement, it can be controlled through the key input audio. Multi-function keyboard is designed to be an ordinary keyboard in the original expansion on the basis of a design. The design of the keyboard in general consists of three modules, namely the keyboard soundmodules, memory modules and select the control module. Ultra high-speed hardware description language VHDL programming function of each module. Not only can realize the function of playing and playing, it can achieve "repeat" function, which can store any piece of music, and real-time play out. System implementation is to use hardware description language VHDL modular way by design, then programming, timing simulation, integration. The system features a relatively complete, there is a certain value. This paper introduces the overall design of the keyboard system, and based on high speed hardware description language VHDL in Xilinx's Spartan Ⅱ series 2sc200PQ208-5 chip programming.KeywordKeyboard; EDA; VHDL; tone occurred;field programmable logic device FPGA;ultra high-speed hardware description language VHDL; organ systems;皖西学院毕业论文设计第3页共36页目录1 引言..................................................................1.1设计的目的...........................................................1.2设计的基本内容.......................................................2 FPGA、EDA、VHDL简介....................................................2.1FPGA工作原理 ........................................................2.1.2 FPGA的基本特点....................................................2.2EDA技术...............................................................2.3硬件描述语言——VHDL ...................................................2.3.1 VHDL的简介.......................................................2.3.2 VHDL语言的特点...................................................2.3.3VHDL语言上机操作条件.............................................2.3.4 VHDL的设计流程...................................................3 音乐知识介绍............................................................4 简易电子琴设计..........................................................4.1系统设计的总思路.....................................................4.2程序设计的流程图.....................................................4.3简易电子琴的工作流程图...............................................4.4简易电子琴中各模块的设计.............................................4.4.1 乐曲自动演奏模块...................................................4.4.2 音调发生模块.......................................................4.4.3 数控分频模块.......................................................4.4.4 顶层设计...........................................................5 系统仿真.................................................................6 结束语..................................................................第3页致谢..................................................................... 参考文献................................................................. 附录.....................................................................1 引言我们生活在一个信息高速发达的时代,各种各样电子产品层出不穷。
简易电子琴设计-可编程逻辑设计实践课程报告

学院:物理与信息工程学院班级:2010级信通____学生:______学号:_________老师:____基于FPGA的简易电子琴设计报告 (3)一、设计简介 (3)二、方案论述 (4)1)、基本乐理知识: (4)2)、模块方案: (4)1、数控分频部分: (4)各音阶频率对应的分频值以及初始化 (5)2、音乐节拍产生器: (5)3、键盘输入及译码模块 (6)4、音量控制模块: (7)5、数码管显示模块: (8)三、总体结构框图: (8)四、单元模块设计 (8)1、键盘输入译码模块ToneData (8)2、播放速度控制模块(包括暂停功能): (10)3、自动演奏模块 (11)4、分频器模块(Speaker): (14)5)、数码管显示译码模块 (15)6)、数码管动态扫描模块 (16)7、音量调节 (18)五、系统测试 (20)六、设计总结 (23)基于FPGA的简易电子琴设计报告一、设计简介本次的课程设计是围绕着可编程逻辑器件进行的,可编程器件强大的并行性能使得其能轻易实现许多顺序执行程序的功能,并且效率高得多,但由顺序执行的思想转化为并行的思维方式,并不是那么容易的。
通过这次课程设计熟悉了FPGA设计的思路与方法,为将来的进一步发展奠定了基础。
本次选择电子琴为课题,并不仅仅因为其较为简单,而是基于个人对于音频等多媒体信息处理的兴趣,希望通过此次课程设计收获些相关的知识。
本次课设设计的电子琴主要实现了以下功能:1、手动演奏功能。
共用到8个按键,其中1个为shift键,用于切换不同组的音符。
Shift置零时,其余七个按键为中音Do至Xi。
Shift置高时,其余七个按键为低音的So La Xi和高音的Do Re Mi Fa。
2、自动演奏功能。
内部可识别21个音符,rom容量为512位,字宽为5位(0~31)。
其中用0表示休止符。
1~7表示低音Do~Xi,11~17表示中音Do~Xi,21~31用于表示高音Do~Xi。
verilogHDL的电子琴设计

河海大学计算机与信息学院(常州)课程设计报告题目电子琴设计专业/学号电科/**********授课班号278605学生姓名马东林指导教师单鸣雷完成时间2014/01/07河海大学本科课程设计报告课程设计(报告)任务书(理工科类)Ⅰ、课程设计(报告)题目:电子琴设计Ⅱ、课程设计(论文)工作内容用FPGA器件驱动蜂鸣器演奏“茉莉花”片段。
一首乐曲包含三个要素:乐曲声音频率,发音时间的长短,停顿的时间。
按照图1乐谱,设计相应电路控制speaker信号的方波频率,某一频率持续时间长短,各频率间间隔大小,就可以推动蜂鸣器演奏乐曲。
图1 茉莉花简谱一、课程设计目标1、培养综合运用知识和独立开展实践创新的能力;2、培养学生独立编写verilog hdl 程序的能力,加深对课本知识的理解。
二、研究方法及手段应用1、将任务分成若干模块,查阅相关论文资料,分模块调试和完成任务;2、两人一组合作分工完成程序的编写和调试。
三、课程设计预期效果1、完成实验环境搭建;2、完成程序的编写和调试;3、能在实验平台上顺利演示效果用蜂鸣器播放一首音乐,并可以按键弹奏;4、锻炼学生的独立分析程序,解决问题的能力以及掌握verilog hdl 的实际应用。
学生姓名:马东林专业年级:电科/2011摘 要乐曲演奏广泛用于自动答录装置、手机铃声、集团电话及智能仪器仪表设备。
实现方法有许多种,在众多的实现方法中,以纯硬件完成乐曲演奏,随着FPGA 集成度的提高,价格下降,EDA 设计工具更新换代,功能日益普及与流行,使这种方案的应用越来越多。
FPGA 预装了很多已构造好的参数化库单元LPM 器件,通过引入支持LPM 的EDA 软件工具,设计者可以设计出结构独立而且硅片的使用效率非常高的产品。
本设计由现场可编程门矩阵(FPGA )作为控制芯片,通过VreilogHDL 硬件描述语言设计,运用自顶而下的设计思想,按功能逐层分割实现层次化的设计。
总体设计方案为先用分频电路产生不同频率方波;再利用利用数控分频器实现speaker 输出信号频率的选择,某一频率持续时间长短,各频率间间隔大小,其中方波的频率决定了音调的高低。
基于FPGA的简易触摸电子琴设计

基于FPGA的简易触摸电子琴设计作者:崔智军刘昭元张瑜来源:《现代电子技术》2014年第22期摘要:简易触摸电子琴是以FPGA芯片作为系统控制核心,通过数控分频的原理实现音乐自动播放、琴键演奏的功能,有限状态机实现触摸控制和LCD显示驱动,再采用友晶科技的4.3寸液晶触摸显示屏(LTM)完成简易触摸电子琴模式选择控制和琴键显示控制。
在DE0⁃Nano FPGA(Altera Cyclone Ⅳ)开发板上的测试表明,所设计的低成本简易触摸电子琴可以实现触摸控制弹奏和自动播放乐曲的功能,同时具有较高的实用价值。
关键词: FPGA;电子琴;液晶显示屏;有限状态机中图分类号: TN710⁃34; TP332 文献标识码: A 文章编号: 1004⁃373X(2014)22⁃0114⁃03Design of simple touch electronic piano based on FPGACUI Zhi⁃jun1, LIU Zhao⁃yuan2, ZHANG Yu1(1. Department of Electronics and Information Engineering, Ankang University, Ankang 725000, China;2. Xi’an ZTE New Software Co., Ltd,Xi’an 710129, China)Abstract: The simple touch electronic piano, which takes FPGA chip as system control core, employs the principle of NC divider to achieve automatic music playing, finite state machine to realize the touch control and LCD display drive, and 4.3 inch LCD touch panel Module (LTM)of Terasic to complete a simple touch electronic piano mode selection control and key display control. The test on DE0⁃NanoFPGA (Altera Cyclone IV) development board show that the design of low⁃cost simple touch electronic piano can achieve the functions of touch control and automatic music playing, and also has high practical value.Keywords: field programmable gate array; electronic piano; liquid crystal display; finite state machine0 引言电子琴因其操作简单,且能模拟各种传统乐器的音色,而深受消费者喜欢。
基于FPGA的简易电子琴设计

课程设计任务书开题报告皖西学院本科毕业论文(设计)中期检查表简易电子琴的设计学生姓名:王春指导老师:郑大腾摘要本系统是采用EDA技术设计的一个简易的八音符电子琴,该系统基于计算机中时钟分频器的原理,采用自顶向下的设计方法来实现,它可以通过按键输入来控制音响。
多功能电子琴的设计是在原有普通电子琴的基础上进行扩充的一个设计。
该电子琴的设计大体可以由三个模块构成,分别是电子琴发声模块、存储器模块和选择控制模块。
用超高速硬件描述语言VHDL编程可以实现各个模块的功能。
不仅能实现弹琴和演奏的功能,它还能实现“复读”的功能,就是可以存储任意一段音乐,并且可以即时的播放出来。
系统实现是用硬件描述语言VHDL 按照模块化方式进行设计,然后进行编程、时序仿真、总体整合。
本系统的功能比较齐全,有一定的现实使用的价值。
本文中介绍了电子琴系统的整体的设计,并基于超高速硬件描述语言VHDL在相关的芯片上编程实现的。
关键字电子琴;EDA;VHDL;音调发生;现场可编程逻辑器件FPGA;超高速硬件描述语言VHDL;电子琴系统;AbstractThis system is designed using EDA technology a simple eight-note keyboard, the system clock divider based on the principle of the computer, using top-down design methodology to implement, it can be controlled through the key input audio. Multi-function keyboard is designed to be an ordinary keyboard in the original expansion on the basis of a design. The design of the keyboard in general consists of three modules, namely the keyboard soundmodules, memory modules and select the control module. Ultra high-speed hardware description language VHDL programming function of each module. Not only can realize the function of playing and playing, it can achieve "repeat" function, which can store any piece of music, and real-time play out. System implementation is to use hardware description language VHDL modular way by design, then programming, timing simulation, integration. The system features a relatively complete, there is a certain value. This paper introduces the overall design of the keyboard system, and based on high speed hardware description language VHDL in Xilinx's Spartan Ⅱ series 2sc200PQ208-5 chip programming.KeywordKeyboard; EDA; VHDL; tone occurred;field programmable logic device FPGA;ultra high-speed hardware description language VHDL; organ systems;目录1 引言..................................................................1.1设计的目的...........................................................1.2设计的基本内容.......................................................2 FPGA、EDA、VHDL简介....................................................2.1FPGA工作原理 ........................................................2.1.2 FPGA的基本特点....................................................2.2EDA技术...............................................................2.3硬件描述语言——VHDL ...................................................2.3.1 VHDL的简介.......................................................2.3.2 VHDL语言的特点...................................................2.3.3VHDL语言上机操作条件.............................................2.3.4 VHDL的设计流程...................................................3 音乐知识介绍............................................................4 简易电子琴设计..........................................................4.1系统设计的总思路.....................................................4.2程序设计的流程图.....................................................4.3简易电子琴的工作流程图...............................................4.4简易电子琴中各模块的设计.............................................4.4.1 乐曲自动演奏模块...................................................4.4.2 音调发生模块.......................................................4.4.3 数控分频模块.......................................................4.4.4 顶层设计...........................................................5 系统仿真.................................................................6 结束语..................................................................致谢..................................................................... 参考文献................................................................. 附录.....................................................................1 引言我们生活在一个信息高速发达的时代,各种各样电子产品层出不穷。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
邮电大学FPGA课程设计报告题目:简易电子琴设计及FPGA功能验证院系:专业班级:学生:XX导师:XX起止时间:2012、6、18至2012、6、29一、课程设计任务:本设计一个简易电子琴,具体功能如下:1、具有手动弹奏和自动播放功能;2、以按键或开关作为电子琴的琴键,输出7个音节的音阶;3、可以自动播放曲目至少两首。
二、课程设计目的:1、培养综合运用知识和独立开展实践创新的能力;2、深入学习Verilog HDL,了解其编程环境;3、学会运用Modelsim和Quartus II等编程仿真软件;4、将硬件语言编程与硬件实物功能演示相结合,加深理解Verilog HDL的学习;三、使用环境:1、软件:Modelsim和Quartus II等编程仿真软件;2、硬件:FPGA开发板。
四、课程设计详细方案及功能验证:1、总体实现方案:1、简易电子琴的设计通过软硬件结合实现,硬件系统包括主控器芯片、9个按键、LED、蜂鸣器等,软件资源包括编写Verilog HDL程序的应用软件Modelsim和仿真软件Quartus II。
电子琴有按键代替琴键的弹奏功能和自动播放功能。
2、整个程序总共分5个模块:主模块,按键模块,曲目1模块,曲目2模块,曲目3模块。
整个方案总共用了9个按键(key1~key9),按键key1~key7作为琴键,通过这七个按键键入不同的音阶。
主模块中key8、key9两个按键用于选择是自动播放还是弹奏曲目,令mm=(key8、key9),用mm值的不同选择调用不同模块。
如果mm=00,则程序调用按键模块;如果mm=01,则调用曲目1模块,播放曲目1;如果mm=10,则调用曲目2模块,播放曲目2;如果mm11,则调用曲目3模块,播放曲目3。
本次设计的框图:2、输入输出信号描述:具体功能描述:3、顶层划分:主模 (outclk beep_r4、主要模块:主模块:功能描述:是四个子模块的核心,通过主模块分别调用四个不同的子模块。
管脚描述:按键模块:功能描述:通过按键key1~key7键入不同的7个音阶,频率不同则蜂鸣器发音就不同;通过mm=(key8、key9)的值选择调用不同曲目模块。
管脚描述:曲目模块:功能描述:不同的曲目模块输出不同的曲调,根据高低音对应的频率不同输出不同曲调的曲目。
在50MHZ的情况下对主时钟分频得到6MHZ的频率,得到在6MHZ下对应的音阶及其对应频率,以及分频数,通过计数分频数,来对不同频率的声音进行输出,实验箱原始时钟为50MHz,分频后变成不同的频率输出,通过蜂鸣器输出不同频率的声音。
音乐的节拍通过分频变为4Hz,作为1/4拍,即每个单位时长0.25s。
管脚描述:信号名称输入/ 输出源功能描述inclk Input Pin 系统时钟50MHzKey(8~9) Input Pin 选择曲目Beep3 Output Pin 输出曲目5、功能仿真:1、综合:2、总体电路图:3、所有输入输出信号:4、管脚分配:输入信号:一个时钟信号,9个按键;输出信号:一个数码管输出,一个蜂鸣器输出音调。
5、时序仿真:仿真结果;设置输入信号key1~key7为高电平,此时设置key8~key9=01,即mm=01,在数码管应该显示1,在仿真结束后,如图示数码管为11111001,即为1,outclk为蜂鸣器的输出,如图示也正确,所以本设计经过仿真证明正确可行。
6、硬件测试结果:在时序验证后下载,通过硬件测试,实验达到预期效果,当mm(key8~key9)=00时,通过key1~key7这7个按键的键入蜂鸣器可以发出do~xi的七个音阶的音,即表示了电子琴的弹奏功能;当mm=01时,播放了第一首歌;mm=10时,播放了第二首歌;mm=11时,播放第三首歌。
通过硬件的测试,所有的设计目标均实现。
7、对结果和结论的问题讨论:实验过程中,蜂鸣器发音时好时坏,有时比较低沉,有时却比较尖锐,这可能是对主系统分频不精确导致的结果,当对主系统时钟不同分频时,结果都不同,最终在多次试验下,得到在6M时钟频率下效果最为理想。
8、音阶及其对应频率(时钟频率为50MHz分为6MHz)五、心得体会:在这次课程设计之前,其实做过了单片机关于蜂鸣器方面的实验,上手起来还是很快的,开始时,先按照老师的要求,写规,确定实现方案,然后在逐一细化,一步一步按照要求去完成整个设计。
本次设计要用quartusII软件,由于之前对此软件不是太熟悉所以导致了一些错误和问题的发生,所以这次课程设计中认真学习了quartusII软件的具体使用步骤和操作流程,对所有可能出现的问题进行逐一攻破。
通过这次实验,我不但熟悉了quartusII软件,也了解了开发的最基本流程和方法,也进一步加深了对Verilog编程语言的理解,最重要的是锻炼了我独立思考和分析的逻辑能力,通过从顶向下的设计方法,一步步实现,然后将整个设计串套起来,是我对设计的流程以及编程有了很大的提高。
通过此次硬件课程设计,使我越来越认识到一点,编程对项目实现有着至关重要的作用,我们在硬件开发的过程中必须重视编程,将编程看作是完善开发的不可缺少的一部分。
在一次次的反复设计、论证和测试中,不仅提高了逻辑分析能力、全面分析问题的能力,还提升了发现问题、解决问题的能力。
虽然设计过程比较繁琐,大大小小也出现了许多问题,但这却磨练了我的意志。
通过各方面的学习,使我的知识面进一步拓宽了。
同时,通过本次课程设计,使我也发现了自己的不足,例如:逻辑分析能力不突出,编程能力不足,解决问题的能力不足,使我认识到在以后的学习中在这些方面要多努力,加以改进,提升自我能力。
我相信通过这次课程设计的学习,对我以后有着十分重要的影响和作用。
附代码:moduledianziqin(inclk,outclk,key1,key2,key3,key4,key5,key6,key7,key8,key9,num);input inclk;input key1,key2,key3,key4,key5,key6,key7,key8,key9;output outclk;output[7:0]num;reg [7:0] num;reg outclk,clk_6M;reg [3:0]c;wire out1,out2,out3,out4;wire[8:0] key;reg [1:0]mm;assign key = {key1,key2,key3,key4,key5,key6,key7,key8,key9}; //由按键拼键为变量key//调用子调块digital_piano m1(.inclk(inclk),.key1(key1),.key2(key2),.key3(key3),.key4(key4),.key5(key5),.key6(key6),.key7(key7),.beep4(out4));bell m2(.inclk(inclk),.beep1(out1));bell2 m3(.inclk(inclk),.beep2(out2));bell3 m4(.inclk(inclk),.beep3(out3));always(posedge inclk)beginif(c<4'd8)c<=c+4'd1;elsebeginc <= 4'd0;clk_6M <= ~clk_6M;endendalways (posedge clk_6M) //在时钟的上升沿检测是否有按键按下beginif(key == 9'b111111110)mm <= 2'b01;else if(key==9'b111111101)mm <= 2'b10;else if(key==9'b111111100)mm <= 2'b11;else mm <= 2'b00;endalways(mm)begincase(mm)2'b01:num<=8'b11111001;2'b10:num<=8'b10100100;2'b11:num<=8'b10110000;default:num<=8'b11000000;endcaseendalways (mm) //按键响应beginif(mm == 2'b01)outclk <= out1;else if(mm == 2'b10)outclk <= out2;else if(mm == 2'b11)outclk <= out3;else outclk <= out4;endendmodule//digital_piano子模块module digital_piano(inclk,key1,key2,key3,key4,key5,key6,key7,beep4); input inclk,key1,key2,key3,key4,key5,key6,key7;output beep4;wire [6:0] key_code;reg [3:0] c;reg clk_6M;reg beep_r;reg [15:0] count;reg [15:0] count_end;parameter Do = 7'b1111110,re = 7'b1111101,mi = 7'b1111011,fa = 7'b1110111,so = 7'b1101111,la = 7'b1011111,si = 7'b0111111;assign key_code = {key7,key6,key5,key4,key3,key2,key1}; assign beep4 = beep_r; //输出音乐always(posedge inclk)beginif(c<4'd8)c<=c+4'd1;elsebeginc <= 4'd0;clk_6M <= ~clk_6M;endendalways(posedge clk_6M) //分频模块,得出乐谱begincount <= count + 16'd1; //计数器加1if(count == count_end)begincount <=16'd0; //计数器清零beep_r <= !beep_r;endendalways(posedge clk_6M) //状态机,根据按键状态,选择不同的音符输出begincase(key_code)Do: count_end <= 16'd11450;re: count_end <= 16'd10204;mi: count_end <= 16'd09090;fa: count_end <= 16'd08571;so: count_end <= 16'd07802;la: count_end <= 16'd06802;si: count_end <= 16'd06060;default:count_end <= 16'd0;endcaseendendmodule//bell子模块《两只老虎》module bell(inclk,beep1);input inclk; //系统时钟output beep1; //蜂鸣器输出端reg [3:0]high,med,low;reg [15:0]origin;reg beep_r; //寄存器reg [7:0]state;reg [15:0]count;assign beep1=beep_r; //输出音乐//时钟频率6MHzreg clk_6MHz;reg [2:0]t1;always(posedge inclk)beginif(cnt1<3'd8)cnt1<=cnt1+3'b1;elsebegincnt1<=3'b0;clk_6MHz<=~clk_6MHz;endend//时钟频率4MHzreg clk_4Hz;reg [24:0]t2;always(posedge inclk)beginif(cnt2<25'd1*******)//cnt2<=cnt2+25'b1;elsebegincnt2<=25'b0;clk_4Hz<=~clk_4Hz;endendalways (posedge clk_6MHz)begincount <= count + 1'b1; //计数器加1 if(count == origin)begincount <= 16'h0; //计数器清零beep_r <= !beep_r; //输出取反endendalways(posedge clk_4Hz)begincase({high,med,low})12'b000000010000:origin=11466;//mid112'b000000100000:origin=10216;//mid212'b000000110000:origin=9101; //mid312'b000001000000:origin=8590; //mid412'b000001010000:origin=7653; //mid512'b000001100000:origin=6818; //mid612'b000000000101:origin=14447;//low5endcaseendalways (posedge clk_4Hz) //歌曲<<two tiger>> beginif(state ==63) state = 0;//计时,以实现循环演奏elsestate = state + 1;case(state)0,1:{high,med,low}=12'b000000010000;//mid12,3:{high,med,low}=12'b000000100000;//mid24,5:{high,med,low}=12'b000000110000;//mid36,7:{high,med,low}=12'b000000010000;//mid18,9:{high,med,low}=12'b000000010000;//mid110,11:{high,med,low}=12'b000000100000;//mid212,13:{high,med,low}=12'b000000110000;//mid314,15:{high,med,low}=12'b000000010000;//mid116,17:{high,med,low}=12'b000000110000;//mid318,19:{high,med,low}=12'b000001000000;//mid420,21,22,23:{high,med,low}=12'b000001010000;//mid524,25:{high,med,low}=12'b000000110000;//mid326,27:{high,med,low}=12'b000001000000;//mid428,29,30,31:{high,med,low}=12'b000001010000;//mid532:{high,med,low}=12'b000001010000;//mid533:{high,med,low}=12'b000001100000;//mid634:{high,med,low}=12'b000001010000;//mid535:{high,med,low}=12'b000001000000;//mid436,37:{high,med,low}=12'b000000110000;//mid338,39:{high,med,low}=12'b000000010000;//mid140:{high,med,low}=12'b000001010000;//mid541:{high,med,low}=12'b000001100000;//mid642:{high,med,low}=12'b000001010000;//mid543:{high,med,low}=12'b000001000000;//mid444,45:{high,med,low}=12'b000000110000;//mid346,47:{high,med,low}=12'b000000010000;//mid148,49:{high,med,low}=12'b000000100000;//mid250,51:{high,med,low}=12'b000000000101;//low552,53,54,55:{high,med,low}=12'b000000010000;//mid156,56:{high,med,low}=12'b000000100000;//mid257,58:{high,med,low}=12'b000000000101;//low559,60,61,62,63:{high,med,low}=12'b000000010000;//mid1default : {high,med,low}=12'bx;endcaseendendmodule//bell2子模块《情歌》module bell2 (inclk,beep2);input inclk; //系统时钟output beep2; //蜂鸣器输出端reg [3:0]high,med,low;reg [15:0]origin;reg beep_r; //寄存器reg [7:0]state;reg [15:0]count;assign beep2=beep_r; //输出音乐//时钟频率6MHzreg clk_6MHz;reg [2:0]t1;always(posedge inclk)beginif(cnt1<3'd8) //8cnt1<=cnt1+3'b1;elsebegincnt1<=3'b0;clk_6MHz<=~clk_6MHz;endend//时钟频率4MHzreg clk_4Hz;reg [24:0]t2;always(posedge inclk)beginif(cnt2<25'd1*******)//13000000cnt2<=cnt2+25'b1;elsebegincnt2<=25'b0;clk_4Hz<=~clk_4Hz;endendalways (posedge clk_6MHz)begincount <= count + 1'b1; //计数器加1 if(count == origin)begincount <= 16'h0; //计数器清零beep_r <= !beep_r; //输出取反endendalways(posedge clk_4Hz)begincase({high,med,low})'b000000000001:origin=22900; //低1'b000000000010:origin=20408; //低2'b000000000011:origin=18181; //低3 'b000000000101:origin=15267; //低5'b000000000110:origin=13605; //低6 'b000000000111:origin=11472; //中1'b000000100000:origin=10216; //中2'b000000110000:origin=9101; //中3'b000001010000:origin=7653; //中5'b000001100000:origin=6818; //中6'b000100000000:origin=5733; //高1'b001000000000:origin=5108; //高2'b001100000000:origin=4551; //高3endcaseendalways (posedge clk_4Hz)beginif(state ==103)state = 0;elsestate = state + 1; //《情歌》case(state)0,1: {high,med,low}='b000000110000;//中32,3: {high,med,low}='b000001010000;//中54,5: {high,med,low}='b000001100000;//中66: {high,med,low}='b000001100000;//中67: {high,med,low}='b000001010000;//中58,9,10: {high,med,low}='b000001100000;//中611: {high,med,low}='b000000110000;//中312,13,14,15: {high,med,low}='b000000100000;//中216,17: {high,med,low}='b000000110000;//中318,19: {high,med,low}='b000001010000;//中520,21: {high,med,low}='b000001100000;//中622: {high,med,low}='b000001100000;//中623: {high,med,low}='b000001010000;//中524,25: {high,med,low}='b000001100000;//中626,27,28,29,30,31:{high,med,low}='b000000110000;//中332,33: {high,med,low}='b000000110000;//中334,35: {high,med,low}='b000001010000;//中538: {high,med,low}='b000001100000;//中6 39: {high,med,low}='b000001010000;//中5 40,41,42: {high,med,low}='b000001100000;//中6 43: {high,med,low}='b000000110000;//中3 44,45,46,47: {high,med,low}='b000000100000;//中2 48,49: {high,med,low}='b000000000101;//中5 50,51: {high,med,low}='b000000110000;//中3 52: {high,med,low}='b000000100000;//中2 53: {high,med,low}='b000000110000;//中3 54: {high,med,low}='b000000100000;//中2 55: {high,med,low}='b000000000111;//1 56,57: {high,med,low}='b000000100000;//中2 58,59,60,61,62,63:{high,med,low}='b000000000110;//低6 64,65: {high,med,low}='b000001100000;//中6 66,67,68,69,70,71:{high,med,low}='b000000100000;//中2 72,73: {high,med,low}='b000000000101;//中5 74,75,76,77,78,79:{high,med,low}='b000000110000;//中3 80: {high,med,low}='b000000100000;//中2 81: {high,med,low}='b000000000111;//1 82,83,84,85,86,87:{high,med,low}='b000001100000;//中6 88,89: {high,med,low}='b000000000101;//中592: {high,med,low}='b000000100000;//中293: {high,med,low}='b000000110000;//中394: {high,med,low}='b000000100000;//中295: {high,med,low}='b000000000111;//196,97: {high,med,low}='b000000100000;//中298,99,100,101,102,103:{high,med,low}='b000001100000;//中6 endcaseendendmodule//bell3子模块《天空之城》module bell3 (inclk,beep3);input inclk; //系统时钟output beep3; //蜂鸣器输出端reg [3:0]high,med,low;reg [15:0]origin;reg beep_r; //寄存器reg [7:0]state;reg [15:0]count;assign beep3=beep_r; //输出音乐//时钟频率6MHzreg clk_6MHz;reg [2:0]t1;always(posedge inclk)beginif(cnt1<3'd8)cnt1<=cnt1+3'b1;elsebegincnt1<=3'b0;clk_6MHz<=~clk_6MHz;endend//时钟频率4MHzreg clk_4Hz;reg [24:0]t2;always(posedge inclk)beginif(cnt2<25'd1*******)//cnt2<=cnt2+25'b1;elsebegincnt2<=25'b0;clk_4Hz<=~clk_4Hz;endendalways (posedge clk_6MHz)begincount <= count + 1'b1; //计数器加1if(count == origin)begincount <= 16'h0; //计数器清零beep_r <= !beep_r; //输出取反endendalways(posedge clk_4Hz)begincase({high,med,low})'b000000000001:origin=22900; //低1'b000000000010:origin=20408; //低2'b000000000011:origin=18181; //低3'b000000000100:origin=17142; //低4 'b000000000101:origin=15267; //低5'b000000000110:origin=13605; //低6'b000000000111:origin=12121; //低7'b000000000111:origin=11472; //中1'b000000100000:origin=10216; //中2'b000000110000:origin=9101; //中3'b000000111000:origin=8571; //中4'b000001010000:origin=7653; //中5'b000001100000:origin=6818; //中6'b000010000000:origin=6060; //中7'b000100000000:origin=5733; //高1'b001000000000:origin=5108; //高2'b001100000000:origin=4551; //高3'b001010000000:origin=4294; //高4'b010*********:origin=3826; //高5'b011000000000:origin=3409; //高6'b010*********:origin=3050; //高7endcaseendalways (posedge clk_4Hz)beginif(state ==195)state = 0;elsestate = state + 1; //kang ding qing gecase(state)0: {high,med,low}='b000001100000;//中61: {high,med,low}='b000010000000;//中72,3,4: {high,med,low}='b000100000000;//高15: {high,med,low}='b000010000000;//中76,7: {high,med,low}='b000100000000;//高18,9: {high,med,low}='b001100000000;//高310,11,12,13,14,15:{high,med,low}='b000010000000;//中7 16,17: {high,med,low}='b000000110000;//中318,19,20: {high,med,low}='b000001100000;//中621: {high,med,low}='b000001010000;//中522,23: {high,med,low}='b000001100000;//中624,25: {high,med,low}='b000000000111;//中126,27,28,29,30,31:{high,med,low}='b000001010000;//中 5 32: {high,med,low}='b000000110000;//中333: {high,med,low}='b000000110000;//中334,35,36: {high,med,low}='b000000111000;//中437: {high,med,low}='b000000110000;//中3 38: {high,med,low}='b000000111000;//中4 39,40,41: {high,med,low}='b000100000000;//高142,43,44: {high,med,low}='b000000110000;//中345,46,47: {high,med,low}='b000100000000;//高148,49,50: {high,med,low}='b000010000000;//中751,52,53: {high,med,low}='b000000111000;//中454,55,56,57,58,59,60,61:{high,med,low}='b000010000000;//中7 62: {high,med,low}='b000001100000;//中663: {high,med,low}='b000010000000;//中764,65,66: {high,med,low}='b000100000000;//高167: {high,med,low}='b010*********;//高768,69: {high,med,low}='b000100000000;//高170,71: {high,med,low}='b001100000000;//高372,73,74: {high,med,low}='b000010000000;//中775,76: {high,med,low}='b000000110000;//中377,78,79: {high,med,low}='b000001100000;//中680: {high,med,low}='b000000000101;//中581,82: {high,med,low}='b000001100000;//中683,84: {high,med,low}='b000000000111;//中185,86,87,88,89,90:{high,med,low}='b000001010000;//中 591: {high,med,low}='b000000110000;//中392: {high,med,low}='b000000110000;//中393,94: {high,med,low}='b000000111000;//中495: {high,med,low}='b000100000000;//高196,97,98: {high,med,low}='b000010000000;//中799,100: {high,med,low}='b000100000000;//高1101,102: {high,med,low}='b001000000000;//高2103: {high,med,low}='b001100000000;//高3 104,105,106,107,108,109:{high,med,low}='b000100000000;//高1 110: {high,med,low}='b000010000000;//中7111,112: {high,med,low}='b000001100000;//中6113,114: {high,med,low}='b000010000000;//中7 115,116: {high,med,low}='b000001010000;//中5117,118,119,120,121,122:{high,med,low}='b000001100000;//中6 123,124: {high,med,low}='b000000000111;//中1 125: {high,med,low}='b001000000000;//高2126,127,128: {high,med,low}='b001100000000;//高3 129: {high,med,low}='b001000000000;//高2 130,131: {high,med,low}='b001100000000;//高3132,133: {high,med,low}='b010*********;//高5 134,135,136,137,138,139:{high,med,low}='b001000000000;//高2 140,141: {high,med,low}='b000001010000;//中5 142,143,144: {high,med,low}='b000100000000;//高1145: {high,med,low}='b000010000000;//中7 146,147: {high,med,low}='b000100000000;//高1 148,149,150,151,152,153,154,155:{high,med,low}='b001100000000;//高3156,157: {high,med,low}='b000001100000;//中6 158,159: {high,med,low}='b000010000000;//中7160,161,162,163:{high,med,low}='b000100000000;//高1 164,165: {high,med,low}='b000010000000;//中7166,167: {high,med,low}='b000100000000;//高1168,169: {high,med,low}='b001000000000;//高2170,171,172: {high,med,low}='b000100000000;//高1173,174,175,176,177,178:{high,med,low}='b000001010000;//中5 179,180: {high,med,low}='b001010000000;//高4181,182: {high,med,low}='b001100000000;//高3183,184,185: {high,med,low}='b001000000000;//高2186,187: {high,med,low}='b000100000000;//高1188,189,190,191,192,193,194,195:{high,med,low}='b001100000000;//高3endcaseendendmodule。