基于FPGA的電子時鐘設(shè)計_第1頁
基于FPGA的電子時鐘設(shè)計_第2頁
基于FPGA的電子時鐘設(shè)計_第3頁
基于FPGA的電子時鐘設(shè)計_第4頁
基于FPGA的電子時鐘設(shè)計_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、Civil Aviation University of China電子技術(shù)應(yīng)用設(shè)計報告基于FPGA的電子時鐘設(shè)計專 業(yè): 通信工程 學(xué) 號: xxxxxxx 學(xué)生姓名: xxx 所屬學(xué)院: 電信學(xué)院 任課教師: xxx 摘要本設(shè)計采用EDA技術(shù),采用原理圖和硬件描述語言VHDL混合編程設(shè)計時鐘邏輯系統(tǒng),在QuartusII5.0工具軟件環(huán)境下,采用自頂向下的設(shè)計方法,由各個基本模塊共同構(gòu)建了一個基于FPGA的電子時鐘。本時鐘系統(tǒng)主芯片采用EP1C6Q240C8N,具有顯示時間、日期、時間及日期校準、整點報時、定時鬧鐘等功能。其中時間采用24小時循環(huán)計數(shù),日期計數(shù)器具有閏年、月大、月小的判斷并

2、準確計數(shù)功能。通過按鍵控制可以實現(xiàn):日期和時間的切換顯示、日期和時間的校準、鬧鐘的開關(guān)控制。關(guān)鍵詞 :FPGA;電子時鐘;原理圖;VHDL語言;AbstractIn my design EDA technology is used, and I designed the clock logic system by means of schematic and VHDL hardware description language. Under QuartusII5.0 Tools software environment, I used the top-down design methodolo

3、gy, where various basic modules work together to build a FPGA-based electronic clock.The main chip of the clock system is EP1C6Q240C8N, which has the function of time display, date display, time and date calibration, the whole point of time, and regular alarm clock. Furthermore, 24-hour cycle, date

4、counter which time has leap-year, month, a small month's judgment and accurate counting function are designed. What we can achieve through the control buttons are as follows: switching the display of date and time, calibration of date and time, and the alarm switch control.Keywords: FPGA; electr

5、onic clock; schematic; VHDL language;目錄電子技術(shù)應(yīng)用設(shè)計報告0基于FPGA的電子時鐘設(shè)計0摘要1Abstract1基于FPGA的電子時鐘設(shè)計31.FPGA介紹32電子時鐘的設(shè)計方案32.1時鐘系統(tǒng)整體介紹32.2分頻器42.3時間計數(shù)模塊52.4日期計數(shù)模塊62.5譯碼器模塊72.6顯示模塊72.7校時模塊82.8鬧鐘模塊103實習(xí)總結(jié)113.1本系統(tǒng)的優(yōu)點113.2本系統(tǒng)的不足113.3想實現(xiàn)卻又沒實現(xiàn)的功能12附錄1:分頻器13附錄2:時間計數(shù)器14附錄3:日期計數(shù)器16附錄4:譯碼器程序20基于FPGA的電子時鐘設(shè)計1.FPGA介紹FPGA(Fiel

6、dProgrammable Gate Array),即現(xiàn)場可編程門陣列,它是在PAL、GAL、CPLD等可編程器件的基礎(chǔ)上進一步發(fā)展的產(chǎn)物。它是作為專用集成電路(ASIC)領(lǐng)域中的一種半定制電路而出現(xiàn)的,既解決了定制電路的不足,又克服了原有可編程器件門電路數(shù)有限的缺點。FPGA采用了邏輯單元陣列LCA(Logic Cell Array)這樣一個概念,內(nèi)部包括可配置邏輯模塊CLB(Configurable Logic Block)、輸出輸入模塊IOB(Input Output Block)和內(nèi)部連線(Interconnect)三個部分。 現(xiàn)場可編程門陣列(FPGA)是可編程器件。與傳統(tǒng)邏輯電路和

