基于VHDL的數字電子鐘系統設計_第1頁
基于VHDL的數字電子鐘系統設計_第2頁
基于VHDL的數字電子鐘系統設計_第3頁
基于VHDL的數字電子鐘系統設計_第4頁
基于VHDL的數字電子鐘系統設計_第5頁
已閱讀5頁,還剩24頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、集成電路軟件設計基于VHDL的數字電子鐘系統設計實驗地點 實驗時間 2012.12.19 學 院 信息工程學院 班 級 姓 名 學 號 成 績 指導老師 2012 年 12 月 19 日數字電子鐘的設計一、設計項目基于VHDL的數字電子鐘系統設計二、設計要求1、采用自頂向下的設計思想;2、使用本學期學習的設計語言VHDL和集成電路設計軟件實現;三、設計任務(設計指標)1、設計數字電子鐘的基本功能:年、月、日、時以24小時制顯示,月日為陽歷顯示,起始時間為:2012年11月26日14:00;2、 支持鬧鈴功能;3、 隨時校時功能;4、閏年提醒;5、中國傳統節假日提醒。四、設計思想電子時鐘是電子設

2、計中用來顯示時間和年月日的一種裝置。是采用自頂向下的設計方法,將數字電子時鐘分成五個子模塊和一個頂層模塊,然后將各個子模塊再細化成為更小的功能塊,直到最后能用vhdl語言進行描述為止。當各個模塊都描述完成并仿真確認無誤后,再采用元件例化,將各個元件一層一層的例化連接起來,直到最后完成系統設計。五、設計原理數字鐘是一個將“ 時”,“年”,“月”,“日”顯示于人的視覺器官的計時裝置。它的計時周期分別為24小時,365天(非閏年),12個月,31天顯示滿刻度為2030年12月31日23時,另外應有鬧鐘報時、閏年提醒,中國傳統節假日提醒等附加功能。因此,該數字鐘電路主要由“時”,“日”,“年”,“月”

3、,計數器、鬧鐘報時電路和轉換器組成,其中年月日是以萬年的整體形式體現。時信號產生器是整個系統的時基信號,它直接決定計時系統的精度,一般用石英晶體振蕩器加分頻器來實現。將標準秒信號送入“時計數器”,“時計數器”采用24進制計數器,每累計24小時發出一個“分脈沖”信號,該信號將作為“萬年歷計數器”的時鐘脈沖。萬年歷的年月日的輸出端一方面輸出顯示,另一方面輸入到鬧鐘中當作鬧鐘中的比較時間當輸入的信息與設定好的一致時,響鈴信號觸發。并在萬年歷中制作出當有閏年或是中國傳統節假日的時候發出高平的信號進行提醒。六、設計方案設計中使用的時元件例化和進程結合的方案。每個元件主要采用進程語句實現,在每個進程主要使

4、用了if_else、if_eslif_elsif_-_else 、case以及賦值語句,實現了模塊化設計,使得整個程序一目了然。整個電子鐘的頂層設計實體為dzz(電子時鐘)模塊,其下又分為:fenpin(分頻)、shi(時脈沖)、萬年歷(年月日)、zhuanhuan(過渡轉換)和naozhong(鬧鐘)五個模塊。需要注意的是,在年月日模塊中的日期模塊對于2月份要按照平年閏年的情況分別處理。在年月日的模塊中對于閏年和中國傳統節假日的提醒也是分別處理的。7、 各模塊實現(一)分頻模塊分頻器電路將20MHZ的高頻方波信號經20M次分頻后得到1Hz的方波信號供秒計數器進行計數。分頻器實際上也就是計數器

5、。而本實驗的計時模塊、鬧鐘模塊需要1hz、100hz的時鐘信號,故需要加以分頻實現所需信號。分頻電路的模塊化示意圖如下:(分頻器的頂層連接圖)(分頻器頂層文件的元件圖)分頻器的子模塊10分頻的網表文件(網表文件)(10分頻元件圖)分頻模塊的仿真波形圖(2) 計時模塊由時計數器組成了最基本的數字鐘計時電路,二十四進制計數器和滿位之后的進位信號組合構成。其模塊化電路示意圖如下:其中preset為使能端高電平有效,co為溢出信號,當時計數到24點的時候會在co處觸發一個上升沿時鐘供后面的萬年歷使用,保證使其工作。計時模塊的仿真波形圖:H_in為校時輸入端(3) 萬年歷模塊萬年歷的模塊由年、月、日的整

