vhdl課程設(shè)計(jì)電子鐘+鬧鈴_第1頁
vhdl課程設(shè)計(jì)電子鐘+鬧鈴_第2頁
vhdl課程設(shè)計(jì)電子鐘+鬧鈴_第3頁
已閱讀5頁,還剩27頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、數(shù)字鐘的設(shè)計(jì)一、系統(tǒng)功能概述(一)、系統(tǒng)實(shí)現(xiàn)的功能:1、具有“時(shí)”、“分”、“秒”的十進(jìn)制數(shù)字顯示(小時(shí)從 00 23 )。2、具有手動(dòng)校時(shí)、校分、校秒的功能。3、有定時(shí)和鬧鐘功能,能夠在設(shè)定的時(shí)間發(fā)出鬧鈴聲。4、能進(jìn)行整點(diǎn)報(bào)時(shí)。從 59分 50秒起,每隔 2秒發(fā)一次低音“嘟”的信號(hào),連 續(xù) 5 次,最后一次為高音“嘀”的信號(hào)。(二)、各項(xiàng)設(shè)計(jì)指標(biāo):1顯示部分采用的6個(gè)LED顯示器,從高位至低位分別顯示時(shí)、分、秒。2、有一個(gè)設(shè)置調(diào)鬧鐘定時(shí)時(shí)間、正常時(shí)間的按鈕,選擇調(diào)的對象。3、有三個(gè)按鈕分別調(diào)時(shí)、分、秒的時(shí)間。4、有一個(gè)按鈕用作開啟 / 關(guān)閉鬧鈴。5、另外需要兩個(gè)時(shí)鐘信號(hào)來給系統(tǒng)提供脈沖信號(hào),

2、使時(shí)鐘和鬧鐘正常工作,分別為1Hz、1kHz的脈沖。二、系統(tǒng)組成以及系統(tǒng)各部分的設(shè)計(jì)1、系統(tǒng)結(jié)構(gòu)描述 / 要求:系統(tǒng)(或頂層文件)結(jié)構(gòu)描述,各個(gè)模塊(或子程序) 的功能描述;(一) 系統(tǒng)的頂層文件:1、 頂層文件圖:(見下頁)2、 各模塊的解釋:1)、7 個(gè)輸入量 clk_1khz 、clk_1hz 、key_slt 、key_alarm 、sec_set 、min_set 、hour_set :其中 clk_1khz 為鬧鈴模塊提供時(shí)鐘,處理后能產(chǎn)生“嘟” 、“嘀”和變化的 鬧鈴聲音; clk_1hz 為計(jì)時(shí)模塊提供時(shí)鐘信號(hào),每秒計(jì)數(shù)一次; key_slt 選擇設(shè) 置對象: 定時(shí)或正常時(shí)間;

3、 key_alarm 能夠開啟和關(guān)閉鬧鈴; sec_set 、min_set 、 hour_set 用于設(shè)置時(shí)間或定時(shí),與 key_slt 相關(guān)聯(lián)。各按鍵輸出為脈沖信號(hào)。(2)、CNT60_A_SE模塊:這個(gè)模塊式將 clk_1hz 這個(gè)時(shí)鐘信號(hào)進(jìn)行 60 進(jìn)制計(jì)數(shù),并產(chǎn)生一個(gè)分鐘的觸發(fā)信號(hào)。該模塊能將當(dāng)前計(jì)數(shù)值實(shí)時(shí)按 BCD碼的格式輸出。將該輸出接到兩位 LED數(shù)碼后能時(shí)時(shí)顯示秒的狀態(tài)。通過alarm_clk可以選擇設(shè)置對象為時(shí)間還是 定時(shí)值。在設(shè)置時(shí)間模式上, key 上的一個(gè)輸入脈沖可以將 clk 的輸入信號(hào)加一。 在設(shè)置定時(shí)模式上, key 上的脈沖只修改定時(shí)值,不影響時(shí)間脈沖 clk

