基于单片机的粮仓温湿度控制系统设计 - 图文

更新时间:2024-04-13 20:42:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

题 目 基于单片机的粮仓温湿度控制系统设计 学生姓名 张大陆 学号 1213014089 所在学院 物理与电信工程学院 专业班级 电子信息工程专业12级3班 指导教师 帅春江 完成地点 陕西理工学院

2016年6月5日

陕西理工学院毕业设计

基于单片机的粮仓温湿度控制系统设计

作者:张大陆

(陕西理工学院 物理与电信工程学院 电子信息工程专业12级3班,陕西 汉中 723001)

指导老师:帅春江

[摘要] 影响粮食安全储存的主要参数是粮仓的温度和湿度,粮仓温湿度测量方法以及相应的智能控制一直是粮食储存的一个重要问题。本设计采用STC89C52单片机最小系统对检测、报警、显示、调控等模块进行多点控制,

传统的温湿度控制利用温度计、湿度表、湿度试纸等测试器材,通过人工进行检测,对不符合温湿度要求的库房进行通风、降温、去湿等操作。这种方法费时费力,效率低,随机性大,误差大,不能及时的解决问题。本设计则通过自动检测、即时报警、自动调控等功能很好的解决了。并且,本设计不仅针对粮仓,对于大多譬如蔬菜大棚、花圃、实验室、医院等需要温湿度检测控制的各个领域都是适用的。

[关键词] 粮仓;温湿度;多点检测控制;单片机

陕西理工学院毕业设计

Design of temperature and humidity control system for granany based

on single chip microcomputer

Author:Dalu Zhang

(Grade 12, Class 3, Major electronic1s and information engineering, School of Physics and Electronic

Information Engineering, Shaanxi University of Technology, Hanzhong 723001, Shaanxi)

Tutor: Chunjiang Shuai

Abstract: Grain is a necessity for human , the grain storage is very essential to the maintenance of social stability

and keep the economy sustainable developmented. And the main parameters to the grain safe storage is the temperature and humidity . This design uses the STC89C52 system of single chip microcomputer to cotrol the modules about the detection , alarm , control and the key . And it could automatic measurement and control without people , and improve effciency and quality of work very well . DHT11 temperature and humidity sensors and OLED display shows real time data and pass to the staff with instant and accurate . While the traditional temperature and humidity control is use of Thermometer , humidity table , humidity dipstick test equipment . Through the artificial testing . Not in conformity with the requirements of the temperature and humidity supply cooling , ventilation , to wet operation . This artificial testing time-consuming , the efficiency is low . This design is by automatic detection , instant alarm , automatic regulation of functions such as a good solution to these problems . At last , this design not only against the granary , but also for most such as vegetable greenhouses , flowers garden , laboratories , hospitals could also be applicabled .

Keywords: Granary; automatic detection and control ;temperature and humidity ;Singlechip

陕西理工学院毕业设计

目录

1引言 ..................................................... 1

1.1 背景及意义 .............................................. 1 1.2现状及发展趋势 .......................................... 1 1.3研究内容 ................................................ 1 2系统总体方案设计 ......................................... 2 2.1设计要求 ................................................ 2 2.2系统基本方案 ............................................ 2 2.2.1传感器方案 ........................................ 2 2.2.2显示器方案 ........................................ 2 2.2.3单片机主芯片方案 .................................. 2 2.3总体设计框图 ............................................ 3 3系统硬件设计 ............................................. 4 3.1主控模块 ................................................ 4 3.1.1 STC89C52芯片 ..................................... 4 3.1.2 STC89C52芯片的管脚、引线与功能 ................... 4 3.1.3 主控模块电路原理图 ................................ 5 3.2温湿度检测模块 .......................................... 6 3.2.1 DHT11传感器简介 .................................. 6 3.2.2 DHT11传感器模块电路 .............................. 7 3.3显示模块 ................................................ 8 3.3.1 OLED显示屏简介 ................................... 8 3.4报警模块 ................................................ 9 3.4.1蜂鸣器介绍 ........................................ 9 3.4.2蜂鸣器工作原理 .................................... 9 3.5温湿度调控模块 .......................................... 9 3.5.1继电器 ............................................ 9 3.5.2 温湿度调控模块 ................................... 10 4系统软件设计 ............................................ 11 4.1主程序设计 ............................................. 11 4.2传感器模块设计 ......................................... 12 4.3 软件调试 ............................................... 12 5系统的安装与调试 ........................................ 14 6结论与展望 .............................................. 17 致谢 ..................................................... 18 参考文献 ................................................. 19 附录A英文文献 ........................................... 20 附录B中文译文 ........................................... 25 附录C系统原理图 ......................................... 28 附录D实物图 ............................................. 29 附录E元器件清单 ......................................... 30 附录F C语言程序 ......................................... 31

陕西理工学院毕业设计

1 引言

1.1 背景及意义

粮食储存是国家针对战争、饥荒和一些突发事件所做的预防准备,所以粮食的储存安全至关重要。目前,我国部分地区的各种大型粮仓都还存在不同程度的粮食变质问题。依据国家粮食保护法,必须定期检查粮仓各点的温湿度,以便及时采取相应的措施。但许多粮仓目前还是采取人工检测的方法,不仅使粮仓工作人员工作量增大,而且工作效率低,尤其是大型粮仓的温度检测任务如不能及时彻底完成,则有可能会造成粮食大面积变质。据有关资料统计,我国每年因粮食变质而损失的粮食达数亿斤,直接造成了巨大的经济损失。

影响粮食安全储藏的主要参数是粮仓的温度和湿度。粮食在正常储藏过程中,如果粮食受潮,就会导致发芽,新陈代谢加快并产生呼吸热,使粮食温度突然升高,引起粮食霉变,造成许多不可挽回的损失。为此,研究与设计以单片机为控制核心,基于数字温度和湿度传感器的自动检测系统,对粮库每个粮仓中各点位的温度及湿度的变化情况进行实时自动测试,一旦出现异常现象便于及时处理,对有效地提高事故的预见性和工作效率有着重要的实际推广价值和理论研究意义。 1.2 现状及发展趋势

早期粮情监测主要采用温湿度计测量法,根据经验放在粮仓的多个测温点,管理人员定期读数,确定粮仓温湿度的高、低,决定是否进行调控。这种方法对储粮有一定的作用,但由于温湿度计精度、人工读数时人为误差等因素影响,检测时不仅效率低,而且精度差,局部温湿度过高不易被及时发现,导致因局部粮食发霉变质引起大面积坏粮的情况时有发生。

近年来,随着单片机的日益成熟和计算机的广泛应用,粮食测控系统的准确性要求越来越高,寻找测控系统最好配置和最佳性价比成为当前的热门研究内容。外国在粮仓情况监测技术上已经达到了非常成熟的地步,在监测系统中广泛应用了高科技数字式传感器。这一种由半导体集成电路与微控制器等最新的技术为核心的传感器,在一个管心上集成了半导体温度监测芯和信号转换芯、接口芯片、储存芯片等,不仅完成检测外,还完成预设范围内的温度、报警功能。由于数字温度传感器直接传出数字信号,从而解决长距离传输的问题,在传输过程中的干扰和衰减而导致的精度降低等问题也会随之解决。影响粮仓温湿度检测技术的重要因素是传感器的技术的发展。 1.3研究内容

本设计使用STC89C52型单片机作为系统硬件核心,具有在线编程功能,且功耗低等特点。检测部分采用四组DHT11温湿度传感器,可以即时的反应粮仓内四个监控点的温度以及湿度的变化,并反馈给单片机,经过单片机处理后控制相应继电器工作完成诸如升温到特定的温度、降温到特定的温度,在湿度控制方面也是如此。

第 1 页 共 39 页

陕西理工学院毕业设计

2 系统总体方案设计

2.1 设计要求

(1)本设计给出粮仓温湿度控制系统的总体方案设想,智能项目,和设计结构规划。

(2)硬件设计:实现对粮仓温湿度采集、控制,以单片机为主的控制器,扩展必要的外部电路,设计制作一个控制系统。

(3)软件设计:各项功能的设计流程。 (4)发挥部分:多点分布式。 2.2 系统基本方案 2.2.1 传感器方案

方案一:选用DS18B20温度传感器作为温度检测模块。DS18B20是一线式数字温度传感器。具有独特的单线式接口方式。测量范围在—10℃~85℃,误差范围在-\\+0.5℃。最高精度可达0.0625℃。选用HS1101湿度传感器作为湿度检测模块,HS1101是电容式湿度传感器。可测量相对湿度范围在0%~100%RH。误差为-\\+2%RH。

方案二: 选用DHT11作为设计的温湿度检测模块。DHT11是一款集成型的数字温湿度一体传感器。

它应用专用的温湿度传感技术以及数字模块采集技术,具有很高的可靠性能与长期的稳定性。电阻式感湿元件和NTC测温元件是传感器的基本组成部分。因此该产品品质优良、响应速度快、抗干扰能力强、性价比极高。测量范围20%~90%RH,0℃~50℃。测温精度为-\\+2℃,测湿精度为-\\+5%RH。完全符合本次毕业设计的要求。

经上述分析,方案一虽然精度更精确。却稍显复杂。方案二即便不能实现方案一的高精度测量。却也能满足设计要求。且简便易行。可靠稳定。具有超高的性价比。故选择方案二。 2.2.2 显示器方案

