电子综合实验报告——数字钟范文

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

电子综合实验报告——数字钟
一、实验题目:数字钟
二、实验内容:
设计一个带闹钟功能的24小时计时器。

它包括以下几个组成部分:①显示屏,由8个七段数码管组成,用于显示当前时间(时:分:秒)或正在设置的当前时间;② Time键、HSet键、MSet键分别用来启动设置时钟的时、分;③复位键,用来还原时钟到初始默认值;
④ Alarm键,用于启动设置闹钟时间;⑤ A键组,用于输入2进制闹钟时间;⑥扬声器(这里用一个发光二极管代替),在当前时钟时间与闹钟时间相同时,发出蜂鸣声(二极管亮)。

主要功能:
(1) 计时功能:这是本数字闹钟设计的基本功能,每隔一分钟计时一次,并在显示屏上显示当前时间。

(2) 闹钟功能:如果当前时间与设置的闹钟时间相同,则“扬声器”发出“蜂鸣声”(二极管亮)。

(3) 设置新的数字钟时间:用户用Time键、HSet键、MSet键对当前时间进行修改。

(4) 设置新的闹钟时间:用户用Alarm键及A键组对闹钟时间进行修改。

(5) 显示所设置的闹钟时间:A键组直接展示输入的闹钟时间。

三、设计方案
根据系统的设计要求,整个系统分为4个模块:时间计数器、闹钟寄
存器、分频器、数码管显示模块。

功能介绍:
(1) 时间计数器:实际上是一个异步复位、异步置数的累加器,通常情况下进行时钟累加计数,必要时可置入新的时钟值,然后从该值开始新的计数。

(2) 闹钟寄存器:用于保存用户设置的闹钟时间,并可设置新的闹钟时钟时间并判断当前时间是否等于闹钟时间。

(3)分频器:把板上输入的6MHz的频率分为1Hz和1kHz,1Hz用于数码管显示,1kHz用于时钟计时。

(4)数码管显示模块:用来显示闹钟时间或当前时间。

设计思路:
顶层RTL图:
(一)时间计数器:
在正常计时,前面计数器的cout(进位端)作为下一个计数器的信号。

当修改当前时间时,选用频率更快的信号,使所显示的时间的值较快的达到要设定的值。

此处用一个2选1的选择器来选择适当的
信号。

此处分和时的修改是分开进行的,分别用Mkey和Hkey进行控制(即:他们作为多路选择器的sel信号)。

VHDL语言:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity times is
port(clk_1Hz:in std_logic;
set:in std_logic;
rst:in std_logic;
s1:in std_logic;
s2:in std_logic;
z:out std_logic;
sec_l,sec_h:out std_logic_vector(3 downto 0);
min_l,min_h:out std_logic_vector(3 downto 0);
hour_l,hour_h:out std_logic_vector(3 downto 0));
end times;
architecture behave of times is
signal zd:std_logic;
begin
process(clk_1Hz,set,rst,s1,s2,zd)
variable msecond1:std_logic_vector(3 downto 0):="1000";
variable msecond2:std_logic_vector(3 downto 0):="0101";
variable mminute1:std_logic_vector(3 downto 0):="0100";
variable mminute2:std_logic_vector(3 downto 0):="0011";
variable mhour11:std_logic_vector(3 downto 0):="1000";
variable mhour22:std_logic_vector(3 downto 0):="0000";
begin
if clk_1Hz'event and clk_1Hz='1'then
if mminute1="0000" and mminute2="0000" then
zd<='1';
else
zd<='0';
end if;
if set='0'then
if s1='0'then
mminute1:=mminute1+1;
if mminute1="1010"then
mminute1:="0000";
mminute2:=mminute2+1;
if mminute2="0110"then
mminute2:="0000";
end if;
end if;
end if;
if s2='0'then
mhour11:= mhour11+1;
if mhour11="1010"then
mhour11:="0000";
if mhour22<"0010"then
mhour22:=mhour22+1;
end if;
elsif mhour22="0010"and
mhour11="0100"then
mhour22:="0000";
mhour11:="0000";
end if;
end if;
elsif rst='0'then
msecond1:="1000"; msecond2:="0101";
mminute1:="0100"; mminute2:="0011";
mhour11:="1000"; mhour22:="0000";
else msecond1:=msecond1+1;
if msecond1="1010"then
msecond1:="0000"; msecond2:=msecond2+1;
if msecond2="0110"then
msecond2:="0000";
mminute1:=mminute1+1;
if mminute1="1010"then
mminute1:="0000";
mminute2:=mminute2+1;
if mminute2="0110"then
mminute2:="0000";
mhour11:=mhour11+1;
if mhour11="1010"then
mhour11:="0000";
if mhour22<"0010"then
mhour22:=mhour22+1;
end if;
elsif mhour22="0010"and mhour11="0100"then
mhour22:="0000";
mhour11:="0000";
end if;
end if;
end if;
end if;
end if;
end if;
end if;
sec_l<=msecond1; sec_h<=msecond2;
min_l<=mminute1; min_h<=mminute2;
hour_l<=mhour11; hour_h<=mhour22;
z<=zd;
end process;
end architecture behave;
(二)闹钟寄存器:
闹钟系统的闹钟时间由闹钟寄存器保存和传递,并与当前的时间进行比较。

