基于VHDL紅外無線燈控系統(tǒng)_第1頁
基于VHDL紅外無線燈控系統(tǒng)_第2頁
基于VHDL紅外無線燈控系統(tǒng)_第3頁
基于VHDL紅外無線燈控系統(tǒng)_第4頁
基于VHDL紅外無線燈控系統(tǒng)_第5頁
已閱讀5頁,還剩15頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、儀電學(xué)院2014年夏季可編程器件及數(shù)字系統(tǒng)設(shè)計(jì)實(shí)習(xí)報(bào)告可編程器件及數(shù)字系統(tǒng)設(shè)計(jì)-基于VHDL的紅外無線燈控系統(tǒng)學(xué)號(hào):65130109姓名:周葛16一:摘要1二:關(guān)鍵字1三:引言1四:系統(tǒng)模塊組成24.1硬件部分24.1.1 核心器件24.1.2 1838一體紅外接收頭24.1.3 成品遙控器34.2模塊組成34.2.1數(shù)碼管顯示模塊34.2.2分頻模塊44.2.3紅外解碼及控制模塊54.3整體系統(tǒng)連接64.3.1頂部實(shí)體原理圖64.3.2文檔結(jié)構(gòu)圖6五:NEC協(xié)議以及紅外解碼過程75.1 NEC協(xié)議介紹75.2 紅外解碼過程85.2.1 設(shè)計(jì)原理85.2.2 解碼電路設(shè)計(jì)過程8六:各模塊源代碼

2、106.1數(shù)碼管驅(qū)動(dòng)模塊10-dongtai.vhd-10-shumaguan.vhd-11-yima38-126.2分頻模塊13-fenpin.vhd-136.3紅外解碼及控制模塊13-MUC.vhd-13七:實(shí)習(xí)設(shè)計(jì)總結(jié)16一:摘要本系統(tǒng)硬件由成品遙控發(fā)射器,1838紅外接收頭,CPLD芯片(EMP570T100C5),八位數(shù)碼管,12個(gè)LED燈組成,軟件用 VHDL 語言有限狀態(tài)機(jī)設(shè)計(jì)紅外遙控解碼電路,并控制LED燈。編譯環(huán)境為Quartus II 9.1。實(shí)現(xiàn)的功能為通過紅外遙控控制12個(gè)燈的亮滅。該電路在 EPM570T100C5 器件驗(yàn)證通過,解碼準(zhǔn)確,穩(wěn)定性好。紅外通信采用NEC

3、協(xié)議,載波頻率為38KHz。二:關(guān)鍵字遙控器解碼;狀態(tài)機(jī);VHDL;CPLD。三:引言由于紅外遙控其體積小、功耗低、功能強(qiáng)、成本低等特點(diǎn),在日常的家電(如電視、音響設(shè)備、空調(diào)、電風(fēng)扇等)都采用紅外線遙控。在有輻射、高壓、有毒氣體等危險(xiǎn)環(huán)境下工作的工業(yè)設(shè)備普遍采用紅外線遙控來完成設(shè)備的操作。紅外線遙控是目前使用最廣泛的一種通信和遙控手段。采用CPLD器件,對紅外信號(hào)解碼并控制12路燈的亮滅,很具有使用價(jià)值,進(jìn)一步加深對硬件描述語言VHDL的理解和應(yīng)用能力。此外,在此系統(tǒng)的基礎(chǔ)上能通過紅外遙控控制更多的器件,因此,本系統(tǒng)還具有充足的擴(kuò)展,升級空間。四:系統(tǒng)模塊組成4.1硬件部分4.1.1 核心器件

4、使用一塊核心板(CPLD器件EMP570T100C5)及焊的一塊實(shí)驗(yàn)板(集成了八位點(diǎn)陣,16個(gè)LED燈等)。數(shù)碼管顯示紅外解碼結(jié)果。12個(gè)LED燈模擬實(shí)際生活中的燈。4.1.2 1838一體紅外接收頭 1838一體紅外接收頭 (如圖)使用時(shí)一般在電源腳間加上濾波電容。4.1.3 成品遙控器成品遙控器(如圖左),功能對照表(如圖右)4.2模塊組成4.2.1數(shù)碼管顯示模塊此模塊有八組五位二進(jìn)制輸入用來輸入每位顯示的數(shù)字的編碼,二組四位二進(jìn)制輸入控制拿來那兩個(gè)位閃動(dòng),一個(gè)時(shí)鐘輸入。輸出有八位段選輸出用來連接數(shù)碼管段選端,八位位選輸出,用來連接數(shù)碼管位選端。使用時(shí),從八組五位輸入端分別輸入待顯示的編碼

