您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页教室灯光控制系统_毕业设计——1

教室灯光控制系统_毕业设计——1

来源:华佗小知识


目录

摘要----------------------------------------------------------1 ABSTRACT--------------------------------------------------2 1.引言--------------------------------------------------------5

1.1本课题研究的意义----------------------------------------5 1.2国内外教室灯光控制器研究的现状及其存在的问题------------5 1.3本课题研究的内容和目标----------------------------------7 1.3.1研究内容------------------------------------------7 1.3.2研究目标------------------------------------------7

1.4本课题拟解决的关键问------------------------------------8

2.教室灯光控制器简介及控制方案的分析---------------------8

2.1教室灯光控制器简介--------------------------------------8 2.2系统控制方案的分析--------------------------------------8

3.系统控制模块的硬件设计-----------------------------------9

3.1控制模块的硬件构成--------------------------------------9 3.2控制系统的主要硬件电路--------------------------- ------9 3.2.1系统主控电路-------------------------------------10 3.2.2在线编程模块电路---------------------------------10 3.2.3系统供电电路-------------------------------------11 3.2.4数据采集电路-------------------------------------12

3.2.5系统时钟电路-------------------------------------16

3.2.6系统看门狗电路-----------------------------------19 3.2.7继电器驱动接口电路--------------------------- ---21 3.2.8超时报警电路-------------------------------------21

4控制模块软件设计与开发-----------------------------------22

4.1系统监控主程序模块-------------------------------------23 4.1.1系统自检初始化-----------------------------------23

4.1.2定时中断处理-------------------------------------24

4.1.3多任务操作系统的构建-----------------------------24

4.2数据采集模块-------------------------------------------25 4.2.1人体存在传感器的优缺点---------------------------25 4.2.2数据采集软件设计的实现---------------------------25 4.2.3人体存在传感器的抗干扰措施-----------------------26 4.2.4人体存在传感器的安装要求-------------------------27

4.3时钟模块-----------------------------------------------27 4.3.1数据输入输出-------------------------------------27 4.3.2时钟内部寄存器的使用-----------------------------28

1

4.3.3时钟自检初始化-----------------------------------29 4.3.4时钟程序设计-------------------------------------30

4.4显示驱动模块-------------------------------------------30

4.4.1 ULN2803驱动器的应用-----------------------------32

4.4.2显示程序设计-------------------------------------32

4.5系统键功能---------------------------------------------33 4.5.1键功能处理程序-----------------------------------33

5系统调试运行及问题分析-----------------------------------34

5.1单片机系统调试方法及步骤-------------------------------34 5.2出现的主要问题及分析解决-------------------------------35

6.结论和建议-------------------------------------------------36

6.1结论---------------------------------------------------36 6.2建议---------------------------------------------------37

7.致谢--------------------------------------------------------38 参考文献-----------------------------------------------------39 附图A--------------------------------------------------------40 附图B -------------------------------------------------------41 附录一 ------------------------------------------------------42 附录二-------------------------------------------------------44

2

1.引言

1.1本课题研究的意义

随着社会经济和科学技术的发展,人们的生活水平也不断提高,导致用电负荷的加剧,又由于世界性的能源危机,能源缺乏已成为世界所面临的严峻问题。而此问题对我国来说尤为严重。随着各类大、中专院校的扩招,教室的扩建,教室照明的需求也越来越多,而教室照明的管理不到位,往往造成电能的巨大浪费,这样,提高教室用电效率就成为首要考虑的问题。

目前对灯光的智能控制,国内外己经开始采用,但对教室灯光的控制,尤其是我国教室灯光的智能控制尤为缺乏和不完善,依然是传统式的人工管理。各类大、中专院校不断扩招,教室不断扩建,教室的用电负荷不断加大,教室用电管理不善,造成学校电能浪费,经济损失,这种的浪费与当今的节约能源理念相违背。再者,现代自动化程度不断提高,计算机技术的普及,灯光的管理也在朝着自动化、智能化方向发展。例如楼道灯光的自动控制等等。所有这些使得教室灯光控制也应该朝着智能的方向发展。于是,开发简便、实用的教室灯光自动控制系统便具有重要的现实意义。

1.2国内外教室灯光控制器研究的现状及其存在的问题

世界各地发电的主要原料是煤炭、石油和天然气,而丹麦在能源利用方面的成功经验提供了很好的借鉴。从1974年以来,尽管丹麦国民收入增长了50%,丹麦总的能源消费量并没有增加。丹麦是OECD成员国中能源消耗量和国民收入比值最小的国家。他们不断地提供一些节能供热系统,例如丹麦热电同供热电厂(CHP),而且,他们尽可能的有效利用资源。这样,他们的能源使用总效率达到了90%。丹麦很重视住房空间用电的节能,并设立了对新建房屋节能的诸多要求。数据显示,居民入住有节能装置的房子时,他们要支付比没有节能方案房屋高出8%的费用。其节能项目经验在欧盟国家中广为流传。还有,欧司朗一斯维尼亚公司不断的推出新型高输出的荧光灯,节约6%的总系统功率,并具有更高的光通和平均光通量。飞利浦照明公司推出的陶瓷金卤灯代替过去的卤钨灯,可节能60%的电能。种种迹象表明世界各国都在采取不同方式来节约能源,节约

3

电能。

