數(shù)字邏輯課程設(shè)計(jì)之電子琴_第1頁
數(shù)字邏輯課程設(shè)計(jì)之電子琴_第2頁
數(shù)字邏輯課程設(shè)計(jì)之電子琴_第3頁
數(shù)字邏輯課程設(shè)計(jì)之電子琴_第4頁
數(shù)字邏輯課程設(shè)計(jì)之電子琴_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、數(shù)字邏輯課程設(shè)計(jì)之電子琴實(shí)驗(yàn)內(nèi)容:設(shè)計(jì)一個(gè)八音電子琴,能通過八個(gè)鍵進(jìn)行手動控制音響,也可以通過自動控制有效自動播放一段音樂。實(shí)驗(yàn)設(shè)計(jì):本實(shí)驗(yàn)分為四個(gè)模塊:一個(gè)模塊是主程序,一個(gè)模塊是自動播放音樂部分,一個(gè)模塊是音調(diào)發(fā)生器部分,一個(gè)模塊是數(shù)控分頻部分。通過接口和結(jié)構(gòu)體component的定義將各個(gè)模塊連接起來。本程序總的有11個(gè)輸入,1個(gè)輸出,2個(gè)輸入為時(shí)鐘脈沖,1個(gè)輸入是控制電子琴自動演奏或者手動演奏的使能端,8個(gè)輸入端為電子琴的八個(gè)鍵,1個(gè)輸出為揚(yáng)聲器輸出音樂。在音調(diào)發(fā)生器部分中,需要按照模=50000/頻率的方法進(jìn)行分頻,但是要達(dá)到提高音量使占空比為50%的效果還需要再對信號進(jìn)行二分頻,因

2、此最后得到的音調(diào)發(fā)生器進(jìn)行分頻預(yù)置值如下:音符 (C)1234567i頻率(Hz)262294330349392440494523模9585757163565047當(dāng)某位音符電平輸入有效時(shí),對應(yīng)不同的分頻預(yù)置值,將分頻預(yù)置值輸出并作為數(shù)控分頻部分的輸入,分頻預(yù)置值控制對主頻的分頻。在數(shù)控分頻部分,將輸入的分頻預(yù)置值和時(shí)鐘脈沖作為輸入,最后輸出直接連接揚(yáng)聲器。這一部分一共包含了兩個(gè)進(jìn)程,第一個(gè)進(jìn)程是根據(jù)不同音符的不同頻率進(jìn)行在主頻下進(jìn)行分頻,得到音符的相應(yīng)頻率,第二個(gè)進(jìn)程是為了提高音量使占空比為50%而進(jìn)行二分頻。在自動播放部分,1個(gè)時(shí)鐘脈沖輸入,1個(gè)自動播放的使能端輸入,還有8個(gè)音符的鍵為輸入

3、,輸出為音符對應(yīng)的8位高低電平,輸出連接到音調(diào)發(fā)生器的8位輸入,如果自動播放的使能端(auto)無效則進(jìn)行手動操作,在手動操作下,該模塊的輸出直接為輸入。如果自動播放的使能端輸入有效,則播放事先存儲的一段音樂,首先將主頻50進(jìn)行10000分頻,因此一個(gè)脈沖為.秒,每來一個(gè)脈沖進(jìn)行計(jì)數(shù)并播放一個(gè)音符。直到設(shè)置的音符全部播放完畢,計(jì)數(shù)器回。源代碼:主模塊部分:定義了結(jié)構(gòu)體和各模塊函數(shù)library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity

4、piano is port(clk0,clk1:in std_logic; auto:in std_logic; inplay:in std_logic_vector(7 downto 0); play:out std_logic); end piano;architecture run of piano is component autoplay is自動播放部分 port(A:in std_logic_vector(7 downto 0); B,C:in std_logic; D:out std_logic_vector(7 downto 0); end component; compon

5、ent tone is音調(diào)發(fā)生器部分 port(A:in std_logic_vector(7 downto 0); B:out integer range 0 to 170); end component; component control is數(shù)控分頻部分 port(A:in std_logic; B:in integer range 0 to 170; C:out std_logic); end component; signal sw0:std_logic_vector(7 downto 0);自動播放部分的輸出和音調(diào)發(fā)生器的輸入,表示八個(gè)音符 signal tone0:intege

6、r range 0 to 170;音調(diào)發(fā)生器的輸出和數(shù)控分頻部分的輸入,表示音符的頻率begin 在這個(gè)進(jìn)程中把各個(gè)部分連接起來 G1:autoplay port map(A=>inplay,B=>auto,C=>clk0,D=>sw0); G2:tone port map(A=>sw0,B=>tone0); G3:control port map(A=>clk1,B=>tone0,C=>play);end run;自動播放模塊:library ieee;use ieee.std_logic_1164.all;use ieee.std_lo

7、gic_arith.all;use ieee.std_logic_unsigned.all;entity autoplay is port(A:in std_logic_vector(7 downto 0); -A=>inplay,B=>auto,C=>clk0,D=>sw0 B,C:in std_logic; D:out std_logic_vector(7 downto 0);end autoplay;architecture music of autoplay is signal clk2:std_logic; -對50脈沖進(jìn)行分頻得到的的脈沖信號 signal

8、count0:integer range 0 to 62; -記錄自動播放的樂曲的脈沖并控制播放 signal count3:integer range 0 to 10000;-分頻時(shí)的計(jì)數(shù) begin separate:process(C,B)分頻將脈沖變?yōu)榈男盘?begin if B='0' then count3<=0;clk2<='0' elsif(C'event and C='1') then count3<=count3+1; if count3=5000 then clk2<='1'

9、elsif count3=10000 then clk2<='0'count3<=0; end if; end if; end process; half:process(clk2) begin if(clk2'event and clk2='1') then如果脈沖個(gè)數(shù)多于自動播放的音符,則計(jì)數(shù)器回,否則記錄第幾個(gè)脈沖 if count0=62 then count0<=0; else count0<=count0+1; end if; end if; end process; musicplay:process(C,B,A)

10、begin if B='1' then啟動自動播放后,在的脈沖下,每來一個(gè)脈沖相應(yīng)播放一個(gè)音符 case count0 is when 0 => D<="00010000" when 1 => D<="00000100" when 2 => D<="00000100" when 3 => D<="00000100" when 4 => D<="00001000" when 5 => D<="0000

11、0010" when 6 => D<="00000010" when 7 => D<="00000010" when 8 => D<="00000001" when 9 => D<="00000010" when 10 => D<="00000100" when 11 => D<="00001000" when 12 => D<="00010000" when 1

12、3 => D<="00010000" when 14 => D<="00010000" when 15 => D<="00010000" when 16 => D<="00010000" when 17 => D<="00000100" when 18 => D<="00000100" when 19 => D<="00001000" when 20 => D<

13、="00000010" when 21 => D<="00000010" when 22 => D<="00000010" when 23 => D<="00000001" when 24 => D<="00000100" when 25 => D<="00010000" when 26 => D<="00010000" when 27 => D<="000000

14、01" when 28 => D<="00000001" when 29 => D<="00000001" when 30 => D<="00000001" when 31 => D<="00000010" when 32 => D<="00000010" when 33 => D<="00000010" when 34 => D<="00000010" when

15、 35 => D<="00000010" when 36 => D<="00000100" when 37 => D<="00001000" when 38 => D<="00001000" when 39 => D<="00000100" when 40 => D<="00000100" when 41 => D<="00000100" when 42 => D&l

16、t;="00000100" when 43 => D<="00000100" when 44 => D<="00001000" when 45 => D<="00010000" when 46 => D<="00010000" when 47 => D<="00010000" when 48 => D<="00000100" when 49 => D<="0000

17、0100" when 50 => D<="00000100" when 51 => D<="00001000" when 52 => D<="00000010" when 53 => D<="00000010" when 54 => D<="00000010" when 55 => D<="00000001" when 56 => D<="00000100" wh

18、en 57 => D<="00010000" when 58 => D<="00010000" when 59 => D<="00000001" when 60 => D<="00000001" when 61 => D<="00000001" when 62 => D<="00000001" when others => null; end case; else D<=A;如果不進(jìn)行自動播放

19、,則將輸入位音符直接輸出,并且不執(zhí)行前兩個(gè)進(jìn)程的操作 end if; end process;end music;音調(diào)發(fā)生器模塊:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity tone is port(A:in std_logic_vector(7 downto 0);輸入的是位音符的電平 B:out integer range 0 to 170);輸出的是各音符對應(yīng)的模值end tone;architecture rtl

20、of tone isbegin search:process(A) begin case A is when "00000001" =>B<=95; when "00000010" =>B<=85; when "00000100" =>B<=75; when "00001000" =>B<=71; when "00010000" =>B<=63; when "00100000" =>B<=56; when

21、 "01000000" =>B<=50; when "10000000" =>B<=47; when others =>B<=170; end case; end process;end rtl;數(shù)控分頻模塊:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity control is port(A:in std_logic;時(shí)鐘信號 B:in integer

22、 range 0 to 170;各音符的模值 C:out std_logic);end control;architecture abc of control is signal spk:std_logic; begintwoclock:process(A,B)將各個(gè)音符按照不同的模值分頻得到各音符的頻率的倍 variable count1:integer range 0 to 170; begin if(A'event and A='1') then if count1=B then count1:=0;spk<='1' else count1:=count1+1;spk<='0' end if; end if; end process;reverse:process(spk)二分頻使占空比為并直接輸出 variable count2:std_logic; begin

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(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

提交評論