电子时钟.docx

上传人:b****7 文档编号:9521226 上传时间:2023-02-05 格式:DOCX 页数:26 大小:266.58KB
下载 相关 举报
电子时钟.docx_第1页
第1页 / 共26页
电子时钟.docx_第2页
第2页 / 共26页
电子时钟.docx_第3页
第3页 / 共26页
电子时钟.docx_第4页
第4页 / 共26页
电子时钟.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

电子时钟.docx

《电子时钟.docx》由会员分享,可在线阅读,更多相关《电子时钟.docx(26页珍藏版)》请在冰豆网上搜索。

电子时钟.docx

电子时钟

黑龙江科技学院

课程设计任务书

一、设计题目:

秒表的设计

二、设计的主要内容:

利用一块芯片完成除时钟源、按键、扬声器喝显示器(数码管)之外的所有数字电路功能。

所有数字逻辑功能都在CPLD器件上用VHDL实现。

秒表有六个输出显示,分别为百分之一秒,十分之一秒、秒、十秒、分、十分,共有6个计数器与之对应,6个计数器全为BCD码输出,这样便于显示器译码的链接。

当计时达60秒后,蜂鸣器响10声。

指导教师:

日期:

教师评语:

 

评阅成绩:

评阅人:

日期:

摘要

本课程设计完成了秒表电子钟的设计,数字电子钟是一种用数字显示秒、分、时的计时装置,由于数字集成电路技术的发展和采用了先进的石英技术,它使数字钟具有走时准确、性能稳定、携带方便等优点。

数字钟已成为人们日常生活中必不可少的必需品,广泛用于个人家庭以及办公室等公共场所,给人们的生活带来极大的方便。

在这里我们将已学过的比较零散的数字电路的知识有机的、系统的联系起来用于实际,来培养我们的综合分析和设计电路的能力。

关键词:

秒表、计时装置、石英技术

第1章电子时钟概述

1.1设计目的

随着时代的发展,社会的进步,现在人们的生活节奏是越来越快,所谓争分夺秒,时间就是金钱之说历史已久,电子时钟也由来变成人们生活必不可少的。

电子时钟有着看时间方便,能够定制提醒,有着任务和日常记事功能。

设计这样的电子时钟,方便了我们的出行,我们的约会,我们的工作等。

通过本次实验掌握多位计数器相连的设计方法。

掌握十进制,六进制,二十四进制计数器的设计方法。

继续巩固多位共阴极扫描显示数码管的驱动及编码。

掌握扬声器的驱动和LED灯的花样显示。

1.2设计要求

为了简化程序设计及增加可读性,本系统仍采取模块化的设计方式,重复使用的功能模块均以组件(component)的形式存在,以便相关块的调用。

主程序内的不同功能的模块构成一个完整的结构。

为了便于时钟计数,需要1hz的时钟信号。

为了节省电路耗电,输出显示采用了四合一七段显示器来显示分与秒共4个数字,另外2个数字的小时显示也采用四合一七段显示器来显示。

由于需要一个除以1024hz的分频器,用来实现系统输入信号产生一个1hz的时钟信号。

能进行正常的时、分、秒计时功能,分别由6个数码管显示24h、60min、60s。

按下rst键时,起到复位功能总清0。

按下choose_mode键时,能够在12进制和24进制之间转换显示。

按下set_hou、set_min可以设置小时和分钟。

可以设置闹铃报时。

第2章电子时钟设计思想

2.1模块设计思想

2.1.1count6模块

 

该模块实现模6输出功能。

当计数满6时,计数器清零并产生一个进位标示。

即当carry2满6时,value2变为1。

2.1.2country10模块

该模块同count6模块相同,当计数器满10时,计数器清零并产生一个进位标示。

即当carry1满10时,value1变为1。

2.1.3count12模块

12进制计数作为一个整体,和cout6和count10相同计数器满12清零。

但不同的时count12定义了一个信号选择信号temp比用case…when…语句实现状态选择,两个输出信号value_1和value_2全位4位以实现两个数码管显示,当value_1>9时value_2位1。

2.1.4count24模块

count24计数器实现原理基本和count12相同,value_lb在0—9之间取值,value_hb在0—2之间取值。

2.1.5decoder7s模块

本模块为7段数码管译码,本模块将十进制数转换成七段数码管所需的数据。

使用case…when…语句实现。

2.1.6division模块

为了便于时钟计数,需要1hz的时钟信号。

我们利用视觉暂留效应,让4个七段显示器轮流供电显示,换句话说,需要进行输出显示扫描。

1024分频产生1hz的时钟信号。

2.1.7reg模块

本模块主要功能为锁存器锁存闹钟数据。

采用D触发器实现。

当lock是上升沿的时候输出数据,否则锁存。

2.1.8scan模块

七段显示器扫描输出模块。

4个串联的四合一七段显示器,将分与秒4个数字共享一组七段显示器组,其中必须使用同步扫描电路。

同时触发该数字所对应的七段显示器的电源引脚。

使用case…when…语句实现状态转移。

2.1.9

timing模块

 