5、(五位),從時(shí)鐘輸入端輸入時(shí)鐘信號(hào),需要閃動(dòng)時(shí)從兩組四位輸入端輸入需要閃動(dòng)的位的二進(jìn)制編碼(四位),不需要時(shí)輸入一個(gè)大于7的二進(jìn)制碼即可。連接好段選、位選端即能使用。4.2.2分頻模塊此模塊用于將2.048MHz的時(shí)鐘頻率分頻為周期為0.125ms的時(shí)鐘信號(hào)。擁有一個(gè)時(shí)鐘輸入端,一個(gè)分頻后時(shí)鐘輸出端。4.2.3紅外解碼及控制模塊此模塊為中心模塊,用于將經(jīng)過1838接收解調(diào)后的紅外信號(hào)進(jìn)行解碼,并且根據(jù)解得的數(shù)據(jù)碼控制各路LED燈的亮滅情況。4.3整體系統(tǒng)連接4.3.1頂部實(shí)體原理圖4.3.2文檔結(jié)構(gòu)圖 五:NEC協(xié)議以及紅外解碼過程5.1 NEC協(xié)議介紹為方便理解所看到的波形是從紅外接收管出來

6、的信號(hào),跟協(xié)議所說的信號(hào)高低(0或1)剛好相反。 NEC協(xié)議是眾多紅外遙控協(xié)議的其中一種,除NEC外,還有RC5、RC6等其它的。市面上買到的非學(xué)習(xí)型萬能電視遙控器大多集成一種或多種編碼是NEC型的,我買的二個(gè)遙控器中就有三種以上編碼是NEC的。NEC編碼的一幀(通常按一下遙控器按鈕所發(fā)送的數(shù)據(jù))由引導(dǎo)碼、地址碼及數(shù)據(jù)碼組成,,如下圖所示,把地址碼及數(shù)據(jù)碼取反的作用是加強(qiáng)數(shù)據(jù)的正確性。引導(dǎo)碼及數(shù)據(jù)的定義如下圖所示,當(dāng)一直按住一個(gè)按鈕的時(shí)候,會(huì)隔110ms左右發(fā)一次引導(dǎo)碼(重復(fù)),并不帶任何數(shù)據(jù) 5.2 紅外解碼過程5.2.1 設(shè)計(jì)原理識(shí)別引導(dǎo)碼方法很簡單,只需要兩段延時(shí)即可。數(shù)據(jù)解碼的核心是如

7、何識(shí)別二進(jìn)制數(shù)碼“0”和“1” 。從上述可知紅外線接收頭輸出的電平信號(hào)相位相反, 即以0.56 ms的低電平和0.565 ms高電平組合表示“0” ;以0.56 ms的低電平跟1.69 ms高電平組合表示 “1” , 它們都是以0.56 ms的低電平開始,以不同的高電平寬度來區(qū)分“0”和“1” 。如果從0.56 ms低電平過后,開始延時(shí)0.565 ms,隨后檢測輸入的狀態(tài),若讀到的為低電平,則說明該位為“0” ,反之則為“1” ,為了可靠起見, 延時(shí)時(shí)間應(yīng)該大于0.565 ms, 但不能超過1.125 ms,否則如果該位為“0” ,讀到的已是下一位的高電平。因此,可以用VHDL語言的有限狀態(tài)機(jī)

8、來檢測輸入電平,實(shí)現(xiàn)狀態(tài)轉(zhuǎn)換和判斷,并結(jié)合延時(shí)電路來識(shí)別“0”和“1” 。5.2.2 解碼電路設(shè)計(jì)過程該控制電路采用VHDL語言的有限狀態(tài)機(jī)設(shè)計(jì)方法來描述和實(shí)現(xiàn),其狀態(tài)轉(zhuǎn)換圖如下圖所示。電路進(jìn)入系統(tǒng)初始狀態(tài)S0,在S0狀態(tài)下時(shí)鐘信號(hào)CLK(T=0.125ms),以一定的頻率采樣跟紅外線接收頭輸出相連的CPLD I/O口輸入信號(hào)din,如果采樣到din=“1”,則沒有接受到紅外信號(hào),即遙控按鍵沒有操作,停留在S0狀態(tài),并繼續(xù)采樣Din輸入信號(hào)的狀態(tài),一旦采樣到輸入信號(hào)din=“0”,則遙控信號(hào)輸出引導(dǎo)碼低電平部分,并轉(zhuǎn)入S1狀態(tài),在S1狀態(tài)下經(jīng)過90T延時(shí)轉(zhuǎn)入狀態(tài)S2,在S2狀態(tài)下如果檢測到di