方案一:采用12864 OLED屏。显示模块是128×64点阵的汉字图形型OLED显示模块,可显示汉字及图形,内置8192个中文汉字(16X16点阵)、128个字符(8X16点阵)及64X256点阵显示RAM(GDRAM),可与CPU直接接口。

方案二:采用HJ1602液晶显示屏。HJ1602A 是一种工业字符型液晶,能够同时显示16x02 即32个字符。(16列2行)。1602只能显示字母、数字和符号能显示16*2个字符,但寄存器不止32个,有一些显示效果,如字符一个个显示、字符从左到右或从右到左显示等等,显示效果简单。

总结:在编程使用方面,两者难度差异较小,OLED屏幕略复杂。但相比于1602液晶屏,OLED 12864所占用单片机管脚少,屏幕亮度高、显示更加清晰、并且显示的内容更多,能更形象具体的实现显示功能。

2.2.3 单片机主芯片方案

方案一:AT89C51是美国ATMEL公司生产的低电压,高性能CMOS型8位单片机,器件采用ATMEL公司的高密度、非易失性存储技术生产,兼容标准MCS-51指令系统,片内置通用8位中央处理器(CPU)和Flash存储单元,功能强大。其片内的4K程序存储器是FLASH工艺的,这种单片机对开发设备的要求很低,开发时间也大大缩短。写入单片机内的程序还可以进行加密,这又很好地保护我们的劳动成果。再者,AT89C51目前的售价比8031还低,市场供应也很充足。AT89C51可构成真正的单片机最小应用系统,缩小系统体积,增加系统的可靠性,降低系统的成本。只要程序长度小于4K,四

[1]

个I/O口全部提供给用户。可用5V电压编程,而且擦写时间仅需lOms。

方案二:STC89C52是STC公司生产的功耗低、性能高CMOS8位微控制器,具有 8K可编程Flash存储器。STC89C52使用的MCS-51内核,做了很大的提高使芯片具有传统的51单片机所不具备的功能。在芯片上,拥有8位CPU和可编程Flash,使得STC89C52为嵌入式控制系统提供灵活和有效的解决方案。具有以下的标准功能:8k字节Flash,512字节RAM,看门狗定时器,32位I/O 口线,内置4KB EEPROM,MAX810复位电路,3个16位定时器/计数器,2个外部中断,全双工串行口。另外STC89C52可降至0Hz静态逻辑操作 ,支持2种软件可选择节电模式。空闲模式下,CPU停止工作,允许RAM、定时器/计数器、串口、中断继续工作。断电保护模式下,RAM

第 2 页 共 39 页

陕西理工学院毕业设计

内容保存,并冻结振荡器,单片机工作停止,直到下一个中断或硬件复位。其最高的运作频率为35MHz,6T/12T可选[2]。下载程序方面直接串口就可以下载。STC89C51系列单片机的指令系统和AT89C51系列的完全兼容,但实际操作却比AT89C51系列有许多优点:

(1)AT89C51不带ISP下载,要用下载器才行,STC89C52可以用USB转串口下载,下载软件免费并且下载源充足。

(2)STC单片机执行指令的速度很快,大约是AT的3-30倍,只需在调试STC时注意加长延时,大约是AT的10—30倍。

(3)STC单片机对工作环境的要求比较低,电压低于5伏时仍然正常工作,甚至3伏到4伏之间都还可以工作,但这样的环境下AT则无法工作。

(4)STC单片机的EA\\VPP 端口默认为悬空高电平,无需添加VCC。

比较这两种方案,基于STC89C52单片机的使用相对简便,并且市面上STC单片机使用量大,货

[3]

源充足,故选择方案二作为主控模块核心。 2.3 总体设计框图

综上各方案所述:采用STC89C52作为主控制系统,12M晶振提供时钟信号,IIC通信OLED 12864显示屏作为显示部分,独立按键进行控制系统工作条件设定,蜂鸣器作为报警发声系统,如图2.1所示 湿度控制模温度控制模块 块 温湿度检测模 块(DHT11) STC89C52 主控模块 时钟模块 显示模块 (12M晶振) (OLED12864) 按键模块 报警模块 (蜂鸣器)

图 2.1 基于单片机的粮仓温湿度控制系统框图

第 3 页 共 39 页

陕西理工学院毕业设计

3 系统硬件设计

3.1 主控模块

3.1.1 STC89C52芯片

STC89C52是STC公司生产的功耗低、性能高CMOS8位微控制器,具有 8K可编程Flash存储器。STC89C52使用的MCS-51内核,做了很大的提高使芯片具有传统的51单片机不具备的功能[4]。STC89C52具有下列主要性能:

⑴ 增强型8051单片机,6 时钟机械周期和12 时钟机械周期可供选择,代码指令完兼容一般8051;

⑵ 工作电压:5.5V~3.3V(5V 单片机)/3.8V~2.0V(3V 单片机);

⑶ 频率的范围:0~40 MHz,相当于普通8051 的0~80 MHz,实际工作频率可达48 MHz ; ⑷ 应用程序写入空间为8K字节; ⑸ 片上集成512 字节RAM; ⑹ 通用I/O 口(32个),复位之后为:P0/P1/P2/P3 是准双向口/弱上拉, P0口是开路输出,当其为总线扩展用时,无需加上上拉电阻,而作为 I/O 口用时,需 加 上 拉 电 阻;

⑺ ISP/IAP,无 需 专 用 编 程 器,无 需 专 用 仿 真 器,可通过串口(RxD/P3.0,TxD/P3.1)直 接 下 载 用 户 程 序,数秒即可完成一片 ; ⑻ 具有EEPROM 功能 ; ⑼ 具 有 看 门 狗 功 能 ;

⑽ 共3个16位定时器。即定时器T0、T1、T2; ⑾ 外部中断2路,下 降 沿 中 断 或 低 电 平 触发,由低电平触发中断方式唤醒Power Down 模式; ⑿ 通 用 异 步 串 行 口(UART),还 可 用 定 时 器 软 件 实 现 多 个UART; ⒀ 工作温度范围:-40~+85℃(工业级)/0~75℃(商业级); ⒁ PDIP封装。

3.1.2 STC89C52芯片的管脚、引线与功能

(1)STC89C52管脚如图3.1所示。

图3.1 STC89C52单片机的管脚图

第 4 页 共 39 页

陕西理工学院毕业设计

(2)管脚功能

VCC:接+5V电源正端。 GND: 接+5V电源地端。

P0口:P0.0-P0.7统称为P0口,在不接片外存储器与不扩展I/O口时,可作为准双向I/O口。

[4]

在接有片外存储器或扩展I/O口时,P0口分时复用为低8位地址总线和双向数据总线。

P1口:P1口是一个8位的双向I/O口,其内部提供上拉电阻。P1口缓冲器能接受输出4TTL门电流。P1口管脚写入1时,被内部上拉为高,可用于输入,由于上拉电阻的缘故,P1口下拉为低电

[5]

平时,将输出电流。

P1.0和P1.1还有第二功能:P1.0可作为定时/计数器2的计数脉冲输入端T2;P1.1可作为定时/计数器2的外部控制端T2EX.

P2口:P2.0-P2.7统称为P2口,一般可作为准双向I/O口使用;在接有片外寄存器或扩展I/O 口且寻址范围超过256B时,P2口用作高8位地址总线。

P3口:P3.0-P3.7统称为P3口,是一个内部带上拉电阻的8位的双向I/O口。除作为准双向I/O口使用外,P3口还可具有第二功能,而且P3口的每一条引脚均可独立定义为第一功能的输入输

[6]

出或第二功能。

RST:复位输出引脚。若该引脚保持两个周期的高电平,则可以使C51处于初始化(复位)工作状态。

EA/VPP:片外存储器访问允许信号,低电平有效。在EA保持低电平期间,不管是否有内部程序存储器,外部程序存储器(0000H-FFFFH)工作,注意:加密位LB1被编程时,EA将内部锁定为RESET。在EA端保持高电平期间,内部的程序存储器工作。其第二功能VPP为对EPROM的编程电源输入。

ALE:地址锁存有效信号输出端。在访问片外程序存储器期间,ALE以每机器周期两次进行信号输出,其下降沿用于控制锁存P0输出的低8位地址;在不访问片外程序寄存器期间,ALE端仍以上诉频率出现,可作为对外输出的时钟脉冲或用于定时目的。但要注意,在访问片外数据寄存器期间,ALE脉冲会跳空一个,此时就不能作为时钟输出了。

PSEN:当该引脚为低电平时,片外程序存储器被选通。在片外程序存储器取指期间,每个机器周期PSEN两次有效,但在访问片外数据存储器时,两次有效的PSEN信号将不会出现。

XTAL1:反向震荡放大器的输入及内部时钟工作电路的输入( 当外接振荡器时,此引脚接振荡器的信号)。

[7]

XTAL2:反向振荡器的输出(当外接振荡器时,此引脚悬浮)。 P3口的第二功能如表3.1所示。

表3.1 P3端口的特殊功能

端口引脚 兼用功能

P3.0 RXD (串行口输入端) P3.1 TXD (串行口输出端)

P3.2 INT0 (外部中断0请求输入端,低电平有效) P3.3 INT1 (外部中断1请求输入端,低电平有效) P3.4 T0 (定时/计数器0计数脉冲输入端) P3.5 T1 (定时/计数器1计数脉冲输入端)

P3.6 WR (外部数据存储器写选通信号输出端,低电平有效) P3.7 RD (外部数据存储器读选通信号输出端,低电平有效)

3.1.3 主控模块电路原理图

