EDA课程设计

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

课程设计报告
设计题目:用VHDL语言实现数字钟的设计
班级:
学号:
姓名: ++++++++
指导教师: ++++++++
设计时间: 2011年12月
摘要
随着电子技术的飞速发展,可编程逻辑器件及其设计技术正在快速进步,而可编程逻辑器件的应用数字系统系统设计技术也在不断进步和更新。

今天我们的课设题目为:数字电子钟的设计。

该多功能的数字钟,具有年、月、日、时、分、秒计数显示功能,以24小时循环计数;具有校对功能以及调整闪烁功能。

在课程设计中采用EDA技术,以硬件描述语言VHDL为系统逻辑描述手段设计文件,在ise开发平台环境下,采用自顶向下的设计方法,由各个基本模块共同构建了一个基于FPGA的数字钟。

系统主芯片,由时钟模块、控制模块、计时模块、数据译码模块、显示以及报时模块组成。

经编译和仿真所设计的程序,在可编程逻辑器件上下载验证,本系统能够完成年、月、日和时、分、秒的分别显示,由按键输入进行数字钟的校时、清零、启停功能。

数字钟采用了六个模块实现,包括一个自定义库。

他们分为:顶层模块timekeeper,秒发生模块:second_wave,时—分—秒计时模块hour_minute_second模块,日期模块date,月年模块month_year,显示控制模块LED_disp,动态显示模块mov。

他们分别完成不同的功能,最后完成我们数字钟的整体功能。

顶层模块:主要实现了调用所有元件的功能,通过调用自定义库文件,还有元件例化完成的。

时分秒模块的功能是:根据lock引脚选择高低电平可以有两种方式(预置和正常计数),up引脚完成增减功能,ov引脚24h计时满进位。

日期模式:ov一脚,当计数满28、29、30、31天时,产生进位脉冲,并且输出日期。

年月模块:输出年月。

LED模块:现实模块,当预置年月日及时分秒是,其他的数码管显示FF。

动态显示:当进行时间设定时,令数码管闪烁。

系统主芯片,由时钟模块、控制模块、计时模块、数据译码模块、显示以及报时模块组成。

经编译和仿真所设计的程序,在可编程逻辑器件上下载验证,本系统能够完成年、月、日和时、分、秒的分别显示,由按键输入进行数字钟的校时、清零、启停功能。

关键词:计数器,译码器,数字,电子钟,模块, LED
目录
摘要
1 课程设计目的……………………………………………………………………
2 课程设计内容及要求……………………………………………………………
2.1 设计任务…………………………………………………………………
2.2 设计要求…………………………………………………………………
3 VHDL程序设计………………………………………………………………
3.1方案论证………………………………………………………………………
3.2 设计思路与方法……………………………………………………………
3.2.1 设计流图……………………………………………………………
3.2.2 各功能模块VHDL代码与电路符号………………………………
4 仿真及分析……………………………………………………………………
5 器件编程下载及设计结果…………………………………………………
6 课程设计总结,包括.收获、体会和建议………………………………
7 参考文献………………………………………………………………………
1、设计目的
掌握利用可编程逻辑器件和EDA设计工具进行电子系统设计的方法
2、设计内容和要求
用VHDL语言实现数字钟的设计,要求设计实现一个具有带预置数的数字钟,具有显示年月日时分秒的功能。

用6个数码管显示时分秒,set按钮产生第一个脉冲时,显示切换年月日,第2个脉冲到来时可预置年份,第3个脉冲到来时可预置月份,依次第4、5、6、7个脉冲到来时分别可预置日期、时、分、秒,第 8个脉冲到来后预置结束,正常工作,显示的是时分秒。

Up为高电平时,upclk 有脉冲到达时,预置位加1.否则减1.
3、VHDL程序设计
3.1方案论证
数字钟采用了六个模块实现,包括一个自定义库。

他们分为:顶层模块timekeeper,秒发生模块:second_wave,时—分—秒计时模块hour_minute_second模块,日期模块date,月年模块month_year,显示控制模块LED_disp,动态显示模块mov。

