EDA樂曲播放電路課程設(shè)計(jì)報(bào)告_第1頁
EDA樂曲播放電路課程設(shè)計(jì)報(bào)告_第2頁
EDA樂曲播放電路課程設(shè)計(jì)報(bào)告_第3頁
EDA樂曲播放電路課程設(shè)計(jì)報(bào)告_第4頁
EDA樂曲播放電路課程設(shè)計(jì)報(bào)告_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、目錄一.課程設(shè)計(jì)概述11.設(shè)計(jì)的題目2 2.設(shè)計(jì)要求2 3.設(shè)計(jì)構(gòu)思2二.總體框圖4三.具體各功能模塊(模塊圖像,程序,波形圖像,波形分析)21.計(jì)數(shù)器模塊2 2.選擇器模塊4 3.數(shù)據(jù)翻譯模塊6 4.數(shù)控分頻模塊7 5.樂曲ROM的三個(gè)模塊10 6.頂層文件的設(shè)計(jì)12 四.總體電路圖(RLT電路圖)14 五.課程設(shè)計(jì)總結(jié)15一.課程設(shè)計(jì)概述1.設(shè)計(jì)的題目樂曲播放電路2.設(shè)計(jì)要求:學(xué)習(xí)利用數(shù)控分頻器設(shè)計(jì)硬件樂曲演奏電路,在實(shí)驗(yàn)四的基礎(chǔ)上,改建電路的設(shè)計(jì),增加功能自動(dòng)選擇曲目,可選的歌曲不少于3首。3.設(shè)計(jì)構(gòu)思(1)音樂硬件演奏電路基本原理 硬件電路的發(fā)聲原理,聲音的頻譜范圍約在幾十到幾千赫茲,

2、若能利用程序來控制FPGA芯片某個(gè)引腳輸出一定頻率的矩形波,接上揚(yáng)聲器就能發(fā)出相應(yīng)頻率的聲音。樂曲中的每一音符對應(yīng)著一個(gè)確定的頻率,要想FPGA發(fā)出不同音符的音調(diào),實(shí)際上只要控制它輸出相應(yīng)音符的頻率即可。樂曲都是由一連串的音符組成,因此按照樂曲的樂譜依次輸出這些音符所對應(yīng)的頻,就可以在揚(yáng)聲器上連續(xù)地發(fā)出各個(gè)音符的音調(diào)。而要準(zhǔn)確地演奏出一首樂曲,僅僅讓揚(yáng)聲器能夠發(fā)生是不夠的,還必須準(zhǔn)確地控制樂曲的節(jié)奏,即樂曲中每個(gè)音符的發(fā)生頻率及其持續(xù)時(shí)間是樂曲能夠連續(xù)演奏的兩個(gè)關(guān)鍵因素。(2) 音符頻率的獲得多個(gè)不同頻率的信號可通過對某個(gè)基準(zhǔn)頻率進(jìn)行分頻器獲得。由于各個(gè)音符的頻率多為非整數(shù),而分頻系數(shù)又不能為

3、小數(shù),故必須將計(jì)算機(jī)得到的分頻系數(shù)四舍五入取整。若基準(zhǔn)頻率過低,則分頻系數(shù)過小,四舍五入取整后的誤差較大。若基準(zhǔn)頻率過高,雖然可以減少頻率的相對誤差,但分頻結(jié)構(gòu)將變大。實(shí)際上應(yīng)該綜合考慮這兩個(gè)方面的因素,在盡量減少誤差的前提下,選取合適的基準(zhǔn)頻率。本設(shè)計(jì)中選取1MHz的基準(zhǔn)頻率。數(shù)控分頻器采用12位二進(jìn)制計(jì)數(shù)器,樂曲中的休止符,只要將分頻系數(shù)設(shè)為0,即初始值=4095,此時(shí)揚(yáng)聲器不會(huì)發(fā)聲。根據(jù)分頻系數(shù),可計(jì)算數(shù)控分頻器得到的初始值。(語言已經(jīng)無法描述其中的原理了,程序可以說明此問題,關(guān)于初始值的解釋,請看下文給出的程序)初始值的計(jì)算公式如下:由于所設(shè)計(jì)的數(shù)控分頻計(jì)采用12MHZ作為時(shí)鐘源,并通