单片机主程序模块通过对DHT11传感器采集到信号的读取,将得到的数据信号进行分析和处理,再将处理后的信号发送给1602液晶显示模块。完成信息的接收与发送。并且连接蜂鸣器。控制报警系统。如图3.2所示。

第 5 页 共 39 页

陕西理工学院毕业设计

图3.2 STC89C52模块电路原理图

3.2 温湿度检测模块

3.2.1 DHT11传感器简介

DHT11传感器是一种由可校准并且输出数字信号的温湿度传感器。它采用了数字式的模块采集和温湿度传感技术,具有非常高的可靠性与长期的使用稳定性。传感器由一个电阻式感湿元件和一

[8]

个NTC测温元件组成。因此该产品品质卓越、响应速度快、抗干扰能力强、性价比极高。每一个DHT11传感器都在非常严格的校验室中进行校验。校验系数则通过程序的方式存储在OTP内存中,在传感器的内部在检测和处理信号时需要调用这些校验系数。而其采用的单线制串行接口,则使系统集成快捷简单。体积小、功耗低,信号传输距离较长,使其成为各类应用场合的极佳选则。产品为 4 针单排引脚封装。连接方便,特殊封装形式可根据用户需求而提供。

DHT11传感器实物图如图3.3所示:

图3.3 DHT11传感器实物图

第 6 页 共 39 页

陕西理工学院毕业设计

(1)引脚介绍:

Pin1:(VDD),电源引脚,供电电压为3~5.5V。Pin2:(DATA),串行数据,单总线。 Pin3:(NC),空脚,请悬浮。Pin4(VDD),接地端,电源负极。 (2)接口说明 :

建议连接线长度短于20米时用5K上拉电阻,大于20米时根据实际情况使用合适的上拉电阻。 DHT11应用电路如图3.4所示。

图3.4 DHT11典型应用电路

(3)数据帧的描述:

DATA 用于单片机与 DHT11之间的同步和通信,采用单总线数据格式,每次通信时间为4ms左右,通信数据会分小数和整数部分。操作流程如下:

每一次完整的数据传输为40bit,先出高位。数据格式是8bit湿度整数数据和8bit湿度小数数据加上8bi温度整数数据和8bit温度小数数据,当数据传输正确时校验和的数据等于“8bit湿度整数数据+8bit湿度小数数据+8bi温度整数数据+8bit温度小数数据”得到结果的末8位。

例如:接受40bit数据如下:

0000 0010 1000 1100 0000 0001 0101 1111 1110 1110 湿度数据 温度数据 校验和

0000 0010 + 1000 1100 + 0000 0001 + 0101 1111 =1110 1110 湿度=65.2%RH 温度=35.1℃

当温度低于0℃时温度数据的最高位置1。 例如:-10.1℃表示为1000 0000 0110 0101

(4)电气特性:VDD=5V,T = 25℃,除非特殊标注。如表3.2所示。

表3.2 DHT11的电气特性 参数 供电 供电电流 采样周期

条件 DC 测量 平均 待机 秒

注:采样周期间隔不得低于1秒钟。

Min 3 0.5 0.2 100 1

Typ 5

max 5.5 2.5 1 150

单位 V mA mA uA 次

3.2.2 DHT11传感器模块电路

DHT11传感器连接STC89C51系列单片机相对比较简单。单片机的P2.0口用来发收串行数据,即数据口。连接传感器的Pin2(单总线,串行数据)。由于测量范围电路小于20米,建议加一个5K

第 7 页 共 39 页

陕西理工学院毕业设计

的上拉电阻,因此在传感器的Pin2口与电源之间连接一个5K电阻。而传感器的电源端口Pin1和Pin4分别接单片机的VDD和GND端。传感器的第三脚悬浮放置。DHT11传感器原件的电路图如图3.5所示:

图3.5 DHT11电路图

3.3显示模块

3.3.1 OLED显示屏简介

OLED是一种机发光二极管,它可以自发光,不需背光源,屏幕对比度高、厚度较薄、可视角度广、有很快的响应速度、使用环境温度范围较大。该屏有以下特点:

⑴ 0.96寸 OLED 有黄蓝,白,蓝三种颜色可选;其中黄蓝是屏上 1/4 部分为黄光,下 3/4 为蓝;而且是固定区域显示固定颜色,颜色和显示区域均不能修改;白光则为纯白,也就是黑底白字;蓝色则为纯蓝,也就是黑底蓝字。

⑵ 分辨率为 128*64

⑶ 多种接口方式;OLED 裸屏总共种接口包括:6800、8080 两种并行接口方式、3 线或 4 线的串行 SPI 接口方式、 IIC 接口方式(只需要 2 根线就可以控制 OLED ) ,这五种接口是通过屏上的 BS0~BS2 来配置的。

⑷两种接口的 Demo 板,接口分别为七针的 SPI/IIC 兼容模块,四针的IIC 模块。 如图3.6所示为IIC四针OLED屏幕

图 3.6 OLED屏正面、反面

第 8 页 共 39 页

陕西理工学院毕业设计

IIC OLED引脚说明如表3.3

表3.3 IIC OLED 12864 显示屏管脚说明

管脚名称 管脚说明 GND 电源地

VCC 电源正(3~5.5V)

SCL OLED 的 D0 脚,在 IIC 通信中为时钟管脚 SDA OLED 的 D1 脚,在 IIC 通信中为数据管脚

3.4报警模块 3.4.1蜂鸣器介绍

蜂鸣器是一体化结构的电子式讯响器。由直流电压供电,广泛应用于电话机、报警器、复印机、

[9]

计算机、打印机、汽车电子设备、定时器等产品中作发声器。 其主要分为电磁式蜂鸣器和压电式蜂鸣器两种类型。 3.4.2蜂鸣器工作原理

如图3.8所示为蜂鸣器工作原理图。

图3.8 蜂鸣器工作原理图

因为单片机的IO口驱动能力不够让蜂鸣器发出声音,所以我们通过三极管放大驱动电流,从而让蜂鸣器发出声音,如果程序控制单片机输出高电平,三极管导通,集电极电流通过蜂鸣器让蜂

[10]

鸣器发出声音;当输出低电平时,三极管截止,没有电流流过蜂鸣器,所以蜂鸣器不会发出声音。 3.5 温湿度调控模块 3.5.1继电器

电磁式继电器一般由铁芯、线圈、衔铁、触点等组成。本设计所用五角继电器为直流输入28-30V,最大输入电流为10A。如图为3.9为5角继电器实物图,图3.10为原理图。

图3.9 五角继电器实物图

第 9 页 共 39 页

陕西理工学院毕业设计

图3.10 五角继电器原理图

当4、5两端加上相应电压时,线圈就会有电流,产生电磁效应,衔铁将会在磁力吸引的作用下克服弹簧拉力吸向铁芯,而带动衔铁的动触点与2点吸合。当线圈断电后,电磁的吸力也随之消失,衔铁就会在弹簧的反作用力下返回3点,使1点与原来的3点吸合。这样吸合、释放从而达到开关

[11]

的目的。

3.5.2 温湿度调控模块

如图3.10位温湿度调控模块原理图

图3.10 温湿度调控模块原理图

当单片机IO口输出高电平时,通过三极管放大,集电极电流通过4、5点的电磁圈从而产生磁

场,会将1点的单刀双掷开关吸引到3点常开点上导通从而实现继电器的功能,外部用电器P1开始正常工作。当单片机IO口输出低电平时,三极管截止,4、5点的电磁圈没有电流经过不会产生磁场,1点开关由于自身弹性形变而弹回2点常闭点。

第 10 页 共 39 页

陕西理工学院毕业设计

4 系统软件设计

4.1主程序设计

在对本设计硬件部分做好认识后,需要建立程序框架的流程图,对整个设计划分软件模块,逐个模块实现其功能,最终把各个子模块合理的连接起来,构成总的程序。主程序首先要对整个系统进行初始化,然后将采集到的温湿度指令传给系统的主流程图如图4.1所示:

开始 初始化 延时 温湿度检测 显示屏显示 Y 温度高于上限 N 蜂鸣器报警 温度低于下限 对应继电器工作 N Y 蜂鸣器报警 对应继电器工作 Y 湿度高于上限 N 蜂鸣器报警 对应继电器工作 湿度低于下限 N Y

蜂鸣器报警 对应继电器工作 图 4.1 主程序流程图 第 11 页 共 39 页

陕西理工学院毕业设计

4.2 传感器模块设计

DHT11传感器模块的软件流程图如图4.2所示

给DHT11上电 延时1S 保持高电平 检测记录信号 输出低电平 延时 输出低电平 数据输出

图4.2 DHT11传感器模块程序流程图

4.3 软件调试

本设计是在Keil C环境下开发的,Keil C软件支持C语言的编程及调试,运用方便,是做C

[12]

语言单片机设计的首选。设计的首要任务是安装和学习使用这个软件,在简单的学习和了解Keil C后,便可在此环境下开始了对本设计所需软件程序进行设计工作。在编译完Keil C后,再运用

[13]

STC_ISP_V480软件烧录到开发板上,实现实物与程序的连接。

在烧录前要对STC_ISP_V480进行一些必要的设置。第一步:设置MCU Type为STC89C52RC;第二步:打开编写好并编译的程序文件,它是以.hex为后缀的文件;第三步:选择对应的COM端口,可在我的电脑的设备管理处查看COM选项;第四步:点击Download/下载,等提示请给MCU上电时,