中国经济持续多年的高速发展让能源问题日益突出。虽然我国能源总储量不低,但由于我国人口众多,所以人均储量少,单位产值的能耗是发达国家的3-10倍。能源问题已成为制约我国国民经济发展的关键问题。从环境和自然资源角度出发,能源问题也是我国长期可持续发展战略中一个关键因素。此外,能源问题不仅关系经济发展和环境生态,在特定情况下还会对社会稳定有很大影响。鉴于能源问题的重要性,我国在绿色照明工程新闻发布,绿色照明工程未来五年间将在公用设施、宾馆、商厦、居民住所等全国建筑物中推广1.5亿只节能灯,节电290亿度电。上海、河北等一些地方采取对节能灯大宗采购每只补贴3至4元的方式进行推广。从普通白炽灯到高效节能灯,使我国的电光源产品结构逐步向节电型转变,荧光灯与普通白炽灯的比例由1995年的l:6.25前的l: 1. 5。 目前,我国照明用电约占社会总用电量的12%,采用高效照明产品代替传统的低效照明产品可节电60%到80%。如今,北京正在大力推行绿色照明工程,己推出上百万只绿色照明光源和部分节能电器,据测算年节约用电可达3442万千瓦时,节约电费2519.7万元。己经在商厦、学校、医院等更换了24万只节能灯具。在奥运工程的建设上,也大量运用节能技术,北京的奥运厂馆“水立方”,通过采用大量的节能灯具,装备新技术,通过增强透光性白天可节约照明能耗50%。

我们党在2000年10月11日党第十五届委员会第五次会议通过的《关于制定国民经济和社会发展第十个五年计划的建议》中明确指出:“加强基础设施建设是今后五年至十年一项十分重要的任务。”其中提到的基础设施建设就包括了能源建设。《建议》还强调了能源建设要发挥资源优势,优化能源结构,提高利用效率。面临如此紧迫的能源问题,我们应该把着眼点放在“高效加强环境保”利用“清洁”能源上4。由此可见,节能照明用电,对节能具有重要的意义。目前国内各类院校中,由于同学们的自觉节能意识薄弱,在光线足够强时也开灯,护洁课上完离开教室后灯还亮着的现象普遍存在;而且,节能规划极为欠缺,教室的灯光控制由管理人员手工代替,教室极多,管理人员忙不过来,这样就造成不必要的电能浪费和经济损失。就我校为例,初步统计大小教室大约安装了共有5400盏灯,以每天仅亮灯8小时来计算,一年中扣除假期后,

4

教室灯的耗电量约为52.25万度,学校在教室用电的经费上就得支出约为30.46万元人民币。而以每天浪费2小时用电来计算,一年大约要浪费13.06万度的电量,占教室照明用电经费的四分之一。我省各类大中专院校及其中小学总共有600百多所,若都象我校一样每年浪费13.06万度电的话,我省就会浪费近7900万度的电。导致电能的极大浪费。再者,每所院校不断的扩招,教室不断的扩建,若再没有改进教室的用电管理设备,那么用电负荷可想而知,浪费的电能就更、凉人了。

基于以上种种原因,提高教室用电效率就成为学校节能的重要且主要的措施之一,因此节能技术的重要手段之一就是教室灯关自动控制系统的设计无疑就成为其中一项重要课题。

1.3本课题研究的内容和目标

1.3.1研究内容

本课题的研究内容有如下几点: (1)了解教室照明光强的标准;

(2)调研教室灯光照明需求以及环境光强弱与开、关灯的关系; (3)研究人体存在探测技术,探测角度与范围;

(4)研究传感器教室分布、安放问题,是否一灯一个传感器或多灯公用传感器等; (5)研究确定人体传感器的有关参数; (6)研究灯光控制器电源问题;

(7)研究控制器参数值设定的要求及方案; (8)研究人工设置参数、掉电保存参数的问题;

(9)研究与现有教室照明相兼容,易替代,不易被偷盗、被仿制,易于维护、维修等控制技术;

(10)研究报警等附加功能问题 1.3.2研究目标

研究的教室灯光控制系统能用于现有教室照明系统的改造,实现对照明系统的人性化智能管理,提高用电效率;实现自动、手动灯光控制相兼容,以降低成本;通过反复试验和改进,最终达到可靠性、实用性、推广性较好的目标。

5

1.4本课题拟解决的关键问题

本课题拟通过试验研究教室灯光的各种控制方案解决如下关键问题: (1)照明回路的控制回路与控制器本身的节能问题; (2)传感器与教室灯配合安装的问题; (3)环境光参数输入采集问题; (4)人存在传感器参数输入采集问题; (5)开、关灯的自动与手动兼容措施;

2.教室灯光控制器简介及控制方案的分析

2.1教室灯光控制器简介

教室灯光控制器可实现有效的教室灯光智能控制。其输入参数主要是人体存在信号和环境光信号等的外界因素,环境光的强度达到一定值时不开灯,环境光强度在一定阀值以下且有人存在时开灯,理论和实验证明用这种方式来对教室灯进行智能控制可以实现上述目标。

教室灯光控制器一般安装在教室内避开电灯直射的位置,且人体传感器安置时应使人体活动方向与人体传感器中两个热释电元连线方向垂直,这样可使人体存在信号采集更加灵敏、可靠,同时还要尽可能避免外界风直接吹向人体传感器。

2.2系统控制方案的分析

所研制的控制器以自然光强度和人体存在作为控制器的主要输入参数。可以实现自动与手动控制相兼容。在自然环境光较强光线足够时,无论人是否存在,都不开灯;在自然环境光较弱时,有人存在且超过一定时间,控制器自动打开电灯,直到人离开后再延时一定时间后关灯。同时,还要按作息时间来控制,夜晚超过12点,若还有人存在,则关闭自动控制器的运行,改用机械开关来手动控制,以解决因特殊情况下,自动控制器的不人性化运行。

本文所研究的教室灯光控制器主要是由硬件和软件两大部分组成。硬件部分是前提,是整个系统执行的基础,它主要为软件提供程序运行的平台。而软件部

6

分,是对硬件端口所体现的信号,加以采集、分析、处理,最终实现控制器所要实现的各项功能,达到控制器自动与手动相结合的教室照明智能控制。

3.系统控制模块的硬件设计