他们分别完成不同的功能,最后完成我们数字钟的整体功能。

顶层模块:主要实现了调用所有元件的功能,通过调用自定义库文件,还有元件例化完成的。

时分秒模块的功能是:根据lock引脚选择高低电平可以有两种方式(预置和正常计数),up引脚完成增减功能,ov引脚24h计时满进位。

日期模式:ov一脚,当计数满28、29、30、31天时,产生进位脉冲,并且输出日期。

年月模块:输出年月。

LED模块:现实模块,当预置年月日及时分秒是,其他的数码管显示FF。

动态显示:当进行时间设定时,令数码管闪烁。

3.2 设计思路与方法
3.2.1 设计流图
3.2.2 各功能模块VHDL代码与电路符号
1).Year_month模块及其电路符号
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following lines to use the declarations that are -- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;
entity month_year is
port(clk0,clk1,ce:in std_logic;
lock:in std_logic_vector(2 downto 0);
up:in std_logic;
mon0,mon1:buffer std_logic_vector(3 downto 0);
year0,year1:buffer std_logic_vector(3 downto 0));
end month_year;
architecture Behavioral of month_year is
signal ty0,ty1,tm0,tm1:std_logic_vector(3 downto 0);
signal clk:std_logic;
begin
ty0<=year0;ty1<=year1;tm0<=mon0;tm1<=mon1;
process(clk0,clk1,lock)
begin
if(lock="000" or lock="001") then
clk<=clk0;
else clk<=clk1;
end if;
end process;
process(clk,ce)
begin
if(clk'event and clk='1') then
if(ce='1') then
if(lock="000") or (lock="001") or(lock="011" and up='1') then
add_month(tm0,tm1,mon0,mon1);
end if;
if(lock="011" and up='0') then
sub_month(tm0,tm1,mon0,mon1);
end if;
if(lock="000"or lock="001") then
if(mon0="0010" and mon1="0001") then
add_year(ty0,ty1,year0,year1);
end if;
end if;
if(lock="010" and up='1') then
add_year(ty0,ty1,year0,year1);
end if;
if (lock="010" and up='0') then
sub_year(ty0,ty1,year0,year1);
end if;
end if;
end if;
end process;
end Behavioral;
Year_month模块电路符号
2). Date模块及其电路符号
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following lines to use the declarations that are
-- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;
------------------------------------------------------------------
entity date is
port( clk0,clk1,ce: in std_logic;
lock: in std_logic_vector(2 downto 0);
up: in std_logic;
mon0,mon1: in std_logic_vector(3 downto 0);
date0,date1: buffer std_logic_vector(3 downto 0);
year0,year1: in std_logic_vector(3 downto 0);
ov: out std_logic);
end date;
------------------------------------------------------------------
architecture Behavioral of date is
signal tempy0: std_logic_vector(1 downto 0);
signal tempy1,clk: std_logic;
signal td0,td1: std_logic_vector(3 downto 0);
begin
tempy0<=year0(1 downto 0); tempy1<=year1(0);
td0<=date0; td1<=date1;
E1:process(clk0,clk1,lock)
begin
if (lock="000" or lock="001") then
clk<=clk0;
else clk<=clk1;
end if;
end process;
E2:process(clk,ce)
begin
if (clk'event and clk='1') then
if (ce='1') then
if (lock="000") or (lock="001") or (lock="100" and up='1') then
if (mon0="0010" and mon1="0000") then
feb_add_day(td0,td1,tempy0,tempy1,date0,date1);
elsif ((mon0="0001" and mon1="0000") or (mon0="0011") or
(mon0="0101") or (mon0="0111") or (mon0="1000") or
(mon0="0000" and mon1="0001") or (mon0="0010" and mon1="0001")) then
oddmonth_add_day(td0,td1,date0,date1);
else evenmonth_add_day(td0,td1,date0,date1);
end if;
end if;
if (lock="100" and up='0') then
if (mon0="0010" and mon1="0000") then
feb_sub_day(td0,td1,tempy0,tempy1,date0,date1);
elsif ((mon0="0001" and mon1="0000") or (mon0="0011") or
(mon0="0101") or (mon0="0111") or (mon0="1000") or
(mon0="0000" and mon1="0001") or(mon0="0010" and mon1="0001")) then
oddmonth_sub_day(td0,td1,date0,date1);
else evenmonth_sub_day(td0,td1,date0,date1);
end if;
end if;
end if;
end if;
end process;
E3:process(ce)
begin
if (clk'event and clk='1') then
if (lock/="000" and lock/="001") then
ov<='1';
elsif (ce='1') then
if (mon0="0010" and mon1="0000") then
if((tempy1='0' and tempy0="00") or (tempy1='1' and tempy0="10")) then
if (date0="1001" and date1="0010") then
ov<='1';
else ov<='0';
end if;
elsif ((mon0="0001" and mon1="0000") or (mon0="0011") or (mon0="0101") or (mon0="0111") or (mon0="1000") or (mon0="0000"
and mon1="0001") or(mon0="0010" and mon1="0001")) then
if (date0="0001"and date1="0011") then
ov<='1';
else ov<='0';
end if;
elsif(date0="0000" and date1="0011") then
ov<='1';
else ov<='0';
end if;
end if;
end if; end process;end Behavioral ;
Date模块电路符号
3). Hour_min_sec模块及其电路符号
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following lines to use the declarations that are -- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;
----------------------------------------------------------------
entity h_m_s_time is
port(clk0,clk1,ce: in std_logic;
sec0,sec1: buffer std_logic_vector(3 downto 0);
lock: in std_logic_vector(2 downto 0);
up: in std_logic;
min0,min1: buffer std_logic_vector(3 downto 0);
hour0,hour1: buffer std_logic_vector(3 downto 0);
ov: out std_logic
);
end h_m_s_time;
---------------------------------------------------------------- architecture Behavioral of h_m_s_time is
signal ts0,ts1,tm0,tm1,th0,th1: std_logic_vector(3 downto 0); signal clk: std_logic;
begin
ts0<=sec0; ts1<=sec1; tm0<=min0; tm1<=min1; th0<=hour0; th1<=hour1;
R0: process(clk0,clk1,lock)
begin
if (lock="000" or lock="001") then
clk<=clk0;
else clk<=clk1;
end if;
end process;
R1: process(clk,lock)
begin
if (clk'event and clk='1') then
if (ce='1') then
if (lock="000") or (lock="001") or (lock="111" and up='1' ) then
addsec_addmin(ts0,ts1,sec0,sec1)
end if;
if (lock="111" and up='0') then
subsec_submin(ts0,ts1,sec0,sec1)
end if;
if (lock="000" or lock="001") then
if (sec0="1001" and sec1="0101") then
addsec_addmin(tm0,tm1,min0,min1);
end if;
if (sec0="1001" and sec1="0101" and min0="1001" and min1="0101") then
addhour(th0,th1,hour0,hour1)
end if;
if (sec0="1001" and sec1="0101" and min0="1001" and min1="0101"
and hour0="1001" and hour1="0101") then
ov<='1';
else ov<='0';
end if;
end if;
if (lock="110" and up='1') then
addsec_addmin(tm0,tm1,min0,min1);
end if;
if (lock="110" and up='0') then
subsec_submin(tm0,tm1,min0,min1);
end if;
if (lock="101" and up='1') then
addhour(th0,th1,hour0,hour1);
end if;
if (lock="101" and up='0') then
subhour(th0,th1,hour0,hour1);
end if;
end if;
end if;
end process;
end Behavioral;
Hour_min_sec模块电路符号
4). 数码管动态闪烁模块
Process(state,clk2hz)
Begin
Case state is
When”00”=>blink<=”000”;
When”01”=>blink<=(2=>clk2hz,others=>’0’);
When”10”=>blink<=(1=>clk2hz,others=>’0’);
When”11”=>blink<=(0=>clk2hz,others=>’0’); End case;
End process;
功能:当进行时间设定时,令数码管闪烁
5). timekeeper顶层控制模块
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following lines to use the declarations that are -- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;
entity timekeeper is
port(up,setpin,upclk,f: in std_logic;
a0,a1,b0,b1,c0,c1: out std_logic_vector( 3 downto 0)
);
end timekeeper;
architecture Behavioral of timekeeper is
---------------second_wave section--------------------------------------- component second_wave is
port( f: in std_logic;
second_wave: buffer std_logic
);
end component;
---------------hour minute second section--------------------------------- component h_m_s_time is
port( clk0,clk1,ce: in std_logic;
sec0,sec1: buffer std_logic_vector(3 downto 0);
lock: in std_logic_vector(2 downto 0);
up: in std_logic;
min0,min1: buffer std_logic_vector(3 downto 0);
hour0,hour1: buffer std_logic_vector(3 downto 0);
ov: out std_logic
);
end component;
------------------------date section-------------------------------- component date is
port( clk0,clk1,ce: in std_logic;
lock: in std_logic_vector(2 downto 0);
up: in std_logic;
mon0,mon1: in std_logic_vector(3 downto 0);
date0,date1: buffer std_logic_vector(3 downto 0);
year0,year1: in std_logic_vector(3 downto 0);
ov: out std_logic
);
end component;
------------------------month year section-------------------------- component month_yaer is
port(clk0,clk1,ce: in std_logic;
lock: in std_logic_vector(2 downto 0);
up: in std_logic;
mon0,mon1: buffer std_logic_vector(3 downto 0);
year0,year1: buffer std_logic_vector(3 downto 0);
);
end component;
-----------------------led display section-------------------------- component led_dis is
port( lock: in std_logic_vector(2 downto 0);
sec0,sec1: in std_logic_vector(3 downto 0);
min0,min1: in std_logic_vector(3 downto 0);
hour0,hour1: in std_logic_vector(3 downto 0);
date0,date1: in std_logic_vector(3 downto 0);
mon0,mon1: in std_logic_vector(3 downto 0);
year0,year1: in std_logic_vector(3 downto 0);
a0,a1,b0,b1,c0,c1: out std_logic_vector( 3 downto 0)
);
end component;
--------------------------------------------------------------------
signal tlock :std_logic_vector(2 downto 0);
signal tsecond_wave :std_logic;
signal tsec0,tsec1 : std_logic_vector(3 downto 0);
signal tmin0,tmin1 : std_logic_vector(3 downto 0);
signal thour0,thour1 : std_logic_vector(3 downto 0);
signal tdate0,tdate1 :std_logic_vector(3 downto 0);
signal tmon0,tmon1 :std_logic_vector(3 downto 0);
signal tyear0,tyear1 :std_logic_vector(3 downto 0);
signal tovday,tovmonth:std_logic;
signal vcc :std_logic;
begin
vcc<='1';
process(setpin)
begin
if (setpin'event and stpin='1') then
tlock<=tlock+'1';
end if;
end process;
U1: second_wave port map (f,tsecond_wave);
U2: h_m_s_time port map (tsecond_wave,upclk,vcc,tsec0,tsec1,tlock,
up,tmin0,tmin1,thour0,thour1,tovday); U3: date port map (tovday,upclk,vcc,tmon0,tmon1,tyear0,
tyear1,tdate0,tdate1,tovmonth);
U4: month_year port map (tovmonth,upclk,vcc,tlock,up,tmon0,
tmon1,tyear0,tyear1);
U5: led_dis port map (tlock,tsec0,tsec1,tmin0,tmin1,thour0,
thour1,tdate0,tdate1,tmon0,tmon1,
tyear0,tyear1,a0,a1,b0,b1,c0,c1);
end Behavioral;
6). 自定义的程序包
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
package pac is
procedure add_year(oldyear0,oldyear1:in std_logic_vector;
signal newyear0:out std_logic_vector;
signal newyear1:out std_logic_vector);
procedure add_month(oldmonth0,oldmonth1:in std_logic_vector;
signal newmonth0,newmonth1:out std_logic_vector);
procedure sub_month(oldmonth0,oldmonth1:in std_logic_vector;
signal newmonth0,newmonth1:out std_logic_vector);
procedure sub_year(oldyear0,oldyear1:in std_logic_vector;
signal newyear0:out std_logic_vector;
signal newyear1:out std_logic_vector);
procedure feb_add_day(oldday0,oldday1:in std_logic_vector;
ty0:in std_logic_vector(1 downto 0);
ty1:in std_logic;
signal newday0,newday1:out std_logic_vector);
procedure feb_sub_day(oldday0,oldday1:in std_logic_vector;
ty0:in std_logic_vector(1 downto 0);
ty1:in std_logic;
signal newday0,newday1:out std_logic_vector);
procedure oddmonth_add_day(oldday0,oldday1:in std_logic_vector;
signal newday0,newday1:out std_logic_vector);
procedure oddmonth_sub_day(oldday0,oldday1:in std_logic_vector;
signal newday0,newday1:out std_logic_vector);
procedure evenmonth_add_day(oldday0,oldday1:in std_logic_vector;
signal newday0,newday1:out std_logic_vector);
procedure evenmonth_sub_day(oldday0,oldday1:in std_logic_vector;
signal newday0,newday1:out std_logic_vector);
procedure addsec_addmin(oldtime0,oldtime1:in std_logic_vector;
signal newtime0,newtime1:out std_logic_vector);
procedure subsec_submin(oldtime0,oldtime1:in std_logic_vector;
signal newtime0,newtime1:out std_logic_vector);
procedure addhour(oldhour0,oldhour1:in std_logic_vector;
signal newhour0,newhour1:out std_logic_vector);
procedure subhour(oldhour0,oldhour1:in std_logic_vector;
signal newhour0,newhour1:out std_logic_vector);
end pac;
package body pac is
procedure add_year(oldyear0,oldyear1:in std_logic_vector;
signal newyear0:out std_logic_vector;
signal newyear1:out std_logic_vector) is
begin
if(oldyear0="1001" and oldyear1/="1001") then
newyear0<="0000";newyear1<=oldyear1+'1';
else
newyear0<=oldyear0+'1';
end if;
if oldyear0="1001" and oldyear1="1001" then
newyear0<="0000";newyear1<="0000";
end if;
end add_year;
procedure add_month(oldmonth0,oldmonth1:in std_logic_vector;
signal newmonth0,newmonth1:out std_logic_vector) is
begin
if oldmonth0="0010" and oldmonth1="0001" then
newmonth0<="0001";newmonth1<="0000";
elsif oldmonth0="1001" then
newmonth0<="0000";newmonth1<=oldmonth1+'1';
else newmonth0<=oldmonth0+'1';
end if;
end add_month;
procedure sub_month(oldmonth0,oldmonth1:in std_logic_vector;
signal newmonth0,newmonth1:out std_logic_vector) is begin
if oldmonth0="0001" and oldmonth1="0000" then
newmonth0<="0010";newmonth1<="0001";
elsif oldmonth0="0000" and oldmonth1="0001" then
newmonth0<="1001";newmonth1<=oldmonth1-'1';
else newmonth0<=oldmonth0-'1';
end if;
if oldmonth0="0000" and oldmonth1="0000" then
newmonth0<="0010";newmonth1<="0001";
end if;
end sub_month;
procedure sub_year(oldyear0,oldyear1:in std_logic_vector;
signal newyear0:out std_logic_vector;
signal newyear1:out std_logic_vector) is
begin
if oldyear0="0000" then
if oldyear1="0000" then
newyear1<="1001";
else newyear1<=oldyear1-'1';
end if;
newyear0<="1001";
else newyear0<=oldyear0-'1';
end if;
end sub_year;
procedure feb_add_day(oldday0,oldday1:in std_logic_vector;
ty0:in std_logic_vector(1 downto 0);
ty1:in std_logic;
signal newday0,newday1:out std_logic_vector) is begin
if oldday0="1000" and oldday1="0010" then
if((ty1='0'and ty0="00") or (ty1='1' and ty0="10")) then
newday0<=oldday0+'1';
else
newday0<="0001";
newday1<="0000";
end if;
elsif oldday0<="1001" and oldday1<="0010" then
newday0<="0001";newday1<="0000";
elsif oldday0="1001" then
newday0<="0000";newday1<=oldday1+'1';
else newday0<=oldday0+'1';
end if;
end feb_add_day;
procedure feb_sub_day(oldday0,oldday1:in std_logic_vector;
ty0:in std_logic_vector(1 downto 0);
ty1:in std_logic;
signal newday0,newday1:out std_logic_vector) is begin
if(oldday0="0000" or oldday0="0001") and oldday1="0000" then
if((ty1='0' and ty0="00") or(ty1='1' and ty0="10")) then
newday0<="1001";newday1<="0010";
else newday0<="1000";newday1<="0010";
end if;
elsif oldday0="0000" and oldday1/="0000" then
newday0<="1001";newday1<=oldday1-'1';
else newday0<=oldday0-'1';
end if;
end feb_sub_day;
procedure oddmonth_add_day(oldday0,oldday1:in std_logic_vector;
begin
if oldday0="0001" and oldday1="0011" then
newday0<="0001";newday1<="0000";
elsif oldday0="1001" then
newday0<="0000";newday1<=oldday1+'1';
else newday0<=oldday0+'1';
end if;
end oddmonth_add_day;
procedure oddmonth_sub_day(oldday0,oldday1:in std_logic_vector;
signal newday0,newday1:out std_logic_vector) is begin
if((oldday0="0001" or oldday0="0000") and oldday1="0000" )then
newday0<="0001";newday1<="0011";
elsif oldday0="0000" and oldday1/="0000" then
newday0<="1001";newday1<=oldday1-'1';
else newday0<=oldday0-'1';
end if;
end oddmonth_sub_day;
procedure evenmonth_add_day(oldday0,oldday1:in std_logic_vector;
signal newday0,newday1:out std_logic_vector) is begin
if oldday0="0000" and oldday1="0011" then
newday0<="0001";newday1<="0000";
elsif oldday0="1001" then
newday0<="0000";newday1<=oldday1+'1';
else newday0<=oldday0+'1';
end if;
end evenmonth_add_day;
procedure evenmonth_sub_day(oldday0,oldday1:in std_logic_vector;
signal newday0,newday1:out std_logic_vector) is begin
if(oldday0="0001" or oldday0="0000") and oldday1="0000" then
newday0<="0000";newday1<="0011";
elsif oldday0="0000" and oldday1/="0000" then
newday0<="1001"; newday1<=oldday1-'1';
else newday0<=oldday0-'1';
end if;
end evenmonth_sub_day;
procedure addsec_addmin(oldtime0,oldtime1:in std_logic_vector;
begin
if(oldtime0="1001")then
newtime0<="0000";
if(oldtime1="0101") then
newtime1<="0000";
else newtime1<=oldtime1+'1';
end if;
else newtime0<=oldtime0+'1';
end if;
end addsec_addmin;
procedure subsec_submin(oldtime0,oldtime1:in std_logic_vector;
signal newtime0,newtime1:out std_logic_vector) is begin
if(oldtime0="0000") then
newtime0<="1001";
if(oldtime1="0000") then
newtime1<="0101";
else newtime1<=oldtime1-'1';
end if;
else newtime0<=oldtime0-'1';
end if;
end subsec_submin;
procedure addhour(oldhour0,oldhour1:in std_logic_vector;
signal newhour0,newhour1:out std_logic_vector) is begin
if(oldhour0="1001") then
newhour0<="0000";newhour1<=oldhour1+'1';
else newhour0<=oldhour0+'1';
end if;
if oldhour0="0011" and oldhour1="0010" then
newhour0<="0000";newhour1<="0000";
end if;
end addhour;
procedure subhour(oldhour0,oldhour1:in std_logic_vector;
signal newhour0,newhour1:out std_logic_vector) is begin
if oldhour0="0000" then
newhour1<=oldhour1-'1';newhour0<="1001";
else newhour0<=oldhour0-'1';
end if;
if oldhour0="0000" and oldhour1="0000" then
newhour0<="0011";newhour1<="0010";
end if;
end subhour;
end pac;
7).LED显示模块
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following lines to use the declarations that are
-- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;
entity led_dis is
port(lock:in std_logic_vector(2 downto 0);
sec0,sec1,min0,min1,hour0,hour1:in std_logic_vector(3 downto 0);
date0,date1,mon0,mon1,year0,year1:in std_logic_vector(3 downto 0);
a0,a1,b0,b1,c0,c1:out std_logic_vector(3 downto 0));
end led_dis;
architecture Behavioral of led_dis is
begin
process(lock,sec0,sec1,min0,min1,hour0,hour1,date0,date1,mon0,mon1,year0,year1) begin
if(lock="000") then
a0<=sec0;a1<=sec1;b0<=min0;b1<=min1;c0<=hour0;c1<=hour1;
end if;
if(lock="001") then
a0<=date0;a1<=date1;b0<=mon0;b1<=mon1;c0<=year0;c1<=year1;
end if;
if(lock="101") then
a0<="1111";a1<="1111";b0<="1111";b1<="1111";c0<=hour0;c1<=hour1;
end if;
if(lock="110") then
a0<="1111";a1<="1111";b0<=min0;b1<=min1;c0<="1111";c1<="1111";
end if;
if(lock="111")then
a0<=sec0;a1<=sec1;b0<="1111";b1<="1111";c0<="1111";c1<="1111";
end if;
if(lock="010") then
a0<="1111";a1<="1111";b0<="1111";b1<="1111";c0<=year0;c1<=year1;
end if;
if(lock="011") then
a0<="1111";a1<="1111";b0<=mon0;b1<=mon1;c0<="1111";c1<="1111";
end if;
if(lock="100") then
a0<=date0;a1<=date1;b0<="1111";b1<="1111";c0<="1111";c1<="1111";
end if;
end process;
end Behavioral;
4、仿真与分析
1).year_month模块仿真波形
2).date模块仿真波形
3).hour_minute_second模块仿真波形
由上述波形可以清楚的看到:
当清0信号(reset)无效时,秒计时器置数,到59秒时回到0,并且从ensec输出一个高电平。