[14]

打开开发板上的开关,它就自行烧录了。

Keil C程序运行如图4.3和4.4所示

第 12 页 共 39 页

陕西理工学院毕业设计

图4.3 keil C运行图

图4.4 程序烧录运行图

在完成对程序的调试及烧录之后,将烧洗好的单片机放入硬件电路板中进行软硬件组合调试。

第 13 页 共 39 页

陕西理工学院毕业设计

5 系统的安装与调试

5.1 硬件安装

硬件部分主要通过万用板电路焊接将各个部分拼接在一起,其组成有控制模块、报警模块、显示模块、按键模块、调控模块。

在焊接过程中,由于所用器件较多前期所设计的一块万用板已不能满足元器件排布,故选择加入了第二块万用板进行焊接工作。在焊接过程中由于使用导线过细,容易断裂导致整体线路接触不良,经常出现短路、断路等问题,所以在复查中大量更换了之前焊接使用的细线,换用较粗的漆包线作为导线,不仅使线路的稳定性得到了大大提升,较粗的导线也提供了一定的固定作用,使整体线路更加稳固。但由于布局的设计缺陷,本次设计所用的OLED 显示屏幕引脚过短,需加装一块排母才能与电路板连接,屏幕不能很好的固定,从而导致会出现接触不良的情况,但在加粗排母引脚后,该问题得到了较好的解决。由于本设计的功能需要多点检测,4组检测模块不能直接焊接在电路板上,所以采用杜邦线连接检测模块与电路板上的排针进行连接,从而解决了检测模块分开分布的问题。在焊接继电器电路时,元器件短缺,所需2K电阻缺失,在经过测试后决定使用双4K电阻并联接入电路达到了同样的效果,但缺点是占用了电路板空间。

如图5.1为硬件外观图

图5.1 硬件外观图

如图5.1中,按下A键可以进入温湿度设定界面,按下B键进行温度和湿度切换,C、D键分别为加和减。图中数字显示屏旁1、2、3、4为4个DHT11温湿度检测模块,图中与之标号相同的调控模块为其对应的监测点温湿度调控端。 5.2 组合调试

调试分为硬件调试和软件调试。硬件调试主要是检测硬件电路是否有短路、断路、虚焊等。显示电路、键盘电路、继电器调控电路是本次设计的主要硬件电路。在搭接实物之前要检查各器件的性能是否符合要求。如导线是否导通,器件是否性能完好等。还有通过编制一些小的调试程序分别对相应各硬件单元电路的功能进行检查。其次,进行软件的调试。先验证子程序的正确性,再将这

第 14 页 共 39 页

陕西理工学院毕业设计

些子程序连接起来进行整体的调试。逐渐的发现错误并改正错误。最后进行软硬件结合调试。检查硬件电路与软件编程是否匹配。在进行软硬件结合调试后发现诸多问题:

⑴在硬件检查中单片机最小系统的复位按键存在连焊情况导致按键被短路无法使用。

⑵主电路板电源模块由于双面板漏锡,电源模块被短路;继电器调控模块中,继电器出口端模拟用电器未加入电源电路,导致继电器工作后用电器不能正常工作。

重新调整电路后,以上问题得以解决。

在基础部件组合调试完成后,开始进行系统功能最终调试。在调试过程中发现,当检测数据超过预设上限数据,报警模块和调控模块开始工作,存在调控模块全部工作时主电路板会出现跳闸断电情况。在对硬件电路和程序过程进行多次检查与调整试验后发现,主电路板电源输入线由于过热导致输入VCC不稳定引起主电路板跳闸,在更换材质更好的电源连线后该问题得到解决。

经过组合调试后,系统可以按照设计功能正常工作,本设计安装调试结束。 如图5.2为系统正常工作时的屏幕显示状态

图5.2 正常工作的屏显状态

当温度超过设定值时,报警模块与调控模块开始工作,蜂鸣器报警,相应继电器工作,风扇工作模拟降温,并且红色二极管发光指示。如图5.3所示,1、2、3、4号检测端温度超限,对应风扇全部工作。

图5.3 温度控制工作 第 15 页 共 39 页

陕西理工学院毕业设计

当湿度超过设定值时,报警模块与调控模块开始工作,蜂鸣器报警,相应继电器工作,加热片工作模拟除湿,并且黄色二极管发光指示。如图5.4所示,1、2、3、4号检测端湿度超限,对应加热片全部工作。

图5.4湿度控制工作

当温湿度超过设定值时,报警模块与调控模块开始工作,蜂鸣器长鸣报警,相应继电器工作,风扇工作模拟降温,加热片工作模拟除湿,并且二极管发光指示。如图5.5所示。

图5.5 温湿度控制同时工作

第 16 页 共 39 页

陕西理工学院毕业设计

6 结论与展望

在经过了多次验证与调试后,本设计完成。

本系统以单片机为核心部件,利用软件编程,最终实现了设计要求。虽然系统还存在一些不足,比如温湿度测量不够精确,特别是湿度,波动误差较大。尝试了各种改进方法。仍然不太理想,不过能反映出设计的目的和要求,与预期的结果相差不多。

经过近两个月的奋斗,从确定题目,到后来查找资料,理论学习,实验编程调试,这一切都使我的理论知识和动手能力有了很大的提高。了解了单片机的硬件结构和软件编程方法,对单片机的工作方式有了很大的认知。同时,对一些外围设备比如传感器、显示屏、键盘、蜂鸣器、继电器等有了一定的了解。学会了对一项工程应该如何设计:首先,要分析需要设计的系统要实现什么功能,需要什么器件;然后,针对设计购买相应的硬件,选用硬件时不仅要选用经济的,更重要的是如何能更精确更方便的完成系统的要求;再次,对各个硬件的驱动软件实现要弄清楚,如何更好的实现各个硬件的协调,更好的通过主控制器件实现硬件的功能。最后,通过各种测试与调试,让设计更好的完成系统要求。

但由于水平有限,本次设计中也存在一定的不足。例如对湿度的控制方面,由于温度时刻都在发生着变化,而湿度的变化又大体上取决于温度。因而对于湿度的控制有点困难。同时由于湿度变化波动比较大,造成报警频繁,为湿度限值的设定也带来了不小的麻烦。

粮仓温湿度控制已经成为了21世纪热门研究话题之一。而智能化的控制温湿度已经发展成为一种必然。随着世界经济的发展,人们生活水平的提高以及社会的进步。我们不可能一直墨守陈规,不能在恪守以前利用人力资源来控制温湿度的方法。不仅浪费大量的人力资源、财力资源,并且控制系统也相对单一化。而采用自动控制的办法,既节省了人力资源,更体现了与时俱进的思想。世界在进步,而这种进步就该体现在各个方面。

第 17 页 共 39 页

陕西理工学院毕业设计

致 谢

毕业在即,为期两个多月的毕业设计过程中,我收获了许多,感悟了许多。

首先我非常感谢院领导对我们毕业生在毕业设计过程中的支持与帮助。其次我要特别感谢帅老师,不管在选题阶段,还是在设计阶段,在制作阶段,他都给予我很多的指导与帮助,老师既要忙于教学,而且科研任务重大,但仍然抽出时间,定期召集我们组的同学给与指导、督促,找到大家存在的问题并加以解决。帅老师给我们提供了丰富的学习资源和良好的学习环境,为我们的毕业设计带来了很大方便。在我完成毕业设计的过程中提供了很多指导性的意见,使我能明确完成自己的设计。帅老师为人严谨,对待问题要求严格,但也正是这样,才使我们这些毕业生有对待毕设的态度有了很大的转变。在此,我衷心感谢帅老师给予我的帮助和教育。最后我要感谢我的同学们,在编写和调试过程遇到困难时,正是由于同学们的帮助我才能顺利的克服困难,我毕业设计的完成离不开同学们的帮助,在此,我真诚地感谢他们。

总之,无论是从同学、老师还是到学校。本次毕业设计过程中我受到了很大的帮助和启发。没有你们,我的毕业设计就坚持不下来。感谢你们,有了你们,我受益匪浅。

第 18 页 共 39 页

陕西理工学院毕业设计

参考文献

[1] 陈明荧.8051单片机课程设计实训教材[M]. 北京:清华大学出版社,2003. [2] 徐新艳.单片机原理、应用与实践[M]. 北京:高等教育出版社,2005.

[3] 吴金戌,沈庆阳,郭庭吉.8051单片机实践与应用[M]. 北京:清华大学出版社,2002.. [4] 张毅刚.MCS-51单片机应用设计[M]. 哈尔滨工业大学出版社,2004 [5] 冯博琴.微型计算机原理与接口技术[M]. 北京:清华大学出版社,2004. [6] 张毅刚.MCS-51单片机应用设计[M]. 哈尔滨工业大学出版社,2004.

[7] 张淑清,姜万录等.单片微型计算机接口技术及应用[M]. 国防工业出版社,2003. [8] 吴金戌,沈庆阳,郭庭吉.8051单片机实践与应用[M]. 北京:清华大学出版社,2001. [9] 冯博琴.微型计算机原理与接口技术[M]. 清华大学出版社,2004..

[10] 王振红,李洋,郝承祥.ISD4004语音芯片的工作原理及其在智能控制系统中的应用[J]. 电子器件2002,25(1). [11] 王千.实用电子电路大全[M]. 电子工业出版社,2001

[12] 赵亮,侯国锐.单片机C语言编程与实例[M]. 北京:人民邮电出版社,2003.

