




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、WORD14/14實驗名稱:數字時鐘設計: 龍 成 班級: 電子與通信工程 學號: 3120302012 成績:一、實驗目的1.掌握各類計數器與它們相連的設計方法;2.掌握多個數碼管顯示的原理與方法;3.掌握模塊化設計方式;4.掌握用VHDL語言的設計思想以與整個數字系統的設計。二、實驗容 1. 設計要求 1)具有時、分、秒計數顯示功能,在數碼管顯示00:00:0023:59:59,以24小時循環計時。 2)完成可以計時的數字時鐘時鐘計數顯示時有LED燈的花樣顯示。 3)具有調節小時、分鐘與清零的功能。 4)具有整點報時功能。 2. 性能指標與功能設計 1)時鐘計數:完成時、分、秒的正確計時并
2、且顯示所計的數字;對秒、分60進制計數,時鐘24進制計數,并且在數碼管上顯示數值。 2)時間設置:手動調節分鐘、小時,可以對所設計的時鐘任意調時間??梢酝ㄟ^實驗板上的鍵7和鍵4進行任意的調整,因為時鐘信號均是1HZ的,所以LED燈每變化一次就來一個脈沖,即計數一次。 3)清零功能:reset為復位鍵,低電平時實現清零功能,高電平時正常計數。 4)蜂鳴器在整點時有報時信號產生,產生“滴答.滴答”的報警聲音。 5)根據進位情況,LED燈在時鐘顯示時有花樣顯示信號產生。 3. 系統方框圖數字時鐘 控制單元時調整分調整使能端信號CLK信號時顯示分顯示秒顯示24進制60進制60進制LED顯示整點報時花樣
3、顯示三、設計原理和過程3.1 硬件設計本設計使用VHDL硬件開發板,可編程邏輯器件EMP1270T144C5系列。設計過程中用到的外圍電路的設計有電源部分,可編程器件EMP1270T144C5,CPLD JTAG接口,晶振和蜂鳴器,LED數碼管顯示,DIP開關與按鍵輸入(具體電路見附錄)3.2 軟件設計 3.2.1 程序包my_pkg的設計說明 為了簡化程序設計增加可讀性,系統采用模塊化的設計方法,重復使用的組件以元件(component)的形式存在,以便相關塊的調用。下面列出my_pkg組件包的代碼。library ieee;use ieee.std_logic_1164.all;packa
4、ge my_pkg is component div40M元器件1 Port( clk: in std_logic; f1hz : out std_logic); end component; component count60元器件2 Port(clr,clk:in std_logic; one :buffer std_logic_vector(3 downto 0); ten :buffer std_logic_vector(3 downto 0); full:out std_logic; dout:buffer std_logic_vector(7 downto 0); end comp
5、onent; component count24元器件3 Port(clr,clk:in std_logic; one :buffer std_logic_vector(3 downto 0); ten :buffer std_logic_vector(3 downto 0); full:out std_logic); end component; component scan6元器件4 port (clr,clk : in STD_LOGIC; h_ten,h_one,m_ten,m_one,s_ten,s_one: in STD_LOGIC_vector(3 downto 0); cs:
6、out STD_LOGIC_vector(5 downto 0); mux_out: out STD_LOGIC_vector(3 downto 0); end component; component bin2led元器件5 port (bin : in std_logic_vector (3 downto 0); led : out std_logic_vector (7 downto 0) ); end component; component sh1k 元器件6 Port( clk: in std_logic;-from system clock(40MHz) f1hz : out s
7、td_logic);- 1Hz output signal end component; component alarm_set元器件7Port(rst,hz1: in std_logic;-system clock 1Hz alarm,ok: in std_logic;-keep pushing to declare alarm set sec_tune: in std_logic; sec_one,sec_ten:out std_logic_vector(3 downto 0);end component;end my_pkg; 3.2.2 count60組件由此提供分(秒)計數值,當分計
8、數器計數到59再來一個脈沖信號秒計數器清零從新開始計數,而進位則作為小時計數器的計數脈沖,使小時計數器計數加1,同時分計數器在分設置時鐘信號的響應下設置分計數器的數值。在count60組件中,個位(one)和十位(ten)分別計數,都設為二進制四位矢量形式,當個位從0計到9時,在下一個clk上升沿來臨后,十位進1,個位變0,十位從0到5計數,在十位為5,個位9的時候,下一個上升沿來臨后,十位個位都變0,進位full加1。因此在程序設計中需要兩個進程process來分別完成計數,秒計數以1Hz的輸入為觸發信號,分計數以秒的full信號為觸發信號。具體的count60的組件代碼如下:Library
9、 ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count60 is Port(clr,clk:in std_logic; one :buffer std_logic_vector(3 downto 0); ten :buffer std_logic_vector(3 downto 0); full:out std_logic; dout:buffer std_logic_vector(7 downto 0);end count60;architecture behav of count60 is
10、 beginprocess(clr,clk) begin if(clr=0)then one=0000; elsif(rising_edge(clk)then if(one=1001)then one=0000; else one=one+1; end if; end if;end process; process(clr,clk) begin if(clr=0)then ten=0000; elsif(rising_edge(clk)then if(one=1001)then if(ten=0101)then ten=0000; else ten=ten+1; end if; end if;
11、 end if;end process ;dout=ten&one;process(clk)滿59進位(置full值beginif(rising_edge(clk)then if ten=0101then if one=1001then full=1; else full=0; end if; else full=0; end if;end if;end process;end behav; 設定clk與clr兩個系統的輸入后,課觀察到one和ten的波形,在計數值達到59后,即ten為0101,one為1001以后,即進位到0000 0000,full進1,波形如下。 3.2.3 count
12、24組件 由此提供時計數值,當時計數器計數到23再來一個脈沖信號秒計數器清零從新開始計數,而進位則作為小時計數器的計數脈沖,使小時計數器計數加1,同時分計數器在分設置時鐘信號的響應下設置時計數器的數值。在count24組件中,個位(one)和十位(ten)分別計數,都設為二進制四位矢量形式,在ten小于2的時候,個位從0計到9時,滿9ten加1,在ten為2的時候,one從0到3計數,one為3時候,在下一個clk上升沿來臨后,ten與one都變0,進位full加1。因此在程序設計中需要多個個進程process來分別完成計數,時計數以分的full的輸入為觸發信號,分計數以秒的full信號為觸發
13、信號。具體的count24的組件代碼如下:Library ieee;Use ieee.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Entity count24 is Port(clr,clk:in std_logic; one :buffer std_logic_vector(3 downto 0); ten :buffer std_logic_vector(3 downto 0); full:out std_logic );end count24;architecture behav of count24 is beginproces
14、s(clr,clk)計數0到23 begin if(clr=0)then ten=0000; one=0000; elsif(rising_edge(clk)then if(ten0010)then if(one1001)then one=one+0001; end if; if one=1001then one=0000; ten=ten+0001; end if; end if; if(ten=0010) then if(one0011)then one=one+0001; end if; if one=0011then one=0000; ten=0000; end if; end if
15、; end if; end process;process(clk)滿23進位beginif(rising_edge(clk)then if ten=0010then if one=0011then full=1; else full=0; end if; else full=0; end if;end if;end process;end behav; 小時計數模塊圖形分析:用來對時進行計數,當記到計數器的低四位小于2時,one從0到9 計數,ten 為2時,one從0到3計數,所以完成了24進制的計數,clk為系統時鐘信號,具體波形如下: 3.2.4 div40M分頻組件 為了便于時鐘計數
16、,需要1Hz的時鐘信號。為了節省電力耗電,輸出采用7段LED數碼管來顯示。要提供秒鐘的源信號,以便正常的計數,另外,6個led數碼管要都顯示,利用人眼的視覺暫留效應,需要1000hZ的時鐘掃描信號。在本系統中,時鐘信號發生器的信號頻率為40MHz,因此要將其進行分頻,產生1HZ和1KHz的信號。代碼如下:Library IEEE;Use IEEE.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Use IEEE.std_logic_arith.all;Entity div40M is Port( clk: in std_logic ; -f
17、rom system clock(40MHz) f1hz: out std_logic);- 1Hz output signalend div40M;architecture arch of div40M issignal count : integer range 0 to 19999999;beginprocess (clk)begin if rising_edge(clk) then count= 10000000 then f1hz=1; else f1hz=0; end if; end if;end process;end arch;本模塊將40MHZ分頻,分成1000HZ,提供掃描
18、(片選)的時間Library IEEE;Use IEEE.std_logic_1164.all;Use ieee.std_logic_unsigned.all;Use IEEE.std_logic_arith.all;Entity sh1k is Port( clk: in std_logic; f1hz: out std_logic);end sh1k;architecture arch of sh1k issignal count : integer range 0 to 39999;beginprocess (clk)begin if rising_edge(clk) then coun
19、t=20000 then f1hz=1; else f1hz=0; end if; end if;end process;end arch;波形分析:具體的分頻波形如下,由于這里的40MHZ太大,仿真時不便觀察這里我們以40KHZ來分頻,效果如下: 3.2.5 scan6掃描組件 由于LED使用動態顯示,因此要采用掃描的方式來點亮各個LED管,人眼的視覺延遲1/32秒。在本模塊中,時、分、秒的每一位數都作為輸入,同時提供一個片選(6位),每來一個clk 進行一次選位循環,即依次點亮6個LED燈管。在點亮的對應管上將該位的數字送給一個輸出端口max_out.送到顯示模塊顯示。具體的代碼如下:li
20、brary IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_arith.all;use IEEE.std_logic_unsigned.all;entity scan6 is port (clr,clk : in STD_LOGIC; h_ten,h_one,m_ten,m_one,s_ten,s_one: in STD_LOGIC_vector(3 downto 0); cs: out STD_LOGIC_vector(5 downto 0);片選 mux_out: out STD_LOGIC_vector(3 downto 0);-要
21、顯示的那一個時鐘位end scan6;architecture arch of scan6 issignal sel : std_logic_vector(2 downto 0);begin process (clr,clk,h_ten,h_one,m_ten,m_one,s_ten,s_one) begin if clr=0 then sel=000; elsif rising_edge(clk) then sel mux_out = s_one; cs mux_out = s_ten; cs mux_out = m_one; cs mux_out = m_ten; cs mux_out =
22、 h_one; cs mux_out = h_ten; cs mux_out ledledledledledledledledledledNULL;END CASE;END PROCESS;end arch;仿真波形如下:3.2.7 alarm_set組件 為了設定鬧鐘,我們設計一個目標調整程序,以1Hz的顯示速率來調整時分秒的顯示。這里的alarm為指撥開關,當為on時,六個數字即顯示00:00:00,以等待輸入,當持續按鍵后,秒從0到59依次增加,再返回0,任何時刻松開按鍵,即為要顯示的值。調分鍵和調時鍵的動作原理一樣。此時OK指撥開關的然在off狀態。代碼如下:library IEEE;
23、 use IEEE.std_logic_1164.all;use IEEE.std_logic_arith.all;use IEEE.std_logic_unsigned.all;Entity alarm_set is Port(rst,hz1: in std_logic;-system clock 1Hz alarm,ok: in std_logic;-keep pushing to declare alarm set sec_tune: in std_logic; sec_one,sec_ten:out std_logic_vector(3 downto 0);End;define the
24、 signal_structure and _flow of the device architecture arch of alarm_set is signal sec_one_tmp: std_logic_vector(3 downto 0) ; signal sec_ten_tmp: std_logic_vector(3 downto 0) ; begin tuning:process(rst,hz1,alarm,ok) begin if rst=1 then sec_one_tmp=0000;sec_ten_tmp=0000; elsif rising_edge(hz1) then
25、if alarm=0 and ok=1 then if sec_tune=1 then if sec_one_tmp=1001 then sec_one_tmp=0000; if sec_ten_tmp0101 then sec_ten_tmp=sec_ten_tmp+0001; else sec_ten_tmp=0000 ; end if; else sec_one_tmp=sec_one_tmp +0001; end if; end if; else null; end if; end if; end process tuning; sec_one=sec_one_tmp; sec_ten
26、clk,f1hz=hz1);元件的調用 u1:count60 port map(clr=clr,clk=hz1,one=sec_one,ten=sec_ten,full=full_sec); u2:count60 port map(clr=clr,clk=full_sec,one=min_one,ten=min_ten,full=full_min); u3:count24 port map(clr=clr,clk=full_min,one=hour_one,ten=hour_ten,full=full_hour);end block normal_counting;scantime:block
27、掃描時間的設定,這里為1毫秒(1000Hz)begin u4:sh1k port map(clk=clk,f1hz=hz1k);end block scantime;scan_display:block將4位二進制的時間轉為BCD碼,顯示.begin u7:alarm_set port map(rst=clr,hz1=hz1,alarm=alarm,ok=ok,sec_tune=sec_button,sec_one=a_sec_one,sec_ten=a_sec_ten); u5:scan6 port map(clr=clr,clk=hz1k,s_one=a,s_ten=b, m_one=c,
28、m_ten=d, h_one=e,h_ten=f, mux_out=time_bin, cs=cs); u6:bin2led port map(bin=time_bin,led=dout);送到端口顯示end block scan_display;beep:process(hz1,clr)beginif rising_edge(hz1) then if sec_ten=0000and sec_one=0000and min_one=0000 and min_ten=0000 then if bb3 then bb=bb+1; beep_driver=hz1; else beep_driver=0; end if; end if; end if;end process; process(cl
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 預防醫學:合理營養與健康
- 主體結構施工方案(方案改版)
- 關于與旅游發展集團成立合資公司的可行性研究報告
- 私立華聯學院《英語視聽說Ⅱ》2023-2024學年第二學期期末試卷
- 四川省涼山彝族自治州昭覺縣2025年四下數學期末監測模擬試題含解析
- 廣州城市理工學院《Linux系統》2023-2024學年第二學期期末試卷
- 項目督導述職報告
- 四川中醫藥高等??茖W校《經典誦讀二》2023-2024學年第一學期期末試卷
- 黑龍江省佳木斯中學2025屆高三下學期高考適應性練習(一)歷史試題試卷含解析
- 中國消防救援學院《半導體材料與器件》2023-2024學年第二學期期末試卷
- 核和輻射事故現場衛生救援
- 學生心理危機識別與干預(家長教師版)
- 廣西建設工程質量檢測和建筑材料試驗收費項目及標準指導性意見(新)2023.10.11
- 象征手法 (2)課件
- 八項規定學習課件
- 《過零丁洋》公開課件
- 黃精栽培技術PPT
- 08S305-小型潛水泵選用及安裝圖集
- 《專利糾紛與處理》PPT課件
- 農業技術推廣知識課程教學大綱
- 員工技能等級評定方案匯編
評論
0/150
提交評論