已阅读5页,还剩12页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
电子琴课程名称: 学院(系): 电子信息工程 专 业: 电子信息工程 班 级: 学生姓名: 学 号: 完成日期: 成 绩: 1 设计要求(1)有两种模式可供选择,分别为弹奏模式和自动演奏模式。(2)在弹奏模式下,分别按下实验箱上七个键,扬声器分别发出中音Do, Re, Mi, Fa, Sol, La, Ti(3)在自动演奏模式下,自动循环播放歌曲Jingle Bells。(4) 由三位数码管分别显示高、中、低音的音符。2 设计分析及系统方案设计a. 设计分析:电子琴的设计包括四个模块:弹奏模块keyplay、自动演奏模块autoplay、查表及显示模块table和分频模块fenpin。 弹奏模块keyplay根据按键动作key产生指示音调的index_key 自动演奏模块autoplay接收1024Hz的时钟信号,输出index_auto 查表及显示模块table根据按键button选择采用index_key或ndex_auto来查分频系数表,输出分频系数tone。同时将音调对应的BCD码code0(低音)、code1(中音)、code2(高音)分别输出给三个数码管。 分频模块fenpin接收tabled输出的分频系数 tone,并据此分频,将对应频率的信号buzz输出给扬声器供其发声。b. 系统设计方案:顶层设计:输入:6MHz时钟clk、1024Hz时钟、按键key6.0、按键button输出:spkout给扬声器 弹奏模块keyplay:将输入key6.0编码为index_key4.0。index_key4.0的高两位表示高、中、低音,00表示低音,01表示中音、10表示高音。由于按键数目有限,只能弹出中音。index_key4.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驱动扬声器发声。设计框图:buzzcode0 code1 code2tonefenpinbuttonIndex_autoIndex_keytableClk2autoplaykeyKeyplay3系统以及模块硬件电路设计译码器译码器译码器 PIO27-24 PIO23-20 PIO23-20 F P G A最小系统 Clk0 Clk5 PIO7 PIO6 PIO5 PIO4 PIO3 PIO2 PIO1 PIO0 spk 6MHz1024Hz Key0Key1Key2Key3Key4Key5Key6Button试验箱使用的是模式3的电路结构。1. 按键PIO7是模式选择按键button,每按下一次改变一次模式2. 按键PIO6-0用于弹奏,在弹奏模式下,被按下时分别发出中音Do, Re, Mi, Fa, Sol, La, Ti。3. Clk0用于分频以供扬声器发声4. Clk5用于控制自动演奏节拍5. 三个数码管用于显示高、中、低音音调下载时选择的开发系统模式以及管脚定义表1 GW48-CK开发系统工作模式:接口名称类型(输入/输出)结构图上的信号名引脚号说明clkINPUTCLK02供分频发声Clk2INPUTCLK583供分频获得节拍KeyINPUTPIO6-011-5按键弹奏ButtonINPUTPIO716模式选择Code0topOUTPUTPIO19-1630-27低音显示Code1topOUTPUTPIO23-2038-35中音显示Code2topOUTPUTPIO27-2449-47,39高音显示SpkoutOUTPUTSPEAKER3发声4 系统的VHDL设计顶层程序:top.vhdlibrary IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity top isport ( clk :in std_logic; clk2:in std_logic;key:in std_logic_vector(6 downto 0);button:in std_logic; spkout :out std_logic;code0top:out std_logic_vector(3 downto 0);code1top:out std_logic_vector(3 downto 0);code2top:out std_logic_vector(3 downto 0); end top;architecture behave of top iscomponent autoplayport ( clk2: in std_logic;index_auto : out std_logic_vector(4 downto 0);end component;component fenpinport(clk:in std_logic; tone:in integer range 0 to 8190; buzz:out std_logic);end component;component tableport(index_auto:in std_logic_vector(4 downto 0);index_key:in std_logic_vector(4 downto 0);button :in std_logic;tone:out integer range 0 to 8190;code0:out std_logic_vector(3 downto 0);code1:out std_logic_vector(3 downto 0);code2:out std_logic_vector(3 downto 0);end component;component keyplayport(key:in std_logic_vector(6 downto 0);index_key:out std_logic_vector(4 downto 0);end component;signal index_auto_top :std_logic_vector(4 downto 0);signal index_key_top :std_logic_vector(4 downto 0);signal tone_top :integer range 0 to 8190;beginu1:autoplay port map(clk2=clk2,index_auto=index_auto_top);u2:fenpin port map(clk=clk,tone=tone_top,buzz=spkout);u3:table port map(index_auto=index_auto_top,index_key=index_key_top,tone=tone_top,button=button,code0=code0top,code1=code1top,code2=code2top);u4:keyplay port map(key=key,index_key=index_key_top);end behave;按键弹奏模块:keyplay.vhdlibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith;use ieee.std_logic_unsigned.all;entity keyplay isport(key:in std_logic_vector(6 downto 0);index_key:out std_logic_vector(4 downto 0);end;architecture behave of keyplay isbeginprocess(key)begincase key iswhen 0000001= index_key index_key index_key index_key index_key index_key index_key index_key=00000;end case;end process ;end behave;自动演奏模块:autoplay.vhdlibrary IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity autoplay isport (clk2: in std_logic;index_auto : out std_logic_vector(4 downto 0);end;architecture behave of autoplay issignal count :integer range 0 to 136;-可根据乐曲长度改变signaljiepai: std_logic;signalj: integer range 0 to 60;beginjiepai1:process(clk2)-分频产生16Hz的节拍beginif clk2 event and clk2 = 1 thenif j = 30thenj = 0;jiepai = not jiepai;elsej = j+1;end if;end if;end process jiepai1;-jiepai = clk2;process(jiepai)beginif jiepaievent and jiepai=1 thenif count=136 then count=0;-可根据乐曲长度改变else count index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_autoindex_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_autoindex_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto index_auto null;end case;end process;end behave;查表及显示模块:table.vhd说明:简谱中音名所对应的频率(Hz)音名频率(Hz)音名频率(Hz)音名频率(Hz)低音1261.6中音1523.3高音11045.5低音2293.7中音2587.3高音21174.7低音3329.6中音3659.3高音31318.5低音4349.2中音4698.5高音41396.9低音5392中音5784高音51568低音6440中音6880高音61760低音7493.9中音7987.8高音71975.5分频系数的计算举例:对中音1求分频系数tone,523.3Hz = 1/(2*(tone+1)*6*106Hz。计算得tone = 5732代码如下:use ieee.std_logic_1164.all;use ieee.std_logic_arith;use ieee.std_logic_unsigned.all;entity table isport(index_key:in std_logic_vector(4 downto 0);index_auto:in std_logic_vector(4 downto 0); button :in std_logic;tone:out integer range 0 to 8190;code0:out std_logic_vector(3 downto 0);code1:out std_logic_vector(3 downto 0);code2:out std_logic_vector(3 downto 0);end;architecture search of table issignal index: std_logic_vector(4 downto 0); signal choice: std_logic;begin process(button)beginif button event and button = 1 then choice=not choice;end if;if choice = 1 thenindex= index_auto;elseindex tone tone tone tone tone tone tone tone tone tone tone tone tone tone tone=0;end case;end process ;process(index)-由index得BCD码beginif(index(4) = 0 and index(3) = 0) thencode0(3) = 0 ;code0(2) = index(2) ;code0(1) = index(1) ;code0(0) = index(0);code1 = 0000;code2 = 0000;elsif (index(4) = 0 and index(3) = 1) thencode0 = 0000;code1(3) = 0 ;code1(2) = index(2) ;code1(1) = index(1) ;code1(0) = index(0);code2 = 0000;elsif (index(4) = 1 and index(3) = 0) thencode0 = 0000;code1 = 0000;code2(3) = 0 ;code2(2) = index(2) ;code2(1) = index(1) ;code2(0) = index(0);end if;end process;end;分频模块:fenpin.vhdlibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity fenpin isport(clk:in std_logic;-6MHz时钟tone:in integer range 0 to 8190;-输入分频系数buzz:out std_logic);-驱动扬声器发声end;architecture behave of fenpin issignalclk_data: std_logic;signali: inte
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论