当清0信号(reset)无效时,分计时器置数,到59秒时回到0,并且从enmin输出一个高电平。

当清0信号(reset)无效时,时计时器置数,到23时回到0,并且从enhour输出一个高电平。

4).second模块仿真波形
由上述波形可以清楚的看到:当清0信号(reset)无效时,秒计时器置数,到59秒时回到
0,并且从ensec输出一个高电平。

5.安装调试
1).时分秒计时器(hour_minute_second)
在时计时器的clkh输入1HZ的时钟信号;清0端(reset)前面一小段为低电平,后面均为高电平;置数端(set)前面一小段为低电平,后面均为高电平;时重置端(h1)可设置数值
在分计时器的clkm输入1HZ的时钟信号;清0端(reset)前面一小段为低电平,后面均为高电平;置数端(set)前面一小段为低电平,后面均为高电平;分重置端(m1)可设置数值
在秒计时器的clk输入1HZ的时钟信号;清0端(reset)前面一小段为低电平,后面均为高电平;置数端(set)前面一小段为低电平,后面均为高电平;秒重置端(s1)可设置数值,保存波形图,进行仿真,各波形图如(4、仿真与分析中所示)。

2).日期计数器(date)
在日期计时器的clk输入1HZ的时钟信号;清0端(reset)前面一小段为低电平,后面均为高电平;置数端(set)前面一小段为低电平,后面均为高电平;日期重置端(s1)可设置数值,保存波形图,进行仿真,各波形图如(4、仿真与分析中所示)。

