Closed-Loop Temperature Control Using MATLAB@Simulink, Real-Time Toolbox and PIC18F452 Microcontroller

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Closed-Loop Temperature Control Using

MATLAB@Simulink, Real-Time Toolbox


and PIC18F452 Microcontroller

Edin Mujčić, Una Drakulić and Merisa Škrgić

Abstract Today’s way of life is closely linked with technology and it would be
impossible without a microcontrollers. They are represented in all spheres of life: in
the automotive industry, robotics, computer systems, home appliances, etc. Also,
today’s life is unthinkable without computers. The combination of computer and
microcontroller provides a very great possibilities, which uses the good features of
both. This chapter describes the use of a computer in combination with
MATLAB@Simulink, Real-time Toolbox and PIC18F452 microcontroller for
closed-loop temperature control. Control and settings for temperature are in
MATLAB@Simulink and they can be very easily adjusted. Also, all the infor-
mation: the refrence temperature, information from controller and the measured
temperature are available at any time in MATLAB@Simulink and can be processed
and stored. For real-time operation is used Real-time Toolbox. The information is
sent from computer over serial port to PIC18F452 microcontroller. The PIC18F452
microcontroller receives information and processes them. Information from
PIC18F452 microcontroller is amplified using a transistor that works as the switch
and the thyristor which is used to turn on the heater. Turning off thyristor is
automatically passing supply voltage through zero. Temperature measurement is
performed using the temperature sensor LM335. Output signal from the sensor is
amplified by using operational amplifier LM324 and after that sent in PIC18F452
microcontroller. The microcontroller processes information and after that send it
over serial port to computer. In this way the loop of temperature control is closed
using a computer and PIC18F452 microcontroller.

E. Mujčić (&)  U. Drakulić  M. Škrgić


University of Bihać, Bihać, Bosnia and Herzegovina
e-mail: [email protected]

© Springer International Publishing AG 2017 301


M. Hadžikadić and S. Avdaković (eds.), Advanced Technologies, Systems,
and Applications, Lecture Notes in Networks and Systems 3,
DOI 10.1007/978-3-319-47295-9_24
302 E. Mujčić et al.

1 Introduction

Temperature is a fundamental and quantitative physical science size of heat. As


such, it had to first of all get independent, objective measure for accurate quanti-
tative comparisons of the degree heat of object, system or process. Temperature is a
measure of the internal energy of the system, while heat is measure of how energy
transferred from one system to another. MATLAB is a very developed language of
technology that combines low cost, visualization and programming in simple
development environment MATLAB [1, 2]. It contains a collection of predefined
functions that are grouped in tool groups (Toolboxes) intended to solve various
problems from scientific field. MATLAB contains different Toolboxes:
Optimization Toolbox, Neural Network Toolbox, Fuzzy Logic Toolbox, Control
System Toolbox, Signal Processing Toolbox, Statistics Toolbox, Real-time
Toolbox, etc. There are many applications of these tools, but we are focused on
the Real-time Toolbox [3, 4]. Real-time simulation represent the simulation speed
of execution as in the real time, there is no faster or slower than reality. It is based
on the integration of fixed step time, which is specified in microseconds or mil-
liseconds. Simulation time represents simulation real-time display and measured
simulation time in real time which performs simulation. The use of real-time
simulation include [5]:
• Setting up and development of prototype
– Validation algorithm
– Easy and fast implementation
• Testing of industrial equipment
– Interaction generate disorders
– Normal and critical situations
– Analysis of equipment from different manufacturers.
Here is described one practically implemented system for closed-loop temper-
ature control. The described system is realized using the PIC18F452 microcon-
troller from familly 18F Microchip manufacturers. The PIC18F452 microcontroller
has many number of components. PIC microcontroller owns 40 or 44 I/O pins,
which makes it a good choice for the realization of these simple devices.
Main features are: collection of 35 instructions, 1024  14 bits of program
memory flash type, 68  8 bit memory RAM type of data, 64  8 bit memory
EEPROM type of information, 13 I/O lines, 8-bit timer, 4 interrupt sources, pos-
sibility of programming protective bits, using energy saving sleep mode. Practical
realization use standard quartz crystal operating frequency of 4 MHz [6–8].
In this paper is described use of PIC18F452 microcontroller in combination with
software package MATLAB@Simulink and Real-time Toolbox for closed-loop
temperature control.
Closed-Loop Temperature Control Using MATLAB@Simulink … 303

2 Closed-Loop Temperature Control

