VHDL多功能数字钟.docx
- 文档编号:17511360
- 上传时间:2023-07-26
- 格式:DOCX
- 页数:28
- 大小:200.08KB
VHDL多功能数字钟.docx
《VHDL多功能数字钟.docx》由会员分享,可在线阅读,更多相关《VHDL多功能数字钟.docx(28页珍藏版)》请在冰点文库上搜索。
VHDL多功能数字钟
基于VHDL语言
数
字
钟
设
计
学院:
信息工程学院
专业:
姓名:
学号:
2010年6月15日
一、设计要求
1、具有以二十四小时制计时、显示、整点报时、时间设置和闹钟的功能。
2、设计精度要求为1秒。
二、设计目的
1.掌握各类计数器以及计数器的级联方式;
2.掌握数码管动态显示的原理与方法;
3.掌握用FPGA技术的层次化设计方法;
4.理解数字逻辑硬件和软件的设计思想;
三、设计环境:
QuartusIICPLD-5型试验箱
四、系统功能描述
1、系统输入:
系统状态及较时、定时转换的控制信号为enset、k、set;
时钟信号clk采用50MHz;校时复位信号为reset,输入信号均由按键信号产生。
2、系统输出:
LED显示输出;蜂鸣器声音信号输出。
3、多功能数字电子钟系统功能的具体描述如下:
(一)计时:
正常工作状态下,每日按24h计时制计时并显示,蜂鸣器无声,逢整点报时。
(二)校时:
在计时显示状态下,按下“enset”键,接着按下“k”键,进入“小时”待校准状态,若此时按下“set”键,小时开始校准;之后按上“k”键则进入“分”待校准状态;继续按下“k”键则进入“秒”待复零状态;再次按上“k”键数码管显示闹钟时间,并进入闹钟“小时”待校准状态;再次按下“k”键则进入闹钟“分”待校准状态;若再按上“k”键恢复到正常计时显示状态。
若校时过程中按下“reset”键,则系统恢复到正常计数状态。
(1)“小时”校准状态:
在“小时”校准状态下,显示“小时”的数码管以2Hz闪烁,并以2Hz的频率递增计数。
(2)“分”校准状态:
在“分”校准状态下,显示“分”的数码管以2Hz闪烁,并以2Hz的频率递增计数。
(3)“秒”校准状态:
在“秒复零”状态下,显示“秒”的数码管以2Hz闪烁,并以1Hz的频率递增计数。
(4)闹钟“小时”校准状态:
在闹钟“小时”校准状态下,显示“小时”的数码管以2Hz闪烁,并以2Hz的频率递增计数。
(5)闹钟“分”校准状态:
在闹钟“分”校准状态下,显示“分”的数码管以2Hz闪烁,并以2Hz的频率递增计数。
(三)整点报时:
蜂鸣器在“59”分钟的第“51”、“53”、“55”、“57”秒发频率为500Hz的低音,在“59”分钟的第“59”秒发频率为1000Hz的高音,结束时为整点。
(四)显示:
要求采用扫描显示方式驱动6个LED数码管显示小时、分、秒。
(五)闹钟:
闹钟定时时间到,蜂鸣器发出频率为1000Hz的高音,持续时间为60秒。
五、各个模块分析说明
1、分频器模块
(1)模块说明:
输入一个频率为50MHz的CLK,利用计数器分出
1KHz的q1KHz,500Hz的q500Hz,2Hz的q2Hz和1Hz的q1Hz。
(2)源程序:
LIBRARYieee;
USEieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
ENTITYfdivIS
PORT(CLK:
INSTD_LOGIC;--输入时钟信号
q1KHz:
BUFFERSTD_LOGIC;
q500Hz:
BUFFERSTD_LOGIC;
q2Hz:
BUFFERSTD_LOGIC;
q1Hz:
OUTSTD_LOGIC);
ENDfdiv;
ARCHITECTUREbhvOFfdivIS
BEGIN
P1KHZ:
PROCESS(CLK)
VARIABLEcout:
INTEGER:
=0;
BEGIN
IFCLK'EVENTANDCLK='1'THEN
cout:
=cout+1;--每来个时钟上升沿时cout开始计数
IFcout<=25000THENq1KHz<='0';--当cout<=25000时,q1KHz输出“0”
ELSIFcout<50000THENq1KHz<='1';--当25000 ELSEcout: =0;--输出“1”,完成1KHz频率输出 ENDIF; ENDIF; ENDPROCESS; P500HZ: PROCESS(q1KHz)--q1KHz作为输入信号,分出q500Hz VARIABLEcout: INTEGER: =0; BEGIN IFq1KHz'EVENTANDq1KHz='1'THEN cout: =cout+1; IFcout=1THENq500Hz<='0';--二分频 ELSIFcout=2THENcout: =0;q500Hz<='1'; ENDIF; ENDIF; ENDPROCESS; P2HZ: PROCESS(q500Hz) VARIABLEcout: INTEGER: =0; BEGIN IFq500Hz'EVENTANDq500Hz='1'THEN cout: =cout+1; IFcout<=125THENq2Hz<='0'; ELSIFcout<250THENq2Hz<='1'; ELSEcout: =0; ENDIF; ENDIF; ENDPROCESS; P1HZ: PROCESS(q2Hz) VARIABLEcout: INTEGER: =0; BEGIN IFq2Hz'EVENTANDq2Hz='1'THEN cout: =cout+1; IFcout=1THENq1Hz<='0'; ELSIFcout=2THENcout: =0;q1Hz<='1'; ENDIF; ENDIF; ENDPROCESS; ENDbhv; (3)模块图: 2、控制器模块 (1)模块说明: 输入端口enset,k,set键来控制6个状态,这六个状态分别是 显示计时时间状态,调计时的时、分、秒状态,调闹铃的时、分的状态,reset键是复位键,用来回到显示计时时间的状态。 (2)源程序: libraryieee; useieee.std_logic_1164.all; entitycontlis port(clk,enset,k,set,reset: instd_logic; cth,ctm,cts,cbh,cbm,flashh,flashm,flashs,sel_show: outstd_logic); endcontl; architecturertlofcontlis typestatsis(s0,s1,s2,s3,s4,s5);--定义6个状态 signalcurrent_state,next_state: stats: =s0; begin process(clk,reset) begin ifreset='1'then current_state<=s0; elsifclk'eventandclk='1'then ifreset='0'then current_state<=next_state; endif; endif; endprocess; process(current_state,enset,k,set) begin casecurrent_stateis whens0=>cth<='0';ctm<='0';cts<='0';cbh<='0';cbm<='0'; flashh<='0';flashm<='0';flashs<='0';sel_show<='0'; if(enset='1'andk='1')then--若enset和k为“1”, next_state<=s1;--由s0态转到s1态 elsenext_state<=s0; endif; whens1=>ctm<='0';cts<='0';cbh<='0';cbm<='0'; flashh<='1';flashm<='0';flashs<='0';sel_show<='0'; ifset='1'thencth<='1';--若set为“1”,cth输出“1” elsecth<='0';--进入调小时状态。 endif; if(enset='1'andk='0')then--若enest为“1”,k为“0”, next_state<=s2;--由s1态转到s2态 elsenext_state<=s1; endif; whens2=>cth<='0';cts<='0';cbh<='0';cbm<='0'; flashh<='0';flashm<='1';flashs<='0';sel_show<='0'; ifset='1'thenctm<='1'; elsectm<='0'; endif; if(enset='1'andk='1')then next_state<=s3; elsenext_state<=s2; endif; whens3=>cth<='0';ctm<='0';cbh<='0';cbm<='0'; flashh<='0';flashm<='0';flashs<='1';sel_show<='0'; ifset='1'thencts<='1'; elsects<='0'; endif; if(enset='1'andk='0')then next_state<=s4; elsenext_state<=s3; endif; whens4=>cth<='0';ctm<='0';cts<='0';cbm<='0'; flashh<='1';flashm<='0';flashs<='0';sel_show<='1'; ifset='1'thencbh<='1'; elsecbh<='0'; endif; if(enset='1'andk='1')then next_state<=s5; elsenext_state<=s4; endif; whens5=>cth<='0';ctm<='0';cts<='0';cbh<='0'; flashh<='0';flashm<='1';flashs<='0';sel_show<='1'; ifset='1'thencbm<='1'; elsecbm<='0'; endif; if(enset='1'andk='0')then next_state<=s0; elsenext_state<=s5; endif; endcase; endprocess; endrtl; (3)仿真波形图: (4)模块图: 3、二选一模块 (1)源程序: ENTITYmux21aIS PORT(a,b,s: INBIT; y: OUTBIT); ENDENTITYmux21a; ARCHITECTUREoneOFmux21aIS BEGIN PROCESS(a,b,s) BEGIN IFs='0'THEN y<=a;ELSE--若s=0,y输出a,反之输出b。 y<=b; ENDIF; ENDPROCESS; ENDARCHITECTUREone; (2)仿真波形图: (3)模块图: 4、计时模块 a、秒计时 (1)源程序: libraryieee; useieee.std_logic_1164.all; useieee.std_logic_unsigned.all; useieee.std_logic_arith; entitycnts60is port(sld0: bufferstd_logic_vector(3downto0);--小时个位 sld1: bufferstd_logic_vector(7downto4);--小时十位 co: outstd_logic; rest: instd_logic; clk: instd_logic); endcnts60; architecturertlofcnts60is begin process(clk,rest) begin ifrest='1'thensld1<="0000";sld0<="0000"; elsif(clk'eventandclk='1')then if(sld1="0101"andsld0="1001")then--当sld1=5,sld0=9时 sld1<="0000";sld0<="0000";co<='1';--全清零,co输出“1” elsifsld0="1001"then sld0<="0000"; sld1<=sld1+1;co<='0';--sld1自加“1” elsesld0<=sld0+1;co<='0'; endif; endif; endprocess; endrtl; (2)仿真波形图: (3)模块图: b、分计时 (1)源程序: libraryieee; useieee.std_logic_1164.all; useieee.std_logic_unsigned.all; useieee.std_logic_arith; entitycnt60is port(sld0: bufferstd_logic_vector(3downto0); sld1: bufferstd_logic_vector(7downto4); co: outstd_logic; clk: instd_logic); endcnt60; architecturertlofcnt60is begin process(clk) begin if(clk'eventandclk='1')then if(sld1="0101"andsld0="1001")then sld1<="0000";sld0<="0000";co<='1'; elsifsld0="1001"then sld0<="0000"; sld1<=sld1+1;co<='0'; elsesld0<=sld0+1;co<='0'; endif; endif; endprocess; endrtl; (2)仿真波形图: (3)模块图: c、小时计时 (1)源程序: libraryieee; useieee.std_logic_1164.all; useieee.std_logic_unsigned.all; useieee.std_logic_arith; entitycnt24is port(sld0: bufferstd_logic_vector(3downto0); sld1: bufferstd_logic_vector(7downto4); clk: instd_logic); endcnt24; architecturertlofcnt24is signals: std_logic_vector(7downto0); begin process(clk) begin s<=sld1&sld0; if(clk'eventandclk='1')then ifs="00100011"then sld1<="0000"; sld0<="0000"; elsifsld0="1001"then sld0<="0000"; sld1<=sld1+1; elsesld0<=sld0+1; endif; endif; endprocess; endrtl; (2)仿真波形图: (3)模块图: d、闹钟分计时 (1)源程序: libraryieee; useieee.std_logic_1164.all; useieee.std_logic_unsigned.all; useieee.std_logic_arith; entitycntm60bis port(sld0: bufferstd_logic_vector(3downto0); sld1: bufferstd_logic_vector(7downto4); en: instd_logic; clk: instd_logic); endcntm60b; architecturertlofcntm60bis begin process(clk) begin if(clk'eventandclk='1')then ifen='1'then if(sld1="0101"andsld0="1001")then sld1<="0000";sld0<="0000"; elsifsld0="1001"then sld0<="0000"; sld1<=sld1+1; elsesld0<=sld0+1; endif; endif; endif; endprocess; endrtl; (2)仿真波形图: (3)模块图: e、闹钟小时计时 (1)源程序: libraryieee; useieee.std_logic_1164.all; useieee.std_logic_unsigned.all; useieee.std_logic_arith; entitycnth24bis port(sld0: bufferstd_logic_vector(3downto0); sld1: bufferstd_logic_vector(7downto4); en: instd_logic; clk: instd_logic); endcnth24b; architecturertlofcnth24bis signals: std_logic_vector(7downto0); begin process(clk,en,sld1,sld0) begin s<=sld1&sld0; if(clk'eventandclk='1')then ifen='1'then ifs="00100011"then sld1<="0000"; sld0<="0000"; elsifsld0="1001"then sld0<="0000"; sld1<=sld1+1; elsesld0<=sld0+1; endif; endif; endif; endprocess; endrtl; (2)仿真波形图: (3)模块图: 5、闹钟比较模块 (1)模块说明: 比较正常计数时间与闹钟定时时间是否相等,若相等,compout输出“1”,反之输出“0”。 (2)源程序: libraryieee; useieee.std_logic_1164.all; entitycompis port(th1,tm1: instd_logic_vector(7downto4); th0,tm0: instd_logic_vector(3downto0); bh1,bm1: instd_logic_vector(7downto4); bh0,bm0: instd_logic_vector(3downto0); compout: outstd_logic); endcomp; architecturertlofcompis begin process(th1,tm1,bh1,bm1,th0,tm0,bh0,bm0) begin if(th1=bh1andtm1=bm1andth0=bh0andtm0=bm0)then compout<='1';--当正常计数时间与闹钟定时时间相等时compout输出1 elsecompout<='0'; endif; endprocess; endrtl; (3)仿真波形图: (4)模块图: 6、报时模块 (1)模块说明: 该模块既实现了整点报时的功能,又实现了闹铃的功能,蜂鸣器通过所选频率的不同,而发出不同的声音。 (2)源程序: libraryieee; useieee.std_logic_1164.all; useieee.std_logic_unsigned.all; entitybelis port(tm1,ts1: instd_logic_vector(7downto4); tm0,ts0: instd_logic_vector(3downto0); compout,q1KHz,q500Hz,openbel: instd_logic; bell: outstd_logic); endbel; architecturertlofbelis signalt: std_logic_vector(7downto0); begin process(compout,q500Hz,q1KHz,openbel,tm1,tm0,ts1,ts0) begin if(openbel='0')then bell<='0'; endif; if(openbel='1')then if(compout='1')then--compout=1,闹铃响 bell<=q1KHz;--bell输出1KHz elsif(tm1="0101"andtm0="1001"andts1="0101")then casets0is when"0001"=>bell<=q500Hz; when"0011"=>bell<=q500Hz; when"0101"=>bell<=q500Hz; when"0111"=>bell<=q500Hz;--bell输出500Hz when"1001"=>bell<=q1KHz;--bell输出1KHz whenothers=>bell<='0'; endcase; elsebell<='0'; endif; endif; endprocess; endrtl; (3)仿真波形图: (4)模块图: 7、控制显示模块 (1)模块说明: 该模块实现了数码管既可以显示正常时间,又可以显示闹钟时间的功能;调时,定时闪烁功能也在此模块中真
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VHDL 多功能 数字