3).年月期计数器(month_year)
在月计时器的clk输入1HZ的时钟信号;清0端(reset)前面一小段为低电平,后面均为高电平;置数端(set)前面一小段为低电平,后面均为高电平;月重置端(s1)可设置数值,保存波形图,进行仿真,各波形图如(4、仿真与分析中所示)。

4).系统总调试(timekeeper)
在秒计时器的clk输入1HZ的时钟信号;清0端(reset)前面一小段为低电平,后面均为高电平;置数端(set)前面一小段为低电平,后面均为高电平;秒重置端(s1)可设置数值为50秒,分重置端(m1)可设置数值为57分, 时重置端(h1)可设置数值为23时,日期重置端可设置数值为15;保存波形图,进行仿真,各波形图如(4、仿真与分析中所示)。

6. 课程设计总结,包括.收获、体会和建议
通过这次设计,进一步加深了对EDA的了解,让我对它有了更加浓厚的兴趣。

特别是当每一个子模块编写调试成功时,心里特别的开心。

但是在编写顶层文件的程序时,遇到了不少问题,特别是各元件之间的连接,以及信号的定义,总是有错误,在细心的检查下,终于找出了错误和警告,排除困难后,程序编译就通过了,心里终于舒了一口气。

在波形仿真时,也遇到了一点困难,想要的结果不能在波形上得到正确的显示:在设定输入的时钟信号后,数字钟开始计数,但是始终看不到小时、星期的循环计数。

