FPGA硬件电子琴.docx
- 文档编号:7141340
- 上传时间:2023-01-21
- 格式:DOCX
- 页数:13
- 大小:95.90KB
FPGA硬件电子琴.docx
《FPGA硬件电子琴.docx》由会员分享,可在线阅读,更多相关《FPGA硬件电子琴.docx(13页珍藏版)》请在冰豆网上搜索。
FPGA硬件电子琴
课程设计报告
(电子设计自动化)
题目
硬件电子琴
学院
信息科学与工程学院
专业
电子科学与技术
班级
08级2班
姓名
闫志伟洪丁达
指导教师
吴丽丽
2010
年
6
月
25
日
电子琴的设计
摘要:
用可编程逻辑器件(PLD)来完成该设计。
核心是一数控分频器,对输入的脉冲进行分频,得到每个音阶对应的频率,由此实现简易电子琴的发音功能。
电子琴可演奏由键盘输入的音阶,同时在数码管上显示对应音节的频率。
本设计基于超高速硬件描述语言VHDL在Altera公司的CycloneⅡ系列的EP2C5T144C8芯片上编程实现;经仿真,硬件测试和调试基本能够达到技术指标,实验结果和仿真结果基本一致。
关键词:
PLD,VHDL,数控分频,电子琴
TheDesignofElectricalOrgan
Abstract:
ThedesignisaccomplishedwithProgrammable-Logic-Device(PLD).Thecoreofitisanumericalcontrolfrequencydivider,whichcandividetheinputpulseintothecorrespondingfrequencytothemusicalscale,sothatitcanachievethesoundingfunctionofsimpleelectronicorgan.Theorgancanplaythemusicalscaleputinwithakeyboard.ThedesignisprogrammedwithVHDLandrealizedinthechipofEP2C5T144C8CycloneⅡseries.Itcanbasicallyreachthetechniqueindexaftersimulating,hardwaredebugging.Theexperimentresultisconsonantwiththesimulatingresult.
Keywords:
PLD,VHDL,numericalcontrolfrequencydivider,electricalorgan
一系统设计
1、设计要求
8个音阶,外部时钟信号12MHz;能同步显示音阶频率。
2设计思路
通过可编程逻辑器件(PLD)和VHDL硬件描述语言来实现电子琴的基本要求。
设计的主体是数控分频器,对输入的频率按照与每个音阶对应的分频系数进行分频,得到各个音阶对应的频率分别在蜂鸣器和数码管上以声音和频率数值的形式作为输出。
3、系统组成及工作原理
图1-2-3-1为系统的工作原理框图。
根据设计要求,提供的外部时钟信号为12MHz,所以在本设计中需要将其进行分频,以得到所需要的脉冲。
键盘编码器的作用是对键盘按键输入的信号进行检测,并且产生相应的分频系数。
音调发生器的主要部分是一个数控分频器,它由一个初值可预置的加法计数器构成,详细工作原理将在后文做介绍,当它接收到一个分频信号时,便对端口的12MHz的输入时钟信号进行分频,之后由扬声器输出对应的声调。
频率计的作用是将各个音阶对应的分频之后的频率通过数码管显示出来。
分频置数
按
键
分
频
器
12MHZ
蜂鸣器
4位测频器
数码管显示
图1-2-3-1工作原理框图
二单元电路设计
1、顶层模块的设计
VHDL采用的是自顶向下的设计方式,顶层模块由音调发生器(tonetaba)、数控分频器(speaker)和频率计(top)三个模块组成。
图2-1-1即是顶层设计原理图。
由键盘输入的信号,进行编码,输出的都是八位二进制数,对应音调发生器的输入。
图2-1-1顶层设计原理图
2、音调发生器模块(tonetaba)的设计
音调发生器的作用是产生获得音阶的分频预置值。
当8位发声控制输入index中的某一位为高电平时,则对应某一音阶的数值将以端口tone输出,作为获得该音阶的分频预置值,该值作为数控分频器的输入,来对12MHz的脉冲进行分频,由此得到每个音阶相应的频率,例如输入index="00000010",即对应的按键是2,产生的分频系数便是1702;同时由high1输出对应该音阶低音显示。
各音阶所对应的频率:
低音1
低音2
低音3
低音4
低音5
低音6
低音7
440Hz
高音1
高音2
高音3
高音4
高音5
高音6
高音7
1760Hz
分频系数的计算:
低音1的频率为,
则分频系数=
=1911,同理可求其他频率的分频系数。
创新点:
利用按键8来区别高低音,当按键8为高电平时,按键1到7分别表示高音的1到7。
当按键8为低时,按键1到7为低音的1到7
when"00000001"=>tone<="";high1<='0';--1911
when"00000010"=>tone<="";high1<='0';--1702
when"00000100"=>tone<="";high1<='0';--1517
when"00001000"=>tone<="";high1<='0';--1432
when"00010000"=>tone<="";high1<='0';--1275;
when"00100000"=>tone<="";high1<='0';--1136
when"01000000"=>tone<="000";high1<='0';--1012
when""=>tone<="000";high1<='1';--478
when""=>tone<="001";high1<='1';--426
when""=>tone<="001";high1<='1';--379
when""=>tone<="001";high1<='1';--358
when""=>tone<="000";high1<='1';--319
when""=>tone<="000";high1<='1';--284
when""=>tone<="000";high1<='1';--253
whenothers=>null;
3、数控分频模块(speaker)的设计
数控分频模块的目的是对基准脉冲分频,得到1,2,3,4,5,6,7七个音符对应频率。
该模块的VHDL描述中包含了三个进程。
首先对12MHz的基准脉冲进行12分频得到1MHz的脉冲,然后按照tone输入的分频系数对1MHz的脉冲再次分频,得到的便是所需要的频率。
而第三个进程的作用是在音调输出时再进行二分频,将脉冲展宽,以使扬声器有足够功率发音。
十二分频:
divideclk:
process(clk)
variablecount4:
std_logic_vector(3downto0);
begin
preclk<='0';
ifcount4>11thenpreclk<='1';count4:
="0000";
elsifclk'eventandclk='1'thencount4:
=count4+1;
endif;
endprocess;
按分频系数进行分频:
genspks:
process(preclk,tone)
variablecount11:
std_logic_vector(10downto0);
begin
ifpreclk'eventandpreclk='1'thencount11:
=count11+1;fullspks<='0';
ifcount11=tonethenfullspks<='1';count11:
="00000000000";
endif;
endif;
endprocess;
二分频使输出有足够大的功率发声:
delayspks:
process(fullspks)
variablecount2:
std_logic;
begin
iffullspks'eventandfullspks='1'thencount2:
=notcount2;
ifcount2='1'thenspks<='1';
elsespks<='0';
endif;
endif;
endprocess;
4、测频计模块(top)的设计
频率计的作用是将各个音阶对应的分频之后的频率通过数码管显示出来。
其外加测频控制信号(clk)为1Hz的标准时钟脉冲,基本构成为4个十进制加计数器和锁存器。
测频结果即为各个音阶对应的频率,由数码管同步显示。
三波形仿真
1.音调发生模块tonetaba的波形仿真图:
仿真图形如上,按键由1依次按到7,按键8为0,tone依次输出低音1到7的分频系数,high1输出为0,表示此时输出为低音。
波形仿真图符合设计,说明设计正确。
2.数控分频仿真波形:
由于spks的频率相较于时钟频率12MHz差别较大,因而未能在图上看到spks的波形变化。
四系统测试
1、测试使用的仪器
Altera公司的CycloneⅡ系列的EP2C5T144C8芯片
康芯教学实验箱
2、测试方法
选择模式5,,数控分频的基准频率用clk0的12MHz输入,4位测频器的输入频率用clk2的1Hz输入。
分配好引脚后,将程序烧到板上,依次按下按键,蜂鸣器发出相应声音,同时数码管显示该音阶对应的频率。
3、指标测试和测试结果
每个音阶对应着不同的频率。
频率的大小直接影响着音调的高低以及失真度。
表4-3-1频率测试
音阶
1
2
3
4
5
6
7
频率(Hz)
高
1048
1175
1322
1397
1562
1765
1980
低
263
294
331
352
392
443
495
测试结果可以看出,得到的频率和分频结果基本一致,发音情况良好,音调准确。
五结束语
本设计利用超高速硬件描述语言VHDL实现了电子琴键盘输入发音的简易功能的设计,经过编程,综合,仿真,下载,芯片烧制,最终做出成品,测试情况良好,能够准确实现音阶的发音功能。
六参考文献
1潘松.黄继业.EDA技术与VHDL(第2版).北京:
清华大学出版社2009.
2网上相关资料.
七附录
程序清单
1.8音阶硬件电子琴顶层文件:
libraryieee;
usemusicis
port(fclk1,fclk12:
instd_logic;
o_high:
outstd_logic;
o_dout:
bufferstd_logic;
fdin:
instd_logic_vector(7downto0);
fout:
outstd_logic_vector(15downto0));
end;
architectureoneofmusicis
componentspeaker
port(clk:
instd_logic;
tone:
instd_logic_vector(10downto0);
spks:
outstd_logic);
endcomponent;
componenttonetaba
port(index:
instd_logic_vector(7downto0);
high1:
outstd_logic;--gaoyin
tone:
outstd_logic_vector(10downto0));
endcomponent;
componentcnt10
port(clk1,rst,en:
instd_logic;
cq:
outstd_logic_vector(3downto0);
cout:
outstd_logic);
endcomponent;
componenttestctl
PORT(CLK:
INSTD_LOGIC;--1Hz
CNT_EN,RST_CNT,LOAD:
OUTSTD_LOGIC);
ENDcomponent;
componentreg16
port(load:
instd_logic;
din:
instd_logic_vector(15downto0);
dout:
outstd_logic_vector(15downto0));
endcomponent;
signaltone1:
std_logic_vector(10downto0);
signalen1,rst1,ld,d1,d2,d3:
std_logic;
signalfd:
std_logic_vector(15downto0);
begin
u1:
tonetabaportmap(index=>fdin,tone=>tone1,high1=>o_high);
u2:
speakerportmap(clk=>fclk12,tone=>tone1,spks=>o_dout);
u3:
testctlportmap(clk=>fclk1,cnt_en=>en1,rst_cnt=>rst1,load=>ld);
u4:
cnt10portmap(clk1=>o_dout,en=>en1,rst=>rst1,cq=>fd(3downto0),cout=>d1);
u5:
cnt10portmap(clk1=>d1,en=>en1,rst=>rst1,cq=>fd(7downto4),cout=>d2);
u6:
cnt10portmap(clk1=>d2,en=>en1,rst=>rst1,cq=>fd(11downto8),cout=>d3);
u7:
cnt10portmap(clk1=>d3,en=>en1,rst=>rst1,cq=>fd(15downto12));
u8:
reg16portmap(load=>ld,din=>fd,dout=>fout);
end;
2.音调发生模块程序:
libraryieee;
usetonetabais
port(index:
instd_logic_vector(7downto0);
high1:
outstd_logic;--gaoyin
tone:
outstd_logic_vector(10downto0));
end;
architectureoneoftonetabais
begin
search:
process(index)
begin
caseindexis
when"00000001"=>tone<="";high1<='0';--1911
when"00000010"=>tone<="";high1<='0';--1702
when"00000100"=>tone<="";high1<='0';--1517
when"00001000"=>tone<="";high1<='0';--1432
when"00010000"=>tone<="";high1<='0';--1275;
when"00100000"=>tone<="";high1<='0';--1136
when"01000000"=>tone<="000";high1<='0';--1012
when""=>tone<="000";high1<='1';--478
when""=>tone<="001";high1<='1';--426
when""=>tone<="001";high1<='1';--379
when""=>tone<="001";high1<='1';--358
when""=>tone<="000";high1<='1';--319
when""=>tone<="000";high1<='1';--284
when""=>tone<="000";high1<='1';--253
whenothers=>null;
endcase;
endprocess;
end;
3.分频模块:
libraryieee;
usespeakeris
port(clk:
instd_logic;
tone:
instd_logic_vector(10downto0);
spks:
outstd_logic);
end;
architectureoneofspeakeris
signalfullspks:
std_logic;
signalpreclk:
std_logic;
begin
divideclk:
process(clk)
variablecount4:
std_logic_vector(3downto0);
begin
preclk<='0';
ifcount4>11thenpreclk<='1';count4:
="0000";
elsifclk'eventandclk='1'thencount4:
=count4+1;
endif;
endprocess;
genspks:
process(preclk,tone)
variablecount11:
std_logic_vector(10downto0);
begin
ifpreclk'eventandpreclk='1'thencount11:
=count11+1;fullspks<='0';
ifcount11=tonethenfullspks<='1';count11:
="00000000000";
endif;
endif;
endprocess;
delayspks:
process(fullspks)
variablecount2:
std_logic;
begin
iffullspks'eventandfullspks='1'thencount2:
=notcount2;
ifcount2='1'thenspks<='1';
elsespks<='0';
endif;
endif;
endprocess;end;
3.4位测频器:
(1)十进制加法器:
libraryieee;
usecnt10is
port(clk1,rst,en:
instd_logic;
cq:
outstd_logic_vector(3downto0);
cout:
outstd_logic);
endcnt10;
architecturebehavofcnt10is
begin
process(clk1,rst,en)
variablecqi:
std_logic_vector(3downto0);
begin
ifrst='1'thencqi:
=(others=>'0');
elsifclk1'eventandclk1='1'then
ifen='1'then
ifcqi<10thencqi:
=cqi+1;
ifcqi=10thencout<='1';cqi:
=(others=>'0');
elsecout<='0';
endif;endif;endif;
endif;
cq<=cqi;
endprocess;
endbehav;
(2)测频控制器:
LIBRARYIEEE;
USETESTCTLIS
PORT(CLK:
INSTD_LOGIC;--1Hz
CNT_EN,RST_CNT,LOAD:
OUTSTD_LOGIC);
ENDTESTCTL;
ARCHITECTUREbehavOFTESTCTLIS
SIGNALDIV2CLK:
STD_LOGIC;
BEGIN
PROCESS(CLK)
BEGIN
IFCLK'EVENTANDCLK='1'THENDIV2CLK<=NOTDIV2CLK;
ENDIF;
ENDPROCESS;
PROCESS(CLK,DIV2CLK)
BEGIN
IFCLK='0'ANDDiv2CLK='0'--zhihouqing0
THENRST_CNT<='1';
ELSERST_CNT<='0';
ENDIF;
ENDPROCESS;
LOAD<=NOTDIV2CLK;CNT_EN<=DIV2CLK;
ENDbehav;
(3)锁存器:
libraryieee;
useREG16is
port(load:
instd_logic;
din:
instd_logic_vector(15downto0);
dout:
outstd_logic_vector(15downto0));
endREG16;
architecturebehavofREG16is
begin
process(load,din)
begin
ifload'eventandload='1'
thendout<=din;
endif;
endprocess;
endbehav;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- FPGA 硬件 电子琴