4、 的狀態(tài)。同時(shí)該模塊具有兩個(gè)輸出口 out_do 、 out_di 來觸發(fā)整點(diǎn)報(bào)時(shí)的“嘟” 、“嘀”聲音。(3) 、CNT60_A_MlN模塊:這個(gè)模塊式將CNT60_A_SE的輸出信號(hào)進(jìn)行60進(jìn)制計(jì)數(shù),并產(chǎn)生一個(gè)時(shí)位 的觸發(fā)信號(hào)。該模塊能將當(dāng)前計(jì)數(shù)值實(shí)時(shí)按 BCD碼的格式輸出。將該輸出接到兩 位 LED 數(shù)碼后能時(shí)時(shí)顯示分的狀態(tài)。 通過 alarm_clk 可以選擇設(shè)置對象為時(shí)間還 是定時(shí)值。在設(shè)置時(shí)間模式上, key 上的一個(gè)輸入脈沖可以將 clk 的輸入信號(hào)加 一。在設(shè)置定時(shí)模式上, key 上的脈沖只修改定時(shí)值,不影響時(shí)間脈沖 clk 的狀 態(tài)。同時(shí)該模塊具有三個(gè)輸出口 out_do

5、、 out_di 、 out_alarm 來觸發(fā)整點(diǎn)報(bào)時(shí)的 “嘟”、“嘀”、鬧鈴聲音。(4) 、CNT24_A_H01模塊:這個(gè)模塊式將CNT60_A_MlN勺輸出信號(hào)做24進(jìn)制計(jì)數(shù)。該模塊能將當(dāng)前計(jì) 數(shù)值實(shí)時(shí)按BCD碼的格式輸出。將該輸出接到兩位LED數(shù)碼后能時(shí)時(shí)顯示時(shí)的狀 態(tài)。通過 alarm_clk 可以選擇設(shè)置對象為時(shí)間還是定時(shí)值。在設(shè)置時(shí)間模式上, key 上的一個(gè)輸入脈沖可以將 clk 的輸入信號(hào)加一。在設(shè)置定時(shí)模式上, key 上 的脈沖只修改定時(shí)值,不影響時(shí)間脈沖 clk 的狀態(tài)。同時(shí)該模塊具有一個(gè)輸出口 out_alarm 來觸發(fā)整點(diǎn)報(bào)時(shí)的鬧鈴聲音。(5) 、PWM_01模塊

6、:該模塊為PWM產(chǎn)生模塊,通過EN可幵啟和關(guān)閉PWM輸出。模塊根據(jù) CLK信 號(hào)二分頻產(chǎn)生的高低音,并組合,能輸出三種聲音狀態(tài)“嘟” 、“嘀”、鬧鈴。而該三種聲音要被秒、分、時(shí)的輸出觸發(fā)才能輸出PWM。(二)系統(tǒng)各個(gè)模塊的VHDLS序:(1)、CNT60_A_SE模塊:程序源代碼如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt60_a_sec isport(clk,clr,enb: in std_logic;-clk:時(shí)鐘輸入信號(hào), clr :清零端, enb :使能端k

7、ey: in std_logic;- 輸入按鍵脈沖,調(diào)整鬧鈴定時(shí)或時(shí)間alarm_clk: in std_logic;-1:alarm 0:clk -設(shè)置模式選擇:鬧鈴調(diào)節(jié)模式、時(shí)間調(diào)節(jié)模式qout_sl: out std_logic_vector(3 downto 0); -顯示輸出秒的低位qout_sh: out std_logic_vector(3 downto 0);-顯示輸出秒的高位co: out std_logic; -進(jìn)位輸出,觸發(fā)分計(jì)數(shù)模塊out_do: out std_logic;-在整點(diǎn)報(bào)時(shí)中輸出“嘟”觸發(fā)信號(hào)out_di: out std_logic -在整點(diǎn)報(bào)時(shí)中輸出“

8、嘀”觸發(fā)信號(hào));end;architecture a of cnt60_a_sec issignal qout2_l:std_logic_vector(3 downto 0);signal qout2_h:std_logic_vector(3 downto 0);signal alarm_l:std_logic_vector(3 downto 0);signal alarm_h:std_logic_vector(3 downto 0);signal clk1,clk2,tclk,aclk,ac_slt: std_logic;beginprocess(alarm_clk) - 當(dāng)該端口輸入一個(gè)脈

9、沖時(shí),修改設(shè)置模式:時(shí)間調(diào)整或 鬧鈴模式切換beginif alarm_clk'event and alarm_clk='1' thenif ac_slt='0' then-如果為定時(shí)模式,將改為鬧鈴模式ac_slt<='1'elseac_slt<='0'end if;end if;end process;process(key,clk,ac_slt)-根據(jù)設(shè)置模式,處理 key 上的脈沖信號(hào)begin時(shí)間調(diào)整模式if ac_slt='0' then -則 tclk<=0 ,通過挖洞方式添