考虑到本系统所安装的环境影响因素比较多,且教室控制设备中的人体存在传感器、光敏三极管等经常会因环境情形变化而不稳定,所以在设计过程中,电子元器件的选用、线路布置和设备的安放要充分考虑到抗干扰问题。

3.1控制模块的硬件构成

系统控制单元是以单片机4主控模块为核心,其它外围电路主要包括:ISP

下载线模块、系统供电模块、硬件时钟模块、看门狗模块、灯光驱动模块、数码管驱动显示模块、环境光模块、EEPROM存储模块、人体存在传感器模块、超时报警模块,其结构框图如图3-1所示:

图3-1系统控制单元结构框图

灯光驱动模块 数码管显示模块 硬件时钟模块 EEEPROM存储器模块 ISP下载线模块 51系统模块 环境光模块 人体存在传感器模块 电源模块 看门狗模块 3.2控制系统的主要硬件电路

3.2.1系统主控电路

7

本系统的主控模块主要采用Atmel公司的ATC52作为主控芯片,它是一种低功耗,8位CMOS工艺处理器,具有8K在线可编程Flash存储器,片内的Flash可多次编程,为在线编程提供了方便。片内有128字节的RAM, 4KB的EEPROM,由于合理的安排使用片内RAM空间,所以没有扩展的片外RAM,使电路结构简捷。因为设备的设置参数是根据实际需要进行更改的,又要求是断电能够保存下来,所以本设备用一片EEPR0M来存储系统的设置参数。ATS52I/0端口与系统其它外围器件接口的分配情况表如表3-1所示。

表3-1外围器件接口的分配

552引脚 P0.0-P0.7 P2.0-P2.7 P1.0 Pl.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 P1.5一P1.7 P3.0一P3.1 P3.2 P3.3 P3.4 P3.5一P3.6 P3.7 外围器件引脚 ULN2803 NPN-9012基极 X5045SI X5045SCK X5045CS X5045S0 DS1302CLK DS1302I0 DS1302RST 说明 数码管段码驱动接口 数码管位控驱动接口 X5045串行输入端 X5045串行时钟端 X5045片选端 X5045串行输出端 系统工作灯显示端口 DS1302时钟线 DS1302数据线 DS1302复位线 工SP在线编程端 数据采集输入端 遥控器接收信号端 人体存在传感器输出信号端 超时报警信号输入端 灯光驱动输入端 光敏三极管输入信号端 3.2.2在线编程模块电路

以往单片机的实验往往依赖于仿真机和单片机学习系统,价格昂贵,近年来,随着FLASH型单片机的广泛应用,采用软件模拟结合写片验证成为一种经济实用

8

的实验方法,尤其是随着单片机技术的发展,很多单片机都具有了ISP功能,不再需要仿真机,将单片机的易用性推向一个新的高度。ATC52芯片就是这样的芯片。

ATC52芯片支持在线编程(ISP)功能,用户可以通过ATC52在线编程接口直接对电路板上的CPU进行在线编程,方便了程序的修改烧写工作。ISP进行在线编程时,用ATC52芯片的P1.5,P1.6,P1.7引脚及RST端口,通过PC并口,根据工SP协议制作简单的编程器就可对CPU进行编程。在线编程(ISP)器的红色LED是电源指示灯,绿色LED是复位指示灯,黄色LED是时钟信号指示灯,每个LED约消耗0.6mA的电流,它们使用的缓冲器不会影响下载线和用户板,当执行菜单命令Reset时可以看到绿色LED闪一下,表示电脑已经可以控制下载线;其下载线正常工作电压为DC3.6-6V,部分电脑即使不连接VCC也可以正常工作,10心的插头和插座有三角形标志的均为第一脚。使用方便、快捷,且工作显示信号清晰。 3.2.3系统供电电路

要取得+5V电压,若选用12V的变压器,整流滤波后输出往往大于12V,会使稳压器功耗大,自身温度较高。故不选用输出电压为12V的变压器,而选用输出电压为9V的变压器。系统接通220V交流电源后,将220V交流电变压到9V,经过二极管全波整流、电解电容Cl,C2滤波,再经一只正输出稳压器LM7805,为了缓冲负载突变,改善瞬态响应,输出端还采用了电容C3、C4,最后得到+5V的直流工作电源,用于给控制系统中单片机系统及其它外围电路的Vcc+端供电。其供电原理图如3.2.3

图3.2.3 供电原理图

9

在硬件时钟模块中,为了在断电后硬件时钟能够正常运行,故采用主从双电源供电方式。硬件时钟一般在系统的+5V主电源情况下工作,而只有系统+5V主电源消失的情况下,为确保硬件时钟的正常运行,设计一个3. 6V的可充电铿电池作为备用电源。具体电路及其原理将在后面的系统时钟电路部分详细说明。 3.2.4数据采集电路

教室中的环境光和人体存在与否是系统的主要输入参数,因此教室中的环境光和人体存在成为系统数据采集的主要对象。常见的环境光采集器件光电传感器有光敏二极管和光敏三极管,根据需求,选用灵敏度较高的光敏三极管。此外,人体传感器要求灵敏度高,可靠性强,本系统采用了逻辑电平输出的HP-208型号的人体存在传感器。 1.环境光采集电路

光电传感器是一种能够将光转换成电量的传感器。采用的光敏三极管除了具有光敏二极管能将光信号转换成电信号的功能外,还有对电信号放大的功能。在无光照时三极管的穿透电流很小,为暗电流Iceo有光照时,产生的Ib增大,成为光电流Ie。光电流的大小与光照强度成正比,于是在负载电阻上就能得到随光照强度变化而变化的电信号。因此光敏三极管灵敏度高,而且体积小、工作电压低、工作电流小、发光均匀稳定、响应速度快、寿命长等优点,其外形电路图形符号如图3.2.4. 1-1

