You are on page 1of 12

BULETINUL INSTITUTULUI POLITEHNIC DIN IAŞI

Publicat de
Universitatea Tehnică „Gheorghe Asachi” din Iaşi
Tomul LVI (LX), Fasc. 4, 2010
SecŃia
AUTOMATICĂ şi CALCULATOARE

THE DESIGN OF TEMPERATURE CONTROL SYSTEM


USING PIC18F46201
BY

BOGDAN LEVĂRDĂ and CRISTINA BUDACIU

Abstract. Applications that require temperature control are often meet in industry.
In this paper a low cost application for temperature control in a ventilation system using
the PIC18F4620 was designed and developed. Ventilating is the process of changing or
replacing air in any space to control temperature or remove moisture, smoke, dust,
unpleasant smells or bacteria. Ventilation in a test room refers both to the exchange of air
to the outside as well as circulation of air within a room. This study includes real time
temperature control using a PID controller implemented on a microcontroller.
Key words: temperature control, educational low cost application, PID controller,
PIC18F4620.
2000 Mathematics Subject Classification: 93C10, 93C40, 93C83.

1. Introduction

Process control is an efficient expression of improving the operation of


a process, the productivity of a plant, and the quality of products. Nowadays,
the demand for accurate temperature control and air ventilation control has
conquered many of industrial domains such as process heat, alimentary
industry, automotive, industrial spaces or office buildings where the air is
cooled in order to maintain a comfortable environment for its occupants. One of
the most important concerns involved in heat area consist in the desired
temperature fruition and consumption optimization. To fulfill such a challenge
one should promote suitable control strategies. In the last decade extensively
research has been made with respect to temperature control for different types

1
This is an extended version of the paper: Levărdă B. and Budaciu C., Temperature Control
Application for a Ventilation System Using PIC18F6420. Proc. ICSTC 2010, 282−286, 2010.
204 Bogdan Levărdă and Cristina Budaciu

of processes. In the paper [8] the authors propose a fuzzy PID thermal control
system for a casting process and in [6] an indirect adaptive general predictive
temperature control of a class of passive HVAC system is design. Real time
PID control for water heating system using PIC16F887 microcontroller was
designed and implemented as is shown in [2]. The authors propose design
architecture for water temperature control. The study implies both acquisition
and modeling techniques and control strategies based on PID controller.
A mandatory demand to implement the agreeably solution is the model
acquirement which describes the complex behavior of the system. The paper
focuses on the model identification and control of temperature in a test room
designed for a ventilation system. The main reason to derive a low cost
application is that to be suitable for different studies with respect to control
strategies for temperature control or to be of interest for plant design. The goal of
this study is to analyze and develop an educational plant that can be used at
different application laboratory where students study about microcontrollers, data
acquisition, system identification and especially control system design. Plant
implementation can easily be reused by users who are not expert in plant design.
The laboratory architecture proposed in this paper permits to run experiments
while interacting with its components. The control architecture allows for the
users to implement their knowledge of control engineering in an easy way due to
process access by a friendly design. The designed application with PIC18F4620 is
also useful in predictive control research for embedded controller [3]. Moreover,
in recent years, the requirements for the quality of control design in process
increased due to the computing power high complexity [1], [9].
The paper is organized as follows: the second part of the paper presents
the cooling system design and implementation with PIC18F4620. The next
section deals with the data acquisition and model identification. In the third part
of the paper a control system design based on PID controller was developed.
Also, some real time experiments have been performed in order to illustrate the
performances of the implemented controller. Finally some conclusions are given.

2. Low Cost Application for Temperature Using PIC18F4620

Large scales of application are dedicated to control the temperature in a


realistic environment suitable to various needs. In order to obtain the optimum
performance it would be advantageous to provide a temperature control
structure by providing a safer cooling or heating system with better
performances in terms of energy efficiency, flexibility and portability.
Extensively research has been made on heating control because of the necessity
in practical applications [7]. In this paper the idea focuses on a simple process
that could be suitable to educational application in order to illustrate different
control design aspects. Moreover, the designed plant is a low cost application
with components easy of access. The plant consists in a cooler, a resistance, a
Bul. Inst. Polit. Iaşi, t. LVI (LX), f. 4, 2010 205