10、加aclk<='0'if clk='1' and key='1' then -clk=1一個(gè)脈沖tclk<='0'elsif clk='0' and key='1' then -clk=0, 則 tclk<=1, 產(chǎn)生一個(gè)高電平,添加一脈沖tclk<='1'elsetclk<=clk;end if;elsif ac_slt='1' then - 鬧鈴調(diào)整模式tclk<=clk;aclk<=key; -key 上的脈沖直接修改鬧

11、鈴定時(shí)值end if;end process;process(tclk,clr,enb) -60進(jìn)制計(jì)數(shù),個(gè)位、十位放在兩個(gè)臨時(shí)變量中,表示秒的狀態(tài)beginif clr='1' then-clearing works at the state of high voltageqout2_l<="0000"qout2_h<="0000"elsif tclk'event and tclk='1' thenif enb='1' then-enable works at high voltage

12、if qout2_l="1001" and qout2_h="0101" thenqout2_l<="0000"-a full mode is completed and a carryout is generatedqout2_h<="0000"elsif qout2_l="1001" thenqout2_l<="0000"qout2_h<=qout2_h+1;elseqout2_l<=qout2_l+1;- in process of cou

13、ntingend if;end if;end if;end process;process(aclk,clr,enb)-修改鬧鈴的定時(shí)值beginif clr='1' then-clearing works at the state of high voltagealarm_l<="0000"alarm_h<="0000"elsif aclk'event and aclk='1' thenif enb='1' then-enable works at high voltageif ala

14、rm_l="1001" and alarm_h="0101" thenalarm_l<="0000"-a full mode is completed and a carryout is generatedalarm_h<="0000"elsif alarm_l="0101" thenalarm_l<="0000"alarm_h<=alarm_h+1;elsealarm_l<=alarm_l+1;- in process of countinge

15、nd if;end if;end if;end process;產(chǎn)生進(jìn)位 , 顯示時(shí)process(qout2_l,qout2_h,alarm_l,alarm_h,alarm_clk)-間或鬧鈴定時(shí)值beginif qout2_l="0000" and qout2_h="0000" thenco<='1'elseco<='0'end if;if ac_slt='0' then -顯示時(shí)間qout_sl<=qout2_l;qout_sh<=qout2_h;else - 顯示定時(shí)值qou

16、t_sh<=alarm_h;qout_sl<=alarm_l;end if;end process;process(qout2_l,qout2_h) -根據(jù)秒的狀態(tài)輸出“嘟” 、“嘀”觸發(fā)信號(hào)beginif qout2_h="0101" thenif qout2_l="0000" thenout_do<='1'elsif qout2_l="0010" thenout_do<='1'elsif qout2_l="0100" thenout_do<='

17、;1'elsif qout2_l="0110" thenout_do<='1'elsif qout2_l="1000" thenout_do<='1'elseout_do<='0'elsif qout2_h="0000" then if qout2_l="0000" then out_di<='1' out_do<='0'elseout_di<='0'end if;elseou

18、t_do<='0'out_di<='0'end if;end process;end;(2)、CNT60_A_MlN模塊:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt60_a_min isport(clk,clr,enb: in std_logic; -clk:時(shí)鐘輸入信號(hào), clr :清零端, enb:使能端key: in std_logic; -輸入按鍵脈沖,調(diào)整鬧鈴定時(shí)或時(shí)間alarm_clk: in std_logic;

19、-1:alarm 0:clk -設(shè)置模式選擇:鬧鈴調(diào)節(jié)模式、時(shí)間調(diào)節(jié)模式qout_ml: out std_logic_vector(3 downto 0); - 顯示輸出分的低位qout_mh: out std_logic_vector(3 downto 0); - 顯示輸出分的高位co: out std_logic; -進(jìn)位輸出,觸發(fā)時(shí)計(jì)數(shù)模塊out_alarm:out std_logic;-鬧鈴觸發(fā)信號(hào),時(shí)間到后輸出高電平觸發(fā)鬧鈴out_do,out_di: out std_logic-在整點(diǎn)報(bào)時(shí)中輸出“嘟” “嘀”觸發(fā)信號(hào));end;architecture a of cnt60_a_m

20、in issignal qout2_l:std_logic_vector(3 downto 0);signal qout2_h:std_logic_vector(3 downto 0);signal alarm_l:std_logic_vector(3 downto 0);signal alarm_h:std_logic_vector(3 downto 0);signal clk1,clk2,tclk,aclk,ac_slt: std_logic;beginprocess(alarm_clk) - 當(dāng)該端口輸入一個(gè)脈沖時(shí),修改設(shè)置模式:時(shí)間調(diào)整或 鬧鈴模式切換beginif alarm_clk