6、型計數形式組合而成,其中年是由2012計數到2030,月是一年12個月的計數,日的計數分為閏年和平年大月和小月的計數部分,當為閏年時2月份的天數為29,當為大月時日的計數為31,當為小月時日的計數為30,。由于需要顯示年、月、日、星期、閏年,故本模塊需要有判斷是否閏年電路,閏年以及非閏年對應的月天數的譯碼電路,12進制BCD計數器(用來月循環計數),100進制BCD計數(用來年循環計數),故先畫出萬年歷的模塊圖如下,然后逐模塊設計實現。其模塊的電路示意圖如下:(網表文件)Preset為使能端,clk接在小時模塊的co端口,data、month、year分別為日、月、年的輸出,co為中國傳統節假

7、日的提醒信號端,連接在外面的chuantong端口,tixing就是為閏年的提醒信號端口,起始的信號都為0當滿足條件是則變為1可接在揚聲器上。萬年歷模塊的仿真波形圖:D_in、m_in、y_in分別為日月年的校時輸入端口,jiaoshi為校時控制端口其子模塊日的仿真波形圖為:其子模塊月的仿真波形圖為:其子模塊年的仿真波形圖為:(4) 鬧鐘模塊鬧鐘模塊是由實時的小時模塊和萬年歷模塊時鐘輸入和手動設定的時、日、月、年模塊組合成的滿足當實時的時間與手動設定的時間相等時,鬧鐘就會輸出一個使能信號使得揚聲器發出聲音。其模塊化的電路示意圖如下:(鬧鐘網表文件)Preset為使能端口,高電平有效,hour、

8、data、month、year為實時輸入的時鐘信號,shi、ri、yue、nian為外界輸入的對于鬧鐘響鈴時間的設定端口,music為響鈴的使能端口。(5) 過渡模塊過渡模塊是為了方便當萬年歷輸出端口要為兩個電路框圖所使用的時候方便連接頂層文件中的中間信號,從而做到萬年歷中的時鐘信號既可以連接到鬧鐘模塊中,也可以連接到外部模塊中顯示出來。其模塊化電路的示意圖如下:其中preset為使能信號,hour、data、month、year為時鐘輸入的信號,連接中間信號。Shi、ri、yue、nian為輸出的時鐘信號用于外部顯示的作用。也就是說當輸入端輸入什么信號的時候,輸出端就會輸出相同的信號。(6)

9、 頂層模塊(dzz模塊)頂層模塊是由前面的五個模塊共同例化形成的,其模塊化的電路示意圖如下:A為時鐘信號clk,vcc為接高電平,接在所有的preset端口,當電源連接時,數字之中開始工作,當斷電的時候電子時鐘不工作,vcc_m接在鬧鐘的控制端口中,及鬧鐘的開關,當開關未開時即vcc_m=0時鬧鐘不工作,當為1時鬧鐘正常工作,當鬧鐘響時調到低電平鬧鐘也停止工作。Naozhong_out為鬧鐘工作輸出口,runnian為閏年提醒端口,chuantong為中國傳統節假日的提醒端口,hour_out、data_out、month_out、year_out為時鐘的顯示在外部的端口。電子鐘的仿真波形文件

10、如下:八、設計結果由上面的仿真波形圖可知,本次實驗基本上完成了實驗設計任務的要求數字電子鐘的基本功能:年、月、日、時以24小時制顯示,月日為陽歷顯示,起始時間為:2012年11月26日14:00;支持鬧鈴功能;閏年提醒;中國傳統節假日提醒。本次實驗的數字電子鐘的初值為2012年11月26日14時,鬧鐘的設定時間是2013年1月1日1時,猶如上圖的波形所表現出來的一樣。九、論文結論在本次的設計實驗過程中出現很多的問題如編程時,經常導致語法錯誤,如:“;”沒有寫上,變量類型沒有預先標明,前后變量名字由于缺少一個或多一個字母而導致出錯。所以在寫程序的時候應該對照錯誤,認真檢查程序,看哪個地方的標點,

