




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、基于CPLD的VHDL語言數字鐘設計基于CPLD的VHDL語言數字鐘(含秒表)設計張偉軍 (002004101751)利用一塊芯片完成除時鐘源、按鍵、揚聲器和顯示器(數碼管)之外的所有數字電路功能。所有數字邏輯功能都在CPLD器件上用VHDL語言實現。這樣設計具有體積小、設計周期短(設計過程中即可實現時序仿真)、調試方便、故障率低、修改升級容易等特點。本設計采用自頂向下、混合輸入方式(原理圖輸入頂層文件連接和VHDL語言輸入各模塊程序設計)實現數字鐘的設計、下載和調試。一、 功能說明已完成功能1. 完成秒分時的依次顯示并正確計數;2. 秒分時各段個位滿10正確進位,秒分能做到滿60向前進位;3
2、. 定時鬧鐘:實現整點報時,又揚聲器發出報時聲音;4. 時間設置,也就是手動調時功能:當認為時鐘不準確時,可以分別對分時鐘進行調整;5. 利用多余兩位數碼管完成秒表顯示:A、精度達10ms;B、可以清零;C、完成暫停可以隨時記時、暫停后記錄數據。 待改進功能:1. 鬧鐘只是整點報時,不能手動設置報時時間,遺憾之一;2. 秒表不能向秒進位,也就是最多只能記時100ms;3. 秒表暫停記錄數據后不能在原有基礎上繼續計時,而是復位重新開始。【注意】秒表為后來添加功能,所以有很多功能不成熟!二、 設計方案1. 數字鐘頂層設計外部輸入要求:輸入信號有1kHz1Hz時鐘信號、低電平有效的秒微秒清零信號CL
3、R、低電平有效的調分信號SETmin、低電平有效的調時信號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;數碼管顯示位選信號SEL012等三個信號。 2. 內部功能模塊主要有: Fenp分頻模塊:主要是整點報時用的1kH與500Hz的脈沖信號,這里的輸入信號是1KHz信號,所以只要一個二分頻即可;時間基準采用1Hz輸入信號直接提
4、供(當然也可以分頻取得,這里先用的是分頻取得的信號,后考慮到精度問題而采用硬件頻率信號。 實現帶有100進制進位和清零功能,暫定等功能的微秒模塊MINSECONDB輸入為1Hz脈沖和低電平的清零信號CLR與暫定信號STOP,輸出微秒個位、十位及進位信號CO(雖然沒有實現進位功能,但還是編寫了這個端口,只是在連線時懸空)。 實現60進制帶有進位和清零功能的秒計數模塊SECOND,輸入為1Hz脈沖和低電平有效的清零信號CLR,輸出秒個位、時位及進位信號CO。 實現60進制帶有進位和置數功能的分計數模塊MINUTE,輸入為1Hz脈沖和高電平有效的使能信號EN,輸出分個位、時位及進位信號CO。 實現2
5、4進制的時計數模塊HOUR,輸入為1Hz脈沖和高電平有效的使能信號EN,輸出分個位、時位。 實現分時復用功能模塊SELTIME,輸入為秒(含個十位)、分、時、掃描時鐘CLK1K,輸出為D和顯示控制信號SEL。實現整點報時功能模塊ALERT,輸入為分秒信號,輸出為高頻聲控Q1K和Q500。實現譯碼顯示功能模塊DISPLAY,輸入為D,輸出為Q三、 設計框圖頻率信號輸入分頻微秒模塊秒模塊分模塊時模塊置數位選顯示模塊進位進位進位高低電平四、 模塊說明(含程序代碼)1. 分頻模塊采用原理圖輸入方式實現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);-計數 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-當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-當記數為98(實際是經過59個記時脈沖)co<
9、;='1'-進位cnt0:="1001"-低位為9elsif cnt0<"1001" then-小于9時cnt0:=cnt0+1;-計數-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);-計數beginif clr='1' then-當ckr為1時,高低位均為0cnt1:="0000"cnt0:="0000"elsif clk'event and clk='1' thenif cnt1="0101" and cnt0="1000" then-當記數為58(實際是經過59個記時脈沖)co<='1'-進位cnt0
12、:="1001"-低位為9elsif cnt0<"1001" then-小于9時cnt0:=cnt0+1;-計數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);-記數beginif clk'event and clk='1' then-上升沿觸發if en='1' then-同時“使能”為1if cnt1="0010" and cnt0="0011" thencnt1:="0000"-高位/低位同時為0時cnt0:="0000"elsif cnt0<"1001" then-低位小于9時,低位記
17、數累加cnt0:=cnt0+1;elsecnt0:="0000"cnt1:=cnt1+1;-高位記數累加end if;end if;end if;h1<=cnt1;h0<=cnt0;end process;end hour_arc;6. 動態掃描模塊 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);-計數信號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-當秒高位為5,低位為9時且分
22、高位為5 if s0="0001" or s0="0011" or s0="0101" or s0="0111" then-當分的低位為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-當秒高位為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. 頂層文件(原理圖輸入) * 數字鐘設計模塊與程序(不含秒表)* 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 光伏產業供應鏈2025年優化與市場競爭力前瞻報告
- 單層裝修租房合同樣本
- 制式綜合市場投資合同標準文本
- 醫療保健合同樣本
- 賣車購買合同標準文本
- 2006版施工合同范例
- 單位清洗合同樣本
- 2025-2030年中國西樂器行業發展格局及投資前景規劃研究報告
- 南京耐磨地坪合同范例
- 賣方英文合同范例
- 2024年汽車維修案例分析方法試題及答案
- 18 井岡翠竹 課件
- 地質災害地震課件
- 粵教粵人版初中地理七下知識梳理
- 共建聯合實驗室合作合同協議書范本模板5篇
- 社會調查方法(第3版)課件:資料處理
- 工程簽工單表格范本
- 土壤微生物與重金屬污染-洞察分析
- 《消費者心理與行為分析》第五版 課件全套 肖澗松 單元1-10 消費者心理與行為概述 - 消費者購買決策與購后行為
- 塑料污染治理-洞察分析
- 反詐知識競賽題庫及答案(共286題)
評論
0/150
提交評論