21、'event and alarm_clk='1' thenif ac_slt='0' then-如果為定時(shí)模式,將改為鬧鈴模式ac_slt<='1'elseac_slt<='0'end if;end if;end process;process(key,clk,ac_slt) - 根據(jù)設(shè)置模式,處理 key 上的脈沖信號(hào)beginif ac_slt='0' then -時(shí)間調(diào)整模式aclk<='0'if clk='1' and key='1'

22、 then-clk=1則 tclk<=0 ,通過挖洞方式添加一個(gè)脈沖tclk<='0'elsif clk='0' and key='1' then-clk=0,則 tclk<=1, 產(chǎn)生一個(gè)高電平,添加一脈沖tclk<='1'elsetclk<=clk;end if;elsif ac_slt='1' then -鬧鈴調(diào)整模式tclk<=clk;aclk<=key; -key 上的脈沖直接修改鬧鈴定時(shí)值end if;end process;process(tclk,clr,e

23、nb) -60進(jìn)制計(jì)數(shù),個(gè)位、十位放在兩個(gè)臨時(shí)變量中,表示分的狀態(tài)beginif clr='1' then-clearing works at the state of high voltageqout2_l<="0000"qout2_h<="0000"elsif tclk'event and tclk='1' thenif enb='1' then-enable works at high voltageif qout2_l="1001" and qout2_h=&

24、quot;0101" thenqout2_l<="0000"-a full mode is completed and a carryoutis generated qout2_h<="0000"elsif qout2_l="1001" thenqout2_l<="0000"qout2_h<=qout2_h+1;elseqout2_l<=qout2_l+1;- in process of counting end if;end if;end if;end process;pr

25、ocess(aclk,clr,enb) - 修改鬧鈴的定時(shí)值beginif clr='1' then-clearing works at the state of high voltage alarm_l<="0000"alarm_h<="0000"elsif aclk'event and aclk='1' thenif enb='1' then-enable works at high voltageif alarm_l="1001" and alarm_h=&qu

26、ot;0101" thenalarm_l<="0000"-a full mode is completed and a carryout is generatedalarm_h<="0000"elsif alarm_l="0101" thenalarm_l<="0000"alarm_h<=alarm_h+1;elsealarm_l<=alarm_l+1;- in process of countingend if;end if;end if;end process;產(chǎn)生進(jìn)位

27、, 顯示process(qout2_l,qout2_h,alarm_l,alarm_h,alarm_clk) -時(shí)間或鬧鈴定時(shí)值 of high voltagebeginif qout2_l="0000" and qout2_h="0000" then co<='1'elseco<='0'end if;if ac_slt='0' thenqout_ml<=qout2_l;qout_mh<=qout2_h;elseqout_mh<=alarm_h;qout_ml<=alar

28、m_l;end if;end process;-判斷定時(shí)值與時(shí)間值相等,輸process(qout2_l,qout2_h,alarm_l,alarm_h)出鬧鈴觸發(fā)信號(hào)beginif qout2_l=alarm_l and qout2_h=alarm_h thenout_alarm<='1'elseout_alarm<='0'end if;end process;process(qout2_l,qout2_h) - 根據(jù)分的狀態(tài)輸出“嘟” 、“嘀”觸發(fā)信號(hào) beginif qout2_l="1001" and qout2_h=&q

29、uot;0101" thenout_do<='1'elseout_do<='0'end if;if qout2_l="0000" and qout2_h="0000" thenout_di<='1'elseout_di<='0'end if;end process;end;(3)、CNT24_A_HOUR塊:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;ent

30、ity cnt24_a_hour isport(clk,clr,enb: in std_logic; -clk:時(shí)鐘輸入信號(hào), clr :清零端,enb:使能端key: in std_logic; -輸入按鍵脈沖,調(diào)整鬧鈴定時(shí)或時(shí)間設(shè)置模式選擇:鬧鈴調(diào)節(jié)模alarm_clk: in std_logic;-1:alarm 0:clk-式、時(shí)間調(diào)節(jié)模式顯示輸出時(shí)的低位qout_hl: out std_logic_vector(3 downto 0); -qout_hh: out std_logic_vector(3 downto 0); -顯示輸出時(shí)的高位co: out std_logic; -進(jìn)

31、位輸出out_alarm:out std_logi-鬧鈴觸發(fā)信號(hào)輸出);end;architecture a of cnt24_a_hour issignal qout2_l:std_logic_vector(3 downto 0);signal qout2_h:std_logic_vector(3 downto 0);signal alarm_l:std_logic_vector(3 downto 0);signal alarm_h:std_logic_vector(3 downto 0);signal clk1,clk2,tclk,aclk,ac_slt: std_logic;beginp