11、變量沒有寫上或標明。再者在進行編譯或波形仿真時,經常得到的不是預想中的結果。而且往往得不出錯誤在哪里,編譯的過程并沒有錯誤但是結果卻是錯的,于是將就將需要編譯或進行仿真的實體文件置頂,經檢錯無誤后,進行波形仿真,在仿真之前合理設置仿真結束時間和信號周期,就可以了。在控制時間的顯示的時候,由于變量太多多發現不能完全的控制住變量,導致仿真波形的是時候出現了高阻的狀態,所以在頂層文件下應該減少變量,仔細推敲,合理命名。雖然只是一個小設計,我卻也從中學到了不少設計流程和一些相關問題。設計是一個十分嚴謹的過程,容不得隨意和馬虎。要想快速而高效地完成一項設計,必須先有一個清晰明了的設計思路,設想好一個整體

12、框架,然后在此基礎上,逐漸將各個部分功能進行完善。在設計的過程中,也曾遇到不少困難,但正所謂堅持就是勝利,要想取得成功,必須要有努力付出,這樣所取得的結果才更有意義。附件(代碼清單)10分頻模塊library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fenpin10 isport (clk:in std_logic;- - 輸入時鐘信號clk_out:buffer std_logic);- -輸出時鐘信號end fenpin10;architecture rtl of fenpin10 is

13、signal cnt:std_logic_vector(3 downto 0);- -定義計數器模值beginprocess (clk)beginif (clkevent and clk=1) thenif (cnt=0100) thenclk_out=not clk_out;cnt=0000;else cntclk,- - ? clk_out=clk_100hz);- - ?u1: fenpin10port map (clk_in=clk_100hz, - - ? clk_out=clk_10hz);- - - ?u2: fenpin10port map (clk_in=clk_10hz,

14、- - ? clk_out=clk_1hz);- - - ?end rtl;分頻器模塊testbench文件LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY testbench IS END testbench; ARCHITECTURE a OF testbench ISsignal clk_1hz: std_logic;signal clk_100hz: std_logic;SIGNAL clk : std_logic := 1 ; COMPONENT fenpin port (clk:in std_logic;clk_1hz,clk_

15、100hz:buffer std_logic);END COMPONENT ; BEGINprocessbeginwait for 50ns;clk clk,clk_1hz=clk_1hz,clk_100hz=clk_100hz) ; END a;時模塊library ieee;use ieee.std_logic_1164.all;entity shi isport(clk :in std_logic; preset : in std_logic; jiaoshi: in std_logic; h_in:in integer range 0 to 23;hour : out integer

16、range 0 to 23; co : out std_logic); end shi;architecture a of shi issignal s :integer range 0 to 23:=14; begin process(clk,preset) begin if preset =0 then s=14; elsif (clkevent and clk=1) then if s23 then s=s+1; else s=0; end if;if s=23 then co=1; else co=0; if jiaoshi=1 then s=h_in; elsif (clkevent

17、 and clk=1) then if s23 then s=s+1; else s=0; end if;if s=23 then co=1; else co=0; end if; end if ; end if; end if; end process; hour =s; end a;時模塊Testbench文件LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY testbench IS END testbench; ARCHITECTURE a OF testbench IS SIGNAL hour : integer :=14 ; si

18、gnal jiaoshi : std_logic:=0; signal h_in: integer:=14; signal co : std_logic:=0; SIGNAL preset : std_logic := 0 ; SIGNAL clk : std_logic := 1 ; COMPONENT shi port(clk :in std_logic; preset : in std_logic; jiaoshi: in std_logic; h_in:in integer range 0 to 23; hour : out integer range 0 to 23; co : ou

19、t std_logic); END COMPONENT ; BEGIN process begin wait for 50ns; clk = not clk; end process; process begin wait for 2000ns; jiaoshi=not jiaoshi; end process; preset jiaoshi, h_in=h_in, clk = clk, preset = preset, co = co, hour = hour) ; END a;萬年歷模塊library ieee; use ieee.std_logic_1164.all; use ieee.

20、std_logic_unsigned.all;use ieee.std_logic_arith.all;entity wannianli is port( preset:in std_logic; clk:in std_logic;jiaoshi:in std_logic;d_in:in integer range 1 to 31;m_in:in integer range 1 to 12;y_in:in integer range 2012 to 2030;data: out integer range 1 to 31;month:out integer range 1 to 12; yea

21、r:out integer range 2012 to 2030;tixing:out std_logic;co:out std_logic); end wannianli; architecture a of wannianli is signal yue:integer range 1 to 12:=11; signal nian:integer range 2012 to 2030:=2012; signal ri:integer range 1 to 31:=26; signal qm:integer range 28 to 31; begin process(yue,nian) be