4、過一次12分頻給出頻率為1MHZ的脈沖溢出信號,再對該1MHZ的溢出信號進(jìn)行12位2進(jìn)制碼的帶預(yù)置數(shù)進(jìn)行計(jì)數(shù),并給出一個(gè)頻率隨預(yù)置數(shù)變化的脈沖信號。由于該脈沖信號不具有驅(qū)動(dòng)蜂鳴器的能力,故對此脈沖信號進(jìn)行2分頻以推動(dòng)蜂鳴器發(fā)聲(3) 樂曲節(jié)奏的控制 一般樂曲最小的節(jié)拍為1/4拍,若將1拍的時(shí)間定為1秒,則只需要輸出4Hz的1/4拍的時(shí)長(0.25秒),對于其它占用時(shí)間較長的節(jié)拍(必為1/4拍的整數(shù)倍)則只需要將該音符連續(xù)輸出相應(yīng)的次數(shù)即可。計(jì)數(shù)時(shí)鐘信號作為輸出音符快慢的控制信號,時(shí)鐘快時(shí)輸出節(jié)拍速度就快,演奏的速度也就快,時(shí)鐘慢時(shí)輸出節(jié)拍的速度就慢,演奏的速度自然降低,由于最后的蜂鳴器前需加一

5、個(gè)二分頻的程序,因此計(jì)數(shù)器的時(shí)鐘信號應(yīng)為4Hz的2倍,即8Hz。(4) 樂譜的發(fā)生本設(shè)計(jì)將樂譜中的音符數(shù)據(jù)存儲(chǔ)在LPM-ROM中,若某音在邏輯中停留了4個(gè)時(shí)鐘節(jié)拍,即1秒的時(shí)間,相應(yīng)地,該音符就要在LPM-ROM中連續(xù)的四個(gè)地址上都存儲(chǔ)。當(dāng)一個(gè)4Hz的時(shí)鐘來時(shí),相應(yīng)地就從LPM-ROM中輸出一個(gè)音符數(shù)據(jù)。(5) 選擇模塊 選擇模塊將用一個(gè)4位數(shù)的控制信號控制樂譜模塊數(shù)據(jù)的選擇性。梁祝二.總體框圖時(shí)鐘計(jì)數(shù)器數(shù)控分頻器選擇器生日快樂隱形的翅膀時(shí)鐘三.具體各功能模塊1.計(jì)數(shù)器模塊在notetabs中設(shè)置了一個(gè)8位二進(jìn)制計(jì)數(shù)器(計(jì)數(shù)最大值為138),作為音符數(shù)據(jù)ROM的地址發(fā)生器。這個(gè)計(jì)數(shù)器的計(jì)數(shù)頻率

6、為4HZ,即每一計(jì)數(shù)值的停留時(shí)間為0.25秒,恰為當(dāng)全音符設(shè)為1秒時(shí),四四拍的4分音符持續(xù)的時(shí)間。例如,notetabs在以下的VHDL邏輯描述中,梁祝樂曲的第一個(gè)音符為“3”,此音在邏輯中停留了4個(gè)時(shí)鐘節(jié)拍,即1秒的時(shí)間,相應(yīng)的,所對應(yīng)的“3”音符分頻預(yù)制值為1036,在speakera中的輸入端停留1秒。隨著notetabs中計(jì)數(shù)器按4HZ的時(shí)鐘頻率作加法計(jì)數(shù)時(shí),即隨地址值遞增時(shí),音符數(shù)據(jù)ROM中的音符從ROM中通過tonelndex端口輸向tonetaba模塊,梁祝樂曲開始連續(xù)自然地演奏起來。(1)模塊圖像:(2)模塊程序library ieee;use ieee.std_logic_1