后来,在数十次的调试之后,才发现是因为输入的时钟信号对于小时、星期来说太短了。

经过屡次调试,终于找到了比较合适的输入数值:分钟的初始值可以设为57(58、59都可以),小时的初始值可以设为23,日期的初始值可以设为15,这样,仿真之后,就能清楚的看出分钟、小时、日的循环计数。

另外,Endtime的值需要设置的长一点:10us左右,输入的时钟周期值要设置的短一点:5ns 左右。

总的来说,这次设计的数字钟还是比较成功的,有点小小的成就感,终于觉得平时所学的知识有了实用的价值,达到了理论与实际相结合的目的,不仅学到了不少知识,而且锻炼了自己的能力,使自己对以后的路有了更加清楚的认识,同时,对未来有了更多的信心。

通过这次对数字钟的设计与制作,让我了解了设计电路的程序,也让我了解了关于数字钟的原理与设计理念,要设计一个电路总要先用仿真仿真成功之后才实际接线的。

但是最后的成品却不一定与仿真时完全一样,因为,再实际接线中有着各种各样的条件制约着。

而且,在仿真中无法成功的电路接法,在实际中因为芯片本身的特性而能够成功。

所以,在设计时应考虑两者的差异,从中找出最适合的设计方法。

通过这次学习,让我对各种电路都有了大概的了解,所以说,坐而言不如立而行,对于这些电路还是应该自己动手实际操作才会有深
刻理解。

对设计的建议:我希望老师在我们动手制作之前应先告诉我们一些关于所做电路的资料、原理,以及如何检测电路的方法,还有关于检测芯片的方法。

这样会有助于我们进一步的进入状况,完成设计.
7.参考文献
《可编程逻辑器件与EDA技术》作者:李景华杜玉远东北大学出版社
《数字系统设计与SOPC技术》作者:李景华杜玉远东北大学出版社
《EDA技术实用教程潘松》作者:黄继业科学出版社
《集成电子技术基础教程》作者:郑家龙,王小海,章安元高等教育出版社《CPLD技术及其应用》作者:宋万杰,罗丰,吴顺君西安电子科技大学出版社。

相关文档
最新文档