若两者相等(分和时分别比较,将两者的结果经过与门输出),则二极管发光。

VHDL语言:
library ieee;
use ieee.std_logic_1164.all;
entity jicun is
generic ( n:integer:=8);
port(D1:in std_logic_vector(3 downto 0);
D2:in std_logic_vector(3 downto 0);
D3:in std_logic_vector(3 downto 0);
D4:in std_logic_vector(3 downto 0);
CP:in std_logic;
set:in std_logic;
s1:in std_logic;
s2:in std_logic;
Q1:out std_logic_vector(3 downto 0);
Q2:out std_logic_vector(3 downto 0);
Q3:out std_logic_vector(3 downto 0);
Q4:out std_logic_vector(3 downto 0)); end jicun;
architecture one of jicun is
signal tmp1:std_logic_vector(3 downto 0); signal tmp2:std_logic_vector(3 downto 0); signal tmp3:std_logic_vector(3 downto 0); signal tmp4:std_logic_vector(3 downto 0); begin
u1:process(CP)
begin
if CP'event and CP='1' then
tmp1<=D1;
tmp2<=D2;
tmp3<=D3;
tmp4<=D4;
end if;
end process;
u2:process(CP)
begin
if CP'event and CP='1' then
Q1<=tmp1;
Q2<=tmp2;
Q3<=tmp3;
Q4<=tmp4;
end if;
end process u2;
end one;
(三)分频器
把板上输入的6MHz的频率分为1Hz和1kHz,1Hz用于数码管显示,1kHz用于时钟计时。

VHDL语言:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity freq is
generic(clk1kHz:integer:=6000;
clk1Hz:integer:=);
port(clk_sys:in std_logic;
clk_1kHz:out std_logic;
clk_1Hz:out std_logic);
end freq;
architecture one of freq is
signal clk1,clk2:std_logic;
begin
p1:process(clk_sys)
variable cnt1:integer range 0 to clk1kHz;
begin
if clk_sys'event and clk_sys='1' then
if cnt1 < integer(clk1kHz/2)-1 then
cnt1:=cnt1+1;
else
cnt1:=0;
clk1<=not clk1;
end if;
end if;
end process p1;
p2:process(clk_sys)
variable cnt2:integer range 0 to clk1Hz;
begin
if clk_sys'event and clk_sys='1'then
if cnt2<integer(clk1Hz/2)-1 then
cnt2:=cnt2+1;
else
cnt2:=0;
clk2<=not clk2;
end if;
end if;
end process p2;
clk_1kHz<=clk1;
clk_1Hz<=clk2;
end one;
(四)数码管显示模块:
由模8计数器,3—8译码器,8选1多路选择器和七段译码器组成。

逻辑图:
三、仿真验证:
(一)时间计数器:
波形图:
信号说明:
End Time: 4us Grid Size: 100ns
clk_1Hz:时钟信号` set:设置时间
rst: 复位键s1:更改当前时间的时
s2:更改当前时间的分
结论:当set键和s1均由1变为0时,更改时;当set键和s2均由1变为0时,更改分,当set键和s1均为0时,时间正常走;当rst由1变为0时,时钟复位。

(二)闹钟寄存器:
波形图:
信号说明:
End Time: 1us Grid Size: 100ns
CP:设置闹钟
D1/D2/D3/D4:分别输入闹钟的时、分
结论:
当CP为1时,开始设置闹钟,D1/D2/D3/D4分别输入4位2进制数,决定闹钟的时、分
(四)数码管显示模块:
波形图:
信号说明:
End Time: 1us Grid Size: 100ns
clk_1kHz:时钟信号
d0~d7:输入数据
结论:当clk_1kHz开始变化,d0~d7接受的时间计数器传来的数据按频率输出,数码管显示变化中的时间。

四、下载验证
对计时功能,闹钟功能,整点报时,设置新的时间,设计新的闹钟时间的功能进行验证。

管脚分配:
五、实验日志。

相关文档
最新文档