首页 第8章程序部分8.18 电子琴程序设计与仿真 2004.8修改

第8章程序部分8.18 电子琴程序设计与仿真 2004.8修改

举报
开通vip

第8章程序部分8.18 电子琴程序设计与仿真 2004.8修改 8.18.4程序设计与仿真 电子琴VHDL程序包含有:顶层程序、音阶发生器程序、数控分频模块程序和自动演奏模块程序。 1.顶层程序与仿真 (1)顶层VHDL程序 --文件名:top.vhd --功能:顶层文件 --最后修改日期:2004.3.20 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity top is Port...

第8章程序部分8.18 电子琴程序设计与仿真 2004.8修改
8.18.4程序 设计 领导形象设计圆作业设计ao工艺污水处理厂设计附属工程施工组织设计清扫机器人结构设计 与仿真 电子琴VHDL程序包含有:顶层程序、音阶发生器程序、数控分频模块程序和自动演奏模块程序。 1.顶层程序与仿真 (1)顶层VHDL程序 --文件名:top.vhd --功能:顶层文件 --最后修改日期:2004.3.20 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity top is Port ( clk32MHz :in std_logic; --32MHz系统时钟 handTOauto : in std_logic; --键盘输入/自动演奏 code1 :out std_logic_vector(6 downto 0); --音符显示信号 index1 :in std_logic_vector(7 downto 0); --键盘输入信号 high1 :out std_logic; --高低音节信号 spkout :out std_logic); --音频信号 end top; architecture Behavioral of top is component automusic Port ( clk :in std_logic; Auto: in std_logic; index2:in std_logic_vector(7 downto 0); index0 : out std_logic_vector(7 downto 0)); end component; component tone Port ( index : in std_logic_vector(7 downto 0); code : out std_logic_vector(6 downto 0); high : out std_logic; tone0 : out integer range 0 to 2047); end component; component speaker Port ( clk1 : in std_logic; tone1 : in integer range 0 to 2047; spks : out std_logic); end component; signal tone2: integer range 0 to 2047; signal indx:std_logic_vector(7 downto 0); begin u0:automusic port map(clk=>clk32MHZ,index2=>index1,index0=>indx,Auto=>handtoAuto); u1: tone port map(index=>indx,tone0=>tone2,code=>code1,high=>high1); u2: speaker port map(clk1=>clk32MHZ,tone1=>tone2,spks=>spkout); end Behavioral; (2)仿真 顶层文件仿真图如图8.18.2所示。 图8.18.2 顶层文件仿真图 2. 音阶发生器程序与仿真 (1) 音阶发生器VHDL程序 --文件名:tone.vhd。 --功能: library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity tone is Port ( index : in std_logic_vector(7 downto 0); --音符输入信号 code : out std_logic_vector(6 downto 0); --音符显示信号 high : out std_logic; --高低音显示信号 tone0 : out integer range 0 to 2047); --音符的分频系数 end tone; architecture Behavioral of tone is begin search :process(index) --此进程完成音符到音符的分频系数译码,音符的显示,高低音阶 begin case index is when "00000001" => tone0<=773;code<="1001111";high<='1'; when "00000010"=> tone0<=912;code<="0010010";high<='1'; when "00000100" => tone0<=1036;code<="0000110";high<='1'; when "00001000" => tone0<=1116;code<="1001100";high<='1'; when "00010000" => tone0<=1197;code<="0100100";high<='1'; when "00100000" => tone0<=1290;code<="0100000";high<='0'; when "01000000" => tone0<=1372;code<="0001111";high<='0'; when "10000000" => tone0<=1410;code<="0000000";high<='0'; when others => tone0<=2047;code<="0000001";high<='0'; end case; end process; end Behavioral; (2)音阶发生器程序仿真 音阶发生器程序仿真图如图8.18.3所示。 图8.18.3 音阶发生器仿真图 3. 数控分频模块程序与仿真 (1) 数控分频模块VHDL程序 --文件名:speaker.vhd。 --功 能:实现数控分频。 --最后修改日期:20004.3.19。 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity speaker is Port ( clk1 : in std_logic; --系统时钟 tone1 : in integer range 0 to 30624; --音符分频系数 spks : out std_logic); --驱动扬声器的音频信号 end speaker; architecture Behavioral of speaker is signal preclk,fullspks:std_logic; begin pulse1:process(clk1) --此进程对系统时钟进行4分频 variable count:integer range 0 to 8; begin if clk1'event and clk1='1' then count:=count+1; if count=2 then preclk<='1'; elsif count=4 then preclk<='0';count:=0; end if; end if; end process pulse1; genspks:process(preclk,tone1) --此进程按照tone1输入的分频系数对8MHz的脉冲再次分频,得到所需要的音符频率 variable count11:integer range 0 to 30624; begin if preclk'event and preclk='1' then if count11 index0<="00000100"; --3 when 1 => index0<="00000100"; --3 when 2 => index0<="00000100"; --3 when 3 => index0<="00000100"; --3 when 4 => index0<="00010000"; --5 when 5 => index0<="00010000"; --5 when 6 => index0<="00010000"; --5 when 7 => index0<="00100000"; --6 when 8 => index0<="10000000"; --8 when 9 => index0<="10000000"; --8 when 10 =>index0<="10000000"; --8 when 11=> index0<="00000100"; --3 when 12=> index0<="00000010"; --2 when 13=> index0<="00000010"; --2 when 14=> index0<="00000001"; --1 when 15=> index0<="00000001"; --1 when 16=> index0<="00010000"; --5 when 17=> index0<="00010000"; --5 when 18=> index0<="00001000"; --4 when 19=> index0<="00001000"; --4 when 20=> index0<="00001000"; --4 when 21=> index0<="00000100"; --3 when 22=> index0<="00000010"; --2 when 23=> index0<="00000010"; --2 when 24=> index0<="00010000"; --5 when 25=> index0<="00010000"; --5 when 26=> index0<="00001000"; --4 when 27=> index0<="00001000"; --4 when 28=> index0<="00000100"; --3 when 29=> index0<="00000100"; --3 when 30=> index0<="00000010"; --2 when 31=> index0<="00000010"; --2 when others => null; end case; else index0<=index2; --键盘输入音符信号输出 end if; end process; end Behavioral; (2)自动演奏模块程序仿真 自动演奏模块仿真图如图8.17.5所示。 图8.18.5 自动演奏模块仿真图 (注:由于输入频率太高,实验条件所限,如按源程序仿真将看不到输出波形,因此将原脉冲的分频点4000000和8000000改为4和8,得到如图的仿真结果,在实际烧制芯片中不作此处理。)
本文档为【第8章程序部分8.18 电子琴程序设计与仿真 2004.8修改】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_388858
暂无简介~
格式:doc
大小:106KB
软件:Word
页数:6
分类:互联网
上传时间:2018-09-08
浏览量:30