基于FPGA的数字钟.doc
数字钟实验设计报告
摘要:FPGA在处理时序逻辑方面具有非常优越的性能,因此可以通过VHDL编程实现计数功能,进而设计一个数字钟。
数字钟实验设计报告
关键字:VHDL,FPGA,数字钟。
一、设计方案:
(1)用两个程序实现实验的功能,主程序实现计数及时间预置功能,子程序实现BCD显示功能。为了使调整时间时按键的反映速度不是太慢,对按键的检测使用1KHz时钟。然后对1KHz信号分频,产生周期为1S的信号,作为驱动时钟秒的信号。
(2)为了使电子钟具有时间可预置功能,即使其工按照按键的输入工作在不同的状态,因此使用状态机实现时间显示及时间调整功能之间的切换。
(3)显示部分使用对数字0~59进行逐个编码的方法,然后将数字的每一位送至实验箱上的七段译码器。
二、设计框图:
主程序部分的状态转移图:
输入1KHZ方波
输入1KHZ方波
60进制计数器(秒计数)
60进制计数器(分计数)
24进制计数
(时计数)
1000分频(1HZ信号)
调秒
调分
调时
4—7显
示译码器
4—7显
示译码器
4—7显
示译码器
进位信号
进位信号
状态转移图:
三、方案实现:
=1\*GB3①主程序:
LIBRARYIEEE;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityClockis
port(mode,set,clr,clk:instd_logic;
BCDHH,BCDHL,BCDMH,BCDML,BCDSH,BCDSL:outstd_logic_vector(3downto0)
);
endentity;
ARCHITECTUREarchOFClockIS
typestis(s0,s1,s2,s3);
signalstate:st;
signalHour,Min,Sec:integerrange0to59;
signalBCDH,BCDM,BCDS:std_logic_vector(7downto0);
signalset_reg:std_logic;
componentBCD
port(DataIn:inintegerrange0to59;
BCDOut:outstd_logic_vector(7downto0));
endcomponent;
BEGIN
process(mode,clr)
begin
if(clr=1)then
state=s0;
else
if(modeeventandmode=1)then
casestateis
whens0=state=s1;
whens1=state=s2;
whens2=state=s3;
whens3=state=s0;
endcase;
endif;
endif;
endprocess;
process(clk,state,clr)
variableclk_cnt:std_logic_vector(9downto0);
begin
if(clr=1)then
Hour=0;Min=0;Sec=0;
set_reg=0;
else
if(clkeventandclk=1)then
casestateis
whens0=
if(clk_cnt=1111100111)then
clk_cnt:=(others=0);
if(Sec=59)then
Sec=0;
if(Min=59)then
Min=0;
if(Hour=23)then
Hour=0;
elseHour=Hour+1;
endif;
elseMin=Min+1;
endif;
elseSec=Sec+1;
endif;
elseclk_cnt:=clk_cnt+1;
endif;
whens1=
if(set=1)then
ifset_reg=0thenset_reg=1;
if(Hour=23)thenHour=0;
elseHour=Hour+1;
endif;
endif;