第一篇:EDA實現(xiàn)多功能數(shù)字鐘
EDA實現(xiàn)多功能數(shù)字鐘
實
驗 報 告
專業(yè)班級:
學(xué)生姓名:
學(xué)生學(xué)號:
目錄
一、內(nèi)容摘要
二、實驗要求
三、各底層模塊設(shè)計
四、總體方案
五、心得體會
一、實驗內(nèi)容
利用 QuartusII 軟件,結(jié)合所學(xué)的數(shù)字電路的知識設(shè)計一個 24 時多功能數(shù) 字鐘,具有正常分、秒計時,動態(tài)顯示的功能。分析整個電路的工作原理,分別說明各子模塊的設(shè)計原理和調(diào)試、仿真、編 程的過程。
二、實驗任務(wù):
用 FPGA 器件和 EDA 技術(shù)實現(xiàn)多功能數(shù)字鐘的設(shè)計
已知條件:
1、MAX+Plus 軟件
2、FPGA 實驗開發(fā)裝置
基本功能:
1、以數(shù)字形式顯示時、分、秒的時間;
2、小時計數(shù)器為 24 進(jìn)制;
3、分、秒計數(shù)器為 60 進(jìn)制。
三、底層模塊設(shè)計(電路原理圖及仿真)
1、小時計數(shù)器為24進(jìn)制 電路原理圖
仿真圖
封裝圖
2、分、秒計時器都為60進(jìn)制 電路原理圖
仿真圖
封裝圖
四、總體方案
按照上述實驗要求,本次電子數(shù)字時鐘實驗,通過兩個模 60 計數(shù)器及一個模 24 計數(shù)器級聯(lián)既可以實現(xiàn)計時模塊。多功能數(shù)字鐘的主體部分 電路原理圖
仿真圖
封裝圖
五、心得體會
剛剛開始覺得做這個電子實驗報告挺難的,因為對軟件的不熟悉和對這個實驗操作的也不熟悉,對著老師給的資料也做了很長時間,就是仿真的時候有些該注意的沒有注意,導(dǎo)致仿真失敗,但是后來還是自己慢慢拿的請教同學(xué)、老師哪里出了問題,后來才做出來了,把60進(jìn)制的做出來了,后來的24進(jìn)制按照老師給的電路原理圖也成功了仿真出來,我用了很長時間才編寫出來,現(xiàn)在看看,也沒有那么難了。同時請教老師,和同學(xué)、通過實驗掌握一些邏輯組合器件的基本功能和用法??傊液芨兄x這次實驗可以給我這樣的機(jī)會,這個實驗給了我很對的收獲,我相信這會對我以后的學(xué)習(xí)很有幫助。
第二篇:eda 實現(xiàn)多功能數(shù)字鐘
一、標(biāo)題:EDA實現(xiàn)多功能數(shù)字鐘
二、任務(wù)書:設(shè)計要求是用FPGA器件和EDA技術(shù)實現(xiàn)多功能數(shù)字鐘的設(shè)計,⑴ 控制功能包括①以數(shù)字形式顯示時、分、秒的時間;②小時計數(shù)器為24進(jìn)制;③分、秒計數(shù)器為60進(jìn)制;④有兩個使能端起到校時、校分的作用,同時按無效;⑤每小時的59分51、53、55、57、59分別以四長聲一短聲進(jìn)行模擬電臺仿真;⑥讓信號燈在晚上19點至早上5點亮;⑵ 在Max+plusⅡ軟件系統(tǒng)平臺上建立多功能數(shù)字鐘電路的頂層電路文件并完成編譯和仿真,并對器件進(jìn)行下載檢查。
三、關(guān)鍵詞:數(shù)字鐘 原理電路 編譯 仿真 下載
四、數(shù)字鐘電路系統(tǒng)的組成框圖:
五、各功能模塊設(shè)計、仿真波形及其分析說明:
1、小時計時模塊:
仿真波形:
分析說明:
當(dāng)小時的高四位為0、1時,小時的低四位為九時,在下一個時鐘的上跳延來了之后,高四位加一;當(dāng)小時的高四位為2,同時低四位為3時,小時的高低四位都清零。實現(xiàn)從00到23的循環(huán)計數(shù)。
2、分鐘計時模塊:
仿真波形:
分析說明:
當(dāng)分鐘的高四位為0、1、2、3、4時,小時的低四位為九時,在下一個時鐘的上跳延來了之后,高四位加一;當(dāng)分鐘的高四位為5時,同時低四位為9時,分鐘的高低四位都清零,實現(xiàn)從00到59的循環(huán)計數(shù)。
3、秒計時模塊(與分計時模塊相同);
4、校時、校分模塊:
仿真波形:
分析說明:
SWM、SWH兩開關(guān)先設(shè)置1,秒時鐘,分時鐘,小時時鐘分別設(shè)置為不同頻率的時鐘,當(dāng)開關(guān)SWM置0即按下時,秒時鐘CPS對分鐘進(jìn)行校對,即如圖所示CPM在SWM為0時頻率與CPS相同;同理,當(dāng)SWH為0時用秒時鐘對小時進(jìn)行校對,即CPH在SWH為0時頻率與CPS相同。當(dāng)SWM、SWH都不為0時,分鐘、小時正常計時。
5、整點報時模塊:
仿真波形:
分析說明:
為實現(xiàn)時鐘在59分51秒53秒55秒57秒時,以低音報時,當(dāng)為59分59秒時以高音報時;所以將M[7..0]從高位到低位設(shè)置為0101 1001轉(zhuǎn)換成十進(jìn)制即為59分,秒的十位都為5所以S7到S4設(shè)置為0101,秒的個位1、3、5、7、9,即0001、0011、0101、0111、1001,從S3到S0只有當(dāng)S3設(shè)置為1的時候秒個位為9,通過分頻以1000HZ輸出以實現(xiàn)高音報時;1、3、5、7時S0都為0,為能同時確定1、3、5、7則將S0設(shè)置為0,S1、S2則為任意。如波形所示,S3取一段設(shè)置為1時,輸出FU變?yōu)?000HZ的高頻報時,其余狀態(tài)一致為500HZ低頻報時,從而實現(xiàn)預(yù)期情況。
6、時段控制模塊:
仿真波形:
分析說明:
從19點到凌晨5點(含5點),燈亮,即完成時段控制。
六、頂層邏輯電路圖、仿真波形及分析結(jié)論:
建立一個頂層文件如圖:
仿真波形如下:
分析結(jié)論:
經(jīng)仿真波形分析①走時正常;②能〝校時〞〝校分〞;③整點報時;④時段控制到位。功能完全符合設(shè)計要求,可以下載。
七、定義芯片管腳號(列表示意)及下載過程:
1、由于提供的實驗箱的七段顯示器是掃描形式工作,需要進(jìn)行譯碼以及選擇掃描,需添加模塊:
該模塊有三部分組成,包括一個8進(jìn)制計數(shù)器,一個3-8數(shù)據(jù)選擇器及七段顯示譯碼器:
將該模塊連入最后的頂層文件中,即可進(jìn)行下載工作。
2、按鍵掃描模塊:由于試驗箱提供的按鍵系統(tǒng)為4*4掃描矩陣,需將橫向或縱向按鍵設(shè)置0或1,該模塊只需要在頂層文件中接4個output出來接地,如圖:
3、分配輸入、輸出信號在器件上的引腳號:
4、引腳分配表:
5、對器件進(jìn)行下載:
選MAX+plus II/Programmer,彈出編程對話框,如圖:
檢查編程文件名和器件,正確,接上硬件后,點擊器件編程。即完成下載。
八、課程設(shè)計中遇到問題及解決方法
Q1:下載后,秒鐘不進(jìn)位
A:檢查原理電路發(fā)現(xiàn)輸入輸出接錯位,經(jīng)更正正常; Q2:到59分51秒等不鬧鐘
A:檢查蜂鳴器是否接錯管腳,下載器上套線是否接好,最后發(fā)現(xiàn)是套線的問題,解決后,正常鳴叫。
九、課程設(shè)計項目最終結(jié)論
通過各模塊級聯(lián)最后成功下載,實現(xiàn)了兩個使能對分秒校時,整點仿電臺報時以及時段控制的多功能數(shù)字鐘。
十、心得體會:
實驗過程中最然遇到了很多困難,從畫圖到理解電路圖,還有接觸沒有接觸過的下載,把紙上的東西用到了硬件中,質(zhì)的改變。看到成功的數(shù)字鐘,很有成就感。好像聽到的蜂鳴聲是從未聽到過的美妙樂曲。課設(shè)給我們指引了又一工作方向,培養(yǎng)對這些的興趣,對以后工作應(yīng)該很有幫助,所以堅定了我課后還要多看書多學(xué)習(xí)這方面知識的信念。
十一、參閱教材及文獻(xiàn):
《電子線路實驗設(shè)計仿真講義》
按鈕,直接對
第三篇:EDA課程設(shè)計——多功能數(shù)字鐘
哈爾濱工業(yè)大學(xué)(威海)電子學(xué)課程設(shè)計報告
帶有整點報時的數(shù)字鐘設(shè)計與制作
姓名: 蔣棟棟 班級: 0802503 學(xué)號: 080250331 指導(dǎo)教師:
井巖
目錄
一、課程設(shè)計的性質(zhì)、目的和任務(wù)????????????3
二、課程設(shè)計基本要求?????????????????3
三、設(shè)計課題要求???????????????????3
四、課程設(shè)計所需要儀器????????????????4
五、設(shè)計步驟?????????????????????4
1、整體設(shè)計框圖???????????????????4
2、各個模塊的設(shè)計與仿真???????????????4
2.1分頻模塊???????????????????????4
2.2計數(shù)器模塊??????????????????????6
2.3控制模塊??????????????????????10
2.4數(shù)碼管分配?????????????????????13
2.5顯示模塊??????????????????????14
2.6報時模塊??????????????????????16
六、調(diào)試中遇到的問題及解決的方法???????????18
七、心得體會?????????????????????18
一、課程設(shè)計的性質(zhì)、目的和任務(wù)
創(chuàng)新精神和實踐能力二者之中,實踐能力是基礎(chǔ)和根本。這是由于創(chuàng)新基于實踐、源于實踐,實踐出真知,實踐檢驗真理。實踐活動是創(chuàng)新的源泉,也是人才成長的必由之路。
通過課程設(shè)計的鍛煉,要求學(xué)生掌握電路的一般設(shè)計方法,具備初步的獨立設(shè)計能力,提高綜合運用所學(xué)的理論知識獨立分析和解決問題的能力,培養(yǎng)學(xué)生的創(chuàng)新精神。
二、課程設(shè)計基本要求
掌握現(xiàn)代大規(guī)模集成數(shù)字邏輯電路的應(yīng)用設(shè)計方法,進(jìn)一步掌握電子儀器的正確使用方法,以及掌握利用計算機(jī)進(jìn)行電子設(shè)計自動化(EDA)的基本方法。
三、設(shè)計課題要求
(1)構(gòu)造一個24小時制的數(shù)字鐘。要求能顯示時、分、秒。(2)要求時、分、秒能各自獨立的進(jìn)行調(diào)整。
(3)能利用喇叭作整點報時。從59分50秒時開始報時,每隔一秒報時一秒,到達(dá)00分00秒時,整點報時。整點報時聲的頻率應(yīng)與其它的報時聲頻有明顯區(qū)別。
#設(shè)計提示(僅供參考):(1)對頻率輸入的考慮
數(shù)字鐘內(nèi)所需的時鐘頻率有:基準(zhǔn)時鐘應(yīng)為周期一秒的標(biāo)準(zhǔn)信號。報時頻率可選用1KHz和2KHz左右(兩種頻率相差八度音,即頻率相差一倍)。另外,為防止按鍵反跳、抖動,微動開關(guān)輸入應(yīng)采用寄存器輸入形式,其時鐘應(yīng)為幾十赫茲。
(2)計時部分計數(shù)器設(shè)計的考慮 分、秒計數(shù)器均為模60計數(shù)器。
小時計數(shù)為模24計數(shù)器,同理可建一個24進(jìn)制計數(shù)器的模塊。(3)校時設(shè)計的考慮
數(shù)字鐘校準(zhǔn)有3個控制鍵:時校準(zhǔn)、分校準(zhǔn)和秒校準(zhǔn)。
微動開關(guān)不工作,計數(shù)器正常工作。按下微動開關(guān)后,計數(shù)器以8Hz頻率連續(xù)計數(shù)(若只按一下,則計數(shù)器增加一位),可調(diào)用元件庫中的邏輯門建一個控制按鍵的模塊,即建立開關(guān)去抖動電路(見書70頁)。
(4)報時設(shè)計的考慮
可以將高頻時鐘分頻得到約2KHz和1KHz的音頻,作為數(shù)字鐘的報時頻率。當(dāng)電子鐘顯示XX:59:50時,數(shù)字鐘開始報時“DO“,持續(xù)一秒,而且每隔一秒報一下,直至顯示XX:00:00時報“DI”,持續(xù)一秒后停止。最后輸出至喇叭。應(yīng)調(diào)用元件庫中的邏輯門建一個控制報時的模塊。
(5)建一個七段譯碼的模塊
因在系統(tǒng)可編程器件實驗箱上的數(shù)碼管沒有經(jīng)過譯碼,故要用AHDL語言寫一個七段譯碼的模塊,且應(yīng)考慮數(shù)碼管為共陽極。數(shù)碼管上的點(D2、D4、D6)應(yīng)置Vcc。
四、課程設(shè)計所需要儀器
1、計算機(jī)一臺
2、quartusⅡ軟件
3、FPGA開發(fā)板
五、設(shè)計步驟
1、模塊介紹
(1)分頻模塊:產(chǎn)生1Hz、1KHz、2KHz頻率(2)計數(shù)器模塊:生成60進(jìn)制、24進(jìn)制計數(shù)器(3)控制模塊:按鍵控制、按鍵消抖
(4)顯示模塊:7段數(shù)碼管顯示器,分別顯示小時、分鐘、秒(5)報時模塊:進(jìn)行整點報時
2、各個模塊的設(shè)計與仿真
2.1分頻模塊
CLK晶振頻率50MHZ,分成2KHZ,1KHZ,1HZ的信號?;鶞?zhǔn)1HZ信號作為時鐘計時的秒計數(shù)時鐘信號;分頻的1KHZ,2KHZ信號用于報時電路的不同聲訊。
程序代碼:
library ieee;use ieee.std_logic_1164.all;entity fre is port(clk ,sel: in std_logic;clk1hz,clk1khz,clk2khz:out std_logic);end fre;architecture beh of fre is signal data1khz,data2khz,data1hz : std_logic := '0';begin clk1hz <= data1hz;clk1khz <= data1khz;clk2khz <= data2khz;clk1khz_pro : process(clk)--產(chǎn)生1khz信號 variable cnt : integer range 0 to 24999;begin if clk'event and clk='1' then if cnt = 24999 then cnt := 0;data1khz <= not data1khz;else cnt := cnt + 1;end if;end if;end process clk1khz_pro;clk2khz_pro : process(clk)--variable cnt : integer range 0 to 12499;begin if clk'event and clk='1' then if cnt = 12499 then cnt := 0;data2khz <= not data2khz;else cnt := cnt + 1;end if;end if;end process clk2khz_pro;clk1hz_pro : process(data1khz)--variable cnt : integer range 0 to 499;begin if data1khz'event and data1khz='1' then if sel='0' then cnt:=0;else if cnt = 499 then cnt := 0;data1hz <= not data1hz;else cnt := cnt + 1;end if;end if;end if;end process clk1hz_pro;end beh;
輸入模塊電路圖:
產(chǎn)生2khz信號 產(chǎn)生1hz 信號 5 freclkclk1hzclk2khzinst selclk1khz2.2計數(shù)器模塊
由秒計數(shù)器,分計數(shù)器,時計數(shù)器組成了最基本的數(shù)字鐘計時電路,兩個六十進(jìn)制計數(shù)器與二十四進(jìn)制計數(shù)器組合構(gòu)成。
程序代碼:
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use IEEE.STD_LOGIC_ARITH.ALL;
entity shuzizhong is port(clk_change : in std_logic;s_en,m_en,h_en:in std_logic;sel:in std_logic;secout,minout,hourout :out std_logic;sl,sh,ml,mh,hl,hh:out std_logic_vector(3 downto 0);a:out std_logic_vector(15downto 0));end shuzizhong;architecture behav of shuzizhong is
signal low_rega,high_rega,low_regb,high_regb,low_regc,high_regc :std_logic_vector(3 downto 0):=“0000”;signal sout,mout,hout :std_logic :='0';begin--秒的60進(jìn)制進(jìn)制 counter_sec_l : process(clk_change,s_en)begin
sl<=low_rega;sh<=high_rega;ml<=low_regb;mh<=high_regb;hl<=low_regc;hh<=high_regc;6 if clk_change'event and clk_change='1' then if s_en='1' then if low_rega=“1001” then low_rega <= “0000”;else low_rega <= low_rega+'1';end if;end if;end if;end process counter_sec_l;counter_sec_h : process(clk_change,s_en,low_rega)begin if clk_change'event and clk_change='1' then if s_en='1' then if low_rega=“1001” then if high_rega =“0101”then high_rega <= “0000”;else high_rega <= high_rega+'1';end if;end if;end if;end if;end process counter_sec_h;sout <= '1' when low_rega=“1001” and high_rega=“0101” else '0';
----分鐘的60進(jìn)制設(shè)置 counter_min_l : process(clk_change,m_en)begin if clk_change'event and clk_change='1' then if m_en='1' then if sout='1'or sel='0' then if low_regb=“1001” then low_regb <= “0000”;else low_regb <= low_regb+'1';end if;end if;end if;end if;end process counter_min_l;counter_min_h : process(clk_change,m_en,low_regb)begin if clk_change'event and clk_change='1' then 7 if sout='1'or sel='0' then if m_en='1' then if low_regb=“1001” then
if high_regb =“0101”then
high_regb <= “0000”;else high_regb <= high_regb+'1';end if;end if;end if;end if;end if;end process counter_min_h;mout <= '1' when low_regb=“1001” and high_regb=“0101”and sout='1' else '0';--小時的24進(jìn)制設(shè)置 counter_hour_l : process(clk_change,h_en)begin if clk_change'event and clk_change='1' then if h_en='1' then if mout='1'or sel='0' then if low_regc=“1001”or hout='1' then low_regc <= “0000”;else low_regc <= low_regc+'1';end if;end if;end if;end if;end process counter_hour_l;counter_hour_h : process(clk_change,h_en,hout)begin if clk_change'event and clk_change='1' then if mout='1'or sel='0' then if h_en='1' then if hout='1' then high_regc<=“0000”;else if low_regc=“1001” then high_regc <= high_regc+'1';end if;end if;end if;8 end if;end if;end process counter_hour_h;hout <= '1' when low_regc=“0011” and high_regc=“0010” else '0';secout<=sout;minout<=mout;hourout<=hout;a<=high_regb&low_regb&high_rega&low_rega;end behav;
輸入模塊電路圖:
shuzizhongclk_changes_enm_enh_enselsecoutminouthouroutsl[3..0]sh[3..0]ml[3..0]mh[3..0]hl[3..0]hh[3..0]a[15..0]inst
2.3控制模塊
分五個狀態(tài)0狀態(tài)正常計時,按下按鍵進(jìn)入下一狀態(tài)開始調(diào)時模式1,按下按鍵進(jìn)入調(diào)秒模式2,按下按鍵進(jìn)入調(diào)分模式3,按下按鍵進(jìn)入調(diào)小時模式4.按下按鍵恢復(fù)正常計時模式。
程序代碼:
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity key_press is port(set ,mode: in std_logic;clk1khz,clk1hz: in std_logic;secout,minout: in std_logic;clk_change,clk2hz_en:out std_logic;sel,s_ce,m_ce,h_ce:out std_logic;s_en,m_en,h_en:out std_logic);end key_press;architecture beh of key_press is 9 signal key1,key2:std_logic;signal sce_reg, mce_reg ,hce_reg:std_logic;signal ssl,ssen,mmen,hhen:std_logic;signal con : integer range 0 to 4 :=0;--按鍵按下(延時)begin
key_press2 : process(set,clk1khz)variable cnt :integer range 0 to 999;begin if set='0' then if clk1khz'event and clk1khz='1'then if cnt=50 and set='0' then cnt :=cnt+1;key2 <= '1';else cnt:=cnt+1;key2 <= '0';end if;end if;else cnt:=0;key2<='0';end if;end process key_press2;key_press1 : process(mode,clk1khz)variable cnt :integer range 0 to 999;begin if mode='0' then if clk1khz'event and clk1khz='1'then if cnt=50 and mode='0' then cnt :=cnt+1;key1 <= '1';else cnt:=cnt+1;key1 <= '0';end if;end if;else cnt:=0;key1<='0';end if;end process key_press1;count : process(key1,key2)begin if key1'event and key1='1' then if con=4 then con<=0;else con<=con+1;end if;end if;10 end process count;con_pro : process(con)begin case con is when 0 => ssl<='1';sce_reg <= '0';ssen <='1';mce_reg <= '0';mmen <='1';hce_reg <= '0';hhen <='1';clk2hz_en <='0';when 1 => ssl<='0';sce_reg <= '0';ssen <='1';mce_reg <= '0';mmen <='1';hce_reg <= '0';hhen <='1';clk2hz_en <='1';when 2 => ssl<='0';sce_reg <= '1';ssen <='1';mce_reg <= '0';mmen <='0';hce_reg <= '0';hhen <='0';clk2hz_en <='1';when 3 => ssl<='0';sce_reg <= '0';ssen <='0';mce_reg <= '1';mmen <='1';hce_reg <= '0';hhen <='0';clk2hz_en <='1';when 4 => ssl<='0';sce_reg <= '0';ssen <='0';mce_reg <= '0';mmen <='0';hce_reg <= '1';hhen <='1';clk2hz_en <='1';when others => ssl<='0';sce_reg <= '0';ssen <='1';mce_reg <= '0';mmen <='1';hce_reg <= '0';hhen <='1';clk2hz_en <='0';end case;end process con_pro;sel_pro : process(ssl)begin case ssl is when '0'=> s_ce<=sce_reg;m_ce<=mce_reg;h_ce<=hce_reg;clk_change<=key2;when '1'=> s_ce<=ssen;11 m_ce<=mmen;h_ce<=hhen;clk_change<=clk1hz;when others=> s_ce<=ssen;m_ce<=secout;h_ce<=minout;clk_change<=clk1hz;end case;end process sel_pro;sel<=ssl;s_en<=ssen;m_en<=mmen;h_en<=hhen;end beh;
輸入模塊電路圖: key_presssetclk_changemodeclk2hz_enclk1khzselclk1hzs_cesecoutm_ceminouth_ces_enm_enh_eninst
2.4數(shù)碼管分配
程序代碼:
library ieee;use ieee.std_logic_1164.all;entity display is port(datain : in std_logic_vector(3 downto 0);dataout : out std_logic_vector(7 downto 0));end display;architecture duan of display is begin process(datain)begin case datain is 12 when “0000” => dataout <=“11000000”;--dp,g,f,e,d,c,b,a when “0001” => dataout <=“11111001”;when “0010” => dataout <=“10100100”;when “0011” => dataout <=“10110000”;when “0100” => dataout <=“10011001”;when “0101” => dataout <=“10010010”;when “0110” => dataout <=“10000010”;when “0111” => dataout <=“11111000”;when “1000” => dataout <=“10000000”;when “1001” => dataout <=“10010000”;when “1010” => dataout <=“10111111”;when “1011” => dataout <=“10000011”;when “1100” => dataout <=“10100111”;when “1101” => dataout <=“10100001”;when “1110” => dataout <=“10000110”;when “1111” => dataout <=“10001110”;when others => null;end case;end process;end;
輸入模塊電路圖:
displaydatain[3..0]dataout[7..0]inst
2.5顯示模塊
使用七段數(shù)碼管顯示小時、分鐘與秒
程序代碼:
library ieee;use ieee.std_logic_1164.all;entity scan is port(clk1khz : in std_logic;sl,sh,ml,mh,hl,hh : in std_logic_vector(3 downto 0);clk2hz_en : in std_logic;s_ce,m_ce,h_ce : in std_logic;en_out : out std_logic_vector(7 downto 0);13 dataout : out std_logic_vector(3 downto 0));end scan;architecture beh of scan is signal cnt : integer range 0 to 7;signal en : std_logic_vector(7 downto 0);signal clk2hz : std_logic;signal h_ce_reg,m_ce_reg,s_ce_reg : std_logic;begin h_ce_reg <= not h_ce;m_ce_reg <= not m_ce;s_ce_reg <= not s_ce;cnt_pro : process(clk1khz)begin if clk1khz'event and clk1khz='1' then if cnt = 7 then cnt <= 0;else cnt <= cnt + 1;end if;end if;end process cnt_pro;clk2hz_pro :process(clk1khz)variable c : integer range 0 to 499 := 0;begin if clk1khz'event and clk1khz='1' then if clk2hz_en ='1' then if c =499 then c := 0;clk2hz <= not clk2hz;else c := c + 1;end if;else clk2hz <= '0';end if;end if;end process clk2hz_pro;scan_pro : process(cnt,sl,sh,ml,mh,hl,hh)begin case cnt is when 0 => dataout <= sl;en <= “11111110”;when 1 => dataout <= sh;en <= “11111101”;when 2 => dataout <= ml;en <= “11110111”;when 3 => dataout <= mh;en <= “11101111”;when 4 => dataout <= hl;en <= “10111111”;14 when 5 => dataout <= hh;en <= “01111111”;when 6 => dataout <= “1010”;en <= “11111011”;when 7 => dataout <= “1010”;en <= “11011111”;when others => null;end case;end process scan_pro;
en_out <= en or((clk2hz & clk2hz)or(h_ce_reg & h_ce_reg))& clk2hz &((clk2hz & clk2hz)or(m_ce_reg & m_ce_reg))& clk2hz &((clk2hz & clk2hz)or(s_ce_reg & s_ce_reg));end beh;
輸入模塊電路圖:
scanclk1khzen_out[7..0]sl[3..0]dataout[3..0]sh[3..0]ml[3..0]mh[3..0]hl[3..0]hh[3..0]clk2hz_ens_cem_ceh_ceinst
2.6報時模塊
利用蜂鳴器進(jìn)行整點報時
程序代碼:
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use IEEE.STD_LOGIC_ARITH.ALL;--整點報時 entity baoshi is port(clk1khz,clk2khz : in std_logic;a:in std_logic_vector(15 downto 0);sel:in std_logic;bell:out std_logic);end baoshi;architecture zhong of baoshi is signal c1,ring:std_logic;begin ring_bell :process(clk1khz,clk2khz)15 begin case a is when “***0” => c1<=clk1khz;when “***0” => c1<=clk1khz;when “***0” => c1<=clk1khz;when “***0” => c1<=clk1khz;when “***0” => c1<=clk1khz;when “***0” => c1<=clk2khz;when “***0” => c1<=clk2khz;when others => c1<='0';end case;end process ring_bell;
bs: process(c1)begin if sel='1' then if c1='1' then ring<='0';else ring<='1';end if;end if;end process bs;bell<=ring;
end zhong;
輸入模塊電路圖:
baoshiclk1khzbellclk2khza[15..0]selinst
整體模塊電路圖
displayshuzizhongs_enm_enh_enselclk_changes_enm_enh_enselsecoutminouthouroutsl[3..0]sh[3..0]ml[3..0]mh[3..0]hl[3..0]hh[3..0]setmodefreclkINPUTVCCINPUTVCCdata[3..0]datain[3..0]secoutminoutinst1scanclk1khzclk1khzsl[3..0]sh[3..0]ml[3..0]mh[3..0]hl[3..0]a[15..0]dataout[7..0]OUTPUTdataout[7..0]en_out[7..0]dataout[3..0]OUTPUTen_out[7..0]data[3..0]key_presssetclk1khzmodeclk1khzclk1hzsecoutminoutclk_changeclk2hz_ensels_cem_ceh_ces_enm_enh_eninst6s_enm_enh_enselinst7a[15..0]INPUTVCChh[3..0]clk2hz_ens_cem_ceh_ceinst4baoshiclk1khzclk2khza[15..0]selclk1khzbellclk2khza[15..0]sel++selclkclk1hzselclk1khzclk2khzinst2clk1khzclk2khzsecoutminoutOUTPUTbellinst
六、調(diào)試中遇到的問題及解決的方法:
1、編程時,經(jīng)常導(dǎo)致語法錯誤,如:“;”沒有寫上,變量類型沒有預(yù)先標(biāo)明,前后變量名字由于缺少一個或多一個字母而導(dǎo)致出錯。解決辦法:對照錯誤,認(rèn)真檢查程序,看哪個地方的標(biāo)點,變量沒有寫上或標(biāo)明。
2、進(jìn)行編譯或波形仿真時,經(jīng)常得到的不是預(yù)想中的結(jié)果。
解決辦法:將需要編譯或進(jìn)行仿真的實體文件置頂,經(jīng)檢錯無誤后,進(jìn)行波形仿真,在仿真之前需要合理設(shè)置仿真結(jié)束時間和信號周期。
3、在控制時間的顯示的時候,由于變量太多多發(fā)現(xiàn)不能完全的控制住變量,導(dǎo)致顯示的時候出現(xiàn)了亂碼,數(shù)碼管顯示不正常 解決辦法:減少變量,仔細(xì)推敲,合理命名。
七、心得體會
一個多星期的課程設(shè)計讓我受益匪淺,也讓我真正明白理論與實踐相結(jié)合的重要性。通過具體實踐才能讓自己清楚哪些知識已經(jīng)掌握,哪些知識仍需鞏固加強。與此同時,我也對EDA以及VHDL語言有了進(jìn)一步了解,對于其結(jié)構(gòu)、語法、功能等認(rèn)識不少。當(dāng)然,我目前所做的還僅僅只是一些基本操作,要想真正將其融會貫通還需要今后更多的學(xué)習(xí)與實踐。雖然只是一個小設(shè)計,我卻也從中學(xué)到了不少設(shè)計流程和一些相關(guān)問題。設(shè)計是一個十分嚴(yán)謹(jǐn)?shù)倪^程,容不得隨意和馬虎。要想快速而高效地完成一項設(shè)計,必須先有一個清晰明了的設(shè)計思路,設(shè)想好一個整體框架,然后在此基礎(chǔ)上,逐漸將各個部分功能進(jìn)行完善。在設(shè)計的過程中,也曾遇到不少困難,但正所謂堅持就是勝利,要想取得成功,必須要有努力付出,這樣所取得的結(jié)果才更有意義。
第四篇:用狀態(tài)機(jī)實現(xiàn)的EDA多功能數(shù)字鐘課程設(shè)計VHDL代碼
設(shè)計并實現(xiàn)具有一定功能的數(shù)字鐘
1、該數(shù)字鐘可以實現(xiàn)3個功能:計時功能、整點報時功能和重置時間功能,因此有3個功能:計時、重置時間、復(fù)位。
2、對所有設(shè)計的小系統(tǒng)能夠正確分析;
3、基于VHDL語言描述系統(tǒng)的功能;
4、在quartus 2環(huán)境中編譯通過;
5、仿真通過并得到正確的波形;
6、給出相應(yīng)的設(shè)計報告。
其中計時模塊有4部分構(gòu)成:秒計時器(second)、分計時器(minute)、時計時器(hour)、日計時器(date)、月計時器(mouth)、年計時器(year)
1)秒計時器(second)是由一個60進(jìn)制的計數(shù)器構(gòu)成的,具有清0、置數(shù)和計數(shù)功能。其中reset為清0信號,當(dāng)reset為0時,秒計時器清0;set 為置數(shù)信號,當(dāng)set為0時,秒計時器置數(shù),置s1的值。clk為驅(qū)動秒計時器的時鐘,sec為秒計時器的輸出,ensec為秒計時器的進(jìn)位信號,作為下一級的時鐘輸入信號。
2)分計時器(minute)是由一個60進(jìn)制的計數(shù)器構(gòu)成的,具有清0、置數(shù)和計數(shù)功能。其中reset為清0信號,當(dāng)reset為0時,分計時器清0;set 為置數(shù)信號,當(dāng)set為0時,分計時器置數(shù),置m1的值。clkm為驅(qū)動分計時器工作的時鐘,與ensec相連接;min為分計時器的輸出;enmin為分計時器的進(jìn)位信號,作為下一級的時鐘輸入信號。
3)時計時器(hour)是由一個24進(jìn)制的計數(shù)器構(gòu)成的,具有清0、置數(shù)和計數(shù)功能。其中reset為清0信號,當(dāng)reset為0時,時計時器清0;set 為置數(shù)信號,當(dāng)set為0時,時計時器置數(shù),置h1的值。clkh為驅(qū)動時計時器工作的時鐘,與enmin相連接;hour為時計時器的輸出;enhour為時計時器的進(jìn)位信號,作為下一級的時鐘輸入信號。
4)日計時器(date1)是由一個60進(jìn)制的計數(shù)器構(gòu)成的,具有清0、置數(shù)和計數(shù)功能。其中reset為清0信號,當(dāng)reset為0時,星期計時器清0;set 為置數(shù)信號,當(dāng)set為0時,星期計時器置數(shù),置d1的值。clkd為驅(qū)動星期計時器工作的時鐘,與enhour相連接;date為日計時器的輸出,endate為分計時器的進(jìn)位信號,作為下一級的時鐘輸入信號,由于月份的天數(shù)存在天數(shù)不同,閏年2月的天數(shù)為28天等情況,還設(shè)計了一個潤年判別器,準(zhǔn)確顯示時間。
5)月計時器(mouth)是由一個60進(jìn)制的計數(shù)器構(gòu)成的,具有清0、置數(shù)和計數(shù)功能。其中reset為清0信號,當(dāng)reset為0時,星期計時器清0;set 為置數(shù)信號,當(dāng)set為0時,星期計時器置數(shù),置mou1的值,clkmou為驅(qū)動星期計時器工作的時鐘,與enday相連接;mou為日計時器的輸出,enmou為分計時器的進(jìn)位信號,作為下一級的時鐘輸入信號。6)計時器(year)是由一個60進(jìn)制的計數(shù)器構(gòu)成的,具有清0、置數(shù)和計數(shù)功能。其中reset為清0信號,當(dāng)reset為0時,星期計時器清0;set 為置數(shù)信號,當(dāng)set為0時,星期計時器置數(shù),置y1的值,clky為驅(qū)動星期計時器工作的時鐘,與enmou相連接;year為日計時器的輸出。VHDL程序
1、屏幕切換模塊
運用狀態(tài)機(jī)進(jìn)行屏幕切換,分別顯示年月日,以及時分秒 library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;--Uncomment the following lines to use the declarations that are--provided for instantiating Xilinx primitive components.--library UNISIM;--use UNISIM.VComponents.all;
entity mux3 is
Port(clk,Reset,sel : in std_logic;
int1,int2,int3,int4,int5,int6,int7,int8,int9,int10,int11,int12:IN STD_LOGIC_VECTOR(3 DOWNTO 0);--rst must
a1,a2,a3,a4,a5,a6: out std_logic_vector(3 downto 0));end mux3;
architecture Behavioral of mux3 is
TYPE states IS(st0, st1, st2, st3, st4, st5, st6, st7);
SIGNAL STX: states;
begin
COM1 : PROCESS(STX,int1,int2,int3,int4,int5,int6,int7,int8,int9,int10,int11,int12)
BEGIN--決定轉(zhuǎn)換狀態(tài)的進(jìn)程
CASE STX IS
WHEN st0 => a1<=int1;a2<=int2;a3<=int3;a4<=int4;a5<=int5;a6<=int6;
WHEN st1 => a1<=int7;a2<=int8;a3<=int9;a4<=int10;a5<=int11;a6<=int12;
WHEN st2 => a1<=int7;a2<=int8;a3<=int9;a4<=int10;a5<=int11;a6<=int12;
WHEN st3 => a1<=int7;a2<=int8;a3<=int9;a4<=int10;a5<=int11;a6<=int12;
WHEN st4 => a1<=int7;a2<=int8;a3<=int9;a4<=int10;a5<=int11;a6<=int12;
WHEN st5 => a1<=int1;a2<=int2;a3<=int3;a4<=int4;a5<=int5;a6<=int6;
WHEN st6 => a1<=int1;a2<=int2;a3<=int3;a4<=int4;a5<=int5;a6<=int6;
WHEN st7 => a1<=int1;a2<=int2;a3<=int3;a4<=int4;a5<=int5;a6<=int6;
WHEN OTHERS => NULL;
END CASE;
END PROCESS COM1;REG: PROCESS(clk,Reset,sel)
--主控時序進(jìn)程
BEGIN
IF Reset = '1' THEN
STX<= st0;
--異步復(fù)位
ELSIF clk='1' AND clk'EVENT THEN
if sel='1' then
CASE STX IS
WHEN st0=>STX<=st1;
WHEN st1=>STX<=st2;
WHEN st2=>STX<=st3;
WHEN st3=>STX<=st4;
WHEN st4=>STX<=st5;
WHEN st5=>STX<=st6;
WHEN st6=>STX<=st7;
WHEN st7=>STX<=st0;
END CASE;
END IF;
END if;END PROCESS;
2、顯示切換程序 library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncomment the following lines to use the declarations that are--provided for instantiating Xilinx primitive components.--library UNISIM;--use UNISIM.VComponents.all;
entity mux1 is
Port(clk,ina,inb,sel,Reset : in std_logic;
result : out std_logic);end mux1;
architecture Behavioral of mux1 is
TYPE state IS(st0,st1,st2,st3,st4,st5,st6,st7);
SIGNAL STX:state;begin REG1: PROCESS(ina,inb,STX)
BEGIN
CASE STX IS
WHEN st0=>result<=ina;
WHEN st1=>result<=ina;
WHEN st2=>result<=inb;
WHEN st3=>result<=inb;
WHEN st4=>result<=inb;
WHEN st5=>result<=inb;
WHEN st6=>result<=inb;
WHEN st7=>result<=inb;
END CASE;
END PROCESS;REG2:PROCESS(clk,sel,Reset)BEGIN IF(Reset='1')THEN
STX<=st0;ELSIF(clk'EVENT AND clk='1')THEN
if sel='1' then CASE STX IS WHEN st0=>STX<=st1;WHEN st1=>STX<=st2;WHEN st2=>STX<=st3;WHEN st3=>STX<=st4;WHEN st4=>STX<=st5;WHEN st5=>STX<=st6;WHEN st6=>STX<=st7;WHEN st7=>STX<=st0;
END CASE;END IF;end if;END PROCESS REG2;
end Behavioral;
3、置數(shù)操作模塊
運用狀態(tài)機(jī),進(jìn)行置數(shù)操作 library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncomment the following lines to use the declarations that are--provided for instantiating Xilinx primitive components.--library UNISIM;--use UNISIM.VComponents.all;
entity mux is
Port(clk,ina,inb,sel,Reset : in std_logic;
r1,r2,r3,r4,r5,r6 : out std_logic);end mux;
architecture Behavioral of mux is TYPE state IS(st0,st1,st2,st3,st4,st5,st6,st7);
SIGNAL STX:state;begin PROCESS(ina,inb,STX)BEGIN CASE STX IS WHEN st0=>r1<=ina;r2<='0';r3<='0';r4<='0';r5<='0';r6<='0';WHEN st1=>r1<=ina;r2<='0';r3<='0';r4<='0';r5<='0';r6<='0';WHEN st2=>r1<='0';r2<='0';r3<='0';r4<='0';r5<='0';r6<=inb;WHEN st3=>r1<='0';r2<='0';r3<='0';r4<='0';r5<=inb;r6<='0';WHEN st4=>r1<='0';r2<='0';r3<='0';r4<=inb;r5<='0';r6<='0';WHEN st5=>r1<='0';r2<='0';r3<=inb;r4<='0';r5<='0';r6<='0';WHEN st6=>r1<='0';r2<=inb;r3<='0';r4<='0';r5<='0';r6<='0';WHEN st7=>r1<=inb;r2<='0';r3<='0';r4<='0';r5<='0';r6<='0';END CASE;END PROCESS;PROCESS(clk,sel,Reset)BEGIN IF(Reset='1')THEN STX<=st0;ELSIF(clk'EVENT AND clk='1')THEN if sel='1' then CASE STX IS WHEN st0=>STX<=st1;WHEN st1=>STX<=st2;WHEN st2=>STX<=st3;WHEN st3=>STX<=st4;WHEN st4=>STX<=st5;WHEN st5=>STX<=st6;WHEN st6=>STX<=st7;WHEN st7=>STX<=st0;
END CASE;END IF;end if;END PROCESS;end Behavioral;end Behavioral;
4、秒顯示模塊 library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncomment the following lines to use the declarations that are--provided for instantiating Xilinx primitive components.--library UNISIM;--use UNISIM.VComponents.all;
entity secute1 is
Port(clkm,set,reset : in std_logic;
sec2,sec1 : inout std_logic_vector(3 downto 0);
ensec : out std_logic);end secute1;
architecture Behavioral of secute1 is
begin
Process(clkm,reset,set)
Begin
If reset='1' then sec2<=“0000”;sec1<=“0000”;
Elsif set='1' then sec2<=“0101”;sec1<=“1000”;
Elsif(clkm'event and clkm='1')then
if sec2=“0101” AND sec1=“1001” then sec2<=“0000”;sec1<=“0000”;ensec<='1';
elsif sec1=“1001” then sec2<=sec2+'1';sec1<=“0000”;ensec<='0';
else sec1<=sec1+'1';ensec<='0';
end if;end if;End process;end Behavioral;
5、分顯示模塊 library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncomment the following lines to use the declarations that are--provided for instantiating Xilinx primitive components.--library UNISIM;--use UNISIM.VComponents.all;
entity minute1 is
Port(clkm,set,reset : in std_logic;
min2,min1 : inout std_logic_vector(3 downto 0);
enmin : out std_logic);end minute1;
architecture Behavioral of minute1 is
begin
Process(clkm,reset,set)
Begin
If reset='1' then min2<=“0000”;min1<=“0000”;
Elsif set='1' then min2<=“0101”;min1<=“1000”;
Elsif(clkm'event and clkm='1')then
if min2=“0101” AND min1=“1001” then min2<=“0000”;min1<=“0000”;enmin<='1';
elsif min1=“1001” then min2<=min2+'1';min1<=“0000”;enmin<='0';
else min1<=min1+'1';enmin<='0';
end if;end if;End process;end Behavioral;
6、小時顯示模塊 library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncomment the following lines to use the declarations that are--provided for instantiating Xilinx primitive components.--library UNISIM;--use UNISIM.VComponents.all;
entity hour1 is
Port(clkh,set,reset: in std_logic;
hor2,hor1 : inout std_logic_vector(3 downto 0);
enhour : out std_logic);end hour1;
architecture Behavioral of hour1 is
begin Process(clkh,reset,set)
Begin
If reset='1' then hor2<=“0000”;hor1<=“0000”;
Elsif set='1' then hor2<=“0010”;hor1<=“0011”;
Elsif(clkh'event and clkh='1')then
if hor2=“0010” AND hor1=“0011” then hor2<=“0000”;hor1<=“0000”;enhour<='1';
elsif hor1=“1001” then hor2<=hor2+'1';hor1<=“0000”;enhour<='0';
else hor1<=hor1+'1';enhour<='0';
end if;
end if;End process;end Behavioral;
7、日顯示模塊(已加入閏年判斷功能)library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncomment the following lines to use the declarations that are--provided for instantiating Xilinx primitive components.--library UNISIM;--use UNISIM.VComponents.all;
entity date1 is
Port(clkd,set : in std_logic;
dat2,dat1 : inout std_logic_vector(3 downto 0);
endate : out std_logic);end date1;
architecture Behavioral of date1 is
begin
Process(clkd,set)
Begin
if set='1' then dat2<=“0010”;dat1<=“1000”;
Elsif(clkd'event and clkd='1')then
if dat2=“0011” AND dat1=“0000” then dat2<=“0000”;dat1<=“0001”;endate<='1';elsif dat1=“1001” then dat2<=dat2+'1';dat1<=“0000”;endate<='0';
else dat1<=dat1+'1';endate<='0';
end if;end if;End process;end Behavioral;
8、月顯示模塊 library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncomment the following lines to use the declarations that are--provided for instantiating Xilinx primitive components.--library UNISIM;--use UNISIM.VComponents.all;
entity month1 is
Port(clkn,set: in std_logic;
mon2,mon1 : inout std_logic_vector(3 downto 0);
enmon : out std_logic);end month1;
architecture Behavioral of month1 is
begin
Process(clkn,set)
Begin
if set='1' then mon2<=“0000”;mon1<=“0110”;
Elsif(clkn'event and clkn='1')then
if mon2=“0001” AND mon1=“0010” then mon2<=“0000”;mon1<=“0001”;enmon<='1';
elsif mon1=“1001” then mon2<=mon2+'1';mon1<=“0000”;enmon<='0';
else mon1<=mon1+'1';enmon<='0';
end if;end if;End process;
9、年顯示模塊 library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;
--Uncomment the following lines to use the declarations that are--provided for instantiating Xilinx primitive components.--library UNISIM;--use UNISIM.VComponents.all;
entity yearth1 is
Port(clkn,set: in std_logic;
year2,year1 : inout std_logic_vector(3 downto 0);
enyear : out std_logic);end yearth1;
architecture Behavioral of yearth1 is
begin
Process(clkn,set)
Begin
if set='1' then year2<=“0001”;year1<=“0001”;
Elsif(clkn'event and clkn='1')then
if year2=“1001” AND year1=“1001” then year2<=“0000”;year1<=“0001”;
elsif year1=“1001” then year2<=year2+'1';year1<=“0000”;enyear<='0';
else year1<=year1+'1';enyear<='0';
end if;end if;
end Behavioral;
第五篇:EDA數(shù)字鐘設(shè)計
數(shù)字鐘
一、實驗?zāi)康?/p>
1、掌握多位計數(shù)器相連的設(shè)計方法。
2、掌握十進(jìn)制,六進(jìn)制,二十四進(jìn)制計數(shù)器的設(shè)計方法。
3、掌握揚聲器的驅(qū)動及報時的設(shè)計。
4、LED燈的花樣顯示。
5、掌握CPLD技術(shù)的層次化設(shè)計方法。
二、實驗器材
1、主芯片Altera EPF10K10LC84-4。2、8個LED燈。
3、揚聲器。4、4位數(shù)碼顯示管。5、8個按鍵開關(guān)(清零,調(diào)小時,調(diào)分鐘)。
三、實驗內(nèi)容
根據(jù)電路特點,運用層次設(shè)計概念設(shè)計。將此設(shè)計任務(wù)分成若干模塊,規(guī)定每一模塊的功能和各模塊之間的接口。
1、時計時程序: library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;
entity hour is
port(reset,clk : in std_logic;
daout : out std_logic_vector(7 downto 0));end hour;
architecture behav of hour is
signal count : std_logic_vector(3 downto 0);signal counter : std_logic_vector(3 downto 0);begin
p1: process(reset,clk)
begin
if reset='0' then
count<=“0000”;
counter<=“0000”;
elsif(clk'event and clk='1')then
if(counter<2)then
if(count=9)then
count<=“0000”;
counter<=counter + 1;
else
count<=count+1;
end if;
else
if(count=3)
then
counter<=“0000”;
else
count<=count+1;
count<=“0000”;
end if;
end if;
end if;
end process;
daout(7 downto 4)<=counter;daout(3 downto 0)<=count;
end behav;
2、分計時程序: library ieee;
use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;
entity minute is
port(reset,clk,sethour: in std_logic;
daout : out std_logic_vector(7 downto 0);
enhour : out std_logic);end minute;
architecture behav of minute is
signal count : std_logic_vector(3 downto 0);signal counter : std_logic_vector(3 downto 0);signal carry_out1 : std_logic;signal carry_out2 : std_logic;begin
p1: process(reset,clk)begin
if reset='0' then
count<=“0000”;
counter<=“0000”;
elsif(clk'event and clk='1')then
if(counter<5)then
if(count=9)then
count<=“0000”;
counter<=counter + 1;
else
count<=count+1;
end if;
carry_out1<='0';
else
if(count=9)then
count<=“0000”;
counter<=“0000”;
carry_out1<='1';
else
count<=count+1;
carry_out1<='0';
end if;
end if;end if;end process;
p2: process(clk)begin
if(clk'event and clk='0')then
if(counter=0)then
if(count=0)then
carry_out2<='0';
end if;
else
carry_out2<='1';
end if;end if;end process;
daout(7 downto 4)<=counter;daout(3 downto 0)<=count;enhour<=(carry_out1 and carry_out2)or sethour;end behav;
3、秒計時程序: library ieee;
use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;
entity second is
port(reset,clk,setmin : in std_logic;
daout : out std_logic_vector(7 downto 0);
enmin : out std_logic);end second;
architecture behav of second is
signal count : std_logic_vector(3 downto 0);signal counter : std_logic_vector(3 downto 0);signal carry_out1 : std_logic;signal carry_out2 : std_logic;begin
p1: process(reset,clk)begin
if reset='0' then
count<=“0000”;
counter<=“0000”;
elsif(clk'event and clk='1')then
if(counter<5)
then
if
(count=9)
then
count<=“0000”;
counter<=counter + 1;
else
count<=count+1;
end if;
carry_out1<='0';
else
if(count=9)
then
count<=“0000”;
counter<=“0000”;
carry_out1<='1';
else
count<=count+1;
carry_out1<='0';
end if;
end if;end if;end process;daout(7 downto
4)<=counter;
daout(3
downto
0)<=count;enmin<=carry_out1 or setmin;end behav;6
4、alert程序: library ieee;
use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;
entity alert is port(clkspk : in std_logic;
second : in std_logic_vector(7 downto 0);
minute : in std_logic_vector(7 downto 0);
speak : out std_logic;
lamp : out std_logic_vector(8 downto 0));end alert;
architecture behav of alert is signal divclkspk2 : std_logic;begin p1: process(clkspk)begin
if(clkspk'event and clkspk='1')then
divclkspk2<=not divclkspk2;
end if;end process;p2: process(second,minute)begin if(minute=“01011001”)then case second is
when “01010001”=>lamp<=“000000001”;speak<=divclkspk2;when “01010010”=>lamp<=“000000010”;speak<='0';when “01010011”=>lamp<=“000000100”;speak<=divclkspk2;when “01010100”=>lamp<=“000001000”;speak<='0';when “01010101”=>lamp<=“000010000”;speak<=divclkspk2;when “01010110”=>lamp<=“000100000”;speak<='0';when “01010111”=>lamp<=“001000000”;speak<=divclkspk2;when “01011000”=>lamp<=“010000000”;speak<='0';when “01011001”=>lamp<=“100000000”;speak<=clkspk;when others=>lamp<=“000000000”;end case;end if;end process;end behav;8
5、seltime程序 library ieee;
use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;
entity seltime is port(ckdsp : in std_logic;
reset : in std_logic;
second : in std_logic_vector(7 downto 0);
minute : in std_logic_vector(7 downto 0);
hour : in std_logic_vector(7 downto 0);
daout : out std_logic_vector(3 downto 0);
sel : out std_logic_vector(2 downto 0));end seltime;
architecture behav of seltime is signal sec : std_logic_vector(2 downto 0);begin
process(reset,ckdsp)begin
if(reset='0')then sec<=“000”;
elsif(ckdsp'event and ckdsp='1')then
sec<=“000”;else
sec<=sec+1;end if;end if;end process;
process(sec,second,minute,hour)begin case sec is
when “000”=>daout<=second(3 downto 0);when “001”=>daout<=second(7 downto 4);when “011”=>daout<=minute(3 downto 0);when “100”=>daout<=minute(7 downto 4);when “110”=>daout<=hour(3 downto 0);when “111”=>daout<=hour(7 downto 4);when others=>daout<=“1111”;end case;end process;
if(sec=“111”)then
sel<=sec;end behav;
6、deled程序: LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;use ieee.std_logic_unsigned.all;
ENTITY deled IS PORT(S: IN STD_LOGIC_VECTOR(3 DOWNTO 0);
A,B,C,D,E,F,G,H: OUT STD_LOGIC);END deled;
ARCHITECTURE BEHAV OF deled IS
SIGNAL DATA:STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL DOUT:STD_LOGIC_VECTOR(7 DOWNTO 0);BEGIN DATA<=S;PROCESS(DATA)BEGIN
CASE DATA IS
WHEN “0000”=>DOUT<=“00111111”;WHEN “0001”=>DOUT<=“00000110”;WHEN “0010”=>DOUT<=“01011011”;WHEN “0011”=>DOUT<=“01001111”;WHEN “0100”=>DOUT<=“01100110”;WHEN “0101”=>DOUT<=“01101101”;WHEN “0110”=>DOUT<=“01111101”;WHEN “0111”=>DOUT<=“00000111”;WHEN “1000”=>DOUT<=“01111111”;WHEN “1001”=>DOUT<=“01101111”;WHEN “1010”=>DOUT<=“01110111”;WHEN “1011”=>DOUT<=“01111100”;WHEN “1100”=>DOUT<=“00111001”;WHEN “1101”=>DOUT<=“01011110”;WHEN “1110”=>DOUT<=“01111001”;WHEN “1111”=>DOUT<=“01000000”;WHEN OTHERS=>DOUT<=“00000000”;END CASE;END PROCESS;H<=DOUT(7);
G<=DOUT(6);
F<=DOUT(5);
E<=DOUT(4);D<=DOUT(3);C<=DOUT(2);B<=DOUT(1);A<=DOUT(0);END BEHAV;
7、頂層原理圖:
四、實驗結(jié)果 頂層原理圖仿真波形:
五、心得體會
1、系統(tǒng)設(shè)計進(jìn)要行充分的方案論證,不可盲目就動手去做;
2、實驗中對每一個細(xì)節(jié)部分都要全面思考,要對特殊情況進(jìn)行處理;
3、對于數(shù)字系統(tǒng),要考慮同步、異步問題;
4、數(shù)字電路的理論分析要結(jié)合時序圖;
5、遇到問題,要順藤摸瓜,分析清楚,不可胡亂改動,每做一次改變都要有充分的理由;
6、模塊化設(shè)計方法的優(yōu)點在于其簡潔性,但是在實驗設(shè)計中也發(fā)現(xiàn),在實驗最終電路確定之前,要盡量減少模塊重疊嵌套,因為在總的電路敲定之前,電路還不成熟,很多地方需要改進(jìn),如果在開始時就進(jìn)行多層模塊化,里層模塊電路的修改將影響其外層的全部電路,這樣就是牽一發(fā)動全身,很顯然,這樣將導(dǎo)致電 數(shù)字鐘課程設(shè)計 電路設(shè)計的低效,所以在設(shè)計過程中,一定要盡量減少超過兩層的模塊;
7、遇到問題花了很長時間沒有解決掉,要學(xué)會想他人請教,別人的不經(jīng)意一點,可能就能把自己帶出思維死區(qū)。