VHDL电子琴实验报告Word文档下载推荐.docx
《VHDL电子琴实验报告Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《VHDL电子琴实验报告Word文档下载推荐.docx(20页珍藏版)》请在冰点文库上搜索。
由于按键数目有限,只能弹出中音。
index_key[4..0]低三位表示音调,001表示do,010表示re,以此类推,000表示不发音。
自动演奏模块autoplay:
把1024Hz的输入时钟分频为16Hz,作为节拍。
将要自动演奏的歌曲预先写为index_auto的格式(index_auto格式与index_key格式相同)。
以16Hz的频率将index_auto输出。
查表及显示模块table:
(1)输入按键button用于选择模式。
由于是琴键式,不能根据button本身的值来选择模式。
故加一个内部信号choice,button每来一个上升沿,choice翻转一次。
Choice为1则把index_auto赋给内部信号index,否则把index_key赋给它。
(2)用index来查表,获得分频系数tone,输出。
(3)同时根据index获得BCD码表示的高、中、低音的音调,输出给数码管。
分频模块fenpin:
输入分频系数tone。
(1)设置内部信号i用于计数,clk_data作为分频结果。
每次clk上升沿检测i是否等于tone,相等则把i清零,并使clk_data翻转,否则i自增1。
(2)把clk_data赋给输出信号buzz,由buzz驱动扬声器发声。
设计框图:
3系统以及模块硬件电路设计
试验箱使用的是模式3的电路结构。
1.按键PIO7是模式选择按键button,每按下一次改变一次模式
2.按键PIO6-0用于弹奏,在弹奏模式下,被按下时分别发出中音Do,Re,Mi,Fa,Sol,La,Ti。
3.Clk0用于分频以供扬声器发声
4.Clk5用于控制自动演奏节拍
5.三个数码管用于显示高、中、低音音调
下载时选择的开发系统模式以及管脚定义
表1GW48-CK开发系统工作模式:
接口
名称
类型
(输入/输出)
结构图上
的信号名
引脚号
说明
clk
INPUT
CLK0
2
供分频发声
Clk2
CLK5
83
供分频获得节拍
Key
PIO6-0
11-5
按键弹奏
Button
PIO7
16
模式选择
Code0top
OUTPUT
PIO19-16
30-27
低音显示
Code1top
PIO23-20
38-35
中音显示
Code2top
PIO27-24
49-47,39
高音显示
Spkout
SPEAKER
3
发声
4系统的VHDL设计
顶层程序:
top.vhd
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
entitytopis
port(clk:
instd_logic;
clk2:
key:
instd_logic_vector(6downto0);
button:
spkout:
outstd_logic;
code0top:
outstd_logic_vector(3downto0);
code1top:
code2top:
outstd_logic_vector(3downto0));
endtop;
architecturebehaveoftopis
componentautoplay
port(clk2:
instd_logic;
index_auto:
outstd_logic_vector(4downto0));
endcomponent;
componentfenpin
port(clk:
tone:
inintegerrange0to8190;
buzz:
outstd_logic);
componenttable
port(index_auto:
instd_logic_vector(4downto0);
index_key:
button:
outintegerrange0to8190;
code0:
code1:
code2:
outstd_logic_vector(3downto0)
);
componentkeyplay
port(key:
outstd_logic_vector(4downto0)
signalindex_auto_top:
std_logic_vector(4downto0);
signalindex_key_top:
signaltone_top:
integerrange0to8190;
begin
u1:
autoplayportmap(clk2=>
clk2,index_auto=>
index_auto_top);
u2:
fenpinportmap(clk=>
clk,tone=>
tone_top,buzz=>
spkout);
u3:
tableportmap(index_auto=>
index_auto_top,index_key=>
index_key_top,tone=>
tone_top,button=>
button,code0=>
code0top,code1=>
code1top,code2=>
code2top);
u4:
keyplayportmap(key=>
key,index_key=>
index_key_top);
endbehave;
按键弹奏模块:
keyplay.vhd
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith;
useieee.std_logic_unsigned.all;
entitykeyplayis
end;
architecturebehaveofkeyplayis
begin
process(key)
begin
casekeyis
when"
"
=>
index_key<
="
01001"
;
--按键从右到左依次表示do,re,mi,fa,sol,la,ti
01010"
01011"
01100"
01101"
01110"
01111"
whenothers=>
00000"
endcase;
endprocess;
自动演奏模块:
autoplay.vhd
entityautoplayis
port(clk2:
architecturebehaveofautoplayis
signalcount:
integerrange0to136;
--可根据乐曲长度改变
signaljiepai:
std_logic;
signalj:
integerrange0to60;
jiepai1:
process(clk2)--分频产生16Hz的节拍
ifclk2'
eventandclk2='
1'
then
ifj=30then
j<
=0;
jiepai<
=notjiepai;
else
=j+1;
endif;
endprocessjiepai1;
--jiepai<
=clk2;
process(jiepai)
ifjiepai'
eventandjiepai='
ifcount=136thencount<
=0;
elsecount<
=count+1;
endif;
endprocess;
music:
process(count)--歌曲jinglebells
casecountis--此case语句:
存储自动演奏部分的曲谱
when0=>
index_auto<
--3第一小节
when1=>
--3
when2=>
when3=>
--0
when4=>
when5=>
when6=>
when7=>
when8=>
when9=>
when10=>
index_auto<
when11=>
when12=>
when13=>
when14=>
when15=>
when16=>
when17=>
when18=>
when19=>
when20=>
when21=>
when22=>
when23=>
when24=>
when25=>
when26=>
when27=>
when28=>
when29=>
when30=>
when31=>
when32=>
when33=>
when34=>
when35=>
--3--第二小节
when36=>
when37=>
when38=>
when39=>
--5
when40=>
when41=>
when42=>
when43=>
--1
when44=>
when45=>
when46=>
when47=>
when48=>
--2
when49=>
when50=>
when51=>
when52=>
when53=>
when54=>
when55=>
when56=>
when57=>
when58=>
when59=>
when60=>
when61=>
when62=>
when63=>
when64=>
when65=>
when66=>
when67=>
when68=>
when69=>
when70=>
--4--第三小节
when71=>
--4
when72=>
when73=>
when74=>
when75=>
when76=>
when77=>
when78=>
when79=>
when80=>
when81=>
when82=>
when83=>
when84=>
when85=>
when86=>
when87=>
when88=>
when89=>
when90=>
when91=>
when92=>
when93=>
when94=>
when95=>
when96=>
when97=>
when98=>
when99=>
when100=>
when101=>
when102=>
--5第四小节
when103=>
when104=>
when105=>
when106=>
when107=>
when108=>
when109=>
when110=>
when111=>
when112=>
when113=>
when114=>
when115=>
when116=>
when117=>
when118=>
when119=>
when120=>
when121=>
when122=>
when123=>
when124=>
when125=>
when126=>
when127=>
when128=>
when129=>
when130=>
when131=>
when132=>