




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、基于CPLD的VHDL語言數(shù)字鐘設(shè)計基于CPLD的VHDL語言數(shù)字鐘(含秒表)設(shè)計張偉軍 (002004101751)利用一塊芯片完成除時鐘源、按鍵、揚聲器和顯示器(數(shù)碼管)之外的所有數(shù)字電路功能。所有數(shù)字邏輯功能都在CPLD器件上用VHDL語言實現(xiàn)。這樣設(shè)計具有體積小、設(shè)計周期短(設(shè)計過程中即可實現(xiàn)時序仿真)、調(diào)試方便、故障率低、修改升級容易等特點。本設(shè)計采用自頂向下、混合輸入方式(原理圖輸入頂層文件連接和VHDL語言輸入各模塊程序設(shè)計)實現(xiàn)數(shù)字鐘的設(shè)計、下載和調(diào)試。一、 功能說明已完成功能1. 完成秒分時的依次顯示并正確計數(shù);2. 秒分時各段個位滿10正確進位,秒分能做到滿60向前進位;3
2、. 定時鬧鐘:實現(xiàn)整點報時,又揚聲器發(fā)出報時聲音;4. 時間設(shè)置,也就是手動調(diào)時功能:當(dāng)認為時鐘不準確時,可以分別對分時鐘進行調(diào)整;5. 利用多余兩位數(shù)碼管完成秒表顯示:A、精度達10ms;B、可以清零;C、完成暫??梢噪S時記時、暫停后記錄數(shù)據(jù)。 待改進功能:1. 鬧鐘只是整點報時,不能手動設(shè)置報時時間,遺憾之一;2. 秒表不能向秒進位,也就是最多只能記時100ms;3. 秒表暫停記錄數(shù)據(jù)后不能在原有基礎(chǔ)上繼續(xù)計時,而是復(fù)位重新開始?!咀⒁狻棵氡頌楹髞硖砑庸δ埽杂泻芏喙δ懿怀墒?!二、 設(shè)計方案1. 數(shù)字鐘頂層設(shè)計外部輸入要求:輸入信號有1kHz1Hz時鐘信號、低電平有效的秒微秒清零信號CL
3、R、低電平有效的調(diào)分信號SETmin、低電平有效的調(diào)時信號SEThour;外部輸出要求:整點報時信號SOUND(59分51357秒時未500Hz低頻聲,59分59秒時為1kHz高頻聲)、時十位顯示信號h1(a,b,c,d,e,f,g)、時個位顯示信號h0(a ,b,c,d,e,f,g)、分十位顯示信號m1及分個位m0、秒十位s1及秒個位s0、微秒十位ms1及微秒個位ms0;數(shù)碼管顯示位選信號SEL012等三個信號。 2. 內(nèi)部功能模塊主要有: Fenp分頻模塊:主要是整點報時用的1kH與500Hz的脈沖信號,這里的輸入信號是1KHz信號,所以只要一個二分頻即可;時間基準采用1Hz輸入信號直接提
4、供(當(dāng)然也可以分頻取得,這里先用的是分頻取得的信號,后考慮到精度問題而采用硬件頻率信號。 實現(xiàn)帶有100進制進位和清零功能,暫定等功能的微秒模塊MINSECONDB輸入為1Hz脈沖和低電平的清零信號CLR與暫定信號STOP,輸出微秒個位、十位及進位信號CO(雖然沒有實現(xiàn)進位功能,但還是編寫了這個端口,只是在連線時懸空)。 實現(xiàn)60進制帶有進位和清零功能的秒計數(shù)模塊SECOND,輸入為1Hz脈沖和低電平有效的清零信號CLR,輸出秒個位、時位及進位信號CO。 實現(xiàn)60進制帶有進位和置數(shù)功能的分計數(shù)模塊MINUTE,輸入為1Hz脈沖和高電平有效的使能信號EN,輸出分個位、時位及進位信號CO。 實現(xiàn)2
5、4進制的時計數(shù)模塊HOUR,輸入為1Hz脈沖和高電平有效的使能信號EN,輸出分個位、時位。 實現(xiàn)分時復(fù)用功能模塊SELTIME,輸入為秒(含個十位)、分、時、掃描時鐘CLK1K,輸出為D和顯示控制信號SEL。實現(xiàn)整點報時功能模塊ALERT,輸入為分秒信號,輸出為高頻聲控Q1K和Q500。實現(xiàn)譯碼顯示功能模塊DISPLAY,輸入為D,輸出為Q三、 設(shè)計框圖頻率信號輸入分頻微秒模塊秒模塊分模塊時模塊置數(shù)位選顯示模塊進位進位進位高低電平四、 模塊說明(含程序代碼)1. 分頻模塊采用原理圖輸入方式實現(xiàn)2分頻與1000分頻,但這里并沒有用到1000分頻,因為后來考慮到精度問題,將千分頻用直接輸入了。程序
6、如圖:利用三個7490進行硬件分頻!2. 微秒模塊采用VHDL語言輸入方式,以時鐘clk,清零信號clr以及暫停信號STOP為進程敏感變量,程序如下:15library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity MINSECONDb isport(clk,clrm,stop:in std_logic;-時鐘/清零信號 secm1,secm0:out std_logic_vector(3 downto 0);-秒高位/低位 co:out std_logic);-輸出/進位信號end MINSEC
7、ONDb;architecture SEC of MINSECONDb issignal clk1,DOUT2:std_logic;beginprocess(clk,clrm)variable cnt1,cnt0:std_logic_vector(3 downto 0);-計數(shù) VARIABLE COUNT2 :INTEGER RANGE 0 TO 10 ;beginIF CLK'EVENT AND CLK='1'THEN IF COUNT2>=0 AND COUNT2<10 THEN COUNT2:=COUNT2+1; ELSE COUNT2:=0; DO
8、UT2<= NOT DOUT2; END IF; END IF;if clrm='1' then-當(dāng)clr為1時,高低位均為0cnt1:="0000"cnt0:="0000"elsif clk'event and clk='1' then if stop='1' then cnt0:=cnt0; cnt1:=cnt1; end if;if cnt1="1001" and cnt0="1000" then-當(dāng)記數(shù)為98(實際是經(jīng)過59個記時脈沖)co<
9、;='1'-進位cnt0:="1001"-低位為9elsif cnt0<"1001" then-小于9時cnt0:=cnt0+1;-計數(shù)-elsif cnt0="1001" then-clk1<=not clk1;elsecnt0:="0000"if cnt1<"1001" then-高位小于9時cnt1:=cnt1+1;elsecnt1:="0000"co<='0'end if;end if;end if;secm1&
10、lt;=cnt1;secm0<=cnt0;end process;end SEC;3. 秒模塊程序清單 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity SECOND isport(clk,clr:in std_logic;-時鐘/清零信號 sec1,sec0:out std_logic_vector(3 downto 0);-秒高位/低位 co:out std_logic);-輸出/進位信號end SECOND;architecture SEC of SECOND isbegi
11、nprocess(clk,clr)variable cnt1,cnt0:std_logic_vector(3 downto 0);-計數(shù)beginif clr='1' then-當(dāng)ckr為1時,高低位均為0cnt1:="0000"cnt0:="0000"elsif clk'event and clk='1' thenif cnt1="0101" and cnt0="1000" then-當(dāng)記數(shù)為58(實際是經(jīng)過59個記時脈沖)co<='1'-進位cnt0
12、:="1001"-低位為9elsif cnt0<"1001" then-小于9時cnt0:=cnt0+1;-計數(shù)elsecnt0:="0000"if cnt1<"0101" then-高位小于5時cnt1:=cnt1+1;elsecnt1:="0000"co<='0'end if;end if;end if;sec1<=cnt1;sec0<=cnt0;end process;end SEC; 4. 分模塊程序清單 library ieee;use i
13、eee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity MINUTE isport(clk,en:in std_logic; min1,min0:out std_logic_vector(3 downto 0); co:out std_logic);end MINUTE;architecture MIN of MINUTE isbeginprocess(clk)variable cnt1,cnt0:std_logic_vector(3 downto 0);beginif clk'event and clk='1
14、' thenif en='1' thenif cnt1="0101" and cnt0="1000" thenco<='1'cnt0:="1001"elsif cnt0<"1001" thencnt0:=cnt0+1;elsecnt0:="0000"if cnt1<"0101" thencnt1:=cnt1+1;elsecnt1:="0000"co<='0'end if;end
15、 if;end if;end if;min1<=cnt1;min0<=cnt0;end process;end MIN;5. 時模塊程序清單 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity HOUR isport(clk,en:in std_logic;-輸入時鐘/高電平有效的使能信號 h1,h0:out std_logic_vector(3 downto 0);-時高位/低位end HOUR;architecture hour_arc of HOUR isbeginpr
16、ocess(clk)variable cnt1,cnt0:std_logic_vector(3 downto 0);-記數(shù)beginif clk'event and clk='1' then-上升沿觸發(fā)if en='1' then-同時“使能”為1if cnt1="0010" and cnt0="0011" thencnt1:="0000"-高位/低位同時為0時cnt0:="0000"elsif cnt0<"1001" then-低位小于9時,低位記
17、數(shù)累加cnt0:=cnt0+1;elsecnt0:="0000"cnt1:=cnt1+1;-高位記數(shù)累加end if;end if;end if;h1<=cnt1;h0<=cnt0;end process;end hour_arc;6. 動態(tài)掃描模塊 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity SELTIME is port( clk:in std_logic;-掃描時鐘 secm1,sec
18、m0,sec1,sec0,min1,min0,h1,h0:in std_logic_vector(3 downto 0);-分別為秒個位/時位;分個位/ daout:out std_logic_vector(3 downto 0);-輸出 sel:out std_logic_vector(2 downto 0);-位選信號end SELTIME;architecture fun of SELTIME is signal count:std_logic_vector(2 downto 0);-計數(shù)信號begin sel<=count; process(clk) begin if(clk
19、39;event and clk='1') then if(count>="111") then count<="000" else count<=count+1; end if; end if; case count is when"111"=>daout<= secm0;-秒個位 when"110"=>daout<= secm1;-秒十位 when"101"=>daout<= sec0;-分個位 when"100
20、"=>daout<= sec1;-分十位 when"011"=>daout<=min0; -時個位 when"010"=>daout<=min1;-時十位 when"001"=>daout<=h0; when others =>daout<=h1; end case; end process;end fun;7. 報時模塊 library ieee;use ieee.std_logic_1164.all;entity ALERT isport(m1,m0,s1,s0
21、:in std_logic_vector(3 downto 0);-輸入秒、分高/低位信號 clk:in std_logic;-高頻聲控制 q500,qlk:out std_logic);-低頻聲控制end ALERT;architecture sss_arc of ALERT is begin process(clk) begin if clk'event and clk='1' then if m1="0101" and m0="1001" and s1="0101" then-當(dāng)秒高位為5,低位為9時且分
22、高位為5 if s0="0001" or s0="0011" or s0="0101" or s0="0111" then-當(dāng)分的低位為1或3或5或7時 q500<='1'-低頻輸出為1 else q500<='0'-否則輸出為0 end if; end if;if m1="0101" and m0="1001" and s1="0101" and s0="1001" then-當(dāng)秒高位為5,
23、低位為9時且分高位為5,-分低位為9時,也就是“59分59秒”的時候“報時” qlk<='1'-高頻輸出為1 else qlk<='0' end if;end if; end process; end sss_arc;8. 顯示模塊 library ieee;use ieee.std_logic_1164.all;entity DISPLAY is port(d:in std_logic_vector(3 downto 0);-連接seltime掃描部分d信號 q:out std_logic_vector(6 downto 0);-輸出段選信號(電平
24、)end DISPLAY;architecture disp_are of DISPLAY isbegin process(d) begincase d is when"0000" =>q<="0111111"-顯示0 when"0001" =>q<="0000110"-顯示1 when"0010" =>q<="1011011"-顯示2 when"0011" =>q<="1001111"-
25、顯示3 when"0100" =>q<="1100110"-顯示4 when"0101" =>q<="1101101"-顯示5 when"0110" =>q<="1111101"-顯示6 when"0111" =>q<="0100111"-顯示7 when"1000" =>q<="1111111"-顯示8 when others =>
26、;q<="1101111"-顯示9end case; end process;end disp_are;9. 頂層文件(原理圖輸入) * 數(shù)字鐘設(shè)計模塊與程序(不含秒表)* 1.分頻模塊(原理圖輸入) 2. 秒模塊程序 library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity SECOND isport(clk,clr:in std_logic; sec1,sec0:out std_logic_vector(3 downto 0); co:out std_logic)
27、;end SECOND;architecture SEC of SECOND isbeginprocess(clk,clr)variable cnt1,cnt0:std_logic_vector(3 downto 0);beginif clr='1' thencnt1:="0000"cnt0:="0000"elsif clk'event and clk='1' thenif cnt1="0101" and cnt0="1000" thenco<='1'c
28、nt0:="1001"elsif cnt0<"1001" thencnt0:=cnt0+1;elsecnt0:="0000"if cnt1<"0101" thencnt1:=cnt1+1;elsecnt1:="0000"co<='0'end if;end if;end if;sec1<=cnt1;sec0<=cnt0;end process;end SEC;3.分模塊程序 library ieee;use ieee.std_logic_1164.al
29、l;use ieee.std_logic_unsigned.all;entity MINUTE isport(clk,en:in std_logic; min1,min0:out std_logic_vector(3 downto 0); co:out std_logic);end MINUTE;architecture MIN of MINUTE isbeginprocess(clk)variable cnt1,cnt0:std_logic_vector(3 downto 0);beginif clk'event and clk='1' thenif en='
30、1' thenif cnt1="0101" and cnt0="1000" thenco<='1'cnt0:="1001"elsif cnt0<"1001" thencnt0:=cnt0+1;elsecnt0:="0000"if cnt1<"0101" thencnt1:=cnt1+1;elsecnt1:="0000"co<='0'end if;end if;end if;end if;min
31、1<=cnt1;min0<=cnt0;end process;end MIN;4.時模塊程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity HOUR isport(clk,en:in std_logic; h1,h0:out std_logic_vector(3 downto 0);end HOUR;architecture hour_arc of HOUR isbeginprocess(clk)variable cnt1,cnt0:std_logic_vector(3
32、downto 0);beginif clk'event and clk='1' thenif en='1' thenif cnt1="0010" and cnt0="0011" thencnt1:="0000"cnt0:="0000"elsif cnt0<"1001" thencnt0:=cnt0+1;end if;end if;end if;h1<=cnt1;h0<=cnt0;end process;end hour_arc;5.掃描模
33、塊程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity SELTIME is port( clk:in std_logic; sec1,sec0,min1,min0,h1,h0:in std_logic_vector(3 downto 0); daout:out std_logic_vector(3 downto 0); sel:out std_logic_vector(2 downto 0);end SELTIME;archi
34、tecture fun of SELTIME is signal count:std_logic_vector(2 downto 0);begin sel<=count; process(clk) begin if(clk'event and clk='1') then if(count>="101") then count<="000" else count<=count+1; end if; end if; case count is when"000"=>daout<=
35、 sec0; when"001"=>daout<= sec1; when"010"=>daout<= min0; when"011"=>daout<= min1; when"100"=>daout<=h0; when others =>daout<=h1; end case; end process;end fun;6.顯示模塊程序library ieee;use ieee.std_logic_1164.all;entity DISPLAY is port
36、(d:in std_logic_vector(3 downto 0); q:out std_logic_vector(6 downto 0);end DISPLAY;architecture disp_are of DISPLAY isbegin process(d) begincase d is when"0000" =>q<="0111111" when"0001" =>q<="0000110" when"0010" =>q<="1011011" when"0011" =>q<="1001111" when"0100" =>q<="1100110" when"0101" =>q<="1101101" when"0110" =>q<="1111101" when"0111" =>q<="0100111" when"1
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 工程部年終總結(jié)及明年計劃
- 英語專業(yè)畢業(yè)論文格式
- 燈具店創(chuàng)業(yè)企劃書
- 融資約束對企業(yè)全球價值鏈位置提升影響的研究
- 鑭錳共摻的鐵酸鉍基異質(zhì)結(jié)的制備及光伏性能研究
- 計及多時間尺度和需求響應(yīng)的綜合能源系統(tǒng)優(yōu)化調(diào)度研究
- 氨基酸兩親分子手性超分子-Cu(Ⅱ)催化劑構(gòu)筑及不對稱催化性能研究
- 五年級語文上冊第五單元22兩彈元勛鄧稼先主題閱讀張愛萍和鄧稼先素材冀教版
- 借款合同補充合同范例
- 九年級道德與法治上冊第一單元富強與創(chuàng)新第一課踏上強國之路第2框走向共同富裕學(xué)案無答案新人教版
- GB 18265-2019危險化學(xué)品經(jīng)營企業(yè)安全技術(shù)基本要求
- 作業(yè)層隊伍建設(shè)重點業(yè)務(wù)課件
- DB31T 685-2019 養(yǎng)老機構(gòu)設(shè)施與服務(wù)要求
- 二年級下冊美術(shù)教案-第5課 美麗的花園|嶺南版
- 人類進化史精品課件
- 魯濱遜漂流記讀后感PPT
- 總包單位向門窗單位移交門窗安裝工程工作面交接單
- 設(shè)備供貨安裝方案(通用版)
- 公開招聘社區(qū)居委專職工作人員考試筆試、面試題集及相關(guān)知識(11套試題含答案)
- 《植物生理學(xué)》課件第三章+植物的光合作用
- 中國藥膳理論與實踐-藥膳基本理論和技能
評論
0/150
提交評論