FPGA硬件电子琴_第1页
FPGA硬件电子琴_第2页
FPGA硬件电子琴_第3页
FPGA硬件电子琴_第4页
FPGA硬件电子琴_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 课程设计报告(电子设计自动化)题 目硬件电子琴学 院信息科学与工程学院专 业电子科学与技术班 级08级2班姓 名闫志伟 洪丁达指导教师吴丽丽2010年6月25日电子琴的设计 摘 要:用可编程逻辑器件(PLD)来完成该设计。核心是一数控分频器,对输入的脉冲进行分频,得到每个音阶对应的频率,由此实现简易电子琴的发音功能。电子琴可演奏由键盘输入的音阶,同时在数码管上显示对应音节的频率。本设计基于超高速硬件描述语言VHDL在Altera公司的Cyclone系列的EP2C5T144C8芯片上编程实现;经仿真,硬件测试和调试基本能够达到技术指标,实验结果和仿真结果基本一致。关键词:PLD,VHDL,数控

2、分频,电子琴 The Design of Electrical Organ Abstract:The design is accomplished with Programmable-Logic-Device (PLD). The core of it is a numerical control frequency divider, which can divide the input pulse into the corresponding frequency to the musical scale, so that it can achieve the sounding functio

3、n of simple electronic organ. The organ can play the musical scale put in with a keyboard . The design is programmed with VHDL and realized in the chip of EP2C5T144C8 Cyclone series. It can basically reach the technique index after simulating, hardware debugging. The experiment result is consonant w

4、ith the simulating result. Keywords:PLD, VHDL, numerical control frequency divider, electrical organ一 系统设计1、 设计要求 8个音阶,外部时钟信号12 MHz;能同步显示音阶频率。2 设计思路 通过可编程逻辑器件(PLD)和VHDL硬件描述语言来实现电子琴的基本要求。 设计的主体是数控分频器,对输入的频率按照与每个音阶对应的分频系数进行分频,得到各个音阶对应的频率分别在蜂鸣器和数码管上以声音和频率数值的形式作为输出。 3、系统组成及工作原理图1-2-3-1为系统的工作原理框图。根据设计要求,

5、提供的外部时钟信号为12MHz,所以在本设计中需要将其进行分频,以得到所需要的脉冲 。键盘编码器的作用是对键盘按键输入的信号进行检测,并且产生相应的分频系数。 音调发生器的主要部分是一个数控分频器,它由一个初值可预置的加法计数器构成,详细工作原理将在后文做介绍,当它接收到一个分频信号时,便对端口的12MHz的输入时钟信号进行分频,之后由扬声器输出对应的声调。频率计的作用是将各个音阶对应的分频之后的频率通过数码管显示出来。 分频置 数按键分频器12MHZ蜂 鸣 器4位测频器数码管显示图1-2-3-1 工作原理框图二 单元电路设计 1、 顶层模块的设计 VHDL采用的是自顶向下的设计方式,顶层模块

6、由音调发生器(tonetaba)、数控分频器(speaker)和频率计(top)三个模块组成。图2-1-1即是顶层设计原理图。由键盘输入的信号,进行编码,输出的都是八位二进制数,对应音调发生器的输入。 图2-1-1 顶层设计原理图 2、 音调发生器模块(tonetaba)的设计音调发生器的作用是产生获得音阶的分频预置值。当8位发声控制输入index中的某一位为高电平时,则对应某一音阶的数值将以端口tone输出,作为获得该音阶的分频预置值,该值作为数控分频器的输入,来对12MHz的脉冲进行分频,由此得到每个音阶相应的频率,例如输入index="00000010",即对应的按键

7、是2,产生的分频系数便是1702;同时由high1输出对应该音阶低音显示。各音阶所对应的频率:低音1低音2低音3低音4低音5低音6低音7261.63Hz293.67Hz329.63Hz349.23Hz391.99Hz440Hz493.88Hz高音1高音2高音3高音4高音5高音6高音71046.5Hz1174.66Hz1318.51Hz1396.92Hz1567.98Hz1760Hz1975.52HZ分频系数的计算:低音1的频率为261.6Hz,则分频系数=1911,同理可求其他频率的分频系数。创新点:利用按键8来区别高低音,当按键8为高电平时,按键1到7分别表示高音的1到7。当按键8为低时,按