7、164.all;use ieee.std_logic_unsigned.all;entity notetabs is port (clk:in std_logic; counter:inout std_logic_vector(7 downto 0);end;architecture one of notetabs is begin cnt8:process(clk,counter) begin if counter =138 then counter <="00000000" elsif (clk'event and clk='1') the

8、n counter <=counter+1; end if; end process; end;(3)仿真波形(4)波形分析由波形可看出來,CLK為輸入時(shí)鐘信號,八位輸出二進(jìn)制信號在時(shí)鐘上升沿加一,經(jīng)分析,該模塊的功能正確。2.選擇模塊選擇器完成歌曲的選擇功能,當(dāng)a輸入為0001時(shí),將Q1信號輸出,對應(yīng)歌曲為梁祝;當(dāng)a為0010時(shí),將Q2的信號輸出,對應(yīng)的歌曲為隱形的翅膀;當(dāng)a為0011時(shí),將Q3的信號輸出,對應(yīng)的歌曲為生日快樂。(1)模塊圖像(2)程序;LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_UNSIG

9、NED.ALL; ENTITY choice IS PORT(a: IN STD_LOGIC_vector(3 downto 0); b:out STD_LOGIC_vector(3 downto 0); INDEX :OUT STD_LOGIC_vector(4 downto 0); Q1:IN STD_LOGIC_vector(4 downto 0); Q2:IN STD_LOGIC_vector(4 downto 0);Q3:IN STD_LOGIC_vector(4 downto 0); END choice; ARCHITECTURE a OF choice IS BEGIN PRO

10、CESS (a,Q1,Q2,Q3) BEGIN CASE a IS WHEN "0001" => b<="0001" INDEX<=Q1; WHEN "0011" => b<="0010" INDEX<=Q2; WHEN "0010" => b<="0011" INDEX<=Q3; WHEN OTHERS => null; END CASE; END PROCESS; END a;(3)波形圖(4)波形分析由波形分析

11、可知,當(dāng)a輸入為0001時(shí),輸出信號b與Q1信號相同,即播放第一首樂曲,此時(shí)b的信號輸出為0001,因此該模塊的功能符合要求。3.數(shù)據(jù)翻譯模塊音符的持續(xù)時(shí)間需根據(jù)樂曲的速度及每個(gè)音符的節(jié)拍數(shù)來決定。Tonetaba模塊的功能首先是為speakera提供決定所發(fā)音符的分頻預(yù)置數(shù),而此數(shù)在speakera輸入口停留的時(shí)間即為此音符的節(jié)拍值。模塊tonetaba是樂曲簡譜碼對應(yīng)的分頻預(yù)置數(shù)查表電路,其中設(shè)置了三首樂曲全部音符所對應(yīng)的分頻預(yù)置數(shù),每一音符的停留時(shí)間有音樂節(jié)拍和音調(diào)發(fā)生器模塊notetabs的CLK的輸入決定,在此為4HZ。(1)模塊圖像(2)程序library ieee;use iee

12、e.std_logic_1164.all;entity tonetaba is port (index:in std_logic_vector(4 downto 0); code: out std_logic_vector (4 downto 0); high: out std_logic; tone:out std_logic_vector(10 downto 0); end; architecture one of tonetaba isbegin search:process(index) begin case index is When "00001"=>to

13、ne<="01100000101"code<="00001"high<='0' When "00010"=>tone<="01110010000"code<="00010"high<='0' When "00011"=>tone<="10000001100"code<="00011"high<='0' When "

14、00100"=>tone<="10000110101"code<="00100"high<='0' When "00101"=>tone<="10010101101"code<="00101"high<='0' When "00110"=>tone<="10100001010"code<="00110"high<='

15、0' When "00111"=>tone<="10101011100"code<="00111"high<='0' When "01000"=>tone<="10110000010"code<="01000"high<='1' When "01001"=>tone<="10111001000"code<="01001&q

16、uot;high<='1' When "01010"=>tone<="11000000110"code<="01010"high<='1' When "01011"=>tone<="11000101000"code<="01011"high<='1' When "01100"=>tone<="11001010110"code

17、<="01100"high<='1' When "01101"=>tone<="11010000100"code<="01101"high<='1' When "01110"=>tone<="11010110101"code<="01110"high<='1' When "01111"=>tone<="110

18、11000000"code<="10001"high<='1' When "10000"=>tone<="11011101010"code<="10010"high<='1' When "10001"=>tone<="11100000111"code<="10011"high<='1' When "10010"=>

19、tone<="11100010110"code<="10100"high<='1' When "10011"=>tone<="11100101111"code<="10101"high<='1' When "10100"=>tone<="11101000110"code<="10110"high<='1' When &quo

20、t;10101"=>tone<="11101011010"code<="10111"high<='1'when others =>null;end case;end process;end;(3)波形圖(4)波形分析從波形圖可看出,當(dāng)輸入信號為00010,輸出為中音2,查預(yù)置初值,發(fā)現(xiàn)完全正確,因此該模塊功能正確。4.數(shù)控分頻器模塊音符的頻率由speakera模塊獲得,這是一個(gè)數(shù)控分頻器。由其CLK端輸入一具有較高頻率(這里是12HZ)的信號,通過speakera分頻后由spkout輸出,由于直接從

21、數(shù)控分頻器中出來的輸出信號是脈寬極窄的脈沖式信號,為了有利于驅(qū)動(dòng)揚(yáng)聲器,需另加一個(gè)D觸發(fā)器以均衡其占空比,但這時(shí)的頻率將是原來的一半。Speakera對CLK輸入信號的分頻比由11位預(yù)置數(shù)tone決定。Spkout的輸出頻率將決定每一音符的音調(diào),這樣,分頻計(jì)數(shù)器的預(yù)制值tone與spkout的輸出頻率,就有了對應(yīng)關(guān)系。例如在tonetaba模塊中若取tone=1036,將發(fā)音符為“3”音的信號頻率。(1)模塊圖像(2)程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity speake

22、ra is port ( clk : in std_logic; tone : in std_logic_vector(10 downto 0); spks : out std_logic);end;architecture one of speakera is signal preclk, fullspks : std_logic;begin divideclk : process(clk) variable count4 : std_logic_vector (3 downto 0); begin preclk <= '0' if count4>11 then

23、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 preclk = '1' then if count11 =16#7ff# then

24、 count11 := tone ; fullspks <= '1' else count11 := count11+1; fullspks <= '0' end if; end if; end process; delayspks : process(fullspks) variable count2 : std_logic;begin if fullspks'event and fullspks = '1' then count2 := not count2; if count2 ='1' then spk

25、s <='1' else spks <='0' end if; end if; end process;end;(3)波形圖(4)波形分析由波形圖分析,當(dāng)tone給出不同的分頻預(yù)置數(shù),觀察到分頻效果是正確的,因此該模塊的功能符合設(shè)計(jì)要求。 5.樂曲ROM的三個(gè)模塊:(1)梁祝 width = 5;depth = 256;address_radix = dec;data_radix = dec;content begin00: 3;01: 3;02: 3;03: 3;04: 5;05: 5;06: 5;07: 6;08: 8;09: 8;10: 8;1

26、1: 9;12: 6;13: 8;14: 5;15: 5;16: 12;17: 12;18: 12;19: 15;20: 13;21: 12;22: 10;23:12;24:9;25:9;26:9;27:9;28:9;29:9;30:9;31:0;32:9;33:9;34:9;35:10;36:7;37:7;38:6;39:6;40:5;41:5;42:5;43:6;44:8;45:8;46:9;47:9;48:3;49:3;50:8;51:8;52:6;53:5;54:6;55:8;56:5;57:5;58:5;59:5;60:5;61:5;62:5;63:5;64:10;65:10;66:

27、10;67:12;68:7;69:7;70:9;71:9;72:6;73:8;74:5;75:5;76:5;77:5;78:5;79:5;80:3;81:5;82:3;83:3;84:5;85:6;86:7;87:9;88:6;89:6;90:6;91:6;92:6;93:6;94:5;95:6;96:8;97:8;98:8;99:9;100:12;101:12;102:12;103:10;104:9;105:9;106:10;107:9;108:8;109:8;110:6;111:5;112:3;113:3;114:3;115:3;116:8;117:8;118:8;119:8;120:6;

28、121:8;122:6;123:5;124:3;125:5;126:6;127:8;128:5;129:5;130:5;131:5;132:5;133:5;134:5;135:5;136:0;137:0;138:0;end;(2)生日快樂WIDTH=5; DEPTH=256; ADDRESS_RADIX=DEC; DATA_RADIX=DEC; CONTENT BEGIN 00:13; 01:13; 02:13; 03:13; 04:13; 05:13; 06:13; 07:12; 08:12; 09:10; 10:10; 11:10; 12:10; 13:12; 14:12; 15:12;

29、16:12; 17:15; 18:15; 19:15; 20:15; 21:13; 22:13; 23:12; 24:12; 25:13; 26:13; 27:13; 28:13; 29:13; 30:13; 31:13; 32:13; 33:10; 34:10; 35:10; 36:10; 37:12; 38:12; 39:13; 40:13; 41:12; 42:12; 43:12; 44:12; 45:10; 46:10; 47:10; 48:10; 49: 8; 50: 8; 51: 6; 52: 6; 53:12; 54:12; 55:10; 56:10; 57: 9; 58: 9;

30、 59: 9; 60: 9; 61: 9; 62: 9; 63: 9; 64: 9; 65: 9; 66: 9; 67: 9; 68: 9; 69: 9; 70: 9; 71:10; 72:10; 73:12; 74:12; 75:12; 76:12; 77:12; 78:12; 79:13; 80:13; 81:10; 82:10; 83:10; 84:10; 85: 9; 86: 9; 87: 9; 88: 9; 89: 8; 90: 8; 91: 8; 92: 8; 93: 8; 94: 8; 95: 8; 96: 8; 97:12; 98:12; 99:12; 100:12; 101:

31、12; 102:12; 103:10; 104:10; 105: 9; 106: 9; 107: 8; 108: 8; 109: 6; 110: 6; 111: 8; 112: 8; 113: 5; 114: 5; 115: 5; 116: 5; 117: 5; 118: 5; 119: 5; 120: 5; 121: 5; 122: 5; 123: 5; 124: 5; 125: 0; 126: 0; 127: 0;128: 0;129: 0;130: 0;131: 0;131: 0;132: 0;133: 0;134: 0;135: 0;136: 0;137: 0;138: 0; END;

32、(3)隱形的翅膀WIDTH=5; DEPTH=256; ADDRESS_RADIX=DEC; DATA_RADIX=DEC; CONTENT BEGIN 00: 10; 01: 10; 02: 12; 03:12; 04:15; 05:15; 06:15; 07:15; 08:15; 09:15; 10:15; 11:15; 12:15; 13:15; 14:15; 15:15; 16:13; 17:13; 18:12; 19:12; 20:13; 21:13; 22:15; 23:15; 24:10; 25:10; 26: 9; 27: 9; 28: 8; 29: 8; 30: 8; 31:

33、 8; 32: 8; 33: 8; 34: 8; 35:8; 36: 8; 37: 8; 38:15; 39:15; 40:15; 41:15; 42:13; 43:13; 44:12; 45:12; 46:10; 47:10; 48:9; 49:9; 50: 8; 51: 9; 52: 9; 53: 9; 54: 9; 55: 9; 56: 9; 57: 9; 58: 9; 59: 9; 60: 10; 61:10; 62:12; 63:12; 64:15; 65:15; 66:15; 67:15; 68:15; 69:15; 70:15; 71:15; 72:15; 73:15; 74:1

34、5; 75:15; 76:13; 77:13; 78:12; 79:12; 80:13; 81:13; 82:15; 83:15; 84:10; 85:10; 86:9; 87:9; 88: 8; 89: 8; 90: 8; 91: 8; 92: 8; 93: 8; 94: 8; 95: 8; 96: 8; 97: 8; 98:15; 99:15; 100:15; 101:15; 102:13; 103:13; 104:12; 105:12; 106:10; 107:10; 108: 9; 109: 9; 110: 8; 111: 8; 112: 8; 113: 8; 114: 8; 115:

35、 8; 116: 8; 117: 8; 118: 8; 119: 8; 120: 10; 121:10; 122:12; 123:12; 124:15; 125:15; 126:15; 127:15; 128:15; 129:15; 130:15; 131:15; 132:14; 133:14; 134:14; 135:14; 136:13; 137:13; 138:12; end; 6. 頂層文件的設(shè)計(jì): library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity yinyuehe ispor

36、t (clk12MHZ:in std_logic; clk8HZ:in std_logic; code1:out std_logic_vector (4 downto 0); high1:out std_logic; a1:in std_logic_vector(3 downto 0); b1:OUT std_logic_vector(3 downto 0); spkout:out std_logic);end;architecture one of yinyuehe is component notetabs is port (clk:in std_logic; counter:inout

37、std_logic_vector(7 downto 0); end component; component yinxingdechiban ISPORT(address: IN STD_LOGIC_VECTOR (7 DOWNTO 0);clock: IN STD_LOGIC ;q: OUT STD_LOGIC_VECTOR (4 DOWNTO 0) ); END component; component shengrikuaile ISPORT(address: IN STD_LOGIC_VECTOR (7 DOWNTO 0);clock: IN STD_LOGIC ;q: OUT STD

38、_LOGIC_VECTOR (4 DOWNTO 0); END component ; component lianzu ISPORT(address: IN STD_LOGIC_VECTOR (7 DOWNTO 0);clock: IN STD_LOGIC ;q: OUT STD_LOGIC_VECTOR (4 DOWNTO 0); END component; component choice IS PORT(a: IN STD_LOGIC_vector(3 downto 0); b:out STD_LOGIC_vector(3 downto 0); INDEX :OUT STD_LOGIC_vector(4 downto 0); Q1:IN STD_LOGIC_vector(4 downto 0); Q2:IN STD_LOGIC_vector(4 downto 0); Q3:IN STD_LOGIC_vector(4 downto 0); END component; component tonetaba is port (index:in std_logic_vector(4 downto 0); code: o

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論