图3.2.4. 1-1

环境光采集电路原理图如图3.2.4 1-2所示。当自然光强大于一定程度时,光敏三极管D6呈现底阻状态<1千欧,三极管Q12的基极电压升高,Q12管饱和

10

导通,集电极输出低电平。当自然光强小于一定程度时,光敏三极管D6呈现高阻状态,100千欧,使三极管Q12截止,集电极输出高电平。其中可变电阻R26可调节,调R26阻值的大小,使Q12三极管受环境光影响在适当的亮度下导通。

图 3.2.4.1-2环境光采集电路原理图

2.人体存在传感器的工作原理

自然界中存在的各种物体,如人体、木材、石头、火焰、冰等都会发出不同波长的红外线,利用红外传感器可对其进行检测。根据工作原理,红外传感器分为热型和量子型两类,热型红外传感器也称热释电红外传感器或被动红外传感器。与量子型相比,响应的红外线波长范围较宽,价格便宜,并可在常温下工作。量子型与热型的特点相反,而且要求冷却条件。本系统采用的是热释电红外传感器,人体存在传感器主要采用了红外传感器的原理,它是目前在防盗报警、火灾检测、自动门、自动水龙头、自动电梯、自动照明等场合,及非接触温度测量等领域应用最广泛的传感器。其原因为:①被测对象自身发射红外线,可不必另设光源;②大气对2-2.61Lm,3-51Lm, 8-141Lm三个被称为“大气窗口”的特定光通量的红外线吸收甚少,可非常容易被检测;③中、远红外线不受可见光影响,可不分昼夜进行检测。人体存在传感器的热释电红外探头的工作原理及特性如下:人体都有恒定的体温,一般在37度,所以会发出特定波长10M 左右的红外线,

11

被动式红外探头就靠探测人体发射的10M左右的红外线而进行工作的。人体发射的10M左右的红外线通过菲泥尔滤光片增强后聚集到红外感应源上。红外感应源采用热释电元件,这种元件在接收到人体红外辐射温度发生变化时就会失去电荷平衡,向外释放电荷,后续电路经检测处理后就能产生由人体存在的信号。 1)这种探头是以探测人体辐射为目标的,所以热释电元件对波长为10M左右的红外辐射非常敏感。

2)为了仅仅对人体的红外辐射敏感,在它的辐射照面覆盖有特殊的菲泥尔滤光片,使环境的干扰受到明显的抑制作用。

3)人体存在的探测,其传感器包含两个互相串联的热释电元,而且制成的两个电极化方向正好相反,环境背景辐射对两个热释元件几乎具有相同的作用,使其产生释电效应相互抵消,于是探测器无信号输出。

4)一旦有人进入探测区域内,人体红外辐射通过部分镜面聚焦,并被人体存在传感器的热释电元接收,但是两片热释电元接收到的热量不同,热释电也不同,不能抵消,经信号处理而输出有人体存在的信号。

5)菲泥尔滤光片根据性能要求不同,具有不同的焦距(感应距离),从而产生不同的监控视场,视场越多,控制越严密。

人体传感器透镜的信号采集敏感区示意图如图4. 2. 2-1

图4. 2. 2-1信号采集敏感区示意图

有人进入时,移动人体发出的红外线被红外传感器接收,则人体存在被感应,并输出高电平。若人体进入最不敏感移动方向时,则人体传感器所体现的信号就

12

会不理想,有时还会产生误动作,所以要特别注意人体传感器的安装方向。 3.人体存在信号采集电路

人体传感器HP-208是深圳市浩博特电子有限公司研发和生产的基于红外线 术的智能产品,它的主要特性如下:

(1)感应为全自动方式,人进入感应范围时输出高电平(高3.3V),人离开应范围则自动延时关闭高电平,输出低电平(低0.3V),其高低电平利于采集; (2)采用可重复触发方式。即感应输出高电平后,在延时时间段内,如果二人体在其感应范围活动,其输出将一直保持高电平,直到人离开后才延时8,15秒后将高电平变为低电平;

(3)人体传感器工作电压宽为DC3V-DC24V;

(4)人体传感器制作成锥面形状,感应范围大,小于140度锥角,感应距了为7米以内;

(5)其静态电流小于50微安,功耗低;

(6)工作温度介于-15度和+70度之间,适应性强; (7)灵敏度高,可靠性强。

人体传感器HP-208型号的正视图如图3.2.4.2-1所示:

图3.2.4.2-2

人体传感器的1号引脚为电源信号端,3号引脚为地信号端,2号引脚为采集信号输出端。在电路设计中,为了使人体传感器的工作更加可靠,介于人体传感器的信号引脚2与地信号引脚3之间加一个6800pF的电容,另外人体存在传感器的信号引脚2与单片机的P3.3引脚相连,P3.3引脚再接一个100K的上

13

拉电阻,增加人体存在传感器输出信号的可靠性,其电路原理图如图3. 2. 4. 2-3

图3.2.4.2-3 HP-208传感器电路原理图

3.2.5系统时钟电路

根据教室灯光使用特性,该系统还应受到时间的控制,控制系统的时间应符合学校的作息时间。比如晚间休息、假期等时间段应该关掉教室灯光控制系统,以节约能源,因此本研究还加入硬件时钟电路以保证系统的智能化运行。 1.硬件时钟芯片的选取及其接口电路

传统的时钟芯片,如MC146818, MC68H68T, LM8365等,这些芯片的引脚太多,体积大,占用的口线多。而现在流行的串行时钟芯片很多,如DS1302,DS1305,DS1307,PCF8485等,这些电路的接口简单、价格低廉、使用方便,被广泛的使用。考虑到本系统停电时只需对时钟电路提供电源、且不需要占用太多单片机资源,本系统采用美国DALLAS公司推出的具有充电能力的低功耗1*8的用于临时性存放数据的RAM寄存器的实时时钟芯片DS1302。

