硬件电子琴及硬件乐曲演奏电路_第1页
硬件电子琴及硬件乐曲演奏电路_第2页
硬件电子琴及硬件乐曲演奏电路_第3页
硬件电子琴及硬件乐曲演奏电路_第4页
硬件电子琴及硬件乐曲演奏电路_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

1、FPGA嵌入式系统设计专题实践结课论文题目:硬件电子琴及硬件乐曲演奏电路专业:电子信息科学与技术一、设计题目硬件电子琴及硬件乐曲演奏电路二、设计目标1.学习利用蜂鸣器和按键设计硬件电子琴2.利用硬件电子琴原理设计硬件演奏电路3.掌握VHDL编程语言,了解实际设计中的优化方案三、设计原理音乐演奏的原理是:由于组成乐曲的每个音符的频率值(音调)及其持续时间(音长)是乐曲演奏的两个基本数据,因此需要控制输出到扬声器的激励信号的频率高低和该频率信号持续的时间。四、设计内容1、硬件电子琴(1)原理图(2).分频器程序-filename clk_div3.vhd-description:LIBRARY I

2、EEE;ENTITY Clk_Div3 ISPORT(clk_in: IN STD_LOGIC;clk_out: OUT STD_LOGIC ) ;END ;ARCHITECTURE myArchitecture OF Clk_Div3 isSIGNAL cnt1, cnt2: integer range 0 to 2;SIGNAL clk1, clk2: STD_LOGIC ; BEGINPROCESS(clk_in)BEGINIF rising_edge(clk_in) THEN IF cnt1 < 2 THEN cnt1 <= cnt1 + 1; ELSEcnt1 <=

3、 0; END IF;IF cnt1 < 1 THEN clk1 <= '1' ELSEclk1 <= '0' END IF;END IF;END PROCESS;PROCESS(clk_in)BEGINIF falling_edge(clk_in) THEN IF cnt2 < 2 THEN cnt2 <= cnt2 + 1 ; ELSEcnt2 <= 0 ;END IF ;IF cnt2 < 1 thenclk2 <= '1' ;ELSEclk2 <= '0' ;END I

4、F ;END IF ;END PROCESS ;clk_out <= clk1 OR clk2 ; END ;(3).七个中音主程序module beepx(clk,key,beep,led,ledbt); input clk;input7:0key; /模块名称beep /系统时钟12MHz /按键输入output beep;output7:0led; /蜂鸣器输出端output7:0ledbt;reg beep_r; /LED输出 /寄存器reg15:0count,count_end;reg7:0key_r;reg7:0led_bt;always(posedge clk)begine

5、ndalways (key)beginkey_r = key; case(key_r) 8'b11111110:begin count_end =16'h2CCA ; key_r = 8'b11111001; led_bt =/中音1的分频系数值 /取键值 count <= count + 1'b1; begin end count <= 16'h0; /计数器清零 /计数器加1 if(count = count_end)&(!(count_end = 16'hffff) beep_r <= !beep_r; /取反输出

6、信号 8'b11111110 ; end8'b11111101:begin count_end =16'h27E8; key_r = 8'b10100100; led_bt =/中音2的分频系数值key_r = 8'b10110000; led_bt = 8'b11111110 ;end 8'b11111011:begin count_end =16'h238D;8'b11111110 ;end /中音3的分频系数值8'b11110111:begin count_end =16'h218E; key_r =

7、 8'b10011001; led_bt = 8'b11111110 ;end /中音4的分频系数值8'b11101111:begin count_end =16'h1DE5; key_r = 8'b10010010; led_bt = 8'b11111110 ;end /中音5的分频系数值8'b11011111:begin count_end =16'h1AA2; key_r = 8'b10000010; led_bt = 8'b11111110 ;end /中音6的分频系数值8'b10111111: b

8、egin count_end =16'h17BA; key_r = 8'b11111000; led_bt = 8'b11111110 ;end /中音7的分频系数值8'b01111110: begin count_end =16'h166B;key_r = 8'b11111001; led_bt = 8'b11111110 ; end /高音1的分频系数值8'b01111101: begin count_end =16'h13F4;key_r = 8'b10100100; led_bt = 8'b1111

9、1110 ; end /高音2的分频系数值8'b01111011: begin count_end =16'h11C7; key_r = 8'b10110000; led_bt = 8'b11111110 ; end /高音3的分频系数值8'b01110111: begin count_end =16'h10C7; key_r = 8'b10011001; led_bt = 8'b11111110 ; end /高音4的分频系数值8'b01101111: begin count_end =16'h0EF3; key

10、_r = 8'b10010010; led_bt = 8'b11111110 ; end /高音5的分频系数值8'b01011111: begin count_end =16'h0D51; key_r = 8'b10000010; led_bt = 8'b11111110 ; end /高音6的分频系数值8'b00111111: begin count_end =16'h0BDD; key_r = 8'b11111000; led_bt = 8'b11111110 ; end /高音7的分频系数值endassign