sensor and a microcontroller that are encapsulated in a small testing room, as is


shown in the Fig. 1. The analog temperature sensor LM335 will offer
information of the current state of degrees at every sampling time.

Fig. 1 − Low cost implementation of the cooling system.

To relieve the performance of the proposed cooling system it is necessary


to increase the test room temperature with an electrical heat resistor made of
nickel. The heat discharge in the small test room will be fixed by limiting the
value of the current with a variable voltage actuator for alternative current. The
function of the cooler will be to decrease the air temperature from the test room.
The microcontroller will send a signal to L298 a H-bridge, who will
command the DC motor of the cooler as is depicted in Fig. 2. In order to adjust
the air temperature to the desired set point, a controller is needed. It is to be
mentioned that the experiment starts from a fixed temperature in the testing
room. The heat resistor is made by nickel and emits a heat quantity in the
environment. To avoid a high temperature degree, the current range of the
resistor is limited by a voltage potentiometer to obtain a 77ºC in the conceived
test room. This part of the system used a 220 V external source. One of the
active elements of the system is the PC cooler. Using the L298 commands, the
motor will spin respecting DC motor speed control strategy. The H Bridge L298
will assure the alimentation for the cooler DC motor. The motor speed is
varying from 950 to 3600 rotation/min offering a maximum 44.3 CMF airflow.
The LM335 analog sensor is a useful transducer for the system. The
sensor operates form -40ºC to 100ºC and in this application is used the plastic
TO-92 packages sensor, considering basic temperature. With one degree
precision and easy to calibrate using a 10 kOhm resistor it offers the actual K
(Kelvin) degrees. The K degree will be converted in Celsius degree, in order to
send the information to the microcontroller.
The proposed development board used in this paper named MDB01
(motherboard) produced by SMTD (Smart Tech Design) was specially
206 Bogdan Levărdă and Cristina Budaciu

designed for application with low cost microcontrollers like Microchip 8 bits
16xxx and 18xxx, with 40 pins, family. This board contains the PIC 18F4620
which can significantly reduce power consumption during operation. The 40
Mhz operating frequency combined with 13 input channels for the 10-bit
Analog-to-Digital Module, 65536 Bytes of Program Memory and 1024 Bytes
for Data EEPROM are a few of the features of 18F4620. The microcontroller
uses a 75 instruction set and 83 extended instruction set enabled. The device
permits enhanced USART Serial Communication and also admits 5 I/O ports
and 4 Timers.
The communication to the computer is made with a USB cable which
adapts the signal to serial communication with a hardware device FT232RL, as
illustrated in [3]. This facility offers the possibility to establish connections with
all modern PC or notebook. MDB01 is equipped with L298 Dual Full Bridge,
providing the command actions. It is a high voltage, high current dual full-
bridge driver designed to accept standard TTL logic levels and drive inductive
loads such as relays, solenoids, DC and stepper motors. Two enable inputs are
provided to enable or disable the device independently of the input signals. In
this application it is used a single input due to one single DC motor. The
emitters of the lower transistors of each bridge are connected together and the
corresponding external terminal can be used for the connection of an external
resistor. An additional supply input is provided so that the logic works at a
lower voltage. A user friendly part of the process is the color LCD S1D15G14
with 98x67 pixels interfaced with 8 bits with 18F4620 which is able to display
in real-time the temperature degree from the sensors.

Fig. 2 − The process scheme.

The developed low cost application is dedicated in order to illustrate


different control strategies for temperature control subject to cooling
Bul. Inst. Polit. Iaşi, t. LVI (LX), f. 4, 2010 207

phenomenon. In the next section, the attention is focused on real time data
acquisition, followed by the open loop model identification.

3. Model Identification and Control Design


for the Cooling System

The study is dedicated to the educational activities in the field of control