分钟与小时计时的模块(与外部联系可设置计时模式),用于显示和调制时间,并选择是12进制还是24进制显示,当select12_24为1时位24进制显示,否则位12进制。

调用count6,count10,count12,count24模块实现时间显示。

2.1.10

clock块

 

 

本模块位上层模块,将各模块组合到一起。

使用component进行元件例化,portmap端口映射。

rst位复位键,当人rst位1时时钟清0。

choose_mode位12进制和24进制选择键,当choose_mode位1时为24进制。

set_min和set_hou位时间设置键。

alarm为闹钟信号,当设置时间和当前时间相同时alarm设为1.

 

第3章模块仿真图与分析

3.1decoder7s模块图

图3-1decoder7s模块图

本模块位7段数码管译码,当binary输入0—9时,bcd输出经转换后的2进制码。

使用case...when...语句实现。

3.2count12模块图

图3-2count12模块图

本模块位12进制计数器,当clr输出1时,输出被清零。

value_l和value_h全变为0。

否则当value_l到9时value_h输出1。

当满12时value_l和value_h全变为0重新计数。

使用case...when...语句实现。

3.3Scan模块图

图3-3scan模块图

Temp从000到101,data0相对应的赋值给dataout,并且choose输出相应的值。

使用case...when...语句实现。

3.4Reg模块图

图3-4reg模块图

当lock为上升沿时将datain输出给dataout。

3.5Count24模块图

图3-5count24模块图

当clr4位零时计数器清零,否则24计数。

使用case...when...语句实现。

3.6Count6模块图

图3-6count6模块图

当clr2位零时计数器清零,否则6计数。

使用case...when...语句实现。

3.7Count10模块图

图3-7county10模块图

当clr1位零时计数器清零,否则10计数。

使用case...when...语句实现。

3.8Timing模块图

图3-8timing模块图

分钟与小时计时的模块(与外部联系可设置计时模式),调用cout6,cout10,cout12,cout24模块。

设置和显示时间。

当select12_24='0'时,12进制显示,否则24进制显示。

setclk_h和setclk_m位时间设置时,当有时钟信号时可设置时间。

使用元件例化和元件调用实现。

3.9Division模块图

图3-9division模块图

3.10Clock模块图

图3-10clock模块图

上层模块,将各模块组合到一起。

使用component进行元件例化,portmap端口映射。

rst位复位键,当人rst位1时时钟清0。

choose_mode位12进制和24进制选择键,当choose_mode位1时为24进制。

set_min和set_hou位时间设置键。

alarm为闹钟信号,当设置时间和当前时间相同时alarm设为1。

第4章实验感想

 正所谓“纸上得来终觉浅,绝知此事要躬行”,通过这次设计,进一步加深了对EDA的了解,让我对它有了更加浓厚的兴趣。

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

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

在波形仿真时,也遇到了一点困难,想要的结果不能在波形上得到正确的显示:

在设定输入的时钟信号后,数字钟开始计数,但是始终看不到小时、星期的循环计数。

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

经过屡次调试,终于找到了比较合适的输入数值。

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

参考文献:

[l]《基于QuartusⅡ的FPGA/CPLD设计》电子工业出版社

[2]《CPLD系统设计技术入门与应用》电子工业出版社

[3]《EDA技术基础》湖南大学出版社

[4]沈明山《EDA技术及可编程器件应用实训》科学出版社

[5]朱正伟《EDA技术及应用》清华大学出版社

 

程序清单:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

useieee.std_logic_arith.all;

entityclockis

port(clk_20m,rst,clk_dis,alarm_set,choose_mode,set_min,set_hou:

instd_logic;

display7:

outstd_logic_vector(6downto0);

select6:

outstd_logic_vector(5downto0);

alarm:

outstd_logic

);

endclock;

architecturebehaveofclockis

signalclk_1s,h:

std_logic;

signalsecond_l,second_h:

std_logic_vector(3downto0);

signalminute_l,minute_h:

std_logic_vector(3downto0);

signalhour_l,hour_h:

std_logic_vector(3downto0);

signalcarry_clk1,carry_clk2,carry_clk3:

std_logic;

signaldecoder_temp:

std_logic_vector(3downto0);

signallock_temp:

std_logic;

signalreg_temp1,reg_temp2:

std_logic_vector(3downto0);

signalreg_temp3,reg_temp4:

std_logic_vector(3downto0);

componentdivisionis

port(clk:

instd_logic;

output:

outstd_logic);

endcomponent;

componentcount10is

port(clk1:

instd_logic;

clr1:

instd_logic;

carry1:

outstd_logic;

value1:

outstd_logic_vector(3downto0));

endcomponent;

componentcount6is

port(clk2:

instd_logic;

clr2:

instd_logic;

carry2:

outstd_logic;

value2:

outstd_logic_vector(3downto0));

endcomponent;

componentregis

port(lock:

instd_logic;

DataIn0,DataIn1:

instd_logic_vector(3downto0);

DataIn2,DataIn3:

instd_logic_vector(3downto0);

DataOut0,DataOut1:

outstd_logic_vector(3downto0);

DataOut2,DataOut3:

outstd_logic_vector(3downto0));