8、键1到7为低音的1到7 high1<='0'-1911 high1<='0'-1702 high1<='0'-1517 high1<='0'-1432 high1<='0'-1275; high1<='0'-1136 when "01000000" => tone<="01111110100" high1<='0'-1012 when "10000001" => t

9、one<="00111011110" high1<='1'-478 when "10000010" => tone<="00110101001" high1<='1'-426 when "10000100" => tone<="00101111011" high1<='1'-379 when "10001000" => tone<="00101100101&q

10、uot; high1<='1'-358 when "10010000" => tone<="00100111110" high1<='1'-319 when "10100000" => tone<="00100011100" high1<='1'-284 when "11000000" => tone<="00011111101" high1<='1'-

11、253 when others =>null;3 、 数控分频模块(speaker)的设计数控分频模块的目的是对基准脉冲分频,得到1,2,3,4,5,6,7七个音符对应频率。该模块的VHDL描述中包含了三个进程。首先对12MHz的基准脉冲进行12分频得到1MHz的脉冲,然后按照tone输入的分频系数对1MHz的脉冲再次分频,得到的便是所需要的频率。而第三个进程的作用是在音调输出时再进行二分频,将脉冲展宽,以使扬声器有足够功率发音。十二分频:divideclk : process(clk) variable count4 :std_logic_vector( 3 downto 0); be

12、gin preclk<='0' if count4>11 then preclk<='1' count4:="0000" elsif clk'event and clk='1' then count4:=count4 + 1; end if; end process;按分频系数进行分频:genspks: process(preclk,tone) variable count11 :std_logic_vector (10 downto 0); begin if preclk'event and

13、 preclk='1' then count11:=count11+1;fullspks<='0' if count11=tone then fullspks<='1' count11:="00000000000" end if; end if; end process;二分频使输出有足够大的功率发声:delayspks: process(fullspks) variable count2 :std_logic; begin if fullspks'event and fullspks ='1

14、9;then count2:=not count2; if count2='1' then spks<='1' else spks<='0' end if; end if; end process;4 、测频计模块(top)的设计 频率计的作用是将各个音阶对应的分频之后的频率通过数码管显示出来。其外加测频控制信号(clk)为1Hz的标准时钟脉冲,基本构成为4个十进制加计数器和锁存器。测频结果即为各个音阶对应的频率,由数码管同步显示。 三 波形仿真1.音调发生模块tonetaba的波形仿真图: 仿真图形如上,按键由1依次按到7,按键8为

15、0,tone依次 输 出低音1到7的分频系数,high1输出为0,表示此时输出为低音。波形仿真图符合设计,说明设计正确。2.数控分频仿真波形:由于spks的频率相较于时钟频率12MHz差别较大,因而未能在图上看到spks的波形变化。四 系统测试1、测试使用的仪器 Altera公司的Cyclone系列的EP2C5T144C8芯片康芯教学实验箱2、测试方法 选择模式5,数控分频的基准频率用clk0的12MHz输入,4位测频器的输入频率用clk2的1Hz输入。分配好引脚后,将程序烧到板上,依次按下按键,蜂鸣器发出相应声音,同时数码管显示该音阶对应的频率。3、指标测试和测试结果 每个音阶对应着不同的频

16、率。频率的大小直接影响着音调的高低以及失真度。 表4-3-1 频率测试音阶12 34567频率(Hz)高 1048117513221397156217651980低263294331352392443495 测试结果可以看出,得到的频率和分频结果基本一致,发音情况良好,音调准确。五 结束语本设计利用超高速硬件描述语言VHDL实现了电子琴 键盘输入发音的简易功能的设计,经过编程,综合,仿真,下载,芯片烧制,最终做出成品,测试情况良好,能够准确实现音阶的发音功能 。 六 参考文献1 潘松.黄继业.EDA技术与VHDL(第2版).北京:清华大学出版社2009.2 网上相关资料.七 附录程序清单1.