7、門陣列(如PAL,GAL及CPLD器件)相比,F(xiàn)PGA具有不同的結(jié)構(gòu),F(xiàn)PGA利用小型查找表(16×1RAM)來實現(xiàn)組合邏輯,每個查找表連接到一個D觸發(fā)器的輸入端,觸發(fā)器再來驅(qū)動其他邏輯電路或驅(qū)動I/O,由此構(gòu)成了既可實現(xiàn)組合邏輯功能又可實現(xiàn)時序邏輯功能的基本邏輯單元模塊,這些模塊間利用金屬連線互相連接或連接到I/O模塊。FPGA的邏輯是通過向內(nèi)部靜態(tài)存儲單元加載編程數(shù)據(jù)來實現(xiàn)的,存儲在存儲器單元中的值決定了邏輯單元的邏輯功能以及各模塊之間或模塊與I/O間的聯(lián)接方式,并最終決定了FPGA所能實現(xiàn)的功能,F(xiàn)PGA允許無限次的編程。2電子時鐘的設(shè)計方案2.1時鐘系統(tǒng)整體介紹本時鐘系統(tǒng)主要

8、由分頻器模塊、計數(shù)模塊、譯碼模塊、顯示模塊、校時模塊以及鬧鐘模塊構(gòu)成。由分頻器從48MHZ晶振中得到1HZ信號給計數(shù)器提供標準時鐘,譯碼器將計數(shù)器數(shù)據(jù)譯碼數(shù)碼管能顯示的信號,顯示模塊掃描譯碼器數(shù)據(jù)并顯示。由于計數(shù)的起始時間不可能與標準時間(如北京時間)一致,故需要在電路上加一個校時電路,同時標準的1HZ時間信號必須做到準確穩(wěn)定。系統(tǒng)框圖如下:按鍵分頻器按鍵晶振期計數(shù)器時間計數(shù)器鬧鐘譯碼器顯示模塊圖2-1時鐘系統(tǒng)框圖2.2分頻器本分頻器采用偶數(shù)分頻,使占空比達到50%很簡單,只要使用一個計數(shù)器,在計數(shù)器的前一半時間里,使輸出電平低電平,在計數(shù)器的后一半時間里,使輸出電平為低電平,這樣輸出的時鐘信