9、n=“1” 則引導(dǎo)碼進(jìn)入的高電平部分,并轉(zhuǎn)入狀態(tài)S3,在S3狀態(tài)下延時(shí),當(dāng)時(shí)間到30T時(shí)轉(zhuǎn)入狀態(tài)S4,從S4開始狀態(tài)機(jī)進(jìn)入數(shù)據(jù)解碼狀態(tài),在S4下檢測到din=“0”,可知遙控編碼信號(hào)輸出正是PPM編碼的0.56 ms的脈寬(0.56 ms載波) ,然后轉(zhuǎn)入狀態(tài)S5,用S5來判斷0.56 ms的脈寬是否已結(jié)束,如果din=“1”則脈寬已結(jié)束,轉(zhuǎn)入狀態(tài)S6,在S6狀態(tài)下延時(shí)3T ,然后轉(zhuǎn)入S7狀態(tài),在狀態(tài)S7下判斷該位是“0”,還是“1”,如果din=“0” 則確定該位是“0”,否則是“1”,并使解碼位數(shù)計(jì)數(shù)器CNT32加1,隨后進(jìn)入S8狀態(tài),在S8下將解出的數(shù)據(jù)移入32位移位寄存器,并通過解碼位

10、數(shù)計(jì)數(shù)器CNT32的值判斷遙控信號(hào)的32位數(shù)據(jù)是否解碼完,如果CNT32<32則仍未解完,轉(zhuǎn)入S9狀態(tài),在S9下判斷遙控信號(hào)PPM編碼的下位0.56 ms的脈寬,當(dāng)Din=“0”時(shí),則是下一位數(shù)據(jù)脈寬,隨即轉(zhuǎn)回狀態(tài)S5,又通過S5、S6、S7、S8、S9狀態(tài)完成數(shù)據(jù)的解碼;如果在S8狀態(tài)下CNT32=32,則32位數(shù)據(jù)已解碼完,轉(zhuǎn)入狀態(tài)S10,在狀態(tài)S10進(jìn)行解碼數(shù)據(jù)的輸出,并轉(zhuǎn)入狀態(tài)S11,在狀態(tài)S11延時(shí)16T,然后返回狀態(tài)S0,至此完成一個(gè)數(shù)據(jù)幀解碼過程。六:各模塊源代碼6.1數(shù)碼管驅(qū)動(dòng)模塊-dongtai.vhd-library ieee;use ieee.std_logic_u

11、nsigned.all;use ieee.std_logic_arith.all;use ieee.std_logic_1164.all;use work.all;entity led_8 isport(duanxuan,weixuan:out std_logic_vector(7 downto 0);bcd0,bcd1,bcd2,bcd3,bcd4,bcd5,bcd6,bcd7: in std_logic_vector(4 downto 0);san1,san2: in std_logic_vector(3 downto 0);clk: in std_logic);end led_8;arc

12、hitecture rtl of led_8 is signal count:std_logic_vector(2 downto 0); signal wx:std_logic_vector(7 downto 0); signal clk2,clk3:std_logic; signal bcd:std_logic_vector(4 downto 0);beginp0:process(clk)variable count2:std_logic_vector(11 downto 0);beginif clk'event and clk='1' thencount2:=cou

13、nt2+1;end if;clk2<=count2(11);end process;p1:process(clk2,count,bcd0,bcd1,bcd2,bcd3,bcd4,bcd5,bcd6,bcd7,san1,san2,clk3,wx)beginif clk2'event and clk2='1'thencount<=count+1;end if;case count iswhen"000"=>bcd<=bcd0;when"001"=>bcd<=bcd1;when"010&qu

14、ot;=>bcd<=bcd2;when"011"=>bcd<=bcd3;when"100"=>bcd<=bcd4;when"101"=>bcd<=bcd5;when"110"=>bcd<=bcd6;when"111"=>bcd<=bcd7;end case;if count=san1 or count=san2 then weixuan<=wx and clk3&clk3&clk3&clk3&a

