音乐流水灯设计.docx
- 文档编号:14430056
- 上传时间:2023-06-23
- 格式:DOCX
- 页数:72
- 大小:3.16MB
音乐流水灯设计.docx
《音乐流水灯设计.docx》由会员分享,可在线阅读,更多相关《音乐流水灯设计.docx(72页珍藏版)》请在冰点文库上搜索。
音乐流水灯设计
一、绪论
1.1设计目的
EDA是电子设计自动化(ElectronicDesignAutomation)的缩写,EDA技术就是以计算机为工具,设计者在EDA软件平台上,用硬件描述语言完成设计文件,然后由计算机自动地完成逻辑编译、化简、分割、综合、优化、布局、布线和仿真,直至对于特定目标芯片的适配编译、逻辑映射和编程下载等工作。
EDA技术的出现,极大地提高了电路设计的效率和可操作性。
本课程设计通过Altera公司的QuartusII软件配合武汉凌特电子技术有限公司生产的LTE-SOPC-02FD型OPC实验开发系统来完成设计。
通过此实验让我们进一步了解,熟悉和掌握CPLD/FPGA开发软件的使用方法及VHDL的编程方法。
1.2设计内容及要求
在本课程设计中使用Altera公司的EP2C35系列的EP2C35F484C7-FPGA芯片,利用SOPC-NIOSII-EP2C35开发板上的资源,实现一个音乐流水灯。
本设计的任务要求通过编程实现一段音乐旋律的循环播放,在音乐播放的过程中,流水灯根据旋律闪烁。
扩展内容:
1利用数码管显示播放时间
2利用16*16点阵显示播放歌曲名称
3利用4×4键盘阵列键盘实现播放歌曲的切换
一、
二、设计原理及方案
2.1设计原理
音乐流水灯主要是点缀公共场合的装饰品,音乐的播放和流水灯有节奏地闪烁,同时达到听觉和视觉的完美结合,成为构成其必不可少的条件。
要了解如何产生不同音阶的音乐,首先要对乐音的特性有所了解。
乐音实际上是有固定频率的信号。
在乐曲的构成中,乐音的频率和持续的时间是其构成的要素。
音阶的各个频率可以通过高频时钟进行分频得到。
音频的高低可以通过外部的LED灯的闪烁来显示,这样在音乐和流水灯的配合下可以使人产生强烈的节奏感。
总原理框图如图2.1所示。
图2.1原理框图
2.2设计方案
总体设计流程如下:
(1)分频主要是通过一个可控分频器实现的。
要得到不同频率的方波,就可以根据此频率计算出分频过程中需要计数的点数,从而通过改变可控分频器的计数初值,在达到计数最大值后对spk端口的信号取反输出不同频率的方波。
采用时钟的频率越高,分频系数越大,分频后的音阶频率就越准确。
但同时由于分频系数大使用的计数单元增加,从而耗费更多的硬件逻辑单元,本次设计采用1MHZ的时钟信号。
音阶频率表如表1所示,各音阶计数初值表如表2所示:
音阶
频率(Hz)
音阶
频率(Hz)
低音1
262
中音2
578
低音2
294
中音3
659
低音3
330
中音5
784
低音5
392
中音6
880
低音6
440
高音1
1046
低音7
494
高音2
1175
中音1
523
高音3
1318
表1音阶频率表
音阶
计数初值
对应初始值
低音1
01100000101
773
低音2
01110010000
912
低音3
10000001100
1036
低音5
10010101101
1197
低音6
10100001010
1290
低音7
10101011100
1372
中音1
10110000010
1410
中音2
10111001000
1480
中音3
11000000110
1542
中音5
11001010110
1622
中音6
11010000100
1668
高音1
11011000000
1728
高音2
11011100011
1763
高音3
11100000010
1794
表2音阶初始值表
(2)经过分频后的信号是一个脉宽极窄的时钟信号,必须对其进行脉冲宽度调整,增大占空比,才能有效地驱动蜂鸣器。
在脉冲宽度调整时会对此信号再次二分频,所以在计算时,以乐音音阶的二倍频率去求取在特定时钟信号下的分频系数,以便在调整占空比后得到正确的音阶频率。
(3)乐曲的频率变化多端,对应的分频系数也不断变化,因此需要将播放的乐曲的分频系数事先存放在ROM中便于读取。
如果将分频系数直接作为存储码存放在寄存器中,势必会占有更大的容量。
因此在这里选取索引值来作为存储码以减小容量。
音阶索引表如表3所示:
音阶
低音1
低音2
低音3
低音5
索引值
1
2
3
5
音阶
低音6
低音7
中音1
中音2
索引值
6
7
8
9
音阶
中音3
中音5
中音6
高音1
索引值
10
12
13
15
音阶
高音2
高音3
索引值
16
17
表3音阶索引表
(4)开发平台上的LED灯数量有限,可以选用有规律的闪烁。
本次设计流水灯依次点亮的方式来闪烁。
三、设计步骤
3.1音乐流水灯模块
3.1.1基本原理
我们知道,声音的频谱范围约在几十到几千赫兹,若能利用程序来控制FPGA某个引脚输出一定频率的矩形波,接上扬声器就能发出相应频率的声音。
而乐曲中的每一音符对应着一个确定的频率,因此,要想FPGA发出不同音符的音调,实际上只要控制它输出相应音符的频率即可。
乐曲都是由一连串的音符组成,因此按照乐曲的乐谱依次输出这些音符所对应的频率,就可以在扬声器上连续地发出各个音符的音调。
而要准确地演奏出一首乐曲,仅仅让扬声器能够发声是不够的,还必须准确地控制乐曲的节奏,即每个音符的持续时间。
由此可见,乐曲中每个音符的发音频率及其持续的时间是乐曲能够连续演奏的两个基本要素,获取这两个要素所对应的数值以及利用这些数值实现所希望乐曲的演奏效果是本实验的关键。
因此要实现在蜂鸣器上播放出有一定规律节奏的简单歌曲,就需要了解各个音阶的频率,以及怎样将这些频率转换为开发系统以及蜂鸣器能够识别的代码。
在LED0~LED11引脚上按照简单音乐的节奏有规律的的输出流水数据,如原来输出的数据是000000000001则表示点亮LED1(共阴接法),流水一次后,输出的数据应该为00000000011,而此时则应点亮LED1~LED2两个发光二极管。
通过程序设置可以实现每个音阶对应一种点亮情况,从而实现音乐流水灯的律动。
3.1.2程序及电路原理图
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
--------------------------------------------------------------------
entitytbis
port(clk:
instd_logic;--ClockSignal
spk:
bufferstd_logic;--speakerdriver
led:
outstd_logic_vector(11downto0);
keyc:
outstd_logic_vector(15downto0);
keyr:
outstd_logic_vector(15downto0);
s1:
instd_logic);
endtb;
--------------------------------------------------------------------
architecturebehaveoftbis
signaltone:
std_logic_vector(10downto0);
signaltone_count:
std_logic_vector(10downto0);
signaltone_index:
integerrange0to18;
signalclk10_count:
std_logic_vector(17downto0);
signaltime:
integerrange0to200;
signalclk10:
std_logic;
begin
process(clk)
begin
if(clk'eventandclk='1')then
clk10_count<=clk10_count+1;
if(clk10_count=16#3fff#)then
clk10<=notclk10;
endif;
endif;
endprocess;
process(clk10)
begin
if(clk10'eventandclk10='1')then
if(time=200)then
time<=0;
else
time<=time+1;
endif;
endif;
endprocess;
process(clk10)
begin
if(clk10'eventandclk10='1')then
casetimeis
when0=>tone_index<=10;
when1=>tone_index<=10;
when2=>tone_index<=10;
when3=>tone_index<=9;
when4=>tone_index<=10;
when5=>tone_index<=10;
when6=>tone_index<=0;
when7=>tone_index<=0;
when8=>tone_index<=10;
when9=>tone_index<=12;
when10=>tone_index<=10;
when11=>tone_index<=9;
when12=>tone_index<=10;
when13=>tone_index<=10;
when14=>tone_index<=8;
when15=>tone_index<=8;
when16=>tone_index<=8;
when17=>tone_index<=9;
when18=>tone_index<=10;
when19=>tone_index<=12;
when20=>tone_index<=10;
when21=>tone_index<=10;
when22=>tone_index<=9;
when23=>tone_index<=9;
when24=>tone_index<=9;
when25=>tone_index<=8;
when26=>tone_index<=9;
when27=>tone_index<=9;
when28=>tone_index<=0;
when29=>tone_index<=0;
when30=>tone_index<=10;
when31=>tone_index<=10;
when32=>tone_index<=10;
when33=>tone_index<=12;
when34=>tone_index<=12;
when35=>tone_index<=10;
when36=>tone_index<=13;
when37=>tone_index<=12;
when38=>tone_index<=12;
when39=>tone_index<=13;
when40=>tone_index<=12;
when41=>tone_index<=12;
when42=>tone_index<=10;
when43=>tone_index<=12;
when44=>tone_index<=12;
when45=>tone_index<=12;
when46=>tone_index<=12;
when47=>tone_index<=12;
when48=>tone_index<=10;
when49=>tone_index<=10;
when50=>tone_index<=9;
when51=>tone_index<=10;
when52=>tone_index<=12;
when53=>tone_index<=12;
when54=>tone_index<=10;
when55=>tone_index<=9;
when56=>tone_index<=9;
when57=>tone_index<=9;
when58=>tone_index<=9;
when59=>tone_index<=8;
when60=>tone_index<=9;
when61=>tone_index<=9;
when62=>tone_index<=9;
when63=>tone_index<=10;
when64=>tone_index<=10;
when65=>tone_index<=10;
when66=>tone_index<=9;
when67=>tone_index<=10;
when68=>tone_index<=10;
when69=>tone_index<=0;
when70=>tone_index<=0;
when71=>tone_index<=10;
when72=>tone_index<=12;
when73=>tone_index<=10;
when74=>tone_index<=9;
when75=>tone_index<=10;
when76=>tone_index<=10;
when77=>tone_index<=8;
when78=>tone_index<=8;
when79=>tone_index<=8;
when80=>tone_index<=9;
when81=>tone_index<=10;
when82=>tone_index<=12;
when83=>tone_index<=10;
when84=>tone_index<=10;
when85=>tone_index<=9;
when86=>tone_index<=9;
when87=>tone_index<=9;
when88=>tone_index<=8;
when89=>tone_index<=9;
when90=>tone_index<=9;
when91=>tone_index<=0;
when92=>tone_index<=0;
when93=>tone_index<=10;
when94=>tone_index<=10;
when95=>tone_index<=10;
when96=>tone_index<=12;
when97=>tone_index<=10;
when98=>tone_index<=13;
when99=>tone_index<=12;
when100=>tone_index<=12;
when101=>tone_index<=13;
when102=>tone_index<=12;
when103=>tone_index<=12;
when104=>tone_index<=10;
when105=>tone_index<=12;
when106=>tone_index<=12;
when107=>tone_index<=12;
when108=>tone_index<=10;
when109=>tone_index<=10;
when110=>tone_index<=9;
when111=>tone_index<=10;
when112=>tone_index<=12;
when113=>tone_index<=10;
when114=>tone_index<=9;
when115=>tone_index<=9;
when116=>tone_index<=8;
when117=>tone_index<=8;
when118=>tone_index<=8;
when119=>tone_index<=8;
when120=>tone_index<=8;
when121=>tone_index<=0;
when122=>tone_index<=0;
when123=>tone_index<=0;
when124=>tone_index<=8;
when125=>tone_index<=9;
when126=>tone_index<=10;
when127=>tone_index<=10;
when128=>tone_index<=10;
when129=>tone_index<=12;
when130=>tone_index<=13;
when131=>tone_index<=13;
when132=>tone_index<=13;
when133=>tone_index<=17;
when134=>tone_index<=16;
when135=>tone_index<=15;
when136=>tone_index<=15;
when137=>tone_index<=13;
when138=>tone_index<=12;
when139=>tone_index<=12;
when140=>tone_index<=13;
when141=>tone_index<=12;
when142=>tone_index<=10;
when143=>tone_index<=9;
when144=>tone_index<=8;
when145=>tone_index<=8;
when146=>tone_index<=6;
when147=>tone_index<=8;
when148=>tone_index<=9;
when149=>tone_index<=9;
when150=>tone_index<=9;
when151=>tone_index<=8;
when152=>tone_index<=9;
when153=>tone_index<=9;
when154=>tone_index<=8;
when155=>tone_index<=9;
when156=>tone_index<=10;
when157=>tone_index<=10;
when158=>tone_index<=10;
when159=>tone_index<=12;
when160=>tone_index<=13;
when161=>tone_index<=13;
when162=>tone_index<=13;
when163=>tone_index<=17;
when164=>tone_index<=16;
when165=>tone_index<=15;
when166=>tone_index<=15;
when167=>tone_index<=16;
when168=>tone_index<=15;
when169=>tone_index<=15;
when170=>tone_index<=15;
when171=>tone_index<=12;
when172=>tone_index<=12;
when173=>tone_index<=12;
when174=>tone_index<=10;
when175=>tone_index<=14;
when176=>tone_index<=15;
when177=>tone_index<=8;
when178=>tone_index<=9;
when179=>tone_index<=10;
when180=>tone_index<=10;
when181=>tone_index<=9;
when182=>tone_index<=9;
when183=>tone_index<=8;
when184=>tone_index<=8;
when185=>tone_index<=8;
when186=>tone_index<=8;
whenothers=>tone_index<=0;
endcase;
endif;
endprocess;
process(tone_index)
begin
casetone_indexis
when0=>tone<="11111111111";--可变的计数初值
when1=>tone<="01100000101";--773(歌曲一未使用)
when2=>tone<="01110010000";--912(歌曲一未使用)
when3=>tone<="10000001100";--1036(歌曲一未使用)
when5=>tone<="10010101101";--1197(歌曲一未使用)
when6=>tone<="10100001010";--1290(歌曲一未使用)
when7=>tone<="10101011100";--1372(歌曲一未使用)
when8=>tone<="10110000010";--1410
when9=>tone<="10111001000";--1480
when10=>tone<="11000000110";--1542
when12=>tone<="11001010110";--1622
when13=>tone<="11010000100";--1668
when15=>tone<="11011000000";--1728
when16=>tone<="11011100011";--1763
when17=>tone<="11100000010";--1794
whenothers=>tone<="11111111111";--others:
nooutput
endcase;
endprocess;
process(clk)--controlthefrequenceofthespeaker
begin
if(clk'eventandclk='1')then
if(tone_count=16#7ff#)then
tone_count<=tone;
if(tone<2047)then
spk<=notspk;
endif;
else
tone_count<=tone_count+1;
end
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 音乐 流水 设计
![提示](https://static.bingdoc.com/images/bang_tan.gif)