9、號就是占空比為50%的偶數(shù)分頻時鐘信號。圖2-2-1分頻器電路設(shè)計本分頻器有48分頻、100分頻、10分頻三個程序模塊構(gòu)成,輸入48MHz,輸出1KHz、100Hz、1Hz時鐘信號。由于本分頻器的判斷條件為if count<(integer(N/2) then,所以當(dāng)N為奇數(shù)時,得到脈沖占空比不為50%。(VHDL程序見附錄1)圖2-2-2分頻器電路模塊2.3時間計數(shù)模塊時間計數(shù)模塊由60進制計數(shù)器和24進制計數(shù)器構(gòu)成。當(dāng)秒計數(shù)器到59后,進位并歸零,分計數(shù)器得到秒計數(shù)器的進位信號后計數(shù)加1,時計數(shù)器同理。(VHDL程序見附錄2) 圖2-3-1六十進制計數(shù)器 圖2-3-2二十四進制計數(shù)器

10、Ø 1khz為蜂鳴器信號輸入端;Ø clk為1HZ時鐘信號輸入端;Ø reset為異步清零信號輸入端;Ø sadd、sdec、madd、mdec、hadd、hdec均為同步校時控制信號輸入端,其中sadd為秒加,sdec為秒減,madd為分加,mdec為分減,hadd為時加,hdec為時減。圖2-3-3計數(shù)器模塊2.4日期計數(shù)模塊本日期計數(shù)模塊具有閏年、閏月、月大、月小判斷并計數(shù)功能。日期控制信號為sel2.0輸入端,當(dāng)sel0= 0時,表示閏年,當(dāng)sel1=1表示4,6,9,11四個月就,sel1=0則表示1、2、3、5、7、8、10、12八個月,當(dāng)s

11、el2=1則表示2月。(VHDL程序見附錄3) 圖2-4-1年月日計數(shù)模塊2.5譯碼器模塊本譯碼器模塊采用VHDL語言編寫,譯碼具有靈活性,方便更改譯碼結(jié)果。輸入數(shù)據(jù)為4位,輸出數(shù)據(jù)為8位。輸入0000到1001譯碼為0到9,輸入1010到1110譯碼為A、b、C、D、E,輸入1111譯碼為橫線。(VHDL程序見附錄4)圖2-5譯碼器模塊2.6顯示模塊本顯示模塊由一個74161計數(shù)器構(gòu)成8進制計數(shù)模塊,輸入1KHz信號,計數(shù)器通過74138使數(shù)碼管輪流工作,同時通過宏模塊選通時間數(shù)據(jù)在數(shù)碼管上顯示。由于數(shù)碼管只有8個,要想在8個數(shù)碼管上顯示時分秒年月日這么多數(shù)據(jù),必須要有切換顯示模塊。本系統(tǒng)利

12、用按鍵控制宏模塊選通時間和日期兩路數(shù)據(jù)分別在數(shù)碼管上顯示。圖2-6-1顯示模塊電路圖圖2-6-2顯示模塊2.7校時模塊校時模塊由8個按鍵組成。當(dāng)按鍵按下輸出低電平,未按下時輸出高電平。圖2-7-1按鍵消抖模塊按鍵消抖模塊由1KHz時鐘信號控制,經(jīng)過D觸發(fā)器和與非門處理后,使得按鍵按下后輸出高電平。未按下時輸出低電平。圖2-7-2八路按鍵模塊圖2-7-3按鍵選通模塊由于時分秒信息和年月日信息分開顯示,所以調(diào)整時間時必須分別對時分秒、年月日進行校準。然而控制信號只有八路,這樣就必須使按鍵信號能分別送進時間計數(shù)模塊和日期計數(shù)模塊。于是編寫下面這部分程序:LIBRARY IEEE;USE IEEE.S

13、TD_LOGIC_1164.ALL;ENTITY channel ISPORT(s:IN STD_LOGIC; data_in:IN STD_LOGIC_VECTOR(6 DOWNTO 0); cal_out:OUT STD_LOGIC_VECTOR(6 DOWNTO 0); time_out:OUT STD_LOGIC_VECTOR(6 DOWNTO 0);END ENTITY;ARCHITECTURE one OF channel ISBEGINPROCESS(s)BEGINCASE s ISWHEN '0'=> cal_out <=data_in; time_

14、out<="0000000"WHEN OTHERS=> time_out <=data_in; cal_out<="0000000"END CASE;END PROCESS;END ARCHITECTURE;這樣就使得當(dāng)控制按鈕按下時,通過顯示模塊切換顯示畫面,同時按鍵分別控制時間計數(shù)模塊和日期計數(shù)模塊。2.8鬧鐘模塊鬧鐘模塊由整點報時和定時鬧鐘兩部分組成。圖2-8-1整點報時模塊當(dāng)時計數(shù)器進位時,進位信號被取出送到蜂鳴器控制端,控制端使能輸入1KHz信號到蜂鳴器,這樣就到達整點報時功能。圖2-8-2定時鬧鐘模塊為了便于演示本鬧鐘

15、模塊定時時間為10秒,具有開啟和關(guān)閉功能。當(dāng)按鍵按下時T觸發(fā)器翻轉(zhuǎn),使能計數(shù)器,當(dāng)計數(shù)器計滿10秒時進位使能蜂鳴器實現(xiàn)鬧鐘效果。當(dāng)再次按下按鍵,T觸發(fā)器再次翻轉(zhuǎn),計數(shù)器關(guān)閉,鬧鐘關(guān)閉。3實習(xí)總結(jié)3.1本系統(tǒng)的優(yōu)點1. 分頻器實現(xiàn)容易,可以任意分頻,連線少。2. 時間計數(shù)器和日期計數(shù)器具有校準信號輸入端,能實現(xiàn)校時和重啟功能3. 日期計數(shù)器能準確的實現(xiàn)閏年、閏月、月大、月小的計數(shù)4. 譯碼器具有靈活性,不受器件限制,可以任意譯碼,實現(xiàn)自己想要的效果。3.2本系統(tǒng)的不足1. 分頻器具有局限性,不能很好的對奇數(shù)個脈沖進行分頻。2. 進位信號與歸零信號不能同步。計數(shù)器計滿歸零時,進位信號不能立即進位,

16、要晚一個時鐘信號。3. 校時操作比較繁瑣。首先是控制按鍵比較多,然后是校準時間時,需要等到秒時鐘信號到來時計數(shù)器才會加一或減一,使得校準時間比較慢。4. 鬧鐘不能設(shè)定,為了便于演示,只做了一個10秒計數(shù)器。3.3想實現(xiàn)卻又沒實現(xiàn)的功能1. 對時間進行校準時,由于受秒時鐘限制,校準操作比較慢。因此嘗試過以下兩種方案:i. 輸入1Hz、2Hz兩個時鐘信號,1Hz信號用于計數(shù)器計數(shù),2Hz信號用于校準時間,但是程序老是報錯,實驗失敗。ii. 校準信號不受時鐘信號控制,當(dāng)按鍵按下時,就使計數(shù)器加一或減一。由于按鍵消抖不是很好,每按下一次按鍵,計數(shù)器增加幾十位,不是預(yù)期效果,實驗失敗。2. 鬧鐘模塊有兩

17、個預(yù)想功能沒有實現(xiàn):i. 定時時間可以設(shè)定。ii. 鬧鐘工作時播放一首歌曲。失敗原因:1.時間不足;2.對電子琴不了解,要完成電子琴模塊,需要大量時間。附錄1:分頻器以下是100分頻程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity divider100 isGENERIC (N:integer:=100);port (clk:in std_logic;outclk:out std_logic);end divider100

18、;architecture one of divider100 issignal count:integer;beginprocess(clk)beginif(clk'event and clk='1') thenif(count=N-1)thencount<=0;elsecount<=count+1;if count<(integer(N/2) thenoutclk<='0'elseoutclk<='1'end if;end if;end if;end process;end one;附錄2:時間計數(shù)器附錄

19、2.1:六十進制計數(shù)器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity second isport(enl,res,clk,sadd,sdec:in std_logic; a,b:out std_logic_vector(3 downto 0); ca:out std_logic);end second;-enl使能 -res清零-clk時鐘-sadd加-sdec減-a低位-b高位-ca進位architecture SEC of second isbeginprocess(enl,cl

20、k,res)variable m0,m1:std_logic_vector(3 downto 0);beginif res='1' then m0:="0000" m1:="0000" ca<='0' elsif clk'event and clk='1' then ca<='0' if sadd='1' or enl='1' then if m0="1000" and m1="0101" then

21、ca<='1' -實際是第59個-脈沖 end if; if m0<"1001" then m0:=m0+1; else m0:="0000" m1:=m1+1; if m1>"0101" then m0:="0000" m1:="0000" ca<='0' end if; end if; elsif sdec='1' then if m0="0000" and m1="0000" t

22、hen m0:="1001" m1:="0101" elsif m0>"0000" then m0:=m0-1; else m0:="1001" m1:=m1-1; end if; end if; end if; a<=m0;b<=m1;end process;end SEC;附錄2.1:二十四進制計數(shù)器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity hour isport(enl,re

23、s,clk,hadd,hdec:in std_logic; a,b:out std_logic_vector(3 downto 0); ca:out std_logic);end hour;-enl使能 -res清零-clk時鐘-hadd加-hdec減-a低位-b高位-ca進位architecture SEC of hour isbeginprocess(enl,clk,res)variable m0,m1:std_logic_vector(3 downto 0);beginif res='1' then m0:="0000" m1:="0000&

24、quot; ca<='0' elsif clk'event and clk='1' then ca<='0' if hadd='1' or enl='1' thenif m0="0011" and m1="0010" then ca<='1' m0:="0000" m1:="0000" end if; if m0<"1001" then m0:=m0+1; else m

25、0:="0000" m1:=m1+1; end if; elsif hdec='1' then if m0="0000" and m1="0000" then m0:="0011" m1:="0010"elsif m0>"0000" then m0:=m0-1; else m0:="1001" m1:=m1-1;end if; end if; end if; a<=m0;b<=m1;end process;end SEC;

26、附錄3:日期計數(shù)器附錄3.1:天計數(shù)器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity day isport(enl,res,clk,dadd,ddec:in std_logic; sel:in std_logic_vector(2 downto 0); a,b:out std_logic_vector(3 downto 0); ca:out std_logic);end day;-sel0-year-0表示閏年-sel1-month,1表示4,6,9,11-0表示1、2、3、5、7、

27、8、10、12-sel2-Feb,1表示2月architecture SEC of day issignal sr0,sr1:std_logic_vector(3 downto 0);beginprocess(sel)beginif sel="001" or sel="000" then sr0<="0001" sr1<="0011"-31elsif sel="100" then sr0<="1001" sr1<="0010"-29

28、elsif sel="101" then sr0<="1000" sr1<="0010"-28else sr0<="0000" sr1<="0011"-30end if;end process;process(enl,clk,res)variable r0,r1:std_logic_vector(3 downto 0);beginif res='1' then r0:="0001" r1:="0000" ca<

29、='0' elsif clk'event and clk='1' then ca<='0' if dadd='1' or enl='1' then if r0=sr0 and r1=sr1 then r0:="0001" r1:="0000" ca<='1' elsif r0<"1001" then r0:=r0+1; ca<='0' else r0:="0000" r1:

30、=r1+1; end if; elsif ddec='1' then if r0="0001" and r1="0000" then r0:=sr0; r1:=sr1; elsif r0>"0000" then r0:=r0-1; else r0:="1001" r1:=r1-1; end if; end if; end if; a<=r0;b<=r1;end process;end SEC;附錄3.2:月計數(shù)器library ieee;use ieee.std_logic_116

31、4.all;use ieee.std_logic_unsigned.all;entity month isport(enl,res,clk,madd,mdec:in std_logic; a,b:out std_logic_vector(3 downto 0); ermonth,msel,ca:out std_logic);end month;-ermonth connect to sel2-msel connect to sel1architecture SEC of month isbeginprocess(enl,clk,res)variable y0,y1:std_logic_vect

32、or(3 downto 0);beginif res='1' then y0:="0001" y1:="0000" ca<='0' elsif clk'event and clk='1' then ca<='0' if madd='1' or enl='1' then if y0="0010" and y1="0001" then y0:="0001" y1:="0000

33、" ca<='1' elsif y0<"1001" then y0:=y0+1; ca<='0' else y0:="0000" y1:=y1+1; end if; elsif mdec='1' then if y0="0001" and y1="0000" then y0:="0010" y1:="0001" elsif y0>"0000" then y0:=y0-1; e

34、lse y0:="1001" y1:=y1-1; end if; end if; end if;if (y0="0100" or y0="0110" or y0="1001" ) and y1="0000")or (y0="0001" and y1="0001") then msel<='1' else msel<='0'end if;if y0="0010" and y1="000

35、0" then ermonth<='1' else ermonth<='0'end if; a<=y0;b<=y1;end process;end SEC;附錄3.3:年計數(shù)器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity year isport(enl,res,clk,yadd,ydec:in std_logic; a,b,c,d:out std_logic_

36、vector(3 downto 0); ysel:out std_logic);end year;-ysel connect to sel0architecture nd of year isbegin process(res,enl,clk)variable n0,n1,n2,n3:std_logic_vector(3 downto 0);begin if res='1' then n0:="0010"n1:="0001"n2:="0000"n3:="0010" elsif clk'eve

37、nt and clk='1' then if yadd='1' or enl='1' then if n0<"1001" then n0:=n0+1; elsif n0="1001" then n0:="0000" n1:=n1+1; if n1="1010" then n1:="0000" n2:=n2+1; end if; if n2="1010" then n2:="0000" n3:=n3+1;

38、 end if; if n3="1010" then n3:="0000" end if; end if; elsif ydec='1' then if n0>"0000" then n0:=n0-1 ; elsif n0="0000" and n1="0000" and n2="0000" and n3="0000" then n0:="1001" n1:="1001" n2:="1

39、001" n3:="1001" elsif n0="0000" and n1="0000" and n2="0000" then n0:="1001" n1:="1001" n2:="1001" n3:=n3-1; elsif n0="0000" and n1="0000" then n0:="1001" n1:="1001" n2:=n2-1; elsif n0=&

40、quot;0000" then n0:="1001" n1:=n1-1; end if; else n3:="0010" end if; if (n0(0)='0' and n0(1)='0' and n1(0)='0')or(n0(0)='0' and n0(1)='1' and n1(0)='1') then ysel<='0' else ysel<='1'end if;end if;a<=n0;b<=n

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論