[13] R.L.Geiger,P.E.Allen,N.R.Strader.VLSI.Design Techniques for Analog And Digitial Ciruits,McGraw-Hill Inc.1990. [14] ANALOG DEVICES.The technology of AT89C51[EB/OL].White Paper,Spe.28.2000.

[15] V.K. Gryzhov, V.G.Korol’kov,E.V.Gryzhov, A.D.Akshinsky.Flexible Converter of Analog Signal into Discrete Digital

One with the Example of Double Integration Voltmeter [J].Automation and Remote Control,2014,75(4).

第 19 页 共 39 页

陕西理工学院毕业设计

附录 A 英文文献

Temperature Control Using a Microcontroller:

An Interdisciplinary Undergraduate Engineering Design Project

James S. McDonald

Department of Engineering Science

Trinity University San Antonio, TX 78212

Abstract

This paper describes an interdisciplinary design project which was done under the author’s supervision by a group of four senior students in the Department of Engineering Science at Trinity University. The objective of the project was to develop a temperature control system for an air-filled chamber. The system was to allow entry of a desired chamber temperature in a prescribed range and to exhibit overshoot and steady-state temperature error of less than 1 degree Kelvin in the actual chamber temperature step response. The details of the design developed by this group of students, based on a Motorola MC68HC05 family microcontroller, are described. The pedagogical value of the problem is also discussed through a description of some of the key steps in the design process. It is shown that the solution requires broad knowledge drawn from several engineering disciplines including electrical, mechanical, and control systems engineering.

1 Introduction

The design project which is the subject of this paper originated from a real-world application. A prototype of a microscope slide dryer had been developed around an OmegaTM model CN-390

temperature controller, and the objective was to develop a custom temperature control system to replace the Omega system. The motivation was that a custom controller targeted specifically for the application should be able to achieve the same functionality at a much lower cost, as the Omega system is unnecessarily versatile and equipped to handle a wide variety of applications.

The mechanical layout of the slide dryer prototype is shown in Figure 1. The main element of the

dryer is a large, insulated, air-filled chamber in which microscope slides, each with a tissue sample encased in paraffin, can be set on caddies. In order that the paraffin maintain the proper consistency, the temperature in the slide chamber must be maintained at a desired (constant) temperature. A second chamber (the electronics enclosure) houses a resistive heater and the temperature controller, and a fan mounted on the end of the dryer blows air across the heater, carrying heat into the slide chamber. This design project was carried out during academic year 1996–97 by four students under the author’s

supervision as a Senior Design project in the Department of Engineering Science at Trinity University. The purpose of this paper is to describe the problem and the students’ solution in some detail, and to discuss some of the pedagogical opportunities offered by an interdisciplinary design project of this type. The students’ own report was presented at the 1997 National Conference on Undergraduate Research [1]. Section 2 gives a more detailed statement of the problem, including performance specifications, and

Section 3 describes the students’ design. Section 4 makes up the bulk of the paper, and discusses in some detail several aspects of the design process which offer unique pedagogical opportunities. Finally, Section 5 offers some conclusions.

2 Problem Statement

The basic idea of the project is to replace the relevant parts of the functionality of an Omega CN-390 temperature controller using a custom-designed system. The application dictates that temperature settings are usually kept constant for long periods of time, but it’s nonetheless important that step changes be tracked in a ―reasonable‖ manner. Thus the main requirements boil down to

·allowing a chamber temperature set-point to be entered,

第 20 页 共 39 页

陕西理工学院毕业设计

·displaying both set-point and actual temperatures, and ·tracking step changes in set-point temperature with acceptable rise time, steady-state error, and overshoot. Although not explicitly a part of the specifications in Table 1, it was clear that the customer desired digital displays of set-point and actual temperatures, and that set-point temperature entry should be digital as well (as opposed to, say, through a potentiometer setting).

3 System Design

The requirements for digital temperature displays and setpoint entry alone are enough to dictate that a microcontrollerbased design is likely the most appropriate. Figure 2 shows a block diagram of the students’ design.

The microcontroller, a MotorolaMC68HC705B16 (6805 for short), is the heart of the system. It

accepts inputs from a simple four-key keypad which allow specification of the set-point temperature, and it displays both set-point and measured chamber temperatures using two-digit seven-segment LED displays controlled by a display driver. All these inputs and outputs are accommodated by parallel ports on the 6805. Chamber temperature is sensed using a pre-calibrated thermistor and input via one of the 6805’s

analog-to-digital inputs. Finally, a pulse-width modulation (PWM) output on the 6805 is used to drive a relay which switches line power to the resistive heater off and on.