15、mp;clk3&clk3&clk3&clk3;else weixuan<=wx;end if;end process;p3:process(clk)variable count0:integer range 0 to 2048000-1:=0;beginif(clk'event and clk='1')thencount0:=count0+1;end if;if count0<1024000 then clk3<='1'elseclk3<='0'end if;if count0=204800

16、0-1 then count0:=0;end if;end process;u1:shumaguan port map(bcd,count,duanxuan,wx);end rtl;-shumaguan.vhd-library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;use work.all;entity shumaguan isport( bcd:in std_logic_vector(4 downto 0); bcd_w:in std_logi

17、c_vector(2 downto 0); duanxuan,weixuan: out std_logic_vector(7 downto 0);end shumaguan;architecture rtl of shumaguan isbeginu1:yima38 port map(bcd_w,weixuan); with bcd select duanxuan<="00000011" when "00000", "10011111" when "00001", "00100101" w

18、hen "00010", "00001101" when "00011", "10011001" when "00100", "01001001" when "00101", "01000001" when "00110", "00011111" when "00111", "00000001" when "01000", "0

19、0001001" when "01001", "00010001" when "01010", "11000001" when "01011", "01100011" when "01100", "10000101" when "01101", "01100001" when "01110", "01110001" when "01111

20、", "11111101" when "10001", "11111111" when others;end rtl;-yima38-library ieee;use ieee.std_logic_1164.all;entity yima38 is port(in1 :in std_logic_vector(2 downto 0); out1: out std_logic_vector(7 downto 0);end yima38;architecture rtl of yima38 isbegin out1<=&qu

21、ot;00000001" when(in1="000")else "00000010" when(in1="001")else "00000100" when(in1="010")else "00001000" when(in1="011")else "00010000" when(in1="100")else "00100000" when(in1="101")el

22、se "01000000" when(in1="110")else "10000000" when(in1="111");end rtl;6.2分頻模塊-fenpin.vhd-library ieee;use ieee.std_logic_unsigned.all;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;entity fenpin isport(inclk:in std_logic; outclk: out std_logic);end fe

23、npin ;architecture rtl of fenpin issignal clk2:std_logic;beginprocess(inclk)variable count4:integer range 0 to 256-1;beginif(inclk'event and inclk='1')thencount4:=count4+1;end if;if count4<128 then clk2<='1'elseclk2<='0'end if;if count4=256-1 then count4:=0;end i

24、f;end process;outclk<=clk2;end rtl;-T=0.125ms6.3紅外解碼及控制模塊-MUC.vhd-library ieee;use ieee.std_logic_unsigned.all;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;entity hongwai_mcu isport(bcd0,bcd1,bcd2,bcd3,bcd4,bcd5,bcd6,bcd7: out std_logic_vector(4 downto 0);san1,san2: out std_logic_vect

25、or(3 downto 0);clkin,in_hongwai:in std_logic;bell:out std_logic;deng:out std_logic_vector(11 downto 0);end hongwai_mcu;architecture bev of hongwai_mcu istype state is(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11);signal current_state :state;signal din:std_logic;signal yonghu1,yonghu2,data1,data2 :std_logic

26、_vector(7 downto 0);signal led :std_logic_vector(11 downto 0);signal flag:std_logic:='1'beginbell<= not in_hongwai;din<=in_hongwai;san1<="1111"san2<="1111"deng<=led;p0:process(clkin)variable value_all:std_logic_vector(0 to 31);variable count:integer range 0

27、 to 100;variable count_32:integer range 0 to 32:=0;beginif clkin'event and clkin='1'thencase current_state iswhen s0=>count_32:=0;flag<='1'value_all:="00000000000000000000000000000000"if din='0' thencurrent_state<=s1;end if;when s1=>if count=69 then

28、current_state<=s2;count:=0;end if;count:=count+1;if din='1' then current_state<=s0;count:=0;end if;when s2=>if din='1' then current_state<=s3;end if;when s3=>if count=30 then current_state<=s4;count:=0;end if;count:=count+1;if din='0' then current_state<=

29、s0;count:=0;end if;when s4=>if din='0' then current_state<=s5;end if;when s5=>if din='1' then current_state<=s6;end if;when s6=>if count=3 then current_state<=s7;count:=0; end if;count:=count+1;when s7=>if din='0' then value_all(count_32):='0'else

30、 value_all(count_32):='1'end if;count_32:=count_32+1;current_state<=s8;count:=0;when s8=>if count_32=32 then current_state<=s10;elsecurrent_state<=s9;end if;when s9=>if din='0' then current_state<=s5;end if;when s10=>yonghu1(7 downto 0)<=value_all(0 to 7);yong

31、hu2(7 downto 0)<=not(value_all(8 to 15);data1(7 downto 0)<=value_all(16 to 23);data2(7 downto 0)<=not(value_all(24 to 31);current_state<=s11;flag<='0'when s11=>if count=16 then current_state<=s0;count:=0; end if;count:=count+1;when others=>null;end case;end if;end process;bcd6<='0'&data2(3 downto 0);bcd7<='0'&data2(7 downto 4);process(flag,data2)beginif flag'event and flag='1' thencase data2 iswhen x"68"=>led(0)<=not led(0);when x"98"=>led(1)<=not led

溫馨提示

  • 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

提交評論