818+电子琴程序设计与仿真luj.docx
摘要: 文中介介绍了电电子琴系系统的整整体设计计,并基基于超高高速硬件件描述语语言VHHDL在在Xillinxx公司的的Spaartaan系系列的22sc2200PPQ2008-55芯片上上编程实实现.电子琴系系统的设设计包含含四个模模块,分分别是控控制输入入电路、FFPGAA、显示示电路和和扬声器器电路。其其中FPPGA模模块的设设计是整整个电子子琴系统统设计的的核心内内容。四四个模块块的有机机组合完完成了电电子琴自自动演奏奏的功能能。文中中还详细细介绍了了FPGGA功能能模块的的原理及及其工作作时序仿仿真图。本本产品的的特点是是成本较较低,性性能稳定定,精度度高,有有一定的的开发价价值。关键词: 现场场可编程程逻辑器器件FPPGA 超高高速硬件件描述语语言VHHDL 电子子琴系统统 自动演演奏8.188.4程序序设计与与仿真电子琴VVHDLL程序包包含有:顶层程程序、音音阶发生生器程序序、数控控分频模模块程序序和自动动演奏模模块程序序。1.顶层层程序与与仿真(1)顶顶层VHHDL程程序-文件件名:ttop.vhdd-功能能:顶层层文件-最后后修改日日期:220044.3.20librraryy IEEEE;use IEEEE.SSTD_LOGGIC_11664.AALL;use IEEEE.SSTD_LOGGIC_ARIITH.ALLL;use IEEEE.SSTD_LOGGIC_UNSSIGNNED.ALLL;entiity topp issPortt ( clkk32MMHz :in stdd_loogicc; -32MMHz系系统时钟钟handdTOaautoo : in stdd_loogicc; -键盘输输入/自自动演奏奏codee1 :oout stdd_loogicc_veectoor(66 doowntto 00); -音音符显示示信号indeex1 :iin sstd_loggic_vecctorr(7 dowwntoo 0); -键键盘输入入信号highh1 :oout stdd_loogicc; -高高低音节节信号spkoout :oout stdd_loogicc); -音频信信号end topp;archhiteectuure Behhaviioraal oof ttop iscompponeent auttomuusiccPortt ( clkk :iin sstd_loggic; Autoo: iin sstd_loggic;indeex2:in stdd_loogicc_veectoor(77 doowntto 00);indeex0 : oout stdd_loogicc_veectoor(77 doowntto 00);end commponnentt;compponeent tonnePortt ( inddex : iin sstd_loggic_vecctorr(7 dowwntoo 0);codee : outt sttd_llogiic_vvecttor(6 ddownnto 0);highh : outt sttd_llogiic;tonee0 : ouut iinteegerr raangee 0 to 20447);end commponnentt;compponeent speeakeerPortt ( clkk1 : inn sttd_llogiic;tonee1 : inn inntegger rannge 0 tto 220477;spkss : outt sttd_llogiic);end commponnentt;signnal tonne2: inntegger rannge 0 tto 220477;signnal inddx:sstd_loggic_vecctorr(7 dowwntoo 0);begiinu0:aautoomussic porrt mmap(clkk=>cclk332MHHZ,iindeex2=>inndexx1,iindeex0=>inndx,Autto=>>hanndtooAutto);u1: tonne pportt maap(iindeex=>>inddx,ttonee0=>>tonne2,codde=>>codde1,higgh=>>higgh1);u2: speeakeer pportt maap(cclk11=>cclk332MHHZ,ttonee1=>>tonne2,spkks=>>spkkoutt);end Behhaviioraal;(2)仿仿真顶层文件件仿真图图如图88.188.2所所示。图8.118.2 顶层文文件仿真真图2. 音音阶发生生器程序序与仿真真(1) 音阶发生生器VHHDL程程序-文件件名:ttonee.vhhd。-功能能:librraryy IEEEE;use IEEEE.SSTD_LOGGIC_11664.AALL;use IEEEE.SSTD_LOGGIC_ARIITH.ALLL;use IEEEE.SSTD_LOGGIC_UNSSIGNNED.ALLL;entiity tonne iisPortt ( inddex : iin sstd_loggic_vecctorr(7 dowwntoo 0); -音符符输入信信号codee : ouut sstd_loggic_vecctorr(6 dowwntoo 0); -音音符显示示信号highh : ouut sstd_loggic; -高低音音显示信信号tonee0 : ouut iinteegerr raangee 0 to 20447); -音符的的分频系系数end tonne;archhiteectuure Behhaviioraal oof ttonee issbegiinsearrch :prroceess(inddex) -此进程程完成音音符到音音符的分分频系数数译码,音音符的显显示,高高低音阶阶begiincasee inndexx isswhenn "00000000001" => tonne0<<=7773;ccodee<=""100011111"higgh<='1''whenn "00000000110"=> ttonee0<=9122;coode<<="0001000100"hhighh<=''1'whenn "00000001000" => tonne0<<=10036;codde<="000001110""hiigh<<='11'whenn "00000010000" => tonne0<<=11116;codde<="100011100""hiigh<<='11'whenn "00001100000" => tonne0<<=11197;codde<="011001100""hiigh<<='11'whenn "00010000000" => tonne0<<=12290;codde<="011000000""hiigh<<='00'whenn "00100000000" => tonne0<<=13372;codde<="000011111""hiigh<<='00'whenn "11000000000" => tonne0<<=14410;codde<="000000000""hiigh<<='00'whenn othherss => tonne0<<=20047;codde<="000000001""hiigh<<='00'end casse;end proocesss;end Behhaviioraal;(2)音音阶发生生器程序序仿真音阶发生生器程序序仿真图图如图88.188.3所所示。图8.118.3 音音阶发生生器仿真真图3. 数数控分频频模块程程序与仿仿真(1) 数控分频频模块VVHDLL程序-文件件名:sspeaakerr.vhhd。-功 能:实现数数控分频频。-最后后修改日日期:2200004.33.199。librraryy IEEEE;use IEEEE.SSTD_LOGGIC_11664.AALL;use IEEEE.SSTD_LOGGIC_ARIITH.ALLL;use IEEEE.SSTD_LOGGIC_UNSSIGNNED.ALLL;entiity speeakeer iisPortt ( clkk1 : iin sstd_loggic; -系系统时钟钟tonee1 : inn inntegger rannge 0 tto 3306224; -音音符分频频系数spkss : ouut sstd_loggic); -驱动动扬声器器的音频频信号end speeakeer;archhiteectuure Behhaviioraal oof sspeaakerr isssignnal prrecllk,ffulllspkks:sstd_loggic;begiinpulsse1:proocesss(cclk11) -此进进程对系系统时钟钟进行44分频variiablle ccounnt:iinteegerr raangee 0 to 8;begiinif cclk11'evventt annd cclk11='11' tthenncouunt:=coountt+1;if ccounnt=22 thhenpprecclk<<='11' elsiif ccounnt=44 thhenpprecclk<<='00'ccounnt:=0;end if; end if;end proocesss ppulsse1;gensspkss:prroceess(preeclkk,toone11) -此进进程按照照tonne1输输入的分分频系数数对8MMHz的的脉冲再再次分频频,得到到所需要要的音符符频率variiablle ccounnt111:inntegger rannge 0 tto 3306224;begiinif pprecclk''eveent andd prrecllk=''1' theenif ccounnt111<toone11 thhenccounnt111:=ccounnt111+1;fulllsppks<<='11' elsee coountt11:=0;fulllsppks<<='00'end if;end if;end proocesss;delaayspps:pproccesss(fuullsspkss) -此进程程对fuullsspkss进行22分频variiablle ccounnt2 :sttd_llogiic:='0''begiinif ffulllspkks'eevennt aand fulllsppks='1'' thhen couunt22:=nnot couunt22;if ccounnt2='1'' thhen spkks<='1''elsee sppks<<='00'end if;end if;end proocesss;end Behhaviioraal;(2) 数控分分频模块块程序仿仿真数控分频频模块程程序仿真真图如图图8.118.4所所示。图8.118.4 数控控分频模模块仿真真图4. 自自动演奏奏模块程程序与仿仿真(1) 自动演奏奏模块VVHDLL程序-文件件名:aautoomussic.vhdd-功 能:实现自自动演奏奏功能。-最后后修改日日期:220044.3.19。librraryy IEEEE;use IEEEE.SSTD_LOGGIC_11664.AALL;use IEEEE.SSTD_LOGGIC_ARIITH.ALLL;use IEEEE.SSTD_LOGGIC_UNSSIGNNED.ALLL;entiity auttomuusicc issPortt ( clkk,Auuto : iin sstd_loggic; -系统时时钟;键键盘输入入/自动动演奏indeex2 : iin sstd_loggic_vecctorr(7 dowwntoo 0); -键盘盘输入信信号indeex0 : oout stdd_loogicc_veectoor(77 doowntto 00); -音符符信号输输出end auttomuusicc;archhiteectuure Behhaviioraal oof aautoomussic issignnal couunt00:inntegger rannge 0 tto 331;-chhanggesignnal clkk2:sstd_loggic;begiinpulsse0:proocesss(cclk,Autto) -此进进程完成成对系统统时钟88M的分分频,得得到4HHz的信信号cllk2variiablle ccounnt:iinteegerr raangee 0 to 800000000;begiinif AAutoo='11' tthenn coountt:=00;cllk2<<='00'elsiif cclk''eveent andd cllk=''1' theen ccounnt:=couunt+1;if ccounnt=4400000000(4) theen cclk22<=''1' elsiif ccounnt=8800000000 (88)thhen clkk2<='0''coountt:=00;end if; end if;end proocesss;musiic:pproccesss(cllk2) -此进进程完成成自动演演奏部分分曲的地地址累加加begiinif cclk22'evventt annd cclk22='11' tthennif ccounnt0=31 theen ccounnt0<<=0;elsee coountt0<=couunt00+1;end if;end if;end proocesss;com11:prroceess(couunt00,Auuto,inddex22)begiinif AAutoo='00' tthenncasee coountt0 iis -此ccasee语句:存储自自动演奏奏部分的的曲whenn 0 => inddex00<=""0000001100"" -33whenn 1 => inddex00<=""0000001100"" -33whenn 2 => inddex00<=""0000001100"" -33whenn 3 => inddex00<=""0000001100"" -33whenn 4 => inddex00<=""0000100000"" -55whenn 5 => inddex00<=""0000100000"" -55whenn 6 => inddex00<=""0000100000"" -55whenn 7 => inddex00<=""0011000000"" -66whenn 8 => inddex00<=""1000000000"" -88whenn 9 => inddex00<=""1000000000"" -88whenn 100 =>>inddex00<=""1000000000"" -88whenn 111=> inddex00<=""0000001100"" -33whenn 122=> inddex00<=""0000000010"" -22whenn 133=> inddex00<=""0000000010"" -22whenn 144=> inddex00<=""0000000001"" -11whenn 155=> inddex00<=""0000000001"" -11whenn 166=> inddex00<=""0000100000"" -55whenn 177=> inddex00<=""0000100000"" -55whenn 188=> inddex00<=""0000010000"" -44whenn 199=> inddex00<=""0000010000"" -44whenn 200=> inddex00<=""0000010000"" -44whenn 211=> inddex00<=""0000001100"" -33whenn 222=> inddex00<=""0000000010"" -22whenn 233=> inddex00<=""0000000010"" -22whenn 244=> inddex00<=""0000100000"" -55whenn 255=> inddex00<=""0000100000"" -55whenn 266=> inddex00<=""0000010000"" -44whenn 277=> inddex00<=""0000010000"" -44whenn 288=> inddex00<=""0000001100"" -33whenn 299=> inddex00<=""0000001100"" -33whenn 300=> inddex00<=""0000000010"" -22whenn 311=> inddex00<=""0000000010"" -22whenn ottherrs => nnulll;end casse;elsee inndexx0<=inddex22; -键键盘输入入音符信信号输出出end if;end proocesss;end Behhaviioraal;(2)自自动演奏奏模块程程序仿真真自动演奏奏模块仿仿真图如如图8.17.5所示示。图8.118.5 自动动演奏模模块仿真真图(注:由由于输入入频率太太高,实实验条件件所限,如如按源程程序仿真真将看不不到输出出波形,因因此将原原脉冲的的分频点点400000000和8800000000改为44和8,得得到如图图的仿真真结果,在在实际烧烧制芯片片中不作作此处理理。)