system design. The general purpose of the process is to ensure a desired
temperature in a closed loop safety operational functionality and for
understanding the dynamics of a cooling system. The basic information about
the process description is given in section II. The aim of this section is to
illustrate how to acquire real time data from the process, the model identification
and control system methods suitable for air temperature control. The system is
linear, discrete-time and single input-single output. The input signal considered is
the duty cycle of the PWM signal and the output is represented by the air
temperature value measured from the LM335 analog sensor.
The system transfer functions are assumed to be functions in continuous
time domain. Acquisition phase represents an important step in model
identification of the dynamics of the plant that requires accuracy in sending input
commands to the system and precise measurement of the output values. This
involves a perfect timing between the command action and output signal. Data
values, command signal and output offer a great possibility to create a complex or
simplified model for the plant. Communication channels must be synchronized
and safeguards must action to the potential external disturbances. The better
model obtained the greater performance control action is performed. However,
the distribution of the temperature depends on a lot of factors which influences
the type and the parameters of the model. The control action is given by the duty
cycle values of the PWM signal which are applied to the cooling DC motor.
The control command from the microcontroller is given using a MicroC
software application, the code being written in C++. In order to obtain the 12 V
at the DC motor it is mandatory to use a suitable frequency to L298 bridge. The
bridge was used to compensate the PIC18F4620 output voltage which was
limited to 5 V, because the PIC voltage reference is given by the PC USB port.
The L298 bridge can offer the 12 V for maximizing the DC motor performance.
It is to be mentioned that the L298 H-Bridge replaces the standard D/A
converter. After setting the DC motor operation frequency value to 2.44 kHz,
different duty cycle values were tested. In the system identification phase, a step
input from 20% to 90% duty cycle was applied.
In order to acquire a representative data set it was assumed that in the
testing room a 77ºC was settled. At this constant ambient temperature value the
experiments started. First it was applied a command action to the motor at the
20% of the duty cycle for 4 min. In this time the output values of the LM335
sensor were collected each second and saved in the EEPROM memory. This
208 Bogdan Levărdă and Cristina Budaciu

quick memory can record very accurate the A/D sent values. A number of
samples in C degrees were recorded in this time.
Stationary regime is settled in about 4 min, afterwards a new command
is sent by the microcontroller to the L298 bridge. This forces the motor to work
at a 90% duty cycle and the air temperature in the test room decreases. The new
temperature values were recorded after the last output value given by the 20%
duty cycle command. It can be mentioned that the 90% duty cycle command
was applied using 1 second sampling time. The values from the EEPROM
memory were sent to a PC using a USB communication cable and all output
values were saved in a text file. FT232RL interface helps to convert the serial
transmitter of the 18F4620 into a large scale USB interface who acts like a
serial communication channel.
The frequency for the DC cooling motor was tested during the
acquisition stage to set up the pulse width period in the time of the experiments.
After testing how the system works at different PWM frequency a 2.44 kHz was
established. Some tests were made in the test room varying the DC motor
cooling power. The PWM command was observed on the oscilloscope as shown
in Fig.3.

Fig. 3 − Oscilloscope 2.44 kHz PWM.

In order to identify the parametrical model of the cooling process the


Identification Toolbox from Matlab was used. The cooling process can be
described as a continuous process but we can control it as a discrete time system.
For a good description of the process we need to create a model of the process.
The communication of the system with a computer is necessary to
transfer the information from the LM335 sensor to the computer. Using the
USB cable, the voltage values from the sensor were read by the analog to digital
converter at every second and after converting to C degree the information were
send to the PC. To found the model of the plant some relevant information need
to be stored. An open loop response can offer necessary information to build a
real model that can be processed in the Identification Toolbox from Matlab
Bul. Inst. Polit. Iaşi, t. LVI (LX), f. 4, 2010 209

environment. A step will be applied to the system and the output response will
be saved in Matlab workspace. The input for the system can be considered the
duty cycle value of the PWM and will be considered in percent values. Some
different values of the step were applied to the system and the responses are
plotted in the Figs. 4 and 5 .

Fig. 4 − Step response at 50% duty cycle.

From the existing responses the last set of data was used to identify the
continuous time model in Matlab software. In the Identification Toolbox, the
command and the output response was used to create a model.

Fig. 5 − Step response at 90% duty cycle.

Sampling period was also introduced for the model realization.