Figure 3 shows a more detailed schematic of the electronics and their interfacing to the 6805. The keypad, a Storm 3K041103, has four keys which are interfaced to pins PA0{ PA3 of Port A, configured as inputs. One key functions as a mode switch. Two modes are supported: set mode and run mode. In set mode two of the other keys are used to specify the set-point temperature: one increments it and one

decrements. The fourth key is unused at present. The LED displays are driven by a Harris Semiconductor ICM7212 display driver interfaced to pins PB0{PB6 of Port B, configured as outputs. The

temperature-sensing thermistor drives, through a voltage divider, pin AN0 (one of eight analog inputs). Finally, pin PLMA (one of two PWM outputs) drives the heater relay.

Software on the 6805 implements the temperature control algorithm, maintains the temperature displays, and alters the set-point in response to keypad inputs. Because it is not complete at this writing, software will not be discussed in detail in this paper. The control algorithm in particular has not been

determined, but it is likely to be a simple proportional controller and certainly not more complex than a PID. Some control design issues will be discussed in Section 4, however.

4 The Design Process

Although essentially the project is just to build a thermostat, it presents many nice pedagogical

opportunities. The knowledge and experience base of a senior engineering undergraduate are just enough to bring him or her to the brink of a solution to various aspects of the problem. Yet, in each case, realworld considerations complicate the situation significantly.

Fortunately these complications are not insurmountable, and the result is a very beneficial design experience. The remainder of this section looks at a few aspects of the problem which present the type of learning opportunity just described. Section 4.1 discusses some of the features of a simplified mathematical model of the thermal properties of the system and how it can be easily validated experimentally. Section 4.2 describes how realistic control algorithm designs can be arrived at using introductory concepts in control design. Section 4.3 points out some important deficiencies of such a simplified modeling/control design process and how they can be overcome through simulation. Finally, Section 4.4 gives an overview of some of the microcontroller-related design issues which arise and learning opportunities offered. 4.1 MathematicalModel

Lumped-element thermal systems are described in almost any introductory linear control systems text, and just this sort of model is applicable to the slide dryer problem. Figure 4 shows a second-order

lumped-element thermal model of the slide dryer. The state variables are the temperatures Ta of the air in

第 21 页 共 39 页

陕西理工学院毕业设计

the box and Tb of the box itself. The inputs to the system are the power output q(t) of the heater and the ambient temperature T¥. ma and mb are the masses of the air and the box, respectively, and Ca and Cb their specific heats. μ1 and μ2 are heat transfer coefficients from the air to the box and from the box to the external world, respectively.

It’s not hard to show that the (linearized) state equationscorresponding to Figure 4 Taking Laplace transforms of (1) and (2) and solving for Ta(s), which is the output of interest, gives the following open-loop model of the thermal system:

where K is a constant and D(s) is a second-order polynomial.K, tz, and the coefficients of D(s) are functions of the variousparameters appearing in (1) and (2).Of course the various parameters in (1) and (2) are completely unknown, but it’s not hard to show that, regardless of their values, D(s) has two real zeros. Therefore the main transfer function of interest (which is the one from Q(s), since we’ll assume constant ambient temperature) can be writtenMoreover, it’s not too hard to show that 1=tp1 <1=tz <1=tp2, i.e., that the zero lies between the two poles. Both of these are excellent exercises for the student, and the result is the openloop pole-zero diagram of Figure 5.

Obtaining a complete thermal model, then, is reduced to identifying the constant K and the three

unknown time constants in (3). Four unknown parameters is quite a few, but simple experiments show that 1=tp1 _ 1=tz;1=tp2 so that tz;tp2 _ 0 are good approximations. Thus the open-loop system is essentially first-order and can therefore be written where the subscript p1 has been dropped .

Simple open-loop step response experiments show that,for a wide range of initial temperatures and heat inputs, K _0:14 _=W and t _ 295 s.1 4.2 Control System Design

Using the first-order model of (4) for the open-loop transfer function Gaq(s) and assuming for the moment that linear control of the heater power output q(t) is possible, the block diagram of Figure 6 represents the closed-loop system. Td(s) is the desired, or set-point, temperature,C(s) is the compensator transfer function, and Q(s) is the heater output in watts.

Given this simple situation, introductory linear control design tools such as the root locus method can be used to arrive at a C(s) which meets the step response requirements on rise time, steady-state error, and overshoot specified in Table 1. The upshot, of course, is that a proportional controller with sufficient gain can meet all specifications. Overshoot is impossible, and increasing gains decreases both steady-state error and rise time.

Unfortunately, sufficient gain to meet the specifications may require larger heat outputs than the heater is capable of producing. This was indeed the case for this system, and the result is that the rise time

specification cannot be met. It is quite revealing to the student how useful such an oversimplified model, carefully arrived at, can be in determining overall performance limitations. 4.3 Simulation Model

Gross performance and its limitations can be determined using the simplified model of Figure 6, but there are a number of other aspects of the closed-loop system whose effects on performance are not so simply modeled. Chief among these are

·quantization error in analog-to-digital conversion of the measured temperature and · the use of PWM to control the heater.

Both of these are nonlinear and time-varying effects, and the only practical way to study them is through simulation (or experiment, of course).

Figure 7 shows a SimulinkTM block diagram of the closed-loop system which incorporates these effects. A/D converter quantization and saturation are modeled using standard Simulink quantizer and saturation blocks. Modeling PWM is more complicated and requires a custom S-function to represent it.

This simulation model has proven particularly useful in gauging the effects of varying the basic PWM

第 22 页 共 39 页

陕西理工学院毕业设计

parameters and hence selecting them appropriately. (I.e., the longer the period, the larger the temperature error PWM introduces. On the other hand, a long period is desirable to avoid excessive relay ―chatter,‖ among other things.) PWM is often difficult for students to grasp, and the simulation model allows an exploration of its operation and effects which is quite revealing. 4.4 The Microcontroller

Simple closed-loop control, keypad reading, and display control are some of the classic applications of microcontrollers, and this project incorporates all three. It is therefore an excellent all-around exercise in microcontroller applications. In addition, because the project is to produce an actual packaged prototype, it won’t do to use a simple evaluation board with the I/O pins jumpered to the target system. Instead, it’s necessary to develop a complete embedded application. This entails the choice of an appropriate part from the broad range offered in a typical microcontroller family and learning to use a fairly sophisticated

development environment. Finally, a custom printed-circuit board for the microcontroller and peripherals must be designed and fabricated.

Microcontroller Selection. In view of existing local expertise, the Motorola line of microcontrollers was chosen for this project. Still, this does not narrow the choice down much. A fairly disciplined study of system requirements is necessary to specify which microcontroller, out of scores of variants, is required for the job. This is difficult for students, as they generally lack the experience and intuition needed as well as the perseverance to wade through manufacturers’ selection guides.

Part of the problem is in choosing methods for interfacing the various peripherals (e.g., what kind of display driver should be used?). A study of relevant Motorola application notes [2, 3, 4] proved very helpful in understandingwhat basic approaches are available, and what microcontroller/peripheral combinations should be considered.

The MC68HC705B16 was finally chosen on the basis of its availableA/D inputs and PWMoutputs as well as 24 digital I/O lines. In retrospect this is probably overkill, as only one A/D channel, one PWM channel, and 11 I/O pins are actually required (see Figure 3). The decision was made to err on the safe side because a complete development system specific to the chosen part was necessary, and the project budget did not permit a second such system to be purchased should the first prove inadequate.

Microcontroller Application Development. Breadboarding of the peripheral hardware, development of microcontroller software, and final debugging and testing of a custom printed-circuit board for the microcontroller and peripherals all require a development environment of some kind. The choice of a development environment, like that of the microcontroller itself, can be bewildering and requires some faculty expertise. Motorola makes three grades of development environment ranging from simple

evaluation boards (at around $100) to full-blown real-time in-circuit emulators (at more like $7500). The middle option was chosen for this project: the MMEVS, which consists of _ a platform board (which supports all 6805-family parts), _ an emulator module (specific to B-series parts), and _ a cable and target head adapter (package-specific). Overall, the system costs about $900 and provides, with some limitations, in-circuit emulation capability. It also comes with the simple but sufficient software development environment RAPID [5].

Students find learning to use this type of system challenging, but the experience they gain in

real-world microcontroller application development greatly exceeds the typical first-course experience using simple evaluation boards.

Printed-Circuit Board. The layout of a simple (though definitely not trivial) printed-circuit board is another practical learning opportunity presented by this project. The final board layout, with package outlines, is shown (at 50% of actual size) in Figure 8. The relative simplicity of the circuit makes manual placement and routing practical—in fact, it likely gives better results than automatic in an application like

第 23 页 共 39 页

陕西理工学院毕业设计

this—and the student is therefore exposed to fundamental issues of printed-circuit layout and basic design rules. The layout software used was the very nice package pcb,2 and the board was fabricated in-house with the aid of our staff electronics technician. 5 Conclusion

The aim of this paper has been to describe an interdisciplinary, undergraduate engineering design project: a microcontroller- based temperature control system with digital set-point entry and

set-point/actual temperature display. A particular design of such a system has been described, and a number of design issues which arise—from a variety of engineering disciplines—have been discussed. Resolution of these issues generally requires knowledge beyond that acquired in introductory courses, but realistically accessible to advance undergraduate students, especially with the advice and supervision of faculty.

Desirable features of the problem, from a pedagogical viewpoint, include the use of a microcontroller with simple peripherals, the opportunity to usefully apply introductorylevel modeling of physical systems and design of closed-loop controls, and the need for relatively simple experimentation (for model validation) and simulation (for detailed performance prediction). Also desirable are some of the technologyrelated aspects of the problem including practical use of resistive heaters and temperature sensors (requiring knowledge of PWM and calibration techniques, respectively), microcontroller selection and use of development systems, and printedcircuit design.

Acknowledgements

The author would like to acknowledge the hard work, dedication, and ability shown by the students involved in this project: Mark Langsdorf, Matt Rall, PamRinehart, and David Schuchmann. It is their project, and credit for its success belongs to them.

第 24 页 共 39 页

陕西理工学院毕业设计

附录 B 中文译文

单片机温度控制:一个跨学科的本科生工程设计项目

JamesS.McDonald

工程科学系三一大学德克萨斯州

圣安东尼奥市78212

本文所描述的是作者领导由四个三一大学高年级学生组成的团队进行的一个跨学科工程项目的设计。该项目的目标是设计一个气室内温度控制系统。该系统的要求是:当实际气室的温度阶跃响应时,规定范围内的温度进入气室后,稳定时的温度误差和超调量必须少于一个绝对温度。本组学生开发设计是基于摩托罗拉MC68HC05系列单片机。该问题的教学价值也通过某些步骤的关键描述在本文说明。研究结果表明,解决该方案需要具有广泛的工程学科知识,包括相关电子、机械和控制系统工程的知识。 1 引言

该设计项目来自一个实际应用问题,一个关于显微镜载玻片干燥剂温控器——欧米茄CN-390温度控制器,而这个设计的目标是研发一个自定义的通用温度控制系统取代欧米茄系统、一个以更低的成本实现相同功能的自定义控制器,就像欧米茄系统一样,并不需要能够全方位的处理各种问题。

该载玻片干燥机的机械布局如图1所示。干燥机的主体是一个足够大的绝缘充气室,里面依次存放着薄纸包着的石蜡。为了使石蜡保持适当稳定性,载玻片气室的温度必须维持稳定。第二个气筒(电子围绕元件)设有一个电阻加热器、一个温度控制器以及一个安装在干燥机上的风扇,是为了把风吹过加热器,把热量带到载玻片气室。 自1996-97学年来,本文作者带领四位三一大学工程科学系的高年级学生开展此项目的研究。本文的目的说明了提出一些问题并详细阐述学生的一些解决方案,而且讨论了这种类型的跨学科设计项目在教学方面应用的问题。这份学生报告曾经在1997年全国本科毕业生研讨会上提出过并讨论过。第2节给出该设计的更多详细情况,包括性能规格。第3节具体 学生的设计。第4节是论文的主体,讨论该设计在教学应用方面的实施问题。最后,第5节全文总结。 2 问题阐述

该项目基本的思想是设计一个自定义温度控制系统来取代相关的欧米茄CN-390温度控制器。温度时通常保持在一个稳定的常数,但重要的是阶跃变化可以被“合理”的跟踪。因此主要要求如下:

·可以对空气室的温度进行设定, ·同时显示设定值和实际温度,

·以及在设定温度值情况下,可接受范围内的跟踪阶跃变化,稳态误差,超调量。

尽管表1部分说明并不明确,但是它清楚的反映了人们对数字显示器在设定值和实际温度的要求和温度应该通过数值输入来设定(而不是,通过电位器设置)。 3.系统设计

根据微控设计,数字温度显示和单点输入的要求可能是最合适的。图2为学生的设计框图。 摩托罗拉MC68HC705B16(简称6805),是系统的核心。它通过一个简单的4键小键盘对温度进行设定,同时使用两个显示驱动控制7段LED数码管来显示定值和气室温度的测量值。所有这些,输入和输出信号与6805的并行口相连。气室的温度值使用预校准热敏电阻测量,并通过6805的数模转换输入。最后,6085的脉冲宽度调制(PWM)输出用来驱动一个继电器,以控制线性电阻加热器的闭合和断开。

图3更详细的显示了6805的接口和电子器件。使用暴风3K041103型号四键键盘,通过PA0-PA3端口进行数据输入。其中一个重要的功能是进行模式切换。两种模式:固定模式和运行模式。在固定模式下,其他两个键用于设定温度,一个增加,一个减少,第四个按键暂无作用。LED显示屏由

第 25 页 共 39 页

陕西理工学院毕业设计

哈里斯半导体ICM7212进行驱动,通过PB0-PB6端口与芯片相连,作为输出。热敏电阻由电压分频器驱动,通过AN0针脚(八个模拟输入端口中的一个)相连。最后,PLMA针脚(两个PWM输出端口中的一个)驱动加热继电器。

单片机原理图是关于用软件实现温度控制算法、保持温度显示以及改变键盘输入响应,这将不会在本文详细讨论,因为这并不是本文的重点,也没有编译完成。软件部分还没有确定控制算法,但很可能是一个简单的比例控制,比PID算法简单。一些控制设计的问题将在第四节讨论。 4 设计过程

虽然该项目的本质是建立一个恒温器,但它有许多很好的契机可以供教学借鉴。高级工程本科教育的知识只是能够让学生们具有解决问题的能力。然而,很多情况下,实际情况却和理论有些不同。不过,这些不是问题,参与这个项目的设计,将获得很多设计方面的宝贵经验。本节的其余部分着眼于其他的几个方面:4.1节讨论系统的一些特征,简化系统热性能的数学模型,以及一些简单理论的证明。4.2节介绍确定实际控制算法。4.3节指出控制设计程序的一些不足,并通过模拟环境,指出怎样克服问题。4.4节给出单片机的一些设计相关概述,以及出现问题和值得借鉴之处。 4.1数学模型

集总元件热系统符合线性控制,适用于载玻片干燥机的问题。图4显示了二阶集总元件热量模型的载玻片干燥机。状态变量是温度,Ta是箱内空气的温度,Tb是箱子本身的温度。该系统输入功率等于q(t)的热量和环境温度T的和。ma,mb分别对应空气和箱子的质量。

Ca和Cb则分别是其对应热量。m1和m2分别是空气与箱子间以及箱子与外界间的传热系数。

拉普拉斯变换(1)和(2)等式,并整理Ta(s)。有趣的是,可以推出一个开环的热系统方程。 其中K是一个常数,D(s)是一个二阶的多项式。K,tz,以及系数D(s)和在(1)和(2)等式中出现的系数功能相近。当然,在(1)和(2)等式中各种参数在未知的情况下,不难证明D(s)与其他参数的值无关,具有两个零点。因此传递函数可以写成(我们假设环境温度为常数)

此外,可以推出1/tp1<1/tz<1/tp2,即,零点在两极之间。开环零极点如图5所示。

为了获取完整的热模型,从(3)式中除去常数K和3个未知的时间常数。四个未知参数并不少,但由简单的实验表明,1/tp1<<1/tz,1/tp2统基本上是一阶函数,且tz,tp2近似为0。

过初始温度和热量值大范围内的设置,简单的开环阶跃响应实验结果表明,K≈0.14o/W,τ≈295S。

4.2 控制系统设计

使用(4)式的一阶开环传递函数Gaq(s),并且假定加热器的输出函数q(t)为线性,图6是系统框图代表闭环系统。Td(s)是设定温度的函数,C(s)是传递函数,Q(s)是热量输出,单位是瓦特。

图6简化的闭环系统框图鉴于这种简单情况,前面所指的线性控制设置,例如,根轨迹法设计法可以使C(s)中符合要求的阶跃响应对应的上升时间、稳态误差和超调量符合表格1所示。当然,一个有足够增益的比例控制器就可以满足各种要求。超调量改变是不可能既增加增益又减少稳态误差和上升时间的。不幸的是,如果要获得足够增益,需要生产超过实际生产能力的大容量加热器。这是本系统的实际问题,将会致使上升时间不符合要求。这要求学生们如何利用这个经过仔细计算的简化模型,在整体性能上达到最佳控制。 4.3 模型仿真

该设计的大部分性能和限制功能,应该可以使用图6简化模型来完成。但有一个数据对闭环系统其他方面的影响并非能够如此简单的仿真。其中最主要的是:

·量化误差的模拟和数模转换, ·测量温度和使用PWM控制加热器。

这两种都是非线性的、时变的。所以唯一切实可行的方法就是通过仿真(或实验)加以研究。 图7Simulink仿真闭环系统框图显示了Simulink情况下的闭环系统框图,其中包括A/D转换和使用标准Simulink量化饱和块建立的饱和量化模型。建立PWM调制模型比较复杂,需要一个自定义的S函数来表示。

这种仿真模型已经被证明在衡量不同的PWM基本参数对设计的影响以及适当参数的选择中特别

第 26 页 共 39 页

陕西理工学院毕业设计

有用。(即时间越长,PWM调制会产生更多温度误差。另一方面,时间越长,继电器抖动机率越小。)PWM调制方法往往很难让学生掌握,并且仿真模型允许研究测试运行和明显的影响。 4.4单片机

简单的闭环控制、键盘输入和显示控制是经典单片机应用技术,这个设计项目包含上述三个方面。因此这是一个优秀的全面的单片机应用练习。

此外,由于该项目是来源于现实,它不会是一个简单的输入输出设计就能完成的。相反,这个项目需要制定一个完整的嵌入式应用。这需要从大量的单片机型号中选取适当的芯片并学着使用一个相当复杂的开发环境。最后,必须设计和选取印刷电路板和单片机,以及外接元件。 单片机选择

从现有的实际经验来看,经常选用摩托罗拉公司的单片机。不过,芯片的选择不应该局限于此。研究表明,系统要求符合工作需求的单片机。这对学生很困难,因为他们缺乏良好的经验与判断能力,只能通过制造商的产品选择指南决定单片机的选择。部分问题是各种外围设备(例如,应该使用哪种显示驱动程序?)连接方法的选择。摩托罗拉的相关应用研究[2,3,4]中的证明是非常有用的,基本阐述了可实用性的连接方法以及单片机和外围连接的组合方式。在最终要求的基础上,选择MC68HC705B16,其现有A/D输入和PWM输出以及24个数字I/O线。这样选择是有必要的,因为此项目需要一个A/D通道、一个PWM通道和11个I/O引脚(见图3)。该决定为了安全方面,因为选择一个完整的开发系统是有必要的,该项目预算中没有足够的资金再次购买元件。 单片机应用开发

外围设备的电路硬件、软件的开发、最终调试、单片机的自定的印刷电路板和外设都需要某种形式的发展环境。

如同单片机本身,一个开发环境的选择是令人困惑并需要一些教师的专业知识。摩托罗拉三级发展环境,包括从简单的评估板(在约100美元)到全面的实时在线仿真器(在大约7500元)。中间选项被选为本项目的MMEVS,其中包括: ·平台板(支持所有6805-family部分),

· 模拟器模块(具体到B系列部分),和 · 电缆头和目标适配器(简明包装)。

学生发现学习使用这类系统的挑战。但他们在现实世界的微控制器应用获得的经验大大超过了第一使用典型的简单评估板的经验。 印刷电路板

一个简单的(虽然布局绝对不平凡)印刷电路板是这个工程提供的另一个现实学习的机会。图8显示最后的板布局与包轮廓(50%实际大小)。相对简单的电路使手工安置和路由实践方面更实际,它有可能提供更好的结果比一个这样的应用程的自动性。学生因此接触到基本印刷电路布局问题和基本的设计规则。本排版软件使用的是非常漂亮的包装印刷电路板,板制作是在内部电子技术员的帮助下完成的。 5 结论

本文的目的是描述一个跨学科的本科工程设计项目:一个基于单片机的温度控制系统,包括设定点输入数字与设定值/实际温度显示。本文已描述了这样系统的一个设计,并且讨论了许多来自工程的问题。这些问题的解决通常需要入门课程要求的知识,尤其是在老师的建议和监督下,实际上可以促进大学生发展。

从教学方法观点看,问题的理想特征包括微控制器和外围设备的简单使用,有效地运用导论水平的物理系统建模和设计闭环控制。并需要相对简单的实验和模拟(详细的性能 预测)。并可取的是一些技术相关方面的问题,包括热敏电阻和温度传感器(分别需要知识 脉宽调制和校准技术)的实际使用、单片机选择和开发系统的使用以及并印制电路设计。 鸣谢

作者要感谢参与这个项目的学生,马克朗·斯道夫,马特洛尔和戴维?舒克曼,表现出辛勤工作、奉献和能力。这个工程和工程成功全赖他们。

第 27 页 共 39 页

陕西理工学院毕业设计

附录C 系统原理图

第 28 页 共 39 页

陕西理工学院毕业设计

附录D 实物图

第 29 页 共 39 页

陕西理工学院毕业设计

附录E 元器件清单

元器件名称 型号 数量 功能

蜂鸣器 Bell 1 报警 电容 10uF 1 电容 20uF 2 发光二极管 8 报警提示 继电器 Relay-SPDT 8 调控段外部用电器开关 显示屏 OLED12864 1 显示模块实时显示 电源接口 Header 2 2

PNP三极管 9012 9 放大电流 电阻 2K 17 上拉电阻 电阻 10K 5 保护电路 按键 SW-PB 5 单片机 STC89C52 1 温湿度传感器 DHT11 4

晶振 12M 1 起振单片机

第 30 页 共 39 页

陕西理工学院毕业设计

附录F 粮仓温湿度控制系统C语言程序

#include \#include \#include \#include \//

#define uchar unsigned char #define uint unsigned int

sbit dht_dat=P1^0; //用哪个 I/O 口自选,注意不要用 P3 口 sbit dht1_dat=P1^1; sbit dht2_dat=P1^2; sbit dht3_dat=P1^3; sbit jdq1= P2^0; sbit jdq2= P2^1; sbit jdq3= P2^2; sbit jdq4= P2^3; sbit jdq5= P2^4; sbit jdq6= P2^5; sbit jdq7= P2^6; sbit jdq8= P2^7; sbit beep= P1^4;

sbit key1= P3^4; sbit key2= P3^5; sbit key3= P3^7; sbit key4= P3^6;

uchar Tmax=30,Hmax=65; uchar setflag=0,rhflag=0;

uchar dht_t1[4]={0,0,0,0},dht_t2[4]={0,0,0,0}; //依次为温度整数部分和温度小数部分 uchar dht_d1[4]={0,0,0,0},dht_d2[4]={0,0,0,0}; //依次为湿度整数部分和湿度小数部分 uchar dht_chk[4]={0,0,0,0}; //和校验,可选择是否使用,具体参照数据手册 uchar dht_num[4]={0,0,0,0}; //用于 while 循环中计数,超时则跳出循环 #ifndef __INF_NEC__ #define __INF_NEC__

extern void dht_delay_10us();

extern void dht_delay_10ms(uchar t); extern uchar dht_readat(); extern void dht_getdat(); extern void dht_init(); #endif

void dht_delay_10us() //自己调,一定要尽量精确到 10us,很重要 {

uchar i=0;

for(i=0;i<1;i++); }

第 31 页 共 39 页

陕西理工学院毕业设计

void dht_delay_10ms(uchar t) //大概 10ms 就行,粗略延时 {

uchar i=0,j=0,k=0; for(i=0;i

for(j=0;j<40;j++)for(k=0;k<75;k++); } }

