Designed and produced an automatic temperature control system.
I. Tasks of the project
Design and production of a water temperature control system, the control object is 1 liters of water purification, containers for enamel utensils. The water temperature can be set manually in a certain range, and can be automatically controlled when the ambient temperature is lowered, in order to keep the set temperature basically unchanged.
1. Basic requirements
(1) The temperature setting range is 40~90℃, and the minimum set degree is 1 ℃.
(2) has the temperature display function, the resolution is 0.1 ℃, the display absolute error is less than 1 ℃.
(3) When the temperature reaches a certain set value and stabilizes, the fluctuation of water temperature is controlled within ±2℃. When the temperature regulation is required to stabilize, the signal must be given out or light.
(4) When the ambient temperature is lowered (for example, with an electric fan) the fluctuation of water temperature is controlled within ±2℃.
2. Play part
(1) When the temperature reaches a certain set value and stabilizes, the fluctuation of water temperature is controlled within ±1℃. When the temperature regulation is required to stabilize, the signal must be given out or light.
(2) The appropriate control method, when the set temperature mutation (from 35 ℃ to 45 ℃), in the overshoot is not more than 2 ℃ premise, minimize the system adjustment time, and require the temperature control of the static error ≤0.5℃.
(3) When the set temperature mutation (from 35 ℃ to 45 ℃), automatically print the water temperature changes over time curve.
(4) Other.
Ii. comparison and selection of schemes
Upon request, the system has at least the following functional modules:
1. Temperature measurement module:
Temperature measurement is one of the core problems of this system. Temperature sensors based on single-chip microcomputer are undoubtedly the best choice, with the common digital temperature sensors and analog temperature sensors.
The former is represented by Ds18b20. It is connected with a microprocessor using a single-bus interface. A single bus is required to enable bidirectional communication between microprocessors. The single bus has the advantages of good economy, strong anti-jamming ability, suitable for harsh environment field temperature measurement, easy to use and so on, so that users can easily set up the sensor network. Wide measurement temperature range, high measurement accuracy ds18b20 measuring range of -55℃~+ 125 ℃, in the -10~+ 85°c range, the accuracy is ±0.5°c. Multi-point Network function multiple Ds18b20 can be connected in parallel on the only single line, to achieve multi-point temperature measurement. The power supply is flexible and the DS18B20 can obtain power from the data line through the internal parasitic circuitry. Therefore, when the timing of the data line meets certain requirements, can not connect the external power supply, so that the system structure more simple, more reliable. Measurement parameters Configurable Ds18b20 Measurement resolution can be programmed by the 9~12 bit. Analog temperature sensor, represented by Pt100.
The DS18B20 has a smaller size, a wider application voltage, more economical, and a smaller package, a wider range of voltages, suitable for building its own economic temperature measurement system, and is therefore favored by designers.
2. Temperature Display module:
Due to the temperature accuracy and real-time requirements, multi-bit dynamic display is required. There are two kinds of common display methods, one is digital tube, the other is LCD screen. Dynamic display is one of the most common multi-digit display methods for digital tube, which is widely used. All the digital pipe selection are connected together, the dynamic display is a number of digital tube, alternating display, the use of human visual pause to see a number of digital tube simultaneously display the effect. Just as the movie we watch is a frame-by-frame display, we see it as dynamic when it's fast enough. When we show that the digital tube is fast enough, we can see that they are displayed at the same time.
1602 Liquid crystal is also called 1602-character Liquid crystal, it is a kind of special used to display letters, numbers, symbols of the lattice-type LCD module. It is composed of several 5x7 or 5x11 bitmap character bits, each bitmap character bit can be used to display a character, each bit has a point spacing between the interval, there is a gap between each line, play the role of character spacing and line spacing.
3. Temperature setting Module:
The tactile switch is an electronic switch that, when used, can be switched on by gently pressing the switch button, and when the hand is loosened, the switch is disconnected. Use 3 switches, respectively, function conversion, set +, set-, to complete all the set operation.
4. Temperature control Module:
Control Core Selection stc89c52. STC89C52 is a low-power, high-performance CMOS8-bit microcontroller produced by STC with a 8K in-system programmable flash memory. STC89C52 uses the classic MCS-51 kernel, the instruction code is fully compatible with the traditional 8051, but also made a lot of improvements so that the chip has a traditional 51 MCU does not have the function. With a smart 8-bit CPU and in-system programmable flash on a single chip, STC89C52 provides a highly flexible, ultra-efficient solution for many embedded control applications. Standard Features: 8k bytes flash,512 byte ram, 32-bit I/O port, watchdog timer, built-in 4KB eeprom,max810 reset circuit, 3 16-bit timers/counters, 4 external interrupts, A 7-Vector 4-level interrupt structure (compatible with the traditional 51 5-Vector 2-level interrupt structure), full-duplex serial port. In addition, stc89x52 can be reduced to 0Hz static logic operation, support 2 kinds of software can choose power Saving mode. Idle mode, the CPU stops working, allowing the RAM, Timer/counter, serial port, interrupt to continue working. The power-down protection mode, the RAM content is saved, the oscillator is frozen, the microcontroller all work stops until the next interrupt or hardware reset. Maximum operating frequency 35mhz,6t/12t is optional. To meet the needs of the system.
The control of the external circuit, through the relay to complete. Use the HK4100F model, the rated voltage of 5V electromagnetic relay. It has the following characteristics.
Cooling module, as the system intends to be heating circuit and relay of the normally open contact, that is, the general situation of the heating device relays and relays are disconnected, so theoretically when the temperature is too high, the relay is disconnected, can be used naturally cooling to achieve normal temperature. To make the effect better, the fan or air conditioning unit can be added to cool down.
5. Sound/Light Alarm module:
The use of green and red LEDs as external temperature in the set range and outside the signal signs, for the latter can add a buzzer or bell as an alarm device, because it may be disturbing, so add the switch, you can manually control whether it alarm.
Third, the circuit design
The system first designs the circuit and simulates the experiment on the protues. According to the above analysis, the design circuit is as follows.
There are several main parts
1. Single Chip microcomputer minimum system
2. Temperature display
3. Heating and Relay Circuits
4. Temperature acquisition and setting
Ds16b20 function Buttons
5. Alarm and Cooling
Iv. programming
V. Test plan
Through Keil compile, and then simulate in protues, test the system operation effect. In order to improve system stability and reliability, choose the actual test on the Development Board and the program debugging on the PC. Finally, the hardware platform is built, by selecting the appropriate specifications of the parts, welding to complete the entire system of predetermined functions.
Six
System Commissioning
By optimizing the interface selection between the microcontroller and the LCD1602, it solves the problem that cannot be displayed until the pull-resistance is not added. The function structure is adjusted so that the temperature is updated in real time, and the sensitivity and real-time of the system are improved. The simulation effect, as shown in.
Vii. Data testing and processing
In order to further close to the actual, the experiment was carried out on the Puzhong em3_v3.0 Model Development Board. The following features were successfully implemented:
(1) The temperature setting range is 0~125℃, and the minimum set degree is 1 ℃. Wider than the required 40~90℃.
(2) has the temperature display function, the resolution is 0.01 ℃, the display absolute error is less than 1 ℃. An order of magnitude greater than the required 0.1 ℃, the absolute error is less than the required 1 ℃.
(3) When the temperature reaches a certain setpoint and stabilizes, the fluctuation of water temperature is controlled within the ±x℃ (integer between 0-9 and adjustable). More flexible and more practical than the required ±2℃.
(4) When the temperature control is required to achieve a stable state, the light signal is given.
(5) When the ambient temperature is not within the set range, the reaction is timely and fast. The temperature is too high, the trigger disconnects, stops heating, cools naturally, and can call the fan to cool down. The temperature is too low and the trigger is closed until it reaches the specified temperature.
The following features are not implemented:
(6) When the set temperature mutation (from 35 ℃ to 45 ℃), the overshoot is not more than 2 ℃ under the premise of minimizing the system adjustment time, and requires the temperature control of the static error ≤0.5℃.
(7) When the set temperature mutation (from 35 ℃ to 45 ℃), automatically print the water temperature changes over time curve.
Viii. Summary
The water temperature automatic control system, a better realization of the artificial setting temperature, real-time display temperature, automatic control temperature function, and the actual application, the improvement of some places, such as improve the accuracy of the temperature display, in addition to achieve the "maximum temperature", "minimum Temperature", "Error range" adjustment, The range of measurement and the range of fluctuation are more flexible, and more practical use value.
However, due to the limited time and ability, there is some part of the function is not realized. In the simulation of software simulation, the effect of protues is stable. Hardware, the implementation of the Em3_v3 Development Board based on the operation and commissioning, the effect is stable, in addition to a separate platform for the experimental device, unfortunately, after many attempts to try, there are still some display problems, not better than the development Board to run.
Ix. Reference Documents
[1] HK4100F Relay Information
[2] EM3_V3 Development Board information
[3]51 Single-chip microcomputer C language Application development Technology Daquan (second edition). People's post and telecommunications publishing house.
X. Appendices:
A, design circuit diagram (schematic, PCB diagram)
B, program (requires text, comments)
Because the program is longer and is restricted by the layout, it is uploaded to
C. Pictures of related works
#include <reg51.h> #include <intrins.h> #define UINT unsigned int #define UCHAR unsigned char/*lcd1602 display module *// * For Protues Simulation # define Lcd1602_datapins p2sbit lcd1602_rs=p3^0;sbit lcd1602_rw=p3^1; Sbit lcd1602_e=p3^2; */#define Lcd1602_datapins p0sbit lcd1602_rs=p2^6;sbit lcd1602_rw=p2^5; Sbit lcd1602_e=p2^7;/* button Adjustment module */sbit k1=p1^1;//function key sbit k2=p1^2;//plus sbit k3=p1^3;//minus void Keyscan (); void Key1_switch (); void Key2_add (); void Key3_minus (); Uchar k_num;void lcd1602_settemp (uchar add,uchar dat); Uchar high=90,low=10,set_t=30 , set_d=2;//the data types here may be problematic!! /* Other module interface */sbit dsport=p3^7; Temperature sensor single Bus end sbit speaker=p1^5;//buzzer sbit relay=p1^4;//relay sbit cooler=p1^7;//Cooling device/*lcd1602 related functions */void delay1us (uint a); void lcd1602_writecom (Uchar com);//lcd1602 write 8-bit command sub-function void Lcd1602_writedata (Uchar dat); void Lcd1602_init ();// LCD1602 initialization subroutine void lcd1602_showtemp (int temp),/*DS18B20 temperature sensor related function */void Delay15us (Uchar aa); Uchar ds18b20init (); void Ds18b20writebyte (Uchar dat); uchar ds18b20readbyte (); void Ds18b20switchteMP (); int ds18b20readtemp (); float Temp_max=125.00,temp_min=-55.00;uchar Ii=0,jj=0,kk=0;uchar words_h[2]={"H="}; Uchar words_l[2]={"l="};uchar words_s[4]={"set="};void sound (); void Temp_control (int Temp); Uchar count=0;// To solve the problem that the main program executes too fast, the key cursor is too late to display the issue void Temp_control (int Temp) {unsigned int kk=400;uchar set_h,set_l;set_h=set_t+set_d;set_l= Set_t-set_d;if (temp<=set_h&&temp>=set_l)//Set temperature range {RELAY = 0;//relay disconnect cooler=0;//fan off}else {tr0=0; while (kk--) {sound ();} RELAY = 1; Relay Open, external circuit (normally open electric shock) closed heating if (temp>=set_h)//temperature is too high {RELAY = 0;//Relay disconnects cooler=1;//open}tr0=1;} /* Other module related functions */void Sound ()//buzzer {Speaker=1;delay15us (40); Speaker=0;delay15us (40);} void Delay1us (UINT a) {uint b,c;for (c=a;c>0;c--) for (b=110;b>0;b--);} void lcd1602_writecom (Uchar com)//write command {lcd1602_e=0; lcd1602_rs=0;//0 write instruction Lcd1602_rw=0; 0 is written lcd1602_datapins=com;delay1us (10); Lcd1602_e=1;delay1us (10); lcd1602_e=0;} void Lcd1602_writedata (Uchar dat)//write data {lcd1602_e=0; Lcd1602_rs=1; lcd1602_rw=0; Lcd1602_datapins=dat;delay1us(10); Lcd1602_e=1;delay1us (10); lcd1602_e=0;} void Lcd1602_init ()//lcd initialization subroutine {//uint num; Lcd1602_writecom (0x38); Open Display lcd1602_writecom (0x0f); On display does not display cursor lcd1602_writecom (0x06); Write a pointer plus 1lcd1602_writecom (0X01); Clear Screen lcd1602_writecom (0x80); Sets the data pointer start lcd1602_writecom (0X80+0X0B); for (ii=0;ii<2;ii++) {lcd1602_writedata (words_h[ii]);} Lcd1602_settemp (13,high); Lcd1602_writecom (0x80+0x40); for (kk=0;kk<4;kk++) {lcd1602_writedata (Words_s[kk]);} Lcd1602_settemp (4+0x40,set_t); Lcd1602_writecom (0x80+0x47); Lcd1602_writedata (0x23); Display the sign lcd1602_writecom (0x80+0x48); Lcd1602_writedata (0x30+set_d); Lcd1602_writecom (0x80+0x4b); for (jj=0;jj<2;jj++) {lcd1602_writedata (WORDS_L[JJ]);} Lcd1602_settemp (13+0x40,low); tmod=0x01; th0= (65536-50000)/256; tl0= (65536-50000)%256; ea=1;//total Interruption et0=1; Tr0=1; }void delay15us (Uchar aa) {do{_nop_ (); _nop_ (); _nop_ (); _nop_ (); _nop_ (); _nop_ (); _nop_ (); _nop_ (); _nop_ (); _nop_ (); _ Nop_ (); _nop_ (); _nop_ (); aa--;} while (AA);} /*DS18B20 temperature sensor related functions */uchar ds18b20init () {Uchar flag;dsport=0; Bus PullLow Delay15us (40),//Delay 480~960usdsport=1;delay15us (2), Flag=dsport;delay15us (6),//DS18B20 signal response, delay 60~240USDELAY15US (); return flag;} Uchar Ds18b20readbyte () {Uchar byte,bi; uint I;for (i=0;i<8;i++) {dsport=0;_nop_ (); _nop_ (); _nop_ (); _nop_ ();// Keep the low level at least 1us, but not less than 15usdsport=1;bi=dsport;//read a single data, loop 8 times for one byte byte = (byte >> 1) | (BI << 7);//Move the byte to the left one bit, then bi,8 the Delay15us (4) with a byte after the right shift 7 bits. return byte; void Ds18b20writebyte (Uchar dat) {uint I; for (i=0;i<8;i++) {dsport=0;_nop_ ();D sport=dat&0x01;//one has to read, Starting from the lowest bit delay15us (5);D sport=1;_nop_ ();d at>>=1; }} void Ds18b20switchtemp () {ds18b20init ();D Elay15us (7);D s18b20writebyte (0XCC);//Skip ROM instruction ds18b20writebyte (0x44);// Start temperature conversion instruction} int ds18b20readtemp () {int Temp=0;uchar temp_h,temp_l;ds18b20switchtemp ();D s18b20init ();D elay1us (1);D S18b20writebyte (0XCC); Skip ROM Operation command Ds18b20writebyte (0XBE); Send read temperature command temp_l = Ds18b20readbyte ();//Read temperature value Total 16 bits, read low byte Temp_h = Ds18b20readbyte (); temp= temp_h;temp<<=8;temp|= Temp_l;return temp;} void Lcd1602_showtemp (int temp) {float Tt;uchar show[5]={0,0,0,0,0};if (temp<0)//temperature is negative {lcd1602_writecom (0x80);//write address 80 means initial address Lcd1602_writedata ('-'); Show negative temp=temp-1;temp=~temp;tt=temp;temp=tt*0.0625*100;} else//temperature is positive {lcd1602_writecom (0x80);//write address 80 indicates the initial address lcd1602_writedata (' + '); Show positive tt=temp;temp=tt*0.0625*100;} show[0]=temp/10000;show[1]=temp%10000/1000;show[2]=temp%1000/100;show[3]=temp%100/10;show[4]=temp%10; Lcd1602_writecom (0x82); Lcd1602_writedata (' 0 ' +show[0]); Hundred lcd1602_writecom (0x83); Lcd1602_writedata (' 0 ' +show[1]); 10-bit lcd1602_writecom (0x84); Lcd1602_writedata (' 0 ' +show[2]); Single-digit lcd1602_writecom (0x85); Lcd1602_writedata ('. '); Lcd1602_writecom (0x86); Lcd1602_writedata (' 0 ' +show[3]); Very bit lcd1602_writecom (0x87); Lcd1602_writedata (' 0 ' +show[4]); Percentile lcd1602_writecom (0x88); Lcd1602_writedata (0XDF); Lcd1602_writecom (0x89); Lcd1602_writedata (' C '); Lcd1602_writecom (0x0C); temp=temp/100; Temp_control (temp);} void Key1_switch ()//function Toggle {Uchar set_h,set_l;set_h=set_t+set_d;set_l=set_t-set_d;//k1 key directive if (k1==0) {DelAy1us (10);//Time-out jitter if (k1==0) {k_num++;while (!K1);//The key does not release if (k_num==1) {tr0=0;//Turn off the timer so that the cursor is displayed lcd1602_writecom (0x80+ 0X46); Lcd1602_writecom (0x0f);D Elay15us (6);} if (k_num==2) {lcd1602_writecom (0x80+0x48); Lcd1602_writecom (0x0f);D Elay15us (6);} if (k_num==3) {lcd1602_writecom (0x80+0x0f); Lcd1602_writecom (0x0f);D Elay15us (6);} if (k_num==4) {lcd1602_writecom (0x80+0x4f); Lcd1602_writecom (0x0f);D Elay15us (6);} if (k_num==5) {k_num=0; Lcd1602_writecom (0x0C);//cursor does not display if (high<low)//used to default{high=90; low=40;//Restore Default} if (set_h>high| | Set_l<low) {high=90; low=10;//restore default value set_t=30; set_d=2;//Restore Default} tr0=1;//timer is turned back on to allow the screen to refresh}}}}void key2_add ()//function plus {if (k_num!=0) {if (k2==0) {delay1us (5); if (k2==0) { while (!K2), if (k_num==1) {set_t++;if (Set_t>=high) Set_t=high; Lcd1602_settemp (4+0x40,set_t); Lcd1602_writecom (0x80+0x46);} if (k_num==2) {set_d++;if (set_d>9) set_d=0; Lcd1602_writecom (0x80+0x48); Lcd1602_writedata (0x30+set_d); Lcd1602_writecom (0x80+0x48);} if (k_num==3) {high++;if (High>=temp_max) high=0; Lcd1602_Settemp (13,high); Lcd1602_writecom (0x80+0x0f);//lcd1602_writecom (0X80+0X40+8);} if (k_num==4) {low++;if (Low>=temp_max) low=0; Lcd1602_settemp (13+0x40,low); Lcd1602_writecom (0x80+0x4f);//lcd1602_writecom (0X80+0X40+13);}}}} void Key3_minus ()//function minus {if (k_num!=0) {if (k3==0) {Delay1us (5), if (k3==0) {while (!K3), if (k_num==1) {if (set_t<=0) set_ t=high+1;set_t--; Lcd1602_settemp (4+0x40,set_t); Lcd1602_writecom (0x80+0x46);} if (k_num==2) {if (set_d<=0) set_d=10;set_d--; Lcd1602_writecom (0x80+0x48); Lcd1602_writedata (0x30+set_d); Lcd1602_writecom (0x80+0x48);} if (k_num==3) {if (high<0) high=temp_max;high--; Lcd1602_settemp (13,high); Lcd1602_writecom (0x80+0x0f);//lcd1602_writecom (0X80+0X40+8);} if (k_num==4) {if (low<=0) low=high;low--; Lcd1602_settemp (13+0x40,low); Lcd1602_writecom (0x80+0x4f);//lcd1602_writecom (0X80+0X40+16);}}}} void Keyscan ()//Key detection {key1_switch (); Key2_add (); Key3_minus ();} void Lcd1602_settemp (uchar add,uchar DAT)//Digital tube development location Display {Uchar head,body,end; head=dat/100; BoDY=DAT%100/10; end=dat%10; Lcd1602_writecom (0x80+add); Lcd1602_writedata (0x30+head); Lcd1602_writedata (0x30+body); Lcd1602_writedata (0x30+end);} void Main () {lcd1602_init (); while (1) {Keyscan (); }}void Timer0 () interrupt 1{th0= (65536-50000)/256; tl0= (65536-50000)%256;count++;if (count==10)//Let the temperature refresh every 0.5s {count=0; Lcd1602_showtemp (Ds18b20readtemp ());}}
Designed and produced an automatic temperature control system.