22、gin case yue is when 1=qm if(nian mod 4)=0 and (nian mod 100)/=0) or (nian mod 400)=0) then qm=29; else qmqm qmqmqmqmqmqmqmqmqmnull; end case ; end process; process(clk,preset) begin if preset=0 then yue =11 ; nian=2012; ri=26; else if (nian mod 4)=0 and (nian mod 100)/=0) or (nian mod 400)=0) then

23、tixing=1; else tixing=0; end if; if (yue=5 and ri=1) or (yue=10 and ri=1 ) or (yue=1 and ri=1) or (yue=8 and ri=15) or (yue=1 and ri=15) then co=1; else co=0; end if; if clkevent and clk=1 then if(ri=qm) then ri=1; if(yue=12)then yue=1;nian=nian+1; else yue=yue+1; end if; elsif(riqm) then ri=ri+1; i

24、f jiaoshi=1 then ri=d_in;yue=m_in;nian=y_in; elsif clkevent and clk=1 then if(ri=qm) then ri=1; if(yue=12)then yue=1;nian=nian+1; else yue=yue+1; end if; elsif(riqm) then ri=ri+1; end if; end if; end if; end if; end if; end process; month=yue; year=nian; data=ri; end a; 萬年歷testbench文件LIBRARY ieee ;

25、USE ieee.std_logic_1164.all ;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all; ENTITY testbench IS END testbench; ARCHITECTURE a OF testbench IS SIGNAL preset : std_logic := 0 ; SIGNAL clk : std_logic := 1 ; signal co: std_logic; SIGNAL tixing:std_logic; signal jiaoshi:std_logic:=1; SIGN

26、AL d_in: integer range 1 to 31:=2; SIGNAL m_in: integer range 1 to 12:=2; SIGNAL y_in: integer range 2012 to 2030:=2013; signal yue:integer range 1 to 12:=11; signal nian:integer range 2012 to 2030:=2012; signal ri:integer range 1 to 31:=26; COMPONENT wannianli port( preset:in std_logic; clk:in std_

27、logic; jiaoshi:in std_logic:=1; d_in:in integer range 1 to 31; m_in:in integer range 1 to 12; y_in:in integer range 2012 to 2030; data: out integer range 1 to 31; month:out integer range 1 to 12; year:out integer range 2012 to 2030; tixing:out std_logic; co:out std_logic); END COMPONENT ; BEGIN proc

28、ess begin wait for 50ns; clk = not clk; end process; process begin jiaoshi=not jiaoshi ; wait for 3000ns; end process; preset = 1 after 20ns; d_in =2 after 10ns; m_in =2 after 10ns; y_in jiaoshi, d_in =d_in, m_in =m_in, y_in =y_in, clk= clk, tixing=tixing, co=co, preset= preset, month=yue, year=nian

29、, data=ri) ; END a;日模塊library ieee;use ieee.std_logic_1164.all;entity ri isport(clk :in std_logic;preset : in std_logic;data : out integer range 1 to 31;co : out std_logic);end ri;architecture a of ri issignal s :integer range 1 to 31;beginprocess(clk,preset)begin if preset =0 then s=1;elsif (clkeve

30、nt and clk=1) then if s31 then s=s+1; else s=1; end if;if s=31 then co=1;else co=0;end if;end if ;end process;data =s;end a;日模塊testbench文件LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY testbench IS END testbench; ARCHITECTURE a OF testbench ISSIGNAL data : integer :=26 ; signal co : std_logic:=

31、0;SIGNAL preset : std_logic := 0 ; SIGNAL clk : std_logic := 1 ; COMPONENT ri port(clk :in std_logic; preset : in std_logic; data : out integer range 1 to 31; co : out std_logic);END COMPONENT ; BEGINprocessbeginwait for 50ns; clk = not clk;end process;preset clk, preset = preset, co = co,data = dat

32、a) ; END a;月模塊library ieee;use ieee.std_logic_1164.all;entity yue isport(clk :in std_logic;preset : in std_logic;month : out integer range 1 to 12;co : out std_logic);end yue;architecture a of yue issignal s :integer range 1 to 12;beginprocess(clk,preset)begin if preset =0 then s=1;elsif (clkevent a

33、nd clk=1) then if s12 then s=s+1; else s=1; end if;if s=12 then co=1;else co=0;end if;end if ;end process;month =s;end a;月模塊testbench文件LIBRARY ieee ; USE ieee.std_logic_1164.all ; ENTITY testbench IS END testbench; ARCHITECTURE a OF testbench ISSIGNAL month : integer :=11 ; signal co : std_logic:=0;