void dht_init() //DHT11 的初始化函数,别忘了写程序时先加上之 {

dht_delay_10ms(100); //DHT11 上电前准备时间,大概 1s dht_dat=1; //总线准备 }

/***********************************************第一DHT11*****************************/

/***********************************************第一DHT11*****************************/

/***********************************************第一DHT11*****************************/

/***********************************************第一DHT11*****************************/

uchar dht_readat() //接收一个 8 位数据,先高位后低位 {

uchar i=0,dat=0; for(i=0;i<8;i++) {

dht_num[0]=2;

while((dht_dat==0)&&(dht_num[0]++));

dht_delay_10us();dht_delay_10us();dht_delay_10us();dht_delay_10us(); dat=dat<<1; if(dht_dat==1) {

dht_num[0]=2; dat=dat|0x01;

while((dht_dat==1)&&(dht_num[0]++)); } }

return dat; }

void dht_getdat() // 给 1 DHT11 一个开始信号,然后读取一次数据,共五个 8 位字节{

uchar i=0; dht_dat=0;

dht_delay_10ms(4);

dht_dat=1; //单片机给起始脉冲信号

第 32 页 共 39 页

个个个个

陕西理工学院毕业设计

dht_delay_10us();dht_delay_10us();dht_delay_10us();dht_delay_10us(); dht_dat=1; //稍作延时,等待 DHT11 返回响应(响应为低电平) if(dht_dat==0) //有响应才接收数据,否则不作处理 {