此芯片采用的是串行通信方式,还可为掉电保护电源提供可编程的充电功能,并且可以关闭充电功能。它可以对年、月、日、周日、时、分、秒进行计时,具有闰年补偿功能,工作电压为2.5V-5. 5V, DS1302是DS1202的升级产品,与DS1202兼容,但增加了主电源、后背电源双电源引脚,同时提供了对后背电源进行涓细电流充电的能力。而且本系统采用的DS1302只需三根线即可与单片机进行通信,体积小,使用简单,时钟精度较高,满足系统的要求,其主要特征见附录一。可为掉电保护电源提供可编程的充电功能的时钟芯片DS1302的引脚图如图1所示。

14

图1 DS1302引脚

DS1302与单片机接口电路连接原理图如图3.2.5其中Vcc2外接3.6V可充电的铿电池,为DS1302的备用电源。Vcc1外接系统供电模块的输出稳定电压+5V,为DS1302的主电源。DS1302由Vcc1和Vcc2两者中较大者供电。系统正常运行时,Vcc1大于Vcc2,因此由Vcc1给DS1302供电,在主电源关闭的情况下,则由Vcc2给DS1302供电,保持时钟的连续运行。Xl和X2是振荡源,外接32. 768kHz晶振。RST是复位/片选线,通过把RST输入驱动置高电平来启动所有的数据传送,与单片机的复位信号相连。时钟输入端SCLK接单片机P1.5引脚,进行时钟控制。数据输入/输出端I/0接单片机P1.6引脚,进行数据传输。

图3.2.5DS1302与单片机接口电路连接原理图

2.硬件时钟芯片的引脚功能及其工作原理

RST是复位/片选线,通过把RST输入驱动置高电平来启动所有的数据传送。RST输入有两种功能:首先,RST接通控制逻辑,允许地址/命令序列送入移位寄存器; 其次,RST提供终止单字节或多字节数据的传送手段。当RST为高电平时,

15

所有的数据传送被初始化,允许对DS1302进行操作。如果在传送过程中RST置为低电平,则会终止此次数据传送,I/0引脚变为高阻态。上电运行时,在Vcc>2. 5V之前,RST必须保持低电平。只有在SCLK为低电平时,才能将RST置为高电平。I/0为串行数据输入输出端(双向),后面有详细说明。SCLK始终是输入端。 硬件时钟芯片DS1302与微处理器进行数据交换时,首先由微处理器向电路发送命令字节,命令字节最高位MSB (D7)必须为逻辑1,如果D7=0,则禁止写DS1302,即写保护:D6=0,指定时钟数据,D6=1,指定RAM数据;D5~D1指定输入或输出的特定寄存器;最低位LSB (DO)为逻辑0,指定写操作(输入),DO=1,指定读操作(输出)。

在DS1302的时钟日历或RAM进行数据传送时,DS1302必须首先发送命令字节。若进行单字节传送,8位命令字节传送结束之后,在下2个SCLK周期的上升沿输入数据字节,或在下8个SCLK周期的下降沿输出数据字节。

DS1302与RAM相关的寄存器分为两类:一类是单个RAM单元,共31个,每个单元组态为一个8位的字节,其命令控制字为COH~FDH,其中奇数为读操作,偶数为写操作;再一类为突发方式下的RAM寄存器,在此方式下可一次性读、写所有的RAM的31个字节。

