EDA计数器设计.docx
《EDA计数器设计.docx》由会员分享,可在线阅读,更多相关《EDA计数器设计.docx(14页珍藏版)》请在冰豆网上搜索。
EDA计数器设计
EDA实验报告
EDA多功能数字时钟设计
摘要:
本实验中我们运用EDA课程中所学的知识,设计了一个拥有时间校正和闹钟功能的24小时制多功能数字时钟。
通过本实验,我们初步了解EDA的设计过程;初步掌握用VHDL语言的设计方法和设计思想;初步熟悉Max+PlusII软件平台的编程和仿真,并通过AEDK-EDA实验板下载模拟实现初步了解了硬件实现的方法。
关键词:
数字时钟、VHDL、FPGA、Max+PlusII
一、设计方案
1.功能描述
本次设计的多功能数字钟具有基本的计时功能和时间校正功能,同时可以进行定时闹铃。
计时功能采用24小时计时,显示时、分、秒。
其中分钟和秒模块采用60进制实现;小时设计了24进制的计数器.时间校正部分,分为时校时和分校时,分别通过控制时校正按钮和分校正按钮来实现.闹铃部分,先通过模式切换按钮进入闹钟定时,然后通过与时间校正相同的方法来进行闹铃时间的预置,当预置到达时间时,时钟将通过蜂鸣器进行闹铃。
2.硬件使用模块:
EPF10K20TC144-4,模块10(蜂鸣器),模块17(脉冲源),模块21(开关设置),模块22(设置跳接模块),模块23(键盘显示模块)
显示/校正时间输出
3.VHDL程序设计框图
闹铃
按钮(模式切换/校正定时部分选择)
数码管选通和显示
模六计数,输出数码管选通信号
闹钟定时时间输出
二、VHDL源程序
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityclockis
port(clk:
instd_logic;----------------------时钟脉冲
clk1:
instd_logic;---------------------数码管选通时钟脉冲
md1:
instd_logic;----------------------模式选择:
0为计时,1为闹钟
md2:
instd_logic_vector(1downto0);---10为时校正(定时),01为分校正(定时)
speak:
outstd_logic;-------------------闹钟0
dout:
outstd_logic_vector(6downto0);--数码管七段码输出
selout:
outstd_logic_vector(2downto0));---数码管选通输出
endclock;
architectureoneofclockis
signalsel:
std_logic_vector(2downto0);--------模6计数信号(数码管选通输入)
signalhou1:
std_logic_vector(3downto0);-------小时十位
signalhou2:
std_logic_vector(3downto0);-------小时个位
signalmin1:
std_logic_vector(3downto0);-------分钟十位
signalmin2:
std_logic_vector(3downto0);-------分钟个位
signalseth1:
std_logic_vector(3downto0);------定时小时十位
signalseth2:
std_logic_vector(3downto0);------定时小时个位
signalsetm1:
std_logic_vector(3downto0);------定时分钟十位
signalsetm2:
std_logic_vector(3downto0);------定时分钟个位
signalsec1:
std_logic_vector(3downto0);-------秒十位
signalsec2:
std_logic_vector(3downto0);-------秒个位
signalh1:
std_logic_vector(3downto0);------输出小时十位
signalh2:
std_logic_vector(3downto0);------输出小时个位
signalm1:
std_logic_vector(3downto0);------输出分钟十位
signalm2:
std_logic_vector(3downto0);------输出分钟个位
signals1:
std_logic_vector(3downto0);------输出秒十位
signals2:
std_logic_vector(3downto0);------输出秒个位
-------------------------------------------------
begin
----------------------------------------------模6计数(数码管选通)
choice:
process(clk1)
begin
ifclk1'eventandclk1='1'then
ifsel="101"then
sel<="000";
else
sel<=sel+1;
endif;
endif;
endprocesschoice;
selout<=sel;
-----------------------------------------------小时十位
h110:
process(clk,hou2,min1,min2,sec1,sec2,md1,md2)
begin
ifclk'eventandclk='1'then
if(hou1="0010"andhou2="0011")and(min1="0101"andmin2="1001")and
(sec1="0101"andsec2="1001")then
hou1<="0000";
elsifhou1="0010"andhou2="0011"andmd1='0'andmd2="10"thenhou1<="0000";
elsif(hou2="1001"and(min1="0101"andmin2="1001")and(sec1="0101"and
sec2="1001"))or(hou2="1001"andmd1='0'andmd2="10")then
hou1<=hou1+1;
endif;
endif;
endprocessh110;
-----------------------------------------------小时个位
h220:
process(clk,min1,min2,sec1,sec2,md1,md2,hou1)
begin
ifclk'eventandclk='1'then
if(hou1="0010"andhou2="0011")and(min1="0101"andmin2="1001")and
(sec1="0101"andsec2="1001")then
hou2<="0000";
elsifhou2="1001"and(min1="0101"andmin2="1001")and(sec1="0101"and
sec2="1001")then
hou2<="0000";
elsif(hou2="1001"andmd1='0'andmd2="10")or(hou1="0010"andhou2="0011"andmd1='0'andmd2="10")then
hou2<="0000";
elsif((min1="0101"andmin2="1001")and(sec1="0101"andsec2="1001"))or
(md1='0'andmd2="10")then
hou2<=hou2+1;
endif;
endif;
endprocessh220;
-----------------------------------------------分钟十位
m110:
process(clk,min2,sec1,sec2,md1,md2)
begin
ifclk'eventandclk='1'then
if(min1="0101"andmin2="1001")and(sec1="0101"andsec2="1001")then
min1<="0000";
elsifmin1="0101"andmin2="1001"and(md1='0'andmd2="01")then
min1<="0000";
elsif(min2="1001"and(sec1="0101"andsec2="1001"))or(min2="1001"and
md1='0'andmd2="01")then
min1<=min1+1;
endif;
endif;
endprocessm110;
----------------------------------------------分钟个位
m220:
process(clk,sec1,sec2,md1,md2)
begin
ifclk'eventandclk='1'then
ifmin2="1001"and(sec1="0101"andsec2="1001")then
min2<="0000";
elsifmin2="1001"and(md1='0'andmd2="01")then
min2<="0000";
elsif(sec1="0101"andsec2="1001")or(md1='0'andmd2="01")then
min2<=min2+1;
endif;
endif;
endprocessm220;
---------------------------------------------秒十位
s110:
process(clk,sec1,sec2)
begin
ifclk'eventandclk='1'then
if(sec1="0101"andsec2="1001")then
sec1<="0000";
elsifsec2="1001"then
sec1<=sec1+1;
endif;
endif;
endprocesss110;
--------------------------------------------秒个位
s220:
process(clk,sec2)
begin
ifclk'eventandclk='1'then
ifsec2="1001"then
sec2<="0000";
elsesec2<=sec2+1;
endif;
endif;
endprocesss220;
-------------------------------------------时间设置小时部分
sethour1:
process(clk,seth2)
begin
ifclk'eventandclk='1'then
ifseth1="0010"andseth2="0011"then
seth1<="0000";
elsifseth2="1001"then
seth1<=seth1+1;
endif;
endif;
endprocesssethour1;
-------------------------------------------
sethour2:
process(clk,md1,md2,seth1)
begin
ifclk'eventandclk='1'then
if(seth1="0010"andseth2="0011")orseth2="1001"then
seth2<="0000";
elsifmd1='1'andmd2="10"then
eth2<=seth2+1;
endif;
endif;
endprocesssethour2;
-------------------------------------------时间设置分钟部分
setmin1:
process(clk,setm1,setm2)
begin
ifclk'eventandclk='1'then
ifsetm1="0101"andsetm2="1001"then
setm1<="0000";
elsifsetm2="1001"then
setm1<=setm1+1;
endif;
endif;
endprocesssetmin1;
----------------------------------------------
setmin2:
process(clk,md1,md2,setm2)
begin
ifclk'eventandclk='1'then
ifsetm2="1001"then
setm2<="0000";
elsifmd1='1'andmd2="01"then
setm2<=setm2+1;
endif;
endif;
endprocesssetmin2;
--------------------------------------------闹铃
speaker:
process(clk1,hou1,hou2,min1,min2)
begin
ifclk1'eventandclk1='1'then
ifseth1=hou1andseth2=hou2andsetm1=min1andsetm2=min2then
if(sec2="0000"orsec2="0010"orsec2="0100"orsec2="0110"orsec2="1000")then
speak<='1';
elsespeak<='0';
endif;
endif;
endif;
endprocessspeaker;
-------------------------------------------数码管显示
disp:
process(sel,md1,hou1,hou2,min1,min2,sec1,sec2,seth1,seth2,setm1,setm2)
begin
ifsel="101"then
caseh1is
when"0000"=>dout<="0111111";
when"0001"=>dout<="0000110";
when"0010"=>dout<="1011011";
whenothers=>dout<="1000000";
endcase;
elsifsel="100"then
caseh2is
when"0000"=>dout<="0111111";
when"0001"=>dout<="0000110";
when"0010"=>dout<="1011011";
when"0011"=>dout<="1001111";
when"0100"=>dout<="1100110";
when"0101"=>dout<="1101101";
when"0110"=>dout<="1111101";
when"0111"=>dout<="0000111";
when"1000"=>dout<="1111111";
when"1001"=>dout<="1101111";
whenothers=>dout<="1000000";
endcase;
elsifsel="011"then
casem1is
when"0000"=>dout<="0111111";
when"0001"=>dout<="0000110";
when"0010"=>dout<="1011011";
when"0011"=>dout<="1001111";
when"0100"=>dout<="1100110";
when"0101"=>dout<="1101101";
whenothers=>dout<="1000000";
endcase;
elsifsel="010"then
casem2is
when"0000"=>dout<="0111111";
when"0001"=>dout<="0000110";
when"0010"=>dout<="1011011";
when"0011"=>dout<="1001111";
when"0100"=>dout<="1100110";
when"0101"=>dout<="1101101";
when"0110"=>dout<="1111101";
when"0111"=>dout<="0000111";
when"1000"=>dout<="1111111";
when"1001"=>dout<="1101111";
whenothers=>dout<="1000000";
endcase;
elsifsel="001"then
cases1is
when"0000"=>dout<="0111111";
when"0001"=>dout<="0000110";
when"0010"=>dout<="1011011";
when"0011"=>dout<="1001111";
when"0100"=>dout<="1100110";
when"0101"=>dout<="1101101";
whenothers=>dout<="1000000";
endcase;
elsifsel="000"then
cases2is
when"0000"=>dout<="0111111";
when"0001"=>dout<="0000110";
when"0010"=>dout<="1011011";
when"0011"=>dout<="1001111";
when"0100"=>dout<="1100110";
when"0101"=>dout<="1101101";
when"0110"=>dout<="1111101";
when"0111"=>dout<="0000111";
when"1000"=>dout<="1111111";
when"1001"=>dout<="1101111";
whenothers=>dout<="1000000";
endcase;
endif;
ifmd1='0'then---------------计时时间显示和设置模式
h1<=hou1;h2<=hou2;
m1<=min1;m2<=min2;
s1<=sec1;s2<=sec2;
else-------------闹铃时间显示和设置模式
h1<=seth1;h2<=seth2;
m1<=setm1;m2<=setm2;
s1<="1111";s2<="1111";
endif;
endprocessdisp;
------------------------------------------
end;
三、仿真结果
我们将上述VHDL程序通过Max+PlusII进行编译仿真,仿真结果符合我们设计所预想的功能。
仿真结果见下图。
图1:
正常计时(md1=0,时钟模式)
(所指处,sel值为0,选通数码管秒个位,dout七段码输出sec2,即2)
图2:
分钟校正(md1=0,时钟模式)
(所指处,sel值为3,选通数码管分钟十位,dout七段码输出min1,即3)
图3:
小时校正(md1=0,时钟模式)
(所指处,sel值为4,选通数码管小时个位,dout七段码输出hou2,即8)
图4:
分钟定时(md1=1,闹钟模式)
(所指处,sel值为3,选通数码管分钟十位,dout七段码输出setm1,即2)
图5:
小时定时(md1=1,闹钟模式)
(所指处,sel值为4,选通数码管小时个位,dout七段码输出seth2,即6)
四、结论与收获
在整个设计过程中,通过查阅相关资料,我们一步步建立了对EDA设计的理解。
通过解决在编程、调试以及仿真过程中的种种问题,也加深了我们对软件设计环境的熟悉程度。
通过仿真,我们也感性地认识到了曾经忽视的问题,比如器件间信号传递的时延以及产生毛刺会对电路功能实现的影响。
而最让我们印象深刻的是一点是,在编程当中,虽然某些程序的结构获得的效果以及软件仿真的结果是一致的,但在实际硬件实现是却会有很大的不同。
而这一切,都让我们获益良多。