Temperature is one of the most important and the most common measurement size
in the technique. People are constantly related with temperature: air temperature,
daily temperature changes, seasonal temperature changes, temperature of human
body, temperature coolant in the car, etc. Temperature is a physical value which is
used for expressing the thermal state of a substance. It depends on how much of
internal energy has a certain object with certain weight and pressure. For precise
temperature control is used closed-loop system. It is shown in Fig. 1.
Temperature reference value, desired temperature, is compared with measured
temperature value. Deviation between reference and measured temperature value is
sent in controller. Based on error, controller affects on executive element in order to
reduce this error to zero. Executive element effects on heater, which heats the
object. Temperature is measured with temperature sensor. This size is very small
and need additional amplifier, which is then compared to reference value. Two most
used types of temperature controllers are:
• The controller with direct ON/OFF temperature control
• Proportional controller with width modulated temperature control

2.1 The Controller with Direct ON/OFF


Temperature Control

An ON/OFF controller is the simplest form of temperature control device (see


Fig. 2). Output from the device is either “on” or “off”, with no middle state.
ON/OFF temperature controller switch output only when temperature crosses the
setpoint. For heating control, output is “on” when temperature is below the setpoint,
and “off” above the setpoint. On/off control is usually used where precise control is
not necessary, in systems which can not handle energy’s being turned “on“and
“off“frequently, where mass of system is so great that temperatures change extre-
mely slowly or for a temperature alarm [9].

Fig. 1 Closed-loop temperature control


304 E. Mujčić et al.

Fig. 2 On/off temperature control

2.2 Proportional Controllers with Width-Modulated


ON/OFF Temperature Control

Proportional controls are designed to eliminate cycling associated with on/off


control. Proportional controller decreases average power being supplied to heater as
temperature approaches setpoint (see Fig. 3). This has effect of slowing down
heater, so that it will not overshoot setpoint but will approach setpoint and maintain
stable temperature. This proportioning action can be accomplished by turning
output “on” and “off” for short intervals [9]. Proportioning action occurs within a
“proportional band” around the setpoint temperature. Outside this band, the con-
troller functions as an on/off unit, with the output either fully on (below the band) or
fully off (above the band). Proportional controller decreases the average power
being supplied to heater as temperature approaches setpoint. This has effect of
slowing down heater so that it will not overshoot the setpoint, but will approach
setpoint and maintain a stable temperature. This proportioning action can be
accomplished by turning the output “on” and “off” for short intervals. Time period
between two successive turnons is known as the “cycle time” or “duty cycle”.
Proportioning action occurs within a “proportional band” around the setpoint
temperature. Within the band, the output is turned “on” and “off” in the ratio of the
measurement difference from the setpoint. At the setpoint (the midpoint of the
Closed-Loop Temperature Control Using MATLAB@Simulink … 305

Fig. 3 Proportional controllers with width-modulated ON/OFF temperature control

proportional band), the output on/off ratio is 1:1 [9]. If temperature is below set-
point, output will be “on” longer. If the temperature is too high, output will be “off”
longer. One of the advantages of proportional control is simplicity of operation. It
may require an operator to make a small adjustment (manual reset) to bring the
temperature to setpoint on initial startup, or if process conditions change signifi-
cantly. This proportional controller varies the ratio of “on” to “off” to control
temperature in closed-loop.

3 Closed-Loop Temperature Control Using


MATLAB@Simulink, Real-Time Toolbox
and PIC18F452 Microcontroller

In this section of the chapter is suggested use of programming language


MATLAB@Simulink and PIC18F452 microcontroller for closedloop temperature
control. For real-time operation is used Real-time Toolbox. In Fig. 4 is shown
functional block diagram for closed-loop temperature control.
Datas from computer over serial port and integrated circuit MAX232 are sent in
the PIC18F452 microcontroller. The PIC18F452 microcontroller processes received
data and forward them to output port RB7.
After amplification in power amplifier, which is realized by using transistor and
thyristor, turns on heater that heats the object in which there is the heater. Turning
off the thyristor is automatically when passing the supply voltage heaters through
zero. With the temperature sensor LM335 is measured temperature inside object.
Information of measured temperature is sent to amplifier implemented with the
operational amplifier LM324. The sensor LM335 on its output provides change of
306 E. Mujčić et al.

Fig. 4 Block diagram for temperature control using PIC18F452 microcontroller