32、rocess(alarm_clk) - 當(dāng)該端口輸入一個(gè)脈沖時(shí),修改設(shè)置模式:時(shí)間調(diào)整或鬧鈴模式切換begin如果為定時(shí)模式,將改為鬧鈴模式if alarm_clk'event and alarm_clk='1' thenif ac_slt='0' then-ac_slt<='1'elseac_slt<='0'end if;end if;end process;process(key,clk,ac_slt) -根據(jù)設(shè)置模式,處理 key 上的脈沖信號(hào)beginif ac_slt='0' then

33、 -時(shí)間調(diào)整模式aclk<='0'if clk='1' and key='1' then-clk=1一個(gè)脈沖則 tclk<=0 ,通過挖洞方式添加tclk<='0'elsif clk='0' and key='1' then-clk=0,則 tclk<=1, 產(chǎn)生一個(gè)高電平,添加一脈沖tclk<='1'elsetclk<=clk;end if;elsif ac_slt='1' then - 鬧鈴調(diào)整模式tclk<=clk;ac

34、lk<=key; -key 上的脈沖直接修改鬧鈴定時(shí)值end if;end process;process(tclk,clr,enb) -24進(jìn)制計(jì)數(shù),個(gè)位、十位放在兩個(gè)臨時(shí)變量中,表示時(shí)的狀態(tài)beginif clr='1' then-clearing works at the state of high voltageqout2_l<="0000"qout2_h<="0000"elsif tclk'event and tclk='1' thenif enb='1' then-en

35、able works at high voltageif qout2_l="1001" thenqout2_l<="0000"-a full mode is completed and a carryout is generatedqout2_h<=qout2_h+1;elsif qout2_l="0011" and qout2_h="0010" thenqout2_l<="0000"qout2_h<="0000"elseqout2_l<=qou

36、t2_l+1;- in process of countingend if;end if;end if;end process;beginif clr='1' then-clearing works at the state of high voltage alarm_l<="0000"alarm_h<="0000"elsif aclk'event and aclk='1' thenif enb='1' then-enable works at high voltageif alarm_

37、l="1001" then alarm_l<="0000"-a full mode is completed and a carryoutis generatedalarm_h<=qout2_h+1;elsif alarm_l="0011" and alarm_h="0010" then alarm_l<="0000"alarm_h<="0000"elsealarm_l<=alarm_l+1;- in process of countingend

38、 if;end if;end if;end process;, 顯示process(qout2_l,qout2_h,alarm_l,alarm_h,alarm_clk) -產(chǎn)生進(jìn)位時(shí)間或鬧鈴定時(shí)值 of high voltagebeginif qout2_l="0000" and qout2_h="0000" thenco<='1'elseco<='0'end if;if ac_slt='0' thenqout_hl<=qout2_l;qout_hh<=qout2_h;elseqou

39、t_hh<=alarm_h;qout_hl<=alarm_l;end if;end process;process(qout2_l,qout2_h,alarm_l,alarm_h)-定時(shí)值與時(shí)間值相等,則輸出鬧鐘觸發(fā)信號(hào)beginif qout2_l=alarm_l and qout2_h=alarm_h thenout_alarm<='1'elseout_alarm<='0'end if;end process;end;2、系統(tǒng)以及各個(gè)模塊的仿真波形( 1)、系統(tǒng)仿真波形:注:由于下面的模塊仿真存在毛刺,導(dǎo)致系統(tǒng)的仿真圖有一定的問題。(2) 、CNT60_A_SE模塊:注:在 50、 52、 54、 56、 58 處有嘟觸發(fā)輸出, 00 處有嘀觸發(fā)輸出等。(3) 、CNT6O_A_MIN模塊:注:本圖展示了按鍵調(diào)節(jié)時(shí)間值和定時(shí)值的仿真波形(部分仿真圖) 。注:該模塊的仿真波形圖,具有嘟、嘀聲音觸發(fā)輸出,定時(shí)與時(shí)間相等時(shí)有鬧鈴觸 發(fā)輸出等。(4) 、CNT24_A_HOUR塊注:該模塊的仿真圖,包含按鍵調(diào)整時(shí)間、定時(shí)值,鬧鐘觸發(fā)輸出等。(5) 、PWM_OU模塊(分三段剪切下來的,展示了三種聲音的效果)(1)、

溫馨提示

  • 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論