17、8音阶硬件电子琴顶层文件:library ieee;use ieee.std_logic_1164.all;entity music isport( fclk1,fclk12: in std_logic; o_high:out std_logic;o_dout: buffer std_logic;fdin: in std_logic_vector(7 downto 0);fout: out std_logic_vector( 15 downto 0);end;architecture one of music is component speakerport( clk: in std_logi

18、c;tone: in std_logic_vector(10 downto 0);spks: out std_logic ); end component; component tonetaba port (index :in std_logic_vector (7 downto 0); high1: out std_logic;-gaoyin tone: out std_logic_vector (10 downto 0); end component; component cnt10 port ( clk1,rst,en: in std_logic; cq: out std_logic_v

19、ector(3 downto 0); cout :out std_logic); end component; component testctl PORT ( CLK : IN STD_LOGIC; - 1Hz CNT_EN,RST_CNT,LOAD : OUT STD_LOGIC); END component; component reg16 port ( load : in std_logic; din: in std_logic_vector(15 downto 0); dout: out std_logic_vector(15 downto 0) ); end component;

20、 signal tone1: std_logic_vector( 10 downto 0); signal en1,rst1,ld,d1,d2,d3: std_logic; signal fd: std_logic_vector(15 downto 0); begin u1: tonetaba port map ( index=>fdin, tone=>tone1, high1=>o_high); u2: speaker port map ( clk=>fclk12, tone=>tone1, spks=>o_dout); u3: testctl port

21、map ( clk=>fclk1, cnt_en=>en1, rst_cnt=>rst1, load=>ld); u4: cnt10 port map ( clk1=>o_dout, en=>en1, rst=>rst1, cq=>fd( 3 downto 0), cout=>d1); u5: cnt10 port map ( clk1=>d1, en=>en1, rst=>rst1, cq=>fd( 7 downto 4), cout=>d2); u6: cnt10 port map (clk1=>d2

22、, en=>en1, rst =>rst1, cq=>fd(11 downto 8), cout=>d3); u7: cnt10 port map (clk1=>d3, en=>en1, rst=>rst1, cq=>fd(15 downto 12); u8: reg16 port map (load=>ld, din=>fd, dout=>fout); end; 2.音调发生模块程序:library ieee;use ieee.std_logic_1164.all;entity tonetaba is port (index

23、:in std_logic_vector (7 downto 0); high1: out std_logic;-gaoyin tone: out std_logic_vector (10 downto 0); end; architecture one of tonetaba is begin search: process(index) begin case index is when "01000000" => tone<="01111110100" high1<='0'-1012 when "10000

24、001" => tone<="00111011110" high1<='1'-478 when "10000010" => tone<="00110101001" high1<='1'-426 when "10000100" => tone<="00101111011" high1<='1'-379 when "10001000" => tone<=&q

25、uot;00101100101" high1<='1'-358 when "10010000" => tone<="00100111110" high1<='1'-319 when "10100000" => tone<="00100011100" high1<='1'-284 when "11000000" => tone<="00011111101" high1

26、<='1'-253 when others =>null; end case; end process; end; 3.分频模块:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity speaker is port( clk: in std_logic; tone: in std_logic_vector(10 downto 0); spks: out std_logic ); end; architecture one of speaker is signal

27、 fullspks: std_logic; signal preclk : std_logic; begin divideclk : process(clk) variable count4 :std_logic_vector( 3 downto 0); begin preclk<='0' if count4>11 then preclk<='1' count4:="0000" elsif clk'event and clk='1' then count4:=count4 + 1; end if; e

28、nd process; genspks: process(preclk,tone) variable count11 :std_logic_vector (10 downto 0); begin if preclk'event and preclk='1' then count11:=count11+1;fullspks<='0' if count11=tone then fullspks<='1' count11:="00000000000" end if; end if; end process; de

29、layspks: process(fullspks) variable count2 :std_logic; begin if fullspks'event and fullspks ='1'then count2:=not count2; if count2='1' then spks<='1' else spks<='0' end if; end if; end process; end; 3. 4位测频器:(1)十进制加法器:library ieee;use ieee.std_logic_1164.all

30、;use ieee.std_logic_unsigned.all;entity cnt10 is port ( clk1,rst,en: in std_logic; cq: out std_logic_vector(3 downto 0); cout :out std_logic); end cnt10; architecture behav of cnt10 is begin process(clk1,rst,en) variable cqi:std_logic_vector(3 downto 0); begin if rst ='1' then cqi :=(others =>'0'); elsif clk1'event and clk1='1' then if en='1' then if cqi<10 then cqi :=cqi+1; if cqi=10 then cout<='1'cqi:=(others=>'0

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论