From Process Models menu one would start to build some simple
models which reflect the dynamic plant. The model obtained is based on
Levenberg Marquardt search method. The Levenberg-Marquardt (LM) algorithm
210 Bogdan Levărdă and Cristina Budaciu

is an iterative technique that locates the minimum of a function that is expressed


as the sum of squares of nonlinear functions. Levenberg-Marquardt (LM)
algorithm is the most widely used optimization algorithm. It outperforms simple
gradient descent and other conjugate gradient methods in a wide variety of
problems [5]. A simple model was found after some simulation tests and the
continuous time mathematical model of first order is:

kf
(1) G f ( s) = e- sL ,
1 + sT f

with the process constant time T f = 45.947 , amplification factor k f = 0.325


and the dead time L = 20.947 measured in samples periods of 1 sec.
In the next paragraph, a PID controller is design with the parameters
tuned based on the experimental methods. The continuous time model (1) is
used in order to create a PID controller.

3. The Control System Design for Temperature Control

In this study a parallel form of a proportional–integral–derivative


controller was implemented. The form of the PID controller in the continuous
time domain is expressed as:

 1 
(2) U(s)=K p ⋅ 1+ +s ⋅ Td  ⋅ E(s) ,
 s ⋅ Ti 

where: E ( s ) is the signal error, U ( s ) − the control input to the process, K p −


the proportional gain, Ti − the integral time constant, Td − the derivative time
constant. The discrete time domain form of the controller became:

 Ts (1-z -1 ) 
(3) U(z)=E(z) ⋅ K p ⋅ 1+ +Td ⋅ ,
 Ti ⋅ (1-z -1 ) Ts 

For the discrete PID, the parameters were calculated with the following
relations:
Kpdiscrete = K p
K p ⋅ Ts
(4) Ti = ,
discrete Ti
K p ⋅ Td
Td discrete =
Ts
Bul. Inst. Polit. Iaşi, t. LVI (LX), f. 4, 2010 211

The realization of the PID controller was based on several experimental


methods: Ziegler-Nichols method based on step response, Chien-Hrones-
Reswick method and the Cohen-Coon method [4]. Using Matlab Simulink
Toolbox the parameters obtained from each method where tested and the best
parameters were used for PID implementation on the microcontroller. The
tunning parameters based on Ziegler-Nichols method are: proportional gain
K p =6.246 , integral time Ti = 61.113 , derivative time Td = 0 . The discrete time
values for sampling period Ts = 1 sec are: Kpdiscrete = 6.246 , Tidiscrete = 0.102 .
These values were tested in a real time application using the microcontroller for
cooling the temperature in the test room from initial condition of 57ºC to a new
reference of 30ºC. Using Chien-Hrones-Reswick method results the following
parameters: proportional gain K p = 2.429 , integral time Ti = 55.136 , derivative
time Td = 0 . The discrete time values using sampling period Ts = 1 sec are:
Kpdiscrete = 2.429 , Tidiscrete = 0.044 . The continuous time parameters from Chien-
Hrones-Reswick method were implemented considering as performances the
zero overshoot and minimum time response.

Fig. 6 − Ziegler-Nichols PI real time response.

In order to get better performances the tuning parameters were slightly


modified such as K p = 5 , and integral time Ti = 40 , resulting the discrete time
values Kpdiscrete = 5 , Tidiscrete = 0.125 .
212 Bogdan Levărdă and Cristina Budaciu

Fig. 7 − Chien-Hrones-Reswick PI reference changing.

With these modified values a new real time temperature control has
been performed, subject to the set point changes.

Fig. 8 − Chien-Hrones-Reswick PI disturbance rejection.

The next experiment starts with a initially temperature of 59ºC in the


test room the reference was settled to 43ºC. A new step value in set point was
set to 30ºC. After the transitory regime the PID controller reach the set point as
is shown in the Fig. 7. The controller is able to reject the load disturbance effect
Bul. Inst. Polit. Iaşi, t. LVI (LX), f. 4, 2010 213

if in the test room the temperature suddenly increased.


The real time experiment demonstrates the fact that the proposed control
system design is able to reject the disturbance, a 120 V voltage on nickel resistor,
the action control compensating the heat quantity as is illustrated in the Fig. 8.