要特别说明的是备用电源,可以用电池或者超级电容器((0.1F以上)。虽然DS1302在主电源掉电后的耗电很小,但是,如果要长时一间保证时钟正常,最好选用小型充电电池。可以用老式电脑主板上的3. 6V充电电池。如果断电时间较短(几小时或几天)时,就可以用漏电较小的普通电解电容器代替。100F就可以保证1小时的正常走时。DS1302在第一次加电后,必须进行初始化操作。初始化后就可以按正常方法调整时间。 3.2.6系统看门狗电路

在单片机工炸过一程中,不可避免的会由于外界的干扰而产生程序跑飞、死机甚至造成整机瘫痪等情况,为了能够恢复单片机的工作,只能采用重新复位的方法,虽然在程序设计中,一可以使用软件陷阱的方法来减少这种情沉的发生,但是不能完全解决这个问题,因此还应该在硬件设计中使用看门狗电路,这样在单片机发生死机的情况下,看门狗将产生一个夏位信号给单片机,使单片机复位重新执行程序:.现在的MCU被集成了越来越多的功能,有的集成了看门狗,如工

16

IMP813L。还有的芯片更是把EEPROM也集成进去,如X5045芯片。由于系统需要看门狗和EEPROM,所以本硬件设计中使用了美国Xicor公司生产的芯片X5045。

X5045具有三种常用的功能:看门狗定时器、复位控制和EEPROM集成在单个8个引脚封装的CMOS器件内,将电源监控和看门狗功能与高速三线非易失性存储器组合庄一起,从而在很人程度上降低了系统成本并减少了对电路板空间的要求,X5045的引脚排列如图3.2.6-1

图 3.2.6-1X5045的引脚排列

看门狗定时器的预置时间是通过X5045的状态寄存器的相应位来设定的。如表3. 2. 6状态寄存器所示,X5045状态寄存器共有6位有含义。其中WD l , WDO和看门狗电路有关,其余位和EEPROVI的工作设置有关。

表3. 2. 6状态寄存器

D7 X D6 X D5 WD1 D4 WD0 D3 BL1 D2 BL0 D! WEL D0 WIP WD1=0,WD0=0,预置时间为1.4S。 WD1=0,WD0=1,预置时间为0.6S。 WD1=1,WD0=0,预置时间为0.2S。 WD1=1,WD0=1,禁止看门狗工作。

看门狗电路的定时时间长短可山具体应用程序的循环屁期决定,通常比系统正常工作时最大循环周期的时间略长即可。本系统中X5045的硬件连接图如图3.2.6-2所示。

17

3.6.2-2 X5045的硬件连接图

系统数据存储及故障保护部分由X5045组成,X5045是一种串行通讯的512字节EEPROM,同时兼有看门狗和电源监控功能,X5045有三种可编程看门狗周期,上电和VCC低于检测门限时,输出复位信号,X5045输出复位高电平有效,为了复位更加可靠,其复位输出端外接一个10K的上拉电阻,并与ATC52的复位端相连。看门狗能在电源上电、掉电期间产生一个复位信号。该芯片还带有一个1. 4秒的看门狗定时器可监控单片机的工作。如果在1. 4秒内未检测到其工作,出现故障,内部定时器将使看门狗WD I处于低电平状态,为系统提供保护,避免死机、程序跑飞或进入死循环等意外的发生。

X5045代表了新一代串行EEPROM的发展趋势,它的运用极大的节省了系统空间和资源,同时简化了电路设计,缩短产品开发周期。 3.2.7继电器驱动接口电路

继电器驱动接口电路如图3.2.7所示,这里继电器由相应的PNP型号的59012三极管来驱动,开机时,单片机初始化后的P3. 5/P3. 6为高电平,三极管截止,所以开机后继电器始终处于释放状态,如果P3. 5/P3. 6为低电平,三极管的基极就会被拉低而产生足够的基极电流,使三极管导通,继电器就会得电吸合,从而驱动负载,点亮相应电灯。继电器的输出端并联100欧的电阻和6800皮法电容,目的是避免继电器吸合与释放期间产生火花。每个继电器都有一对常开常闭

18

的触点,便于在其他电路中使用,继电器线圈两端反相并联的二极管是起到吸收反向电动势的功能,保护相应的驱动三极管,这种继电器驱动方式硬件结构比较简单。

图3.2.7继电器驱动电路图

3.2.8 超时报警电路

在教室中,若采用手动方式控制时,一方面由于学生及管理人员的疏忽,教室里没有人而灯还亮着,导致教室灯工作超时,能源浪费,于是本系统采用超时报警电路,以声音的方式来提醒管理人员是否关闭电源。另一方面由于学生学习紧张,在夜里忘了时间点,学习期间开灯时间过长,致使教室灯工作超时,于是本系统超时报警电路就会发出声音,提醒学生应该休息或必需改用遥控器手动方式来控制灯了。这样,还可以更好地保护公共设施。本系统采用超时报警的电路如图3.2.9的P3.4端口外加一个10K的上拉电阻,再经过限流电阻100欧与三极管C945的基极相连。当P3.4端口为低电平,即基极为低电平时,三极管导通,驱动蜂鸣器发出声音,以示教室灯工作超时。若P3. 4端口为高电平,即基极为高电平时,三极管截止,蜂鸣器不工作,教室灯工作正常。本系统采用超时报警电路方便了管理人员对教室的管理,能够更好地、及时地管理教室。

19

图 3.2.9 超时报警的电路

20

21

22

附录一 部分元器件特性介绍

一、单片机ATS52

AT系列单片机是由美国ATMEL公司将闪速存储器与MCS-51控制器相

结合开发

生产的一种新型8位单片机,它不但具有一般MCS-51单片机的所有特性,而且还拥

有一些独特的优点,使8位单片机更具生命力。 它具有以下主要特性: (1)与MCS-51系列单片机兼容

(2) 8K Bytes, Flash存储器,在线编程,可写1000次 ( 3) 4. 0-5. 5V的工作电压 (4)自带256X8bit RAM (5) 32个可编程I/0管脚 (6) 3个16-Bit定时器/计数器 (7) 8个中断源 (8)自带看门狗

二、时钟芯片DS1302

DS1302特征:

(1)实时时钟,可以对秒、分、时、周、日、月、年以及带闰年补偿的年进行计数;

(2)与T'I'L兼容(V}}=5V )、 (3)2. 0-5. 5V的宽电压范围 (4具有主从双电源方式,从电源为 (5 8个中断源 (6)自带看门狗

三、看门狗芯片X5045X5045引脚功能如下:

23

CS: 选输入;

SO: 行输出,数据由此引脚逐位输出;

SI: 行输入,数据或命令由此引脚逐位写入X5045;

SCK 串行时钟输入,其上升沿将数据或命令写入,下降沿将数据输出; WP: 保护输入,当它低电平时,写操作被禁止; Vss: 地 Vcc: 源电压 RESET: 位输出

X5045在读写操作之前,需要先向它发出指令,指令名及指令格式如表1所示。

表1 X5045指令及其含义 指令名 WREN WRDI RDSR WRSR READ WRITE

24

指令格式 00000110 00000100 00000101 00000001 0000A801 0000A801 操作 设置写使能锁存器(允许写操作) 复位写使能锁存器(禁止写操作) 读状态寄存器 写状态寄存器 把开始于所选地址的寄存器中的数据读出 把数据写入开始于所选地址的寄存器

附录二

DP-Ethernet: the Profibus DP protocol implemented on

Ethernet

S. Vitturi

National Research Council, ISIB-CNR, Corso Stati Uniti 4, I-35127 Padova, Italy Received 7 January 2002; revised 27 September 2002; accepted 10 October 2002

Abstract

The use of Ethernet networks at the low level of factory automation systems, which is even more frequent, requires the adoption of real time protocols to implement the typical functions of this level.This paper investigates the possibility of using of a very popular fieldbus protocol, Profibus DP, as a real time protocol for Ethernet. The proposal, named DP-Ethernet, makes use of the IEEE 802.2 Logical Link Control to implement the Profibus DP functions on Ethernet. The paper shows how DP-Ethernet could be implemented maintaining the compatibility with already existing Profibus DP applications. Moreover, some DP-Ethernet performance figures, obtained with a software simulation package, are given. q 2002 Elsevier Science B.V. All rights reserved.

Keywords: Ethernet; Profibus DP; Real time; Protocol

1.Introduction

Communication networks currently have a widespread use at all hierarchical levels of factory automation systems. Unfortunately, the lack of a well clear standardisation process together with the continuously changing communication requirements have led to the necessity of using an heterogeneous variety of networks and protocols. As a result, several types of networks, such as for example fieldbuses, Local Area Networks (LANs) and Wide Area Networks (WANs), are commonly encountered in factory automation systems. This scenario, at the highest hierarchical levels, is rapidly converging towards a de facto standardisation, because, thanks to the impressive growth of the Internet, some very popular protocols such as for example FTP, HTTP, based on the TCP/IP suite are even more adopted also in industrial applications. These protocols are usually implemented on Ethernet networks whose physical extension is limited to that of the plant under

25

control: the resulting networks are normally referred to as Intranets.

Conversely, the situation is particularly critical at the lowest level of factory automation systems, called ‘device level’, where fieldbuses are typically used. In this area there has been a proliferation of proprietary products, which are incompatible among each other. At present, many of these products have been included in some international standards such as for example IEC 61158, EN 50170 and EN50254. However, although some considerable efforts to reach a form of harmonisation (e.g. the NOHA ESPRIT project), they are still incompatible. An interesting tendency originated recently is represented by the possibility of using Ethernet networks also at the device level of factory automation systems. The advantages of such a solution are indubitable, among them: a very easy integration with the higher levels, the big availability of hardware components, the possibility of accessing the device level through the Internet/Intranet. The use of Ethernet networks at the device level requires suitable real time protocols to implement the typical functions performed at this level. Unfortunately, at present a protocol of this type worldwide recognized as ‘the standard’ is not available. Also in this case, however, some proprietary products are already on the market, and there is the concrete risk of assisting to a new ‘fieldbus war’.

For this purpose it is worth mentioning that the IAONA organization encourages the growth of open networking in factory automation systems and the adoption of Ethernet at all levels. IAONA, in particular has the objective of harmonising the different protocols available for Ethernet and to prevent further incompatibilities.This paper investigates the possibility of adopting a very popular fieldbus protocol, Profibus DP, as a real time protocol for Ethernet networks employed at the device level. In practice, the paper proposes of implementing an Ethernet network with the Profibus DP protocol placed on top of its data link layer. As it will be shown, this solution, which for commodity will be later on referred to as DP-Ethernet, may be realized in a simple way. Moreover, as in this case the interface to the user applications does not change, DP-Ethernet could replace Profibus DP in any already established application. In detail, the structure of the paper is the following: Section2 reports the main features of Profibus DP.

Particular attention will be given to the functions available to the user applications and to their mapping onto data link layer services. Section 3 illustrates the features of Ethernet and of the Logical Link Control (LLC) protocol, which are extensively used by DP-Ethernet. Section 4

26

describes how DP-Ethernet may be implemented. Section 5 takes into consideration some typical configurations of DP-Ethernet and evaluates their performances using a suitable software simulation package.

2. Profibus DP

Profibus DP is a protocol designed to perform cyclic high speed data exchange between process controllers and field devices, such as sensors and actuators, in a master-slave configuration.

The first version of the Profibus DP standard was issued in 1994. Subsequently it was included in the European Standard EN50170. In 1997 an extension, named DPV1, added acyclic functionalities to this fieldbus and, finally, at the beginning of 2000, a completely revised version of Profibus DP became part of the IEC 61158 international fieldbus standard. The communication profile of Profibus DP is shown in Fig. 1. As can be seen, some of the ISO/OSI layers are empty, and the Profibus DP protocol is placed on top of the data link layer, named Fieldbus Data Link, FDL. The access to the physical medium realized by FDL is based on a technique very similar to that specified by the IEEE 802.4 standard, token bus. The token is circulated among active stations which form a logical ring, but also passive stations can be connected to the network: as they do not receive the token, they can only answer to specific requests coming from an active station. An important parameter, the target token rotation time, TTR, is set in all the stations during the network configuration phase and represents the maximum time requested by a complete token circulation in the logical ring.

When receiving the token, a station computes the maximum time it can be used (token holding time, TTH) as the difference between TTR and the actual duration of the last token rotation (real token rotation time, TRR). The FDL protocol specifies two possible priorities for the Protocol Data Units (PDUs), transmitted on the network: high and low. The Profibus DP protocol defines three possible types of devices that can be present on the network: Class 1 masters, which are typically control devices, such as for example PLCs, CNCs, PCs. Class 2 masters, used for network configuration and administration tasks. Slaves, which are input–output devices employed to realise the interface with the plant. Because the use of class 2 masters have no relevance for the aim of this paper, in the following the term masters will

27

be used to indicate uniquely class 1 master devices. Although the Profibus DP standard allows for the realisation of network configurations with more than one master device (multimaster), most of the already existing applications are based on monomaster network configurations. As can be seen in Fig. 1, Profibus DP has two major components: the User Interface and the Direct Data Link Mapper which are present, with different functions, both in master and slave stations. The User Interface of a master has basically the task of handling the slaves assigned to it. This is accomplished by using a set of User Interface functions, made available from the DDLM, which are shortly illustrated in the following. After power on, a slave waits for its initialisation from a master: this is realised by means of two functions, named DDLM_set_prm (set parameters) and DDLM_chk_cfg (check configuration). At the end of a successful initialisation, the slave enters the data exchange phase, during which it cyclically exchanges input–output data with the master by means of the DDLM_data_exchange function. In this phase a slave, when polled, may signal the presence of a diagnostic message.

As a consequence, the master, at the end of the current polling cycle, is forced to read the slave diagnostic with the DDLM_slave_diag function. Moreover, during the data exchange phase, a master can send some Fig. 1. Profibus DP communication profile. global control commands to the slaves in order to synchronise the acquisition of the inputs and/or the sending of the outputs: to this purpose the DDLM_global_control function is used. This function can address either a single slave or a group of slaves. The DDLM has also the task of mapping the User Interface functions onto FDL services. For this purpose it uses two different services available from the Profibus data link layer, namely the Send and Request Data with Reply, SRD, and the Send Data with No Acknowledge, SDN. SRD is a connectionless confirmed service by means of which a source station can send up to 246 data octets to a destination station.

This latter is requested to acknowledge the correct reception of the data. In the response frame the destination station can include, if previously prepared, a maximum of 246 data octets to send back to the source. SDN is a connectionless unconfirmed service used to send up to 246 data octets to either a single station or a group of stations. In this case, the destinations do not send back the acknowledgments of the correct reception, but the source station generates a local confirm meaning that the data have been correctly submitted to FDL. The DDLM uses the SDN service to implement the DDLM_global_control function and the SRD service to implement all

28

the other functions. SDN is necessary because it is the only FDL service which can address a group of stations, as necessitated by the global control. In order to specify the different User Interface functions, the DDLM makes use of the Service Access Points, SAPs, which are present in the PDUs of FDL. Thus, for example, a DDLM_slave_diag request is implemented by a SRD request where the source SAP #62 and the destination SAP #60 are specified. Whereas, the DDLM_set_prm function is implemented specifying the source SAP #62 and the destination SAP #61. As an example, Fig. 2 shows the sequence of the primitives necessary to realize the DDLM_chk_cfg function (destination SAP source SAP 62).

3. The data link layer

The data link layer of Ethernet The IEEE 802 committee, which issued the LAN standards, has split the data link layer of a LAN into two sublayers: the LLC and the Medium Access Control (MAC).

The LLC represents the common interface for all the LANs towards the upper layers, while the MAC specifies the protocols to access the physical medium. In practice, the IEEE 802 committee defines different LANs types characterised by differentMAC protocols, all of them using LLC on top. For Ethernet, the MAC has been standardised by the IEEE 802.3 subcommittee and uses a technique to access the physical medium known as Carrier Sense, Multiple Access with Collision Detection (CSMA/CD).3.1. Logical Link ControlLLC provides three types of service: unacknowledged connectionless service, connection-mode service and acknowledged connectionless service. As DP-Ethernet makes use of both types of the connectionless service they will be shortly illustrated in the following. The unacknowledged connectionless service, named DLUNITDATA allows for the transmission of a set of data octets from one LLC user to either a single or a group of remote LLC users.

With this service, every transmission is independent of others, and the sending user does not receive the confirm of the reception of the data from the destination.With the acknowledged connectionless service one LLC user can send a set of data octets to another and obtain the confirm of the correct reception of the data. Actually, two different services are available: that used by DP-Ethernet is called DL-REPLY and foresees a mechanism of bilateral data exchange. In practice, the destination user which receives the data with the DL-REPLY service may send

29

back to the source, together with the confirm of the reception, a set of data octets, if these latter were previously prepared with the DL-REPLAY-UPDATE service. The PDU of LLC is shown in Fig. 3. The field Control, when the PDU is used for connectionless services, is limited to one octet. In detail, for the DLUNITDATA service, the PDU carrying the data transmitted after the issuing of a request primitive is called Unnumbered Information, UI. For the DL-REPLY service, the PDUs involved are AC0 or AC1. After a request primitive either AC0 or AC1 is transmitted. The remote user will respond with a PDU of the same type and with the complementary number (i.e. when AC0 is transmitted, AC1 must be received and vice versa). 3.2. The IEEE 802.3 CSMA/CD

The CSMA/CD technique specifies that every station continuously senses the network and acquires the frames directed to itself. A station wishing to transmit simply verifies if the network is idle and then sends the message. Obviously, there is the possibility of having a collision between two or more frames transmitted contemporaneously. In this case the stations involved have to retransmit their frames after a random time calculated according to a rule known as the truncated binary back off exponential algorithm.

This time is expressed as a multiple, R, of a network parameter called slot time, tSL. R is randomly chosen in the interval 0–2k, where k is the minimum between 10 and the number of attempts to retransmit the frame. After a user-defined number of attempts without success, the MAC reports an error to the LLC. The occurrence of collisions makes the behaviour of Ethernet networks non deterministic. This is the principal reason for what Ethernet, in the past, was not considered suitable for real time applications, such those requested at the device level of factory automation systems.

However, the situation is significantly changing because, with the introduction of switches, collisions can be practically eliminated. An Ethernet switch is an ‘intelligent’ device equipped with a number of ports to which either the network segments or the single stations can be connected. The peculiarity of a switch is the ability of addressing frames only towards their destinations. As a consequence, with these devices, many transmissions can take place simultaneously without colliding, contrarily to what happens in the ‘traditional’ networks called shared Ethernet implementations. If a switch is used, the only possibility of having a collision is verified when two or more stations transmit contemporaneously towards the same station. Also in

30

this case, however, the collision can be avoided by means of a buffering functionality, which is implemented in many switches. Another important advantage of Ethernet is the high transmission speeds: from the initial speed of 10 Mbit/s it is now possible to 、 implement networks operating at 100 Mbit/s and 1 Gbit/s. The PDU of the IEEE 802.3

MAC is shown in Fig. 4. The PDU has a minimum length of 512 bits, necessary to ensure the correct operation of the collision detection technique. For this reason the field ‘Pad’ might be filled with the necessary number of octets. The minimum length is computed starting from the ‘Destination address’ field, hence the size of the shortest frame is 576 bits.

31

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务