基于FPGA的数字钟
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
数字钟实验设计报告
摘要:FPGA 在处理时序逻辑方面具有非常优越的性能,因此可以通过VHDL 编程实现计数功能,进而设计一个数字钟。
关键字:VHDL,FPGA,数字钟。
一、设计方案:
(1)用两个程序实现实验的功能,主程序实现计数及时间预置功能,子程序实现BCD 显示功能。为了使调整时间时按键的反映速度不是太慢,对按键的检测使用1KHz 时钟。然后对1KHz 信号分频,产生周期为1S 的信号,作为驱动时钟秒的信号。
(2)为了使电子钟具有时间可预置功能,即使其工按照按键的输入工作在不同的状态,因此使用状态机实现时间显示及时间调整功能之间的切换。
(3)显示部分使用对数字0~59进行逐个编码的方法,然后将数字的每一位送至实验箱上的七段译码器。
二、设计框图:
主程序部分的状态转移图:
状态转移图: 输
入
1
K
H
Z
方
波 60进制计数器(秒计数) 60进制计数器(分计数) 24进制计数 (时计数) 1000分频(1HZ 信号) 调秒 调分
调时 4—7显 示译码4—7显 示译码
4—7显 示译码
进位信号 进位信号
三、方案实现:
①主程序:
LIBRARY IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity Clock is
port(mode,set,clr,clk:in std_logic;
BCDHH,BCDHL,BCDMH,BCDML,BCDSH,BCDSL:out std_logic_vector(3 downto 0) );
end entity;
ARCHITECTURE arch OF Clock IS
type st is(s0,s1,s2,s3);
signal state:st;
signal Hour,Min,Sec: integer range 0 to 59;
signal BCDH,BCDM,BCDS:std_logic_vector(7 downto 0);
signal set_reg:std_logic;
component BCD
port(DataIn: in integer range 0 to 59;
BCDOut: out std_logic_vector(7 downto 0));
end component;
BEGIN
process(mode,clr)
begin
if(clr='1') then
state<=s0;
else
if(mode'event and mode='1') then
case state is
when s0=>state<=s1;
when s1=>state<=s2;
when s2=>state<=s3;
when s3=>state<=s0;
end case;
end if;
end if;
end process;
process(clk,state,clr)
variable clk_cnt: std_logic_vector(9 downto 0);
begin
if(clr='1') then
Hour<=0;Min<=0;Sec<=0;
set_reg<='0';
else
if(clk'event and clk='1') then
case state is
when s0 =>
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;
else Hour<=Hour+1;
end if;
else Min<=Min+1;
end if;
else Sec<=Sec+1;
end if;
else clk_cnt:=clk_cnt+1;
end if;
when s1 =>
if (set='1') then
if set_reg='0' then set_reg<='1';
if(Hour=23) then Hour<=0;
else Hour<=Hour+1;
end if;
end if;
else set_reg<='0';
end if;
when s2 =>
if (set='1') then
if set_reg='0' then set_reg<='1';
if(Min=59) then Min<=0;
else Min<=Min+1;
end if;
end if;
else set_reg<='0';
end if;
when s3 =>
if(set='1') then
if set_reg='0' then set_reg<='1';