dht_num[0]=2;while((dht_dat==0)&&(dht_num[0]++)); dht_num[0]=2;while((dht_dat==1)&&(dht_num[0]++)); dht_d1[0]=dht_readat(); dht_d2[0]=dht_readat(); dht_t1[0]=dht_readat(); dht_t2[0]=dht_readat();

dht_chk[0]=dht_readat();//一次读出五个数据 }

dht_dat=1; //释放总线

dht_delay_10ms(10); //稍作延时 }

/**************************************************************************************/

/***********************************************第2个DHT11*****************************/

/***********************************************第2个DHT11*****************************/

/***********************************************第2个DHT11*****************************/

/***********************************************第2个DHT11*****************************/

uchar dht2_readat() //接收一个 8 位数据,先高位后低位 {

uchar i=0,dat=0; for(i=0;i<8;i++) {

dht_num[1]=2;

while((dht1_dat==0)&&(dht_num[1]++));

dht_delay_10us();dht_delay_10us();dht_delay_10us();dht_delay_10us(); dat=dat<<1; if(dht1_dat==1) {

dht_num[1]=2; dat=dat|0x01;

while((dht1_dat==1)&&(dht_num[1]++)); } }

return dat; }

第 33 页 共 39 页

陕西理工学院毕业设计

void dht2_getdat() // 给 1 DHT11 一个开始信号,然后读取一次数据,共五个 8 位字节 {

uchar i=0; dht1_dat=0;

dht_delay_10ms(4);

dht1_dat=1; //单片机给起始脉冲信号

dht_delay_10us();dht_delay_10us();dht_delay_10us();dht_delay_10us(); dht1_dat=1; //稍作延时,等待 DHT11 返回响应(响应为低电平) if(dht1_dat==0) //有响应才接收数据,否则不作处理 {

dht_num[1]=2;while((dht1_dat==0)&&(dht_num[1]++)); dht_num[1]=2;while((dht1_dat==1)&&(dht_num[1]++)); dht_d1[1]=dht2_readat(); dht_d2[1]=dht2_readat(); dht_t1[1]=dht2_readat(); dht_t2[1]=dht2_readat();

dht_chk[1]=dht2_readat();//一次读出五个数据 }

dht1_dat=1; //释放总线

dht_delay_10ms(10); //稍作延时 }

/**************************************************************************************/

/***********************************************第3个DHT11*****************************/

/***********************************************第3个DHT11*****************************/

/***********************************************第3个DHT11*****************************/

/***********************************************第3个DHT11*****************************/

uchar dht3_readat() //接收一个 8 位数据,先高位后低位 {

uchar i=0,dat=0; for(i=0;i<8;i++) {

dht_num[2]=2;

while((dht2_dat==0)&&(dht_num[2]++));

dht_delay_10us();dht_delay_10us();dht_delay_10us();dht_delay_10us(); dat=dat<<1; if(dht2_dat==1) {

dht_num[2]=2;

第 34 页 共 39 页

陕西理工学院毕业设计

dat=dat|0x01;

while((dht2_dat==1)&&(dht_num[2]++)); } }

return dat; }

void dht3_getdat() // 给 1 DHT11 一个开始信号,然后读取一次数据,共五个 8 位字节 {

uchar i=0; dht2_dat=0;

dht_delay_10ms(4);

dht2_dat=1; //单片机给起始脉冲信号

dht_delay_10us();dht_delay_10us();dht_delay_10us();dht_delay_10us(); dht2_dat=1; //稍作延时,等待 DHT11 返回响应(响应为低电平) if(dht2_dat==0) //有响应才接收数据,否则不作处理 {

dht_num[2]=2;while((dht2_dat==0)&&(dht_num[2]++)); dht_num[2]=2;while((dht2_dat==1)&&(dht_num[2]++)); dht_d1[2]=dht3_readat(); dht_d2[2]=dht3_readat(); dht_t1[2]=dht3_readat(); dht_t2[2]=dht3_readat();

dht_chk[2]=dht3_readat();//一次读出五个数据 }

dht2_dat=1; //释放总线

dht_delay_10ms(10); //稍作延时 }

/**************************************************************************************/

/***********************************************第4个DHT11*****************************/

/***********************************************第4个DHT11*****************************/

/***********************************************第4个DHT11*****************************/

/***********************************************第4个DHT11*****************************/

uchar dht4_readat() //接收一个 8 位数据,先高位后低位 {

uchar i=0,dat=0; for(i=0;i<8;i++) {

dht_num[3]=2;

while((dht3_dat==0)&&(dht_num[3]++));

第 35 页 共 39 页

陕西理工学院毕业设计

dht_delay_10us();dht_delay_10us();dht_delay_10us();dht_delay_10us(); dat=dat<<1; if(dht3_dat==1) {

dht_num[3]=2; dat=dat|0x01;

while((dht3_dat==1)&&(dht_num[3]++)); } }

return dat; }

void dht4_getdat() // 给 1 DHT11 一个开始信号,然后读取一次数据,共五个 8 位字节 {

uchar i=0; dht3_dat=0;

dht_delay_10ms(4);

dht3_dat=1; //单片机给起始脉冲信号

dht_delay_10us();dht_delay_10us();dht_delay_10us();dht_delay_10us(); dht3_dat=1; //稍作延时,等待 DHT11 返回响应(响应为低电平) if(dht3_dat==0) //有响应才接收数据,否则不作处理 {

dht_num[3]=2;while((dht3_dat==0)&&(dht_num[3]++)); dht_num[3]=2;while((dht3_dat==1)&&(dht_num[3]++)); dht_d1[3]=dht4_readat(); dht_d2[3]=dht4_readat(); dht_t1[3]=dht4_readat(); dht_t2[3]=dht4_readat();

dht_chk[3]=dht4_readat();//一次读出五个数据 }

dht3_dat=1; //释放总线

dht_delay_10ms(10); //稍作延时 }

void baojing() {

if(dht_t1[0]>Tmax){jdq1=0;beep=0;dht_delay_10ms(5);}else{jdq1=1;beep=1;dht_delay_10ms(5);} if(dht_d1[0]>Hmax){jdq2=0;beep=0;dht_delay_10ms(5);}else{jdq2=1;beep=1;dht_delay_10ms(5);}

if(dht_t1[1]>Tmax){jdq3=0;beep=0;dht_delay_10ms(5);}else{jdq3=1;beep=1;dht_delay_10ms(5);} if(dht_d1[1]>Hmax){jdq4=0;beep=0;dht_delay_10ms(5);}else{jdq4=1;beep=1;dht_delay_10ms(5);}

if(dht_t1[2]>Tmax){jdq5=0;beep=0;dht_delay_10ms(5);}else{jdq5=1;beep=1;dht_delay_10ms(5);} if(dht_d1[2]>Hmax){jdq6=0;beep=0;dht_delay_10ms(5);}else{jdq6=1;beep=1;dht_delay_10ms(5);}

第 36 页 共 39 页

本文来源:https://www.bwwdw.com/article/cjkp.html

Top