endcomponentreg;

componenttimingis

port(clr_time:

instd_logic;

setclk_h:

instd_logic;

setclk_m:

instd_logic;

select12_24:

instd_logic;

data_min_l:

outstd_logic_vector(3downto0);

data_min_h:

outstd_logic_vector(3downto0);

data_hou_l:

outstd_logic_vector(3downto0);

data_hou_h:

outstd_logic_vector(3downto0));

endcomponenttiming;

componentscanis

port(clk_scan:

instd_logic;

data0,data1,data2:

instd_logic_vector(3downto0);

data3,data4,data5:

instd_logic_vector(3downto0);

dataout:

outstd_logic_vector(3downto0);

choose:

outstd_logic_vector(5downto0));

endcomponent;

componentdecoder7sis

port(binary:

instd_logic_vector(3downto0);

bcd:

outstd_logic_vector(6downto0));

endcomponentdecoder7s;

begin

U1:

divisionportmap(clk_20m,clk_1s);

U2:

count10portmap(clk_1s,rst,carry_clk1,second_l);

U3:

count6portmap(carry_clk1,rst,carry_clk2,second_h);

h<=set_minorcarry_clk2;

U4:

timingportmap(rst,set_hou,h,choose_mode,minute_l,minute_h,hour_l,hour_h);

U6:

scanportmap(clk_dis,second_l,second_h,minute_l,minute_h,hour_l,hour_h,decoder_temp,select6);

U7:

decoder7sportmap(decoder_temp,display7);

U8:

regportmap(lock_temp,minute_l,minute_h,hour_l,hour_h,reg_temp1,reg_temp2,reg_temp3,reg_temp4);

P1:

process(clk_20m,alarm_set)

begin

ifalarm_set='1'thenlock_temp<='1';

elselock_temp<='0';

endif;

endprocess;

P4:

process(clk_20m,lock_temp)

begin

ifreg_temp1=minute_landreg_temp2=minute_handreg_temp3=hour_landreg_temp4=hour_hthen

alarm<='1';

endif;

endprocess;

endarchitecture;

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

useieee.std_logic_arith.all;

entitycount6is

port(clk2:

instd_logic;

clr2:

instd_logic;

carry2:

outstd_logic;

value2:

outstd_logic_vector(3downto0));

endentitycount6;

architecturebehaveofcount6is

begin

process(clk2,clr2)

variabletemp:

std_logic_vector(3downto0);

begin

ifclr2='1'thentemp:

=(others=>'0');

elsifclk2'eventandclk2='1'then

iftemp<5thentemp:

=temp+1;

carry2<='0';

elsetemp:

=(others=>'0');

carry2<='1';

endif;

endif;

value2<=temp;

endprocess;

endarchitecturebehave;

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

useieee.std_logic_arith.all;

entitycount10is

port(clk1:

instd_logic;

clr1:

instd_logic;

carry1:

outstd_logic;

value1:

outstd_logic_vector(3downto0));

endentity;

architecturebehaveofcount10is

begin

process(clk1,clr1)

variabletemp:

std_logic_vector(3downto0);

begin

ifclr1='1'thentemp:

=(others=>'0');

elsifclk1'eventandclk1='1'then

iftemp<9thentemp:

=temp+1;

carry1<='0';

elsetemp:

=(others=>'0');

carry1<='1';

endif;

endif;

value1<=temp;

endprocess;

endarchitecturebehave;

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

useieee.std_logic_arith.all;

entitycount12is

port(clk3:

instd_logic;

clr3:

instd_logic;

value_l:

outstd_logic_vector(3downto0);

value_h:

outstd_logic_vector(3downto0)

);

endentitycount12;

architecturebehaveofcount12is

signaltemp:

std_logic_vector(3downto0);

begin

P1:

process(clk3,clr3)

begin

ifclr3='1'thentemp<=(others=>'0');

elsifclk3'eventandclk3='1'then

iftemp<11thentemp<=temp+1;

elsetemp<=(others=>'0');

endif;

elsenull;

endif;

endprocess;

P2:

process(clk3,temp,clr3)

begin

casetempis

when"0000"=>value_l<=(others=>'0');

value_h<=(others=>'0');

when"0001"=>value_l<="0001";

value_h<="0000";

when"0010"=>value_l<="0010";

value_h<="0000";

when"0011"=>value_l<="0011";

value_h<="0000";

when"0100"=>value_l<="0100";

value_h<="0000";

when"0101"=>value_l<="0101";

value_h<="0000";

when"0110"=>value_l<="0110";

value_h<="0000";

when"0111"=>value_l<="0111";

value_h<="0000";

when"1000"=>value_l<="1000";

value_h<="0000";

when"1001"=>value_l<="1001";

value_h<="0000";

when"1010"=>value_l<="0000";

value_h<="0001";

when"1011"=>value_l<="0001";

value_h<="0001";

whenothers=>null;

endcase;

endprocess;

endarchitecturebehave;

libraryieee;

useieee.s

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 数学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1