4. Conclusions

In this paper a low cost application for temperature control in a


ventilation system using the PIC18F4620 was designed and developed. The
laboratory architecture proposed in this paper is able to run experiments while
interacting with its components. The control architecture allows for the users to
implement their knowledge of control engineering in an easy way due to
process access by a friendly design. Some PID tuning methods have been tested
and adjustments have been made to the parameters in order to obtain better
performances. The implemented PID controller on PIC18F4620 can offer zero
steady state error even if a load disturbance is introduced in the test room. In the
cases where the plant response is slow, it may be possible to decrease the
processor speed and save power. Future work includes research of some
advanced control strategies and the implementation on this low cost plant,
which may reflect better control actions in terms of small sampling rate.

A c k n o w l e d g e m e n t s. This work was supported by CNCSIS-


UEFISCSU, project number PN II-RU PD cod 331/2010.

Received: November 4, 2010 “Gheorghe Asachi” Technical University of Iaşi,


Department of Automatic Control and
Applied Informatics
e-mail: chalauca@yahoo.com

REFERENCES

1. Bouhenchir H., Cabassud M., Le Lann M., Casamatta V.G., A General Simulation
Model and a Heating–Cooling Strategy to Improve Controllability of Batch
Reactors. Trans IchemE, Part A, 79, 641–654, 2001.
2. Imbrahim D., Microcontroller Based Temperature Monitoring and Control. Newnes,
2002.
3. Kadirkamanathan V., Halauca C., Anderson S., Predictive Control of Fast-Sampled
Systems Using the Delta-Operator. International Journal of Systems Science,
40, 7, 745−756, 2009.
4. Lazăr C., Vrabie D., Carari S., Sisteme automate cu regulatoare PID. Edit.
MatrixRom, Bucureşti, 2004.
5. Manolis I., Lourakis A., A Brief Description of the Levenberg-Marquardt Algorithm
Implemened by Levmar. 2005.
214 Bogdan Levărdă and Cristina Budaciu

6. Rousseau T., Structure Design and Indirect Adaptive General Predictive


Temperature Control of a Class of Passive HVAC. Journal WSEAS
Transactions on Systems and Control, Vol. 3, 6, June 2008.
7. Weijun Y., Xianyi Q., The Constant Temperature Automatic Control System Design
of 3G Base Station without Man’s Guard. Proceedings of 2009 International
Conference on Information Engineering and Computer Science, ICIECS 2009.
8. Yang T., Xiang C., Henry H., A Fuzzy PID Thermal Control for Die Casting
Processes. 22nd IEEE International Symposium on Intelligent Control, 2008.
9. Zhenduo L., Huussen F., Hybrid Model-Based Predictive Control and Proportional-
Integral-Derivative Temperature Control System for LPCVD Processes. 2008.

PROIECTAREA UNUI SISTEM DE REGLARE A TEMPERATURII


AERULUI, UTILIZÂND PIC18F4620

(Rezumat)

În acest studiu s-a proiectat şi implementat o machetă de laborator pentru


controlul temperaturii utilizând microcontroller-ul PIC18F4620. Arhitectura aplicaŃiei
permite realizarea mai multor experimente dedicate conducerii automate a proceselor, în
special reglarea temperaturii aerului într-o cameră de test. Utilizând mediul de
programare MikroC şi limbajul de nivel înalt C, s-a dezvoltat un algoritm pentru
transmiterea şi achiziŃia datelor, date ce ulterior au fost interpretate pentru realizarea
unui model care să descrie cât mai bine dinamica procesului. Pentru reglarea
temperaturii s-au proiectat regulatoare PID utilizând metodele de acordare clasice.
Scopul principal al acestui studiu constă în implementarea şi testarea în timp real a
sistemului proiectat în scop didactic şi de cercetare. Regulatorul de tip PID a fost testat
pentru variaŃia referinŃei-temperatura aerului dorită şi în prezenŃa introducerii unei
perturbaŃii de sarcină. Rezultatele obŃinute scot în evidenŃă rejectarea perturbaŃiei şi
prezenŃa unei erori de regim staŃionar nule.

You might also like