34、SIGNAL preset : std_logic := 0 ; SIGNAL clk : std_logic := 1 ; COMPONENT yue port(clk :in std_logic; preset : in std_logic; month : out integer range 1 to 12; co : out std_logic);END COMPONENT ; BEGINprocessbeginwait for 50ns; clk = not clk;end process;preset clk, preset = preset, co = co, month = m

35、onth) ; END a;年模塊library ieee;use ieee.std_logic_1164.all;entity nian isport(clk :in std_logic;preset : in std_logic;year : out integer range 2012 to 2030;co : out std_logic);end nian;architecture a of nian issignal s :integer range 2012 to 2030;beginprocess(clk,preset)begin if preset =0 then s=2012

36、;elsif (clkevent and clk=1) thenif s2030 then s=s+1;else s=2012;end if;if s=2030 then co=1;else co=0;end if;end if ;end process;year =s;end a;年模塊testbench文件library ieee;use ieee.std_logic_1164.all;entity nian isport(clk :in std_logic;preset : in std_logic;year : out integer range 2012 to 2030;co : o

37、ut std_logic);end nian;architecture a of nian issignal s :integer range 2012 to 2030;beginprocess(clk,preset)begin if preset =0 then s=2012;elsif (clkevent and clk=1) thenif s2030 then s=s+1;else s=2012;end if;if s=2030 then co=1;else co=0;end if;end if ;end process;year =s;end a;鬧鐘模塊library ieee;us

38、e ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity naozhong isport (clk,preset:in std_logic;-時鐘、使能信號 hour: in integer range 0 to 23; data: in integer range 1 to 31; month:in integer range 1 to 12; year:in integer range 2012 to 2030;-輸入的設定時間 ri:in integer range 1 to 31:=26; shi: in inte

39、ger range 0 to 23:=14; yue:in integer range 1 to 12:=11; nian: in integer range 2012 to 2030:=2012; -輸入的實時時間 music:out std_logic);-音樂使能信號end naozhong;architecture rtl of naozhong issignal temp:integer range 0 to 23:=0;beginprocess (clk,preset)beginif (clkevent and clk=1) then-判斷設定時間和實時時間是否相等 if (yea

40、r=nian)and(data=ri)and(month=yue)and(hour=shi)and(preset=1) then music=1; if (hour=5) then temp=0 ;else temp=hour+1;-當相等時自動計時一分鐘 end if; elsif (preset=0) then music=0;-按停止鍵鬧鐘停止 end if; if (temp=shi) then music=0;-不按停止鍵一分鐘自動停止 end if;end if;end process ;end rtl;過渡模塊library ieee;use ieee.std_logic_116

41、4.all;use ieee.std_logic_unsigned.all;entity zhuanhuan is port (preset:in std_logic; hour: in integer range 0 to 23; data: in integer range 1 to 31; month:in integer range 1 to 12; year:in integer range 2012 to 2030; shi: out integer range 0 to 23:=14; ri:out integer range 1 to 31:=26; yue:out integ

42、er range 1 to 12:=11; nian: out integer range 2012 to 2030:=2012);end zhuanhuan;architecture a of zhuanhuan issignal y0:integer range 0 to 23:=14;signal y1:integer range 1 to 31:=26;signal y2:integer range 1 to 12:=11;signal y3:integer range 2012 to 2030:=2012;beginprocess (preset,hour,data,month,ye

43、ar)begin-case hour isif (preset=0)then y0=14 ; y1=26 ; y2=11 ; y3=2012;else y0=hour;y1=data;y2=month;y3=year;end if;end process;shi=y0;ri=y1;yue=y2;nian=y3;end a;頂層模塊library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity dzz isport( a:in std_logi

44、c;vcc:in std_logic;vcc_m:in std_logic;js:in std_logic;s: in integer range 0 to 23;r: in integer range 1 to 31;y:in integer range 1 to 12; n:in integer range 2012 to 2030; j:in integer range 0 to 23; k:in integer range 1 to 31; l:in integer range 1 to 12; m:in integer range 2012 to 2030;hour_out:out integer range 0 to 23;data_out: out integer range 1 to 31;month_out:out integer range 1 to 12; year_out:out integer range 2012 to 2030;naozhong_out:out std_logic;runnian:out std_logic;chuantong:out std_logic);end dzz;architecture rtl of dzz is-component fenpin i

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論