10 mV when temperature change for 1 K. It is small signal and for that reason it
must be amplified using the operational ampfier LM324. That amplified signal is
sent in the PIC18F452 microcontroller, i.e. pin RA1. From pin RA1 analog signal is
forwarded in A/D convertor.
In A/D convertor analog voltage value is converted to digital. Digital informa-
tion of measured temperature value, using serial port, is forwarded to computer.
In Fig. 5 is shown appearance of the finished system for closed-loop temperature
control using MATLAB@Simulink, Real-time Toolbox and PIC18F452
microcontroller.

Fig. 5 Appearance of the finished system for closed-loop temperature control


Closed-Loop Temperature Control Using MATLAB@Simulink … 307

In the black box is located heater and temperature sensor, and it is environment
in which temperature is controled. As the box is made of metal, there are also a
large heat loss, which requires more frequent involvement of the heater.
For communication (sending and receiving data) with the PIC18F452 micro-
controller are used the simulink blocks “Packet Input” and “Packet Output” which
are previously set for the serial communication. That is shown in Fig. 6.
Of course, the same set is in the PIC18F452 microcontroller. In Fig. 7 is shown
simulink scheme that is used for temperature control using the PIC18F452
microcontroller. Using Real-time Toolbox is allowed to work in real time. For that
is used Real-Time Windows Target rtwin.tlc. Measured temperature is processed in
PIC18F452 microcontroller and than over serial port is forwarded to block “Packet
Input”. After that, receiving, measured temperature is sent to block “Processing the
measured temperature”. In this block information of temperature is processed and
adjusted for the range in which there is reference temperature value. However, for
room temperature output value from this block is zero and with increasing

Fig. 6 Block “Packet Input” for receiving data using serial port
308 E. Mujčić et al.

Fig. 7 Simulink scheme for closed-loop temperature control using MATLAB@Simulink and
real-time toolbox

Fig. 8 Experimental results obtained using closed-loop temperature control for designed system
Closed-Loop Temperature Control Using MATLAB@Simulink … 309

temperature at the same time that value is also increasing. Than, processed value of
measured temperature in adder is compared with the reference temperature value.
Using, in this case, ON/OFF temperature controller, this value is processed and
sent to block “Packet Output”, and than over serial port is forwarded to PIC18F452
microcontroller and power amplifiers on heater.

4 Experimental Results

In this section of paper are presented experimental results for closed-loop tem-
perature control using MATLAB@Simulink, Real-time Toolbox and the
PIC18F452 microcontroller. It is used ON/OFF temperature controller. Because of
great features of simulink, we can quickly and easily replace ON/OFF temperature
controller with another temperature controller, e.g. the PID controller. Values of
reference temperature is in relative units for easy and precise results presentation.
After experiment analysis we got experimental results as shown in Fig. 8. Based on
Fig. 8, we can conclude that closed-loop temperature control is working properly.
When temperature exceeds set limit heater is turning off, and inversely. Maximum
and minimum temperature value is adjusted within ON/OFF temperature controller.
Error that occur when reading measured temperature occur because of to 8-bit
resolution A/D converter. Taking average temperature value is obtained nearly ideal
value of measured temperature. Temperature reference value can be optionally
seted during work by simply entering another value in block “Reference value of
temperature”. To show temperature value we can use different temperature scales.

5 Conclusion

Based on the experimental result, we can conclude that designed system is working
properly and that can be used to measure temperature in closed loop. If generalize,
we can conclude that combination of MATLAB@Simulink, Real-time Toolbox and
microcontroller can be used on different systems. In this way are used good features
of MATLAB@Simulink for easy adjustment parameters of system as well as good
features of PIC18F microcontroller series. All-important information’s can be
stored and displayed using wide spectrum of tools for graphical processing
information.

References

1. Matlab R (2009) Documentation. The Mathworks


2. Gilat A (2011) MATLAB an introduction with applications, 4th edn. Wiley, New York
310 E. Mujčić et al.

3. Ban Ž, Matuško J, Petrović I (2010) Primjena programskog sustava Matlab za rješavanje


tehničkih problema, Graphis, Zagreb
4. Lent CS (2013) Learning to program with MATLAB. Wiley, New York
5. Real-Time Windows Target User’s guide: for use with real-time workshop, The Mathworks,
version 2, pp 3–33
6. Dogan I (2008) Advanced PIC microcontroller projects in C. Elsevier, Burlington
7. PIC18F42X, Data Sheet, FLASH-Based 8-Bit CMOS Microcontroller, 2003
8. Chartrand L, Huang HW (2005) PIC microconteroller: an introduction to software & hardware
interfacing, Mankato
9. http://www.omega.com/temperature/Z/pdf/z110–114.pdf. 16 Mar 2016

You might also like