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

更新时间:2024-05-17 23:47: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 页

陕西理工学院毕业设计

(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 页

陕西理工学院毕业设计

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 页

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

Top