数字钟课程设计报告.docx
《数字钟课程设计报告.docx》由会员分享,可在线阅读,更多相关《数字钟课程设计报告.docx(28页珍藏版)》请在冰点文库上搜索。
数字钟课程设计报告
JIANGSUTEACHERSUNIVERSITYOFTECHNOLOGY
数字电路课程设计报告
基于FPGA的数字钟的设计
学院名称:
电气信息工程学院
专业:
测控技术与仪器
班级:
08测控2班
姓名:
査婷婷
学号:
08314215
合作者姓名:
徐姣婷
指导教师姓名:
翟丽芳樊寅逸
2010年12月
一:
课题要求:
1:
技术要求:
本设计主要利用VHDL语言在EDA平台上设计一个电子数字钟,它的计时周期为24小时,具有闹钟功能。
总的程序由几个各具不同功能的单元模块程序拼接而成,其中包括分频程序模块、时分秒计数和、三输入数据选择器程序模块、译码显示程序模块和运用顶层文件来拼接程序模块。
并且使用QUARTUS II软件进行电路波形仿真,下载到FPGA芯片里面进行验证。
2:
功能要求:
1)时钟计数:
完成时、分、秒的正确计时并且显示所计的数字;对秒、分——60进制计数,即从0到59循环计数,时钟——24进制计数,即从0到23循环计数,并且在数码管上显示数值。
钟信号均是1HZ的,所以每LED灯变化一次就来一个脉冲,即计数一次。
2)清零功能:
reset为复位键,低电平时实现清零功能,高电平时正常计数。
可以根据我们自己任意时间的复位。
3)蜂鸣器在整点时有报时信号产生,蜂鸣器报警。
产生“滴答.滴答”的报警声音。
4)LED灯的时钟信号时1HZ,所以每LED灯变化一次就来一个脉冲时间。
LED不停的闪烁,从而产生“花样”信号。
本系统可以由秒计数器、分钟计数器、小时计数器、一个顶层文件构成。
采用自顶向下的设计方法,子模块利用VHDL语言设计,顶层文件用也用VHDL语言设计方法。
显示:
用数码管显示。
3本人的工作:
我主要承担的是软件部分。
用EDA中的VHDL语言来设计软件先用仿真波形检验是否符合要求,在下载到FPGA芯片中与硬件部分的电路连接起来,看是否达到我们所期望的要求。
二:
设计方案;
1数字钟设计的电路内部原理框图:
工作原理:
先由FPGA的17引脚引入50MHZ的信号,在经分频分频到1HZ和1000HZ的信号。
将1HZ的信号分别送入时分秒和闪灯模块中进行计数和闪灯闪耀。
当时间到达整点时,蜂鸣器报警,即Q1显示高电平。
时分秒的计数信号经HHH模块译码经数码管显示。
EN是使能端,当按下时具有清零功能。
三:
单元电路设计:
分频模块:
程序如下:
libraryieee;
useieee.std_logic_1164.all;
entityfenpinis
port(clk6:
instd_logic;
q1000,q5,q1:
outstd_logic);
endfenpin;
architectureccc_arcoffenpinis
signalx:
std_logic;
begin
process(clk6)
variablecnt:
integerrange0to24999;
begin
ifclk6'eventandclk6='1'then
ifcnt<24999then
cnt:
=cnt+1;
else
cnt:
=0;
x<=notx;
endif;
endif;
endprocess;
q1000<=x;
process(x)
variablecnt2:
integerrange0to999;
variabley:
std_logic;
begin
ifx'eventandx='1'then
ifcnt2<999then
cnt2:
=cnt2+1;
q1<='0';
else
cnt2:
=0;
q1<='1';
endif;
endif;
ifx'eventandx='1'then
y:
=noty;
endif;
q5<=y;
endprocess;
endccc_arc;
仿真波形如下:
秒模块:
程序如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitysecondis
port(clk1,en1:
instd_logic;
qa:
outstd_logic_vector(3downto0);
co1:
outstd_logic;
qb:
outstd_logic_vector(3downto0));
endsecond;
architectureccofsecondis
signalcout2,cout1:
std_logic_vector(3downto0);
signalmm:
std_logic;
begin
process(clk1,en1)
begin
ifen1='1'then
if(clk1'eventandclk1='1')then
if(cout2=5andcout1=9)thencout2<="0000";cout1<="0000";mm<='1';
elseif(cout1=9)thencout2<=cout2+1;cout1<="0000";mm<='0';
elsecout2<=cout2;cout1<=cout1+1;mm<='0';
endif;
endif;
endif;
endif;
endprocess;
co1<=mm;
qa<=cout2;
qb<=cout1;
endcc;
仿真后的波形显示如下:
分模块:
程序如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityminuteis
port(clk2,en2:
instd_logic;
qc:
outstd_logic_vector(3downto0);
co2:
outstd_logic;
qd:
outstd_logic_vector(3downto0));
endminute;
architecturebbofminuteis
signalcout2,cout1:
std_logic_vector(3downto0);
signalcc:
std_logic;
begin
process(clk2,en2)
begin
ifen2='1'then
if(clk2'eventandclk2='1')then
if(cout2=5andcout1=9)thencout2<="0000";cout1<="0000";cc<='1';
elseif(cout1=9)thencout2<=cout2+1;cout1<="0000";cc<='0';
elsecout2<=cout2;cout1<=cout1+1;cc<='0';
endif;
endif;
endif;
endif;
endprocess;
co2<=cc;
qc<=cout2;
qd<=cout1;
endbb;
波形仿真以后如下:
时模块
程序如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityhouris
port(clk3,en3:
instd_logic;
qe:
outstd_logic_vector(3downto0);
qf:
outstd_logic_vector(3downto0));
endhour;
architectureaaofhouris
signalcout2,cout1:
std_logic_vector(3downto0);
begin
process(clk3,en3)
begin
ifen3='1'then
if(clk3'eventandclk3='1')then
if(cout2=2andcout1=3)thencout2<="0000";cout1<="0000";
elseif(cout1=9)thencout2<=cout2+1;cout1<="0000";
elsecout2<=cout2;cout1<=cout1+1;
endif;
endif;
endif;
endif;
endprocess;
qe<=cout2;
qf<=cout1;
endaa;
仿真后的波形图如下:
整点报时模块:
libraryieee;
useieee.std_logic_1164.all;
entitysstis
port(m1,m0,s1,s0:
instd_logic_vector(3downto0);
clk4:
instd_logic;
q500:
outstd_logic);
endsst;
architecturesssofsstis
begin
process(clk4,m1,m0,s1,s0)
begin
if(clk4'eventandclk4='1')then
ifm1="0101"andm0="1001"ands1="0101"then
ifs0="0101"ors0="0110"ors0="0111"ors0="1000"ors0="1001"then
q500<='1';
else
q500<='0';
endif;
endif;
endif;
endprocess;
endsss;
仿真波形如下:
选择模块
程序如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityhhhis
port(n1,n2,n3,n4,n5,n6:
instd_logic_vector(3downto0);
a:
instd_logic_vector(2downto0);
qqq:
outstd_logic_vector(3downto0));
endhhh;
architectureddofhhhis
begin
withaselect
qqq<=n1when"000",
n2when"001",
n3when"010",
n4when"011",
n5when"100",
n6when"101",
"0000"whenothers;
enddd;
仿真后波形如下:
片选模块:
程序如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitygggis
port(m:
instd_logic_vector(2downto0);
b:
outstd_logic_vector(5downto0));
endggg;
architectureeeofgggis
begin
withmselect
b<="100000"when"000",
"010000"when"001",
"001000"when"010",
"000100"when"011",
"000010"when"100",
"000001"when"101",
"111111"whenothers;
endee;
仿真波形后如下:
信号转换
程序如下:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitycnt6is
port(clk5:
instd_logic;
n:
outstd_logic_vector(2downto0));
endcnt6;
architecturebehavofcnt6is
signalq1:
std_logic_vector(2downto0);
begin
process(clk5)
begin
if(clk5'eventandclk5='1')then
ifq1<5thenq1<=q1+1;
elseq1<=(others=>'0');
endif;
endif;
endprocess;
n<=q1;
endbehav;
仿真后波形如下:
数码管显示模块;
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitydecoderis
port(x:
instd_logic_vector(3downto0);
y:
outstd_logic_vector(6downto0));
enddecoder;
architectureoneofdecoderis
begin
withxselect
y<="1111110"when"0000",
"0110000"when"0001",
"1101101"when"0010",
"1111001"when"0011",
"0110011"when"0100",
"1011011"when"0101",
"1011111"when"0110",
"1110000"when"0111",
"1111111"when"1000",
"1111011"when"1001",
"0000000"whenothers;
endone;
仿真后的波形如下:
循环闪亮三个灯模块:
程序如下:
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYalertIS
PORT(clk:
INSTD_LOGIC;
lamp0,lamp1,lamp2:
OUTSTD_LOGIC);
ENDalert;
ARCHITECTUREfunOFalertIS
SIGNALcount:
STD_LOGIC_VECTOR(1DOWNTO0);
BEGIN
lamper:
PROCESS(clk)
BEGIN
IF(rising_edge(clk))THEN
IF(count<="10")THEN
IF(count="00")THEN
lamp0<='0';
lamp1<='0';
lamp2<='1';--循环点亮三只灯
ELSIF(count="01")THEN
lamp0<='0';
lamp1<='1';
lamp2<='0';
ELSIF(count="10")THEN
lamp0<='1';
lamp1<='0';
lamp2<='0';
ENDIF;
count<=count+1;
ELSE
count<="00";
ENDIF;
ENDIF;
ENDPROCESSlamper;
ENDfun;
仿真以后的波形如下:
四:
顶层电路设计:
顶层文件的程序如下:
libraryieee;
useieee.std_logic_1164.all;
entitydigital_clockis
port(clk,en:
instd_logic;
q1:
outstd_logic;
r:
outstd_logic_vector(5downto0);
q0:
outstd_logic_vector(6downto0);
yellow,red,green:
outstd_logic);
enddigital_clock;
architecturemainofdigital_clockis
componentfenpin
port(clk6:
instd_logic;
q1000,q1,q5:
outstd_logic);
endcomponent;
componenthour
port(clk3,en3:
instd_logic;
qe:
outstd_logic_vector(3downto0);
qf:
outstd_logic_vector(3downto0));
endcomponent;
componentminute
port(clk2,en2:
instd_logic;
qc:
outstd_logic_vector(3downto0);
co2:
outstd_logic;
qd:
outstd_logic_vector(3downto0));
endcomponent;
componentsecond
port(clk1,en1:
instd_logic;
qa:
outstd_logic_vector(3downto0);
co1:
outstd_logic;
qb:
outstd_logic_vector(3downto0));
endcomponent;
componentsstis
port(m1,m0,s1,s0:
instd_logic_vector(3downto0);
clk4:
instd_logic;
q500:
outstd_logic);
endcomponent;
componenthhh
port(n1,n2,n3,n4,n5,n6:
instd_logic_vector(3downto0);
a:
instd_logic_vector(2downto0);
qqq:
outstd_logic_vector(3downto0));
endcomponent;
componentggg
port(m:
instd_logic_vector(2downto0);
b:
outstd_logic_vector(5downto0));
endcomponent;
componentcnt6is
port(clk5:
instd_logic;
n:
outstd_logic_vector(2downto0));
endcomponent;
componentdecoder
port(x:
instd_logic_vector(3downto0);
y:
outstd_logic_vector(6downto0));
endcomponent;
componentalertIS
PORT(clk:
INSTD_LOGIC;
lamp0,lamp1,lamp2:
OUTSTD_LOGIC);
ENDcomponent;
signalh,i,j,z:
std_logic;
signalk,l,e,f,u,v,t:
std_logic_vector(3downto0);
signals:
std_logic_vector(2downto0);
begin
u1:
fenpinportmap(clk6=>clk,q1=>h,q1000=>z);
u2:
secondportmap(clk1=>h,en1=>en,qa=>k,qb=>l,co1=>I);
u3:
minuteportmap(clk2=>h,en2=>I,qc=>e,qd=>f,co2=>j);
u4:
hourportmap(clk3=>h,en3=>j,qe=>u,qf=>v);
u5:
sstportmap(m1=>e,m0=>f,s1=>k,s0=>l,clk4=>h,q500=>q1);
u6:
hhhportmap(n1=>k,n2=>l,n3=>e,n4=>f,n5=>u,n6=>v,qqq=>t,a=>s);
u7:
gggportmap(b=>r,m=>s);
u8:
cnt6portmap(n=>s,clk5=>z);
u9:
decoderportmap(x=>t,y=>q0);
u10:
alertportmap(clk=>h,lamp0=>yellow,lamp1=>red,lamp2=>green);
endarchitecturemain;
仿真波形如下:
五:
硬件电路设计与安装图
1)元件清单
200欧姆电阻:
12个
1000欧姆电阻:
19个
数码管:
6个
发光二极管:
红黄绿各1个
蜂鸣器:
1个
三极管:
6个
通用板:
1个
杜邦线:
若干
2)电路安装图
六:
硬件电路安装与调试
1)
电路板的布线
硬件班上对应芯片上的引脚:
CLK:
17
EN:
69
Q0(0):
65
Q0
(1):
63
Q0
(2):
59
Q0(3):
57
Q0(4):
53
Q0(5):
51
Q0(6):
47
Q1:
44
R(0):
42
R
(1):
40
R
(2):
31
R(3):
28
R(4):
26
R(5):
24
GREEN:
80
RED:
86
YELLOW:
92
2)焊接的技巧及注意事项
焊前准备:
电烙铁以及镊子、剪刀、斜口钳、尖嘴钳、焊料、焊剂等工具。
用烙铁加热备焊件。
送入焊料,熔化适量焊锡。
移开焊锡。
当焊锡流动覆盖焊接点,迅速移开电烙铁。
掌握好焊接的温度和时间。
在焊接时,要有足够的热量和温度。
如温度过低,焊锡流动性差,很容易凝固,形成虚焊;如温度过高,将使焊锡流淌,焊点不易存锡,焊剂分解速度加快,使金属表面加速氧化,并导致印制电路板上的焊盘脱落。
尤其在使用天然松香作助焊剂时,锡焊温度过高,很易氧化脱皮而产生炭化,造成虚焊。
按照手工焊接的基本操作方法进行焊接,将各个原器件按照要求都焊接在面包板上,完成器件的安装与焊接。
在焊接结束之后,开始调试硬件板。
首先将电路接到+5伏电源上,观察数码管显示是否正常。
如果显示正常,计数正确,是从00:
00:
00计数到23:
59:
59说明电路原理和安装焊接正确,设计、调试成功。
如果不是上面所说情况,说明电路存在问题,需要找出问题所在,仔细检查电路是否设计正确、是