11、 beep =beep_r;assign led =key_r;assign ledbt = led_bt ;endmodule2. 硬件乐曲演奏电路。(1)内存分配图/输出音乐 /输出按键状态 default:count_end = 16'hffff; endcase(2)主程序library IEEE;ENTITY buzzer ISPORT (ch : IN std_logic;-键盘与歌曲播放选择 cho : IN std_logic;-歌曲切换 key_data : IN std_logic_vector(2 DOWNTO 0);-电子琴组合键盘输入 clk : IN std

12、_logic;-系统时钟out_bit : OUT std_logic);-输出给蜂鸣器END buzzer;ARCHITECTURE arch OF buzzer ISCOMPONENT liangzhuPORT(address:in std_logic_vector(7 downto 0);clock:in std_logic; q:out std_logic_vector(15 downto 0); END COMPONENT;signal sta1: std_logic_vector(7 downto 0);signal sta: integer range 0 to 147;sign

13、al count: std_logic_vector(15 DOWNTO 0);signal count_end: std_logic_vector(15 DOWNTO 0);signal count1: std_logic_vector(23 DOWNTO 0);signal out_bit_temp : std_logic; signal key_temp : std_logic_vector(2 DOWNTO 0); signal count_end_temp : std_logic_vector(15 DOWNTO 0); signal choice : std_logic;-音调分频

14、数BEGIN out_bit<=out_bit_temp; key_temp<=key_data;PROCESS(cho)-歌曲间切换 BEGINIF(cho'EVENT AND cho='1')THENchoice<=NOT choice; END IF; END PROCESS;PROCESS(clk)-分频后的音调输出控制BEGINIF(clk'EVENT AND clk='1')THENcount <=count+1;IF (count = count_end) THENcount <=x"0000

15、" out_bit_temp<=NOT out_bit_temp; END IF; END IF;END PROCESS;U :liangzhu PORT MAP (address=>sta1,q=>count_end_temp,clock=>clk); -与liangzhu.vhd的接口PROCESS(clk,ch,choice,cho)-音调单位时长和曲谱依次播放(sta自加)控制 BEGIN IF(ch='1')THEN-键盘与歌曲播放切换 IF(clk'EVENT AND clk='1')THEN IF(coun

16、t1<t) THEN count1<=count1+1; ELSE count1<=x"000000" IF(choice='1')THEN sta<=0; IF(sta1=10001010)THENsta1<="00000000" ELSE sta1<=sta1+1; count_end<=count_end_temp;-梁祝曲谱信息赋给count_end END IF; ELSE sta1<="00000000" IF(sta=147)THENsta<=0; E

17、LSE sta<=sta+1; CASE sta IS-友谊天长地久曲谱信息 WHEN 0|1=>count_end<=suo0; WHEN 2 TO 8=>count_end<=duo; WHEN 9|10=>count_end<=me; WHEN 11 TO 14=>count_end<=lai; WHEN 15=>count_end<=duo; WHEN 16|17=>count_end<=lai; WHEN 18|19=>count_end<=me; WHEN 20 TO 24=>count

18、_end<=duo; WHEN 25|26=>count_end<=me; WHEN 27|28=>count_end<=suo; WHEN 29 TO 33=>count_end<=la; WHEN 34 TO 38=>count_end<=la; WHEN 39 TO 42=>count_end<=suo; WHEN 43 TO 45=>count_end<=me; WHEN 46|47=>count_end<=duo; WHEN 48 TO 51=>count_end<=lai; WHE

19、N 52=>count_end<=duo; WHEN 53|54=>count_end<=lai;WHEN 55|56=>count_end<=me; WHEN 57 TO 60=>count_end<=duo; WHEN 61 TO 63=>count_end<=la0; WHEN 64 TO 65=>count_end<=suo0; WHEN 66 TO 69=>count_end<=duo; WHEN 70 TO 73=>count_end<=duo; WHEN 74|75=>count

20、_end<=la; WHEN 76 TO 79=>count_end<=suo; WHEN 80 TO 82=>count_end<=me; WHEN 83|84=>count_end<=duo; WHEN 85 TO 88=>count_end<=lai; WHEN 89=>count_end<=duo; WHEN 90|91=>count_end<=lai; WHEN 92|93=>count_end<=la; WHEN 94 TO 97=>count_end<=suo; WHEN 98

21、TO 100=>count_end<=me; WHEN 101|102=>count_end<=suo; WHEN 103 TO 106=>count_end<=la; WHEN 107 TO 110=>count_end<=la; WHEN 111|112=>count_end<=duo1; WHEN 113 TO 116=>count_end<=suo; WHEN 117 TO 119=>count_end<=me; WHEN 120|121=>count_end<=duo; WHEN 122 TO 125=>count_end<=lai; WHEN 126=>count_end<=duo; WHEN 127|128=>count_end<=lai; WHEN 129|130=>count_end<=me; WHEN 131 TO 134=>count_end<=duo; WHEN 135 TO 137=>count_end<=la0; WHEN 138|139=>count_end<=suo0;WHEN 140 TO 143=>count_end<=duo; WHEN 144 TO 1

温馨提示

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

评论

0/150

提交评论