EDA实验报告音阶发生器.docx
《EDA实验报告音阶发生器.docx》由会员分享,可在线阅读,更多相关《EDA实验报告音阶发生器.docx(14页珍藏版)》请在冰豆网上搜索。
![EDA实验报告音阶发生器.docx](https://file1.bdocx.com/fileroot1/2023-1/10/6c323e03-e648-471a-aee2-ed3ba6231451/6c323e03-e648-471a-aee2-ed3ba62314511.gif)
EDA实验报告音阶发生器
EDA实验报告
——音阶发生器
5110309343
李翼泽
2013.4.18
EDA实验报告
——音阶发生器
一、实验目的
1.了解音阶发生的原理,学会用硬件描述语言来建立音阶发生器模块。
2.利用该软件进行可编程逻辑器件设计,完成音节发生器的逻辑仿真功能。
3.使用编译器将设计实现,下载到JDEE—10实验箱上进行调试和验证所设计的音阶发生器的功能。
二、实验器材
1.Pentium—Ⅲ计算机一台;
2.JDEE—10实验箱一只;
三、实验要求
利用实验板构成一个音阶发生器,要求能产生音名A到G之间的音阶,以一秒一个音阶的速度自动演奏,并可随时手控停在某个音阶上。
为了知道音名,要求能以简谱方式显示之。
音名与频率的关系:
音乐上的十二平均律规定:
每两个八度音之间的频率相差一倍。
在这两个八度音之间,分成十二个半音,每两个相领半音的频率比为
。
另外还规定,音名A的频率为440Hz。
音名B到C之间、E到F之间为半音,其余为全音。
这样,可计算得从A(简谱的低音6)到al(简谱的高音6)之间的每个音名的频率为:
A:
440Hza:
880Hzal:
1760Hz
B:
493.88Hzb:
987.76Hz
C:
523.25Hzc:
1046.50Hz
D:
587.33Hzd:
1174.66Hz
E:
659.25Hze:
1318.51Hz
F:
698.46Hzf:
1396.92Hz
G:
783.99Hzg:
1567.98Hz
四、方案设计
由高频信号经过分频得到低频,采取以下思路:
采用4M时钟频率,根据各个音阶与4M的比例来设计不同进制的分频比的计数器,采用4M作为输入,可以得到相应频率的音阶。
另,可以看出每差七个音名其频率降低一半,那么可以通过设计二分频计数器来减少分频计数器的设计工作量。
又由于各音阶频率较高,因此需要加入T触发器。
下面给出al音阶的频率发生器设计程序以及二分频器的设计程序。
1)al音阶频率发生器设计
subdesignfreqal
(clk:
input;
freqal:
output;
)
variable
count[20..0]:
dff;
begin
defaults
freqal=gnd;
enddefaults;
count[].clk=clk;
ifcount[]==h"94F"thenfreqal=vcc;count[].d=h"0";
elsecount[].d=count[].q+1;
endif;
end;
2)二分频器设计
subdesignfreqaal
(clk:
input;
freqaal:
output;
)
variable
count[20..0]:
dff;
begin
defaults
freqaal=gnd;
enddefaults;
count[].clk=clk;
ifcount[]==h"1"thenfreqaal=vcc;count[].d=h"0";
elsecount[].d=count[].q+1;
endif;
end;
类比可以做出其余音阶的频率发生器并通过与二分频器相连接可以得到全部15个音阶。
下面设计不同音阶按照预定顺序输出的模块。
可以预先设定顺序,并且根据预先设定的顺序对不同频率进行选通,并且设置CLK输入来控制音阶播放的速度。
下面给出该模块的设计程序:
subdesignbaise
(alow,ahigh,a1,blow,bhigh,clow,chigh,dlow,dhigh,elow,ehigh,flow,fhigh,glow,ghigh:
input;
clk:
input;
spk:
output;)
variable
count[4..0]:
dff;
begin
count[].clk=clk;
ifcount[]==h"0"thenspk=alow;endif;
ifcount[]==h"1"thenspk=blow;endif;
ifcount[]==h"2"thenspk=clow;endif;
ifcount[]==h"3"thenspk=dlow;endif;
ifcount[]==h"4"thenspk=elow;endif;
ifcount[]==h"5"thenspk=flow;endif;
ifcount[]==h"6"thenspk=glow;endif;
ifcount[]==h"7"thenspk=ahigh;endif;
ifcount[]==h"8"thenspk=bhigh;endif;
ifcount[]==h"9"thenspk=chigh;endif;
ifcount[]==h"a"thenspk=dhigh;endif;
ifcount[]==h"b"thenspk=ehigh;endif;
ifcount[]==h"c"thenspk=fhigh;endif;
ifcount[]==h"d"thenspk=ghigh;endif;
ifcount[]==h"e"thenspk=a1;count[].d=h"0";
elsecount[].d=count[].q+1;
endif;
end;
因为这个模块是通过CLK来驱动的,因此可以再在发生CLK的计数器上设置COUNTENALE来控制CLK,从而控制音阶播放的暂停。
因为要求使用按键来控制,那么需要设计消除抖动电路以及TOGGLE模块。
D触发器可以实现按键消除抖动,消除抖动的电路设计如下:
通过这个电路可以消除微动开关的抖动,又因为需要按动微动开关后,音阶播放暂停,再按动微动开关后音阶播放继续,因此需要设计具有TOGGLE功能的模块,设置初始输出值为1。
Toggle功能可以通过一个D触发器将其输出反向后接在输入端,将其输出反向后接在计数器的en端,即可实现按键控停。
接下来是数码管显示简谱,此时可以在选通音阶的模块的基础上加入对数码管的控制,来使输出的音阶和简谱名同步。
A、a、al——6B、b——7
C、c——1D、d——2
E、e——3F、f——4
G、g——5空音——0
下面给出该模块的源程序:
subdesign7segement
(alow,ahigh,al,blow,bhigh,clow,chigh,dlow,dhigh,
elow,ehigh,flow,fhigh,glow,ghigh:
input;
clk:
input;
spk:
output;
seg[7..0]:
output;
)
variable
count[5..0]:
dff;
begin
defaults
seg[7..0]=VCC;
enddefaults;
count[].clk=clk;
ifcount[]==h"00"thenspk=alow;seg[]=h"41";endif;
ifcount[]==h"01"thenspk=blow;seg[]=h"1f";endif;
ifcount[]==h"02"thenspk=clow;seg[]=h"9f";endif;
ifcount[]==h"03"thenspk=dlow;seg[]=h"25";endif;
ifcount[]==h"04"thenspk=elow;seg[]=h"0d";endif;
ifcount[]==h"05"thenspk=flow;seg[]=h"99";endif;
ifcount[]==h"06"thenspk=glow;seg[]=h"49";endif;
ifcount[]==h"07"thenspk=ahigh;seg[]=h"41";endif;
ifcount[]==h"08"thenspk=bhigh;seg[]=h"1f";endif;
ifcount[]==h"09"thenspk=chigh;seg[]=h"9f";endif;
ifcount[]==h"0a"thenspk=dhigh;seg[]=h"25";endif;
ifcount[]==h"0b"thenspk=ehigh;seg[]=h"0d";endif;
ifcount[]==h"0c"thenspk=fhigh;seg[]=h"99";endif;
ifcount[]==h"0d"thenspk=ghigh;seg[]=h"49";endif;
ifcount[]==h"0e"thenspk=al;seg[]=h"41";endif;
ifcount[]==h"0f"thenspk=GND;
seg[]=h"03";count[].d=h"0";
elsecount[].d=count[].q+1;endif;
end;
至此,基础部分的要求已经全部完成。
下面进入拓展部分的设计。
2.拓展部分
乐曲播放,只需要根据乐曲的乐谱以及不同的时长来选通各个音阶即可。
本次试验我以《喀秋莎》作为示例音乐。
以下是《喀秋莎》的简谱:
本音乐1秒作为一个节拍,空音通过使输出为GND实现。
在点阵上显示音阶名A、B、C、D、E、F、G、a、b、c、d、e、f、g、al以及0。
因此可以在选通模块加入对点阵的控制信号输出,再经过一个译码模块来将对应音阶显示在点阵当中。
下面给出《喀秋莎》的选通模块的设计程序以及点阵译码模块的设计程序。
1)《喀秋莎》选通模块程序:
subdesign7segement1
(alow,ahigh,al,blow,bhigh,clow,chigh,dlow,dhigh,
elow,ehigh,flow,fhigh,glow,ghigh:
input;
clk:
input;
spk:
output;
seg[7..0]:
output;
dz[3..0]:
output;
)
variable
count[5..0]:
dff;
begin
defaults
seg[7..0]=VCC;
dz[3..0]=VCC;
enddefaults;
count[].clk=clk;
ifcount[]==h"00"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"01"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"02"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"03"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"04"thenspk=chigh;seg[]=h"9f";dz[]=h"6";endif;
ifcount[]==h"05"thenspk=chigh;seg[]=h"9f";dz[]=h"6";endif;
ifcount[]==h"06"thenspk=chigh;seg[]=h"9f";dz[]=h"6";endif;
ifcount[]==h"07"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"08"thenspk=chigh;seg[]=h"9f";dz[]=h"6";endif;
ifcount[]==h"09"thenspk=chigh;seg[]=h"9f";dz[]=h"6";endif;
ifcount[]==h"0a"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"0b"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"0c"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"0d"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"0e"thenspk=elow;seg[]=h"0D";dz[]=h"9";endif;
ifcount[]==h"0f"thenspk=gnd;seg[]=h"03";dz[]=h"f";endif;
ifcount[]==h"010"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"011"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"012"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"013"thenspk=chigh;seg[]=h"9f";dz[]=h"6";endif;
ifcount[]==h"014"thenspk=dhigh;seg[]=h"25";dz[]=h"8";endif;
ifcount[]==h"015"thenspk=dhigh;seg[]=h"25";dz[]=h"8";endif;
ifcount[]==h"016"thenspk=dhigh;seg[]=h"25";dz[]=h"8";endif;
ifcount[]==h"017"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"018"thenspk=dhigh;seg[]=h"25";dz[]=h"8";endif;
ifcount[]==h"019"thenspk=dhigh;seg[]=h"25";dz[]=h"8";endif;
ifcount[]==h"01a"thenspk=chigh;seg[]=h"9f";dz[]=h"6";endif;
ifcount[]==h"01b"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"01c"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"01d"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"01e"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"01f"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"20"thenspk=ehigh;seg[]=h"0D";dz[]=h"a";endif;
ifcount[]==h"21"thenspk=ehigh;seg[]=h"0d";dz[]=h"a";endif;
ifcount[]==h"22"thenspk=al;seg[]=h"41";dz[]=h"2";endif;
ifcount[]==h"23"thenspk=al;seg[]=h"41";dz[]=h"2";endif;
ifcount[]==h"24"thenspk=ghigh;seg[]=h"49";dz[]=h"e";endif;
ifcount[]==h"25"thenspk=ghigh;seg[]=h"49";dz[]=h"e";endif;
ifcount[]==h"26"thenspk=al;seg[]=h"41";dz[]=h"2";endif;
ifcount[]==h"27"thenspk=ghigh;seg[]=h"49";dz[]=h"e";endif;
ifcount[]==h"28"thenspk=fhigh;seg[]=h"99";dz[]=h"c";endif;
ifcount[]==h"29"thenspk=fhigh;seg[]=h"99";dz[]=h"c";endif;
ifcount[]==h"2a"thenspk=ehigh;seg[]=h"0d";dz[]=h"a";endif;
ifcount[]==h"2b"thenspk=dhigh;seg[]=h"25";dz[]=h"8";endif;
ifcount[]==h"2c"thenspk=ehigh;seg[]=h"0d";dz[]=h"a";endif;
ifcount[]==h"2d"thenspk=ehigh;seg[]=h"0d";dz[]=h"a";endif;
ifcount[]==h"2e"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"2f"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"30"thenspk=gnd;seg[]=h"03";dz[]=h"f";endif;
ifcount[]==h"31"thenspk=fhigh;seg[]=h"99";dz[]=h"c";endif;
ifcount[]==h"32"thenspk=dhigh;seg[]=h"25";dz[]=h"8";endif;
ifcount[]==h"33"thenspk=dhigh;seg[]=h"25";dz[]=h"8";endif;
ifcount[]==h"34"thenspk=ehigh;seg[]=h"0d";dz[]=h"a";endif;
ifcount[]==h"35"thenspk=ehigh;seg[]=h"0d";dz[]=h"a";endif;
ifcount[]==h"36"thenspk=ehigh;seg[]=h"0d";dz[]=h"a";endif;
ifcount[]==h"37"thenspk=chigh;seg[]=h"9f";dz[]=h"6";endif;
ifcount[]==h"38"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"39"thenspk=elow;seg[]=h"0d";dz[]=h"9";endif;
ifcount[]==h"3a"thenspk=chigh;seg[]=h"9f";dz[]=h"6";endif;
ifcount[]==h"3b"thenspk=bhigh;seg[]=h"1f";dz[]=h"4";endif;
ifcount[]==h"3c"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"3d"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"3e"thenspk=ahigh;seg[]=h"41";dz[]=h"1";endif;
ifcount[]==h"3f"then
spk=ahigh;seg[]=h"41";dz[]=h"1";count[].d=h"0";
elsecount[].d=count[].q+1;endif;
end;
2)译码模块程序
subdesigndzled
(
inputclk[2..0]:
input;
dz[3..0]:
input;
row[8..1]:
output;
red[16..1]:
output;
)
begin
table
dz[3..0],inputclk[2..0]=>row[8..1],red[16..1];
h"0",h"0"=>h"1",h"ffe7";
h"0",h"1"=>h"2",h"ffdb";
h"0",h"2"=>h"4",h"ffbd";
h"0",h"3"=>h"8",h"ffbd";
h"0",h"4"=>h"10",h"ff81";
h"0",h"5"=>h"20",h"ffbd";
h"0",h"6"=>h"40",h"ffbd";
h"0",h"7"=>h"80",h"ffbd";
h"1",h"0"=>h"1",h"ffc3";
h"1",h"1"=>h"2",h"ffbd";
h"1",h"2"=>h"4",h"ffbf";
h"1",h"3"=>h"8",h"ff83";
h"1",h"4"=>h"10",h"ffbd";
h"1",h"5"=>h"20",h"ffbd";
h"1",h"6"=>h"40",h"ff43";
h"1",h"7"=>h"80",h"ffff";
h"2",h"0"=>h"1",h"fdc3";
h"2",h"1"=>h"2",h"fdbd";
h"2",h"2"=>h"4",h"fdbf";
h"2",h"3"=>h"8",h"fd83";
h"2",h"4"=>h"10",h"fdbd";
h"2",h"5"=>h"20",h"fdbd";
h"2",h"6"=>h"40",h"fd43";
h"2",h"7"=>h"80",h"c1ff";
h"3",h"0"=>h"1",h"ffff";
h"3",h"1"=>h"2",h"ffe1";
h"3",h"2"=>h"4",h"ffdd";
h"3",h"3"=>h"8",h"ffdd";
h"3",h"4"=>h"10",h"ffe1";
h"3",h"5"=>h"20",h"ffdd";
h"3",h"6"=>h"40",h"ffdd";
h"3",h"7"=>h"80",h"ffe1";
h"4",h"0"=>h"1",h"fffd";
h"4",h"1"=>h"2",h"fffd";
h"4",h"2"=>h"4",h"fffd";
h"4",h"3"=>h"8",h"ffe1";
h"4",h"4"=>h"10",h"ffdd";
h"4",h"5"=>h"20",h