5. chapter 5shodhganga.inflibnet.ac.in/bitstream/10603/24249/10/10... · · 2014-09-03temperature...
TRANSCRIPT
107
CHAPTER 5
DESIGN AND IMPLEMENTATION OF A PIC 16F877A
MICROCONTROLLER FOR PLASTIC EXTRUSION SYSTEM
5.1 REAL TIME HARDWARE MODEL
This chapter presents design and implementation of a complete
temperature control scheme of the plastic extruder incorporating the
embedded neuro fuzzy controller using a PIC 16F877A microcontroller.
The performance of the neuro fuzzy logic based temperature controller
for plastic extruder is investigated experimentally at different
temperature set point conditions. The experimental results show that the
embedded neuro fuzzy controller is more robust and, hence, found to be
a suitable replacement of the conventional controllers for the
temperature control of plastic extruder.
5.2 EMBEDDED SYSTEM
Embedded systems are highly specialized, often reactive sub
systems that provide information processing and control. Embedded
systems are omnipresent nowadays and make possible, the creation of
systems with a functionality that cannot be provided by human beings.
The term embedded system thus encompasses a broad class of systems,
ranging from simple microcontrollers to large and complex multi-
processor and distributed systems.
108
The advent of intelligent programmable embedded design
provides the ability to implement any required hardware programmable
device for the design automation in industries and laboratories.
Laboratory and industrial automation use minimal hardware and
maximum support of software.
The process temperature is accurately controlled without
extensive operator involvement; with the use of a temperature control
relies upon a controller, which accepts a temperature sensor
thermocouple as the input. It compares the actual temperature to the
desired control temperature or set point, and provides an output to a
control element.
Microcontroller is a general purpose device, which integrates a
number of the components on to single chip. It has inbuilt central
processing unit, both read only memory and random access memory,
parallel digital I/O peripherals to make it as a mini computer.
Microcontrollers are available in different configurations, low cost and
compact size with power saving mode and high operating speeds. These
features encourages for implementing conventional and neural fuzzy
logic in an inexpensive microcontroller in the closed loop control
system.
The significant part of embedded system development is the
designing of hardware and software for the specific application. In the
present work PIC 16F877A 8-Bit microcontroller has been used to
implement the control algorithm and having special features like 32K
reprogramming flash memory, 512 bytes of internal RAM, 32
programmable I/O lines and eight interrupt sources. The microcontroller
109
consists of a timer module and an analog to digital converter to accept
analogue input for data processing. To make the data flow between
controllers to other devices the serial I/O port is used.
5.3 INTRODUCTION TO PIC 16F877A CONTROLLER
PIC is a family of Harvard architecture microcontrollers made
by Microchip technology, derived from the PIC1640, originally
developed by the Microelectronics division of General Instrument. The
name PIC initially is referred to Peripheral Interface Controller. PICs are
popular with developers due to their low cost, wide availability, large
user base, extensive collection of application notes, availability of low
cost, free development tools and serial programming (and re-
programming with flash memory) capability.
The microcontroller is from PIC series. PIC microcontroller is
the first reduced instruction set computing based microcontroller
fabricated in complementary metal oxide semiconductor, that uses
separate bus for instruction and data allowing simultaneous access of
program and data memory. The main advantage of CMOS and RISC
combination is low power consumption resulting in a very small chip
size with a small pin count. The main advantage of CMOS is that, it has
immunity to noise than other fabrication techniques.
Microcontrollers offer different kinds of memories. EEPROM,
EPROM, FLASH etc. are some of the memories of which FLASH is the
most recently developed. The technology used in PIC 16F877 is FLASH
technology, so that data is retained even when the power is switched off.
Easy programming and erasing are the other features of PIC 16F877.
110
The heart of the microcontroller is the CPU core. In the past, this has
traditionally been based on an 8-bit microprocessor unit. PIC micro
devices are grouped by the size of the instruction word. The three
current PIC micro families are
Base-line: 12-bit instruction word length
Mid-range:14-bit instruction word length
High-end: 16-bit instruction word length
5.3.1 Characteristics of PIC 16F877A
The PIC controller compared to other controllers is with low
cost. The clock speed of the controllers is high with the rate of 20MHz.
8Kx14 words of FLASH program memory, 368X8 bytes of data
memory (RAM), 256x8 bytes of EEPROM data memory and this is
enough for the temperature control application. At the maximum clock
rate, a PIC executes most of its instructions in 0.2 micro seconds or 5
instructions per microseconds. It has high speed in executing instruction.
The efficiency and accuracy is very high. The instruction set consists of
35 instructions. For executing a program it requires only small steps.
Power on reset and brown out protection ensure that the chip operates
only when the supply voltage is within sections. A watch timer resets
the PIC, if the chip malfunctions and deviates from its normal position.
Any one of the core clock options can be supported including a low cost
RC oscillator and a high accuracy crystal oscillator.
These versatile timers can be characterized by inputs; control
outputs and provide internal timing for program executions. The PIC
microcontroller has a number of inbuilt modules such as analog to
111
digital converter, universal asynchronous transmitter and receiver that
increases versatility of microcontroller. The PIC IC (Integrated Chip) is
having wide operating voltage range from 2.5 to 6V, using power saving
devices with a less power loss.
The PIC start plus development system includes PIC start plus
development programmer and machine perception laboratory. The PIC
start plus programmer gives the product developer the ability to program
user software into any of the supported microcontrollers. The PIC start
plus software running under MP LAB provides full interactive control
over the programmer.
5.3.2 Core Architecture of PIC 16F877A
PIC controller architecture is simple. It is characterized by the
features like using separate code and data spaces. The PIC controller is
with small number of fixed length instructions and most of the
instructions are single cycle execution (4 clock cycles), with single
delay cycles upon branches and skips. The RAM location of PIC
controller function as registers, as both source and destination of math
and other functions. The data space mapped CPU, port, and peripheral
registers in PIC 16F877A microcontroller and the program counter is
mapped.
5.3.3 Data Space and Code Space of PIC 16F877A
PICs have a set of registers that function as general purpose
RAM. Special purpose control registers for on-chip hardware resources
are also mapped into the data space. The addressability of memory
112
varies depending on device series, and all PIC devices have some
banking mechanism to extend the addressing to additional memory.
In other microcontrollers, the register movement is achieved
through the accumulator. External data memory is not directly
addressable. PIC code space is generally implemented as EPROM,
ROM, or FLASH ROM. In general, external code memory is not
directly addressable, due to the lack of an external memory interface.
5.3.4 Stacks of PIC 16F877A
PICs have a hardware call stack, which is used to save return
addresses. The hardware stack is not software accessible on earlier
devices, but this is changed with the updated series devices. Hardware
support for a general purpose parameter stack was lacking in early
series, but this is greatly improved in the updated series, making the
updated series architecture friendlier to high level language compilers.
5.3.5 Performance of PIC 16F877A
The clock speed is 20MHz. The TACQ or acquisition time is
19.2 µs. The architectural decisions are directed at the maximization of
top-end speed, or more precisely of speed to cost ratio. PIC architecture
was among the first scalar CPU designs, and is still among the simplest
and cheapest. The Harvard architecture in which instructions and data
come conveniently from separate sources simplifies timing and
microcircuit design greatly.
113
PIC is particularly suited to the implementation of fast lookup
tables in the program space. The optimization is facilitated by the
relatively large program space of PIC and by the design of the
instruction set, which allows for embedded constants. The simplicity of
PIC, and its scalar nature, also serves to simplify significantly the
construction of real time code. It is typically possible to multiply the line
count of a PIC assembler listing by the instruction cycle time to
determine execution time. The delay is constant even though
instructions can take one or two instruction cycles, a dead cycle is
optionally inserted into the interrupt response sequence to make the
delay. External interrupts have to be synchronized with the four clock
instruction cycle. Internal interrupts are already synchronized.
5.4 NEURO FUZZY CONTROLLER IMPLEMENTATION
The conventional and neuro fuzzy controllers are simulated in
MATLAB/Simulink. The neuro fuzzy logic controllers have shown
excellent results in MATLAB/Simulink, especially when used with
nonlinear control systems. The Figure 5.1 shows the block diagram of
the temperature control of the plastic extruder. The temperature sensing
device senses the temperature and amplifier increases the signal. The
amplified signal is converted to digital signal given as the input to the
microcontroller and compared to the set point temperature. The error
signal drives the driver and the heater turns on or turns off. Figure 5.2
shows the photograph of the two stage plastic extruder with gear setup.
The photograph of the plastic extruder is with two stage heaters, gear
setup and an induction motor. Thermocouples are attached with the
heater and sensing the temperature. Microcontroller produces control
114
signal to the heater depends on the error signal. The circuit diagram for
the PIC 16F877A controller based temperature controller model for the
plastic extruder is shown in Figure 5.3.
Figure 5.1 Block Diagram of the PIC 16F877A Temperature
Controller for the Plastic Extruder
Figure 5.2 Photograph of the Two Stage Plastic Extruder with Gear
Setup
115
Figure 5.3 Circuit Diagram for the PIC 16F877A Temperature
Controller for the Plastic Extruder
5.4.1 Power Supply
The power supply circuits are built using rectifiers, filters and
voltage regulators. Starting with an ac voltage, a steady dc voltage is
obtained by rectifying the ac voltage after filtered to a dc level and
finally regulated to obtain a desired fixed dc voltage. The regulation is
116
usually obtained from an IC voltage regulator unit, which takes dc
voltage and provides sufficient lower dc voltage, which remains the
same even if the input dc voltage varies, or the output load connected to
the dc voltage changes.
The ac voltage, typically 120 V rms, is connected to a
transformer, which steps the ac voltage down to the level for the desired
dc output. A diode rectifier then provides a full-wave rectified voltage
that is initially filtered by a simple capacitor filter and smoothing of dc
voltage. This resulting dc voltage usually has some harmonics.
A regulator circuit is used for this dc input to provide a dc
voltage that has not only much less ripple voltage but also remains the
same dc value even if the input dc voltage varies to some extent, or the
load connected to the output dc voltage changes. This voltage regulation
is usually obtained using one of the popular voltage regulator IC units.
Voltage regulators comprise a class of widely used integrated
circuit. Regulator IC units contain the circuitry for reference source,
comparator amplifier, control device, and overload protection all in a
single IC. The internal construction of the IC is different from that
described for discrete voltage regulator circuits; the external operation is
mostly the same. IC units provide regulation of either a fixed positive
voltage, a fixed negative voltage, or an adjustable set voltage. The
regulators can be selected for operation with load currents from
hundreds of milli Amperes to tens of Amperes, corresponding to power
ratings from milli watts to tens of watts.
117
5.4.2 Thermocouple
The temperature sensor used for the measurement is J type
thermocouple. A practical thermocouple consists of two wires of
dissimilar metals that are electrically joined. Thermoelectric voltage is
produced by the temperature gradient along the thermocouple wires. A
thermocouple is a junction between two different metals that produces a
voltage related to a temperature difference. Thermocouples are a widely
used type of temperature sensor for measurement and control and can
also be used to convert heat gradient into electricity.
They are inexpensive and interchangeable and are supplied
along with standard connectors that can measure a wide range of
temperatures. Thermocouple output signals are typically in the millivolt
range and generally have a very low temperature to voltage sensitivity.
Two temperature sensors used here is J type thermocouple.
Thermocouples are still the cheapest method for measuring high
temperatures, and accuracy of even ±5 Degree Celsius is often not a
problem when measuring temperatures greater than several hundred
Degree Celsius.
Junction of dissimilar metals will produce an electric potential
related to temperature. Thermocouples for practical measurement of
temperature are junctions of specific alloys which have a predictable and
repeatable relationship between temperature and voltage.
Thermocouples are widely used in industry; applications include
temperature measurement for kilns, gas turbine exhaust, diesel engines,
and other industrial processes.
118
The conductor is subjected to a thermal gradient. It will
generate a voltage known as the thermoelectric effect or Seebeck effect.
Using a dissimilar metal to complete the circuit creates a circuit in
which the two legs generate different voltages, leaving a small
difference in voltage available for measurement. That difference
increases with temperature, and is between 1 and 70 microvolt’s per
Degree Celsius (µV/°C) for standard metal combinations.
For typical metals used in thermocouples, the output voltage
increases almost linearly with the temperature difference (∆T) over a
bounded range of temperatures. For precise measurements or
measurements outside of the linear temperature range, non-linearity
must be corrected. The nonlinear relationship between the temperature
difference (∆T) and the output voltage (mV) of a thermocouple can be
calculated by a polynomial shown in Equation (5.1)
N
n n
n 0
T a U=
∆ =∑ (5.1)
The coefficients are given for n from 0 to between 5 and 13
depending upon the metals. In some cases, better accuracy is obtained
with additional non polynomial terms. In modern equipment the
equation is usually implemented in a digital controller or stored in a look
up table and older devices use analog circuits.
Type K (chromel{90 percent nickel and 10 percent
chromium}–calomel)(Calomel consisting of 95% nickel, 2%
manganese, 2% Aluminum and 1% silicon) is the most common general
purpose thermocouple with a sensitivity of approximately 41 µV/°C,
119
chromel positive relative to calomel. It is inexpensive, and a wide
variety of probes, available in its −200 °C to +1350 °C / -328 °F to
+2462 °F range. Type K was specified at a time when metallurgy was
less advanced than it is today, and consequently characteristics may vary
considerably between samples. One of the constituent metals is nickel.
The characteristics of thermocouples made with magnetic
material are that they undergo a step change in output, when the
magnetic material reaches its Curie point. Type E (chromel–constantan)
has a high output (68 µV/°C) which makes it well suited to cryogenic
use. Additionally, it is non-magnetic. Type J (iron–constantan) has a
more restricted range than type K (−40 to +750 °C), but higher
sensitivity of about 55 µV/°C. The Curie point of the iron (770 °C)
causes an abrupt change in the characteristics, which determines the
upper temperature limit.
The temperature range of J type Thermocouple is 0°C To 724°C.
The temperature range of K type Thermocouple 0°C To 1260°C. Both
types are producing same accuracy output. The experimental set up is
using J type thermocouple. Cost of J and K type thermocouples are
same. The temperature used in the research work is 70°C to 200°C. So, J
type Thermocouple is chosen for the research work.
5.4.3 Ultra Offset Operational Amplifier
The sensor output is very low voltage and amplified for data
acquisition. The amplification is achieved through the ultra offset
operational inverting amplifier. This is achieved using Op07 amplifier.
Figure 5.4 shows the circuit diagram of the operational amplifier. The
120
OP07 has very low input offset voltage (75 µV max for OP07E) that is
obtained by trimming at the wafer stage. The OP07 also features low
input bias current (±4nA for the OP07E) and high open-loop gain (200
V/mV for the OP07E). Figure 5.5 shows the photograph of the
temperature sensing and operational amplifier.
Figure 5.4 Circuit Diagram of the Operational Amplifier
121
Figure 5.5 Photograph of the Temperature Sensing and
Operational Amplifier
5.5 CIRCUIT OPERATION
The temperature measurement by the thermocouple is
amplified and converted to digital signal using analog to digital
converter. The amplified and converted output is given as input to the
port A pin of PIC16F877A microcontroller. The microcontroller
PIC16F877A set point temperature is compared with the measured
value. The microcontroller has inbuilt ADC. This converts analog signal
to 8/10 bit digital signal.
According to the error, the control signal is generated and
controls the respective driver. The driver actuates the respective heater.
The relay is connected to the microcontroller, so the heater switching
can be controlled. The relay is not connected directly to the
122
microcontroller because the outputs are not sufficient to drive, so, relay
driver is used.
The driver is used as the control actuating device for the
heater. The relay with 12V is used, that cannot be controlled by the
microcontroller directly. Upper limit of normal 2003 (14pin dual inline
package) relay driver IC is used to drive relay. The keypad is used to set
the temperature values. The rating of the heater is with 1.0KW. The real
time implementation takes two reference set point temperatures 70oC,
100oC for the plastic extrusion model.
Push button switch is used as the keypad and with the pull up
resistors (10 Kilo Ohms) the switch is connected to the microcontroller.
When the button is pressed the port is pulled down and pin to 0v or
ground. The liquid crystal display is interfaced with the microcontroller
and act as a display element.
The display is used to know the set point and current
temperature values. LCD control pins such as E, RS and RW are
connected to microcontroller, so the controlling data displays the status
of the LCD. PIC controller is interfaced with LCD through the 8 bit
mode. Figure 5.6 shows the photograph of the temperature controller set
up for plastic extruder. Figure 5.7 shows the photograph of embedded
controller setup.
123
Figure 5.6 Photograph of the Temperature Controller Set Up For
Plastic Extruder
Figure 5.7 Photograph of Embedded Controller
124
5.6 RELAY DRIVER CIRCUIT
The ULN2803A is a monolithic high voltage, high current
Darlington transistor array. The device consists of eight NPN Darlington
pairs that feature high voltage outputs with common cathode clamp
diodes for switching inductive loads. The collector current rating of each
Darlington pair is 500 mA.
ULN2803 is an integrated circuit chip with eight Darlington
pair. So 8 relay can be derived. Relay driver IC (ULN2803) is used to
drive relay, since the output voltage from microcontroller will be 5V and
source & sink current will be only 25mA and that is not sufficient to
drive relay. The output from relay driver was about 12V and the
collector current rating is about 500mA that is sufficient to drive the
relay.
The Darlington pairs are parallelly connected for higher
current capability. They are used for relay drivers, hammer drivers, lamp
drivers, display drivers, line drivers, and logic buffers. The ULN2803A
has a 2.7 Kilo Ohms series base resistor for each Darlington pair for
operation directly with TTL or 5-V CMOS devices. The ULN2803A is
packed in a standard 18-pin dual in-line (N) package. The driver is used
as the control actuating device for the heater.
5.7 INTERFACE HARDWARE TO PIC16F877A
The HD44780-LCD display (16x2) used for the displaying the
characters. The data transmitted in either two 4 bit operations or one 8
125
bit operation, thus allowing interfacing with 4 or 8 bit MCUs. The
display interfaced in 4 bit mode using (D4-D7) data pins and RS, R/W,
EN were the control pins used to control the display to initialize and
write the data over the display. EN pin used to enable the LCD to
initialize and write the data over RAM or to read internal register such
as busy flag. The register selects RS used to select instruction register or
data register.
5.8 MPLAB SOFTWARE AND APPRAISAL
The neuro fuzzy temperature controller for the plastic extruder
using embedded microcontroller is implemented through the PIC
16F877A microcontroller. The control algorithm has been written in
Hi Tech C code in MPLAB software. After developing the application
program, it has been downloaded to selected target machine.
5.8.1 Implementation Steps
• Initially ports of 16F877A are configured using TRIS registers.
This is to choose I/O pins and analog input pins.
• The ADC is configured for using internal clock as source for
conversion. Two analog inputs are given to A/D converter of
microcontroller.
• Sampled digital data read from ADRESH, ADRES registers.
• T1 and T2 temperature set through the keyboard.
126
• The measured temperature compared with the set value. Depend
upon the difference the relay is on or off the heater. Precision of
the temperature control is high because of 8bit digital output with
low acquisition time.
The set points temperatures 70oC, 100
oC are applied for the
experimental setup. Relay method is used for controlling the operation
of the heater. The performance of the developed embedded conventional
and neuro fuzzy control system has been tested experimentally to
regulate the temperature of a plastic extrusion system.
The temperature control system is built and tested to evaluate
the performance of a novel neuro fuzzy logic control algorithm. From
the experimental results, it has been seen that the controller performance
is superior to the already existing controllers. The neuro fuzzy controller
violates the values beyond boundary and limits the set point. The
controller is programmed for define set of values and attains the set
point temperature quickly; damping ratio is very less and closing to the
MATLAB/Simulink results. The experimental results show the
controller algorithm regulates the temperature without any overshoot,
unlike the conventional controllers. The experimental results for the
neuro fuzzy controller are shown in Figure 5.8.
The MATLAB/Simulink and experimental results are similar
to each other. This means the model of the plastic extruder behaves
similar to the real plastic extruder. Naturally, the experimental graphical
results are not as smooth as the MATLAB/Simulink graphical results.
Two set point temperatures are applied as 70oC, 100
oC settling
127
temperature for experimental results. Relay method neuro fuzzy
controller enables the best performance with time domain specifications.
In hardware relay method, neuro fuzzy controller gives the best response
among all the controllers for both MATLAB/Simulink and experiments.
Figure 5.8 Experimental Results for the Neuro Fuzzy
Controller
5.9 ENCAPSULATION
In this chapter, a temperature controller for a plastic extruder
using a digital controller has been developed and implemented. The
controller employs neuro fuzzy logic digital temperature controller. The
128
experimental hardware results are composed with the
MATLAB/Simulink results.
Experimental results in this chapter show that the temperature
control for the various temperature set points can be achieved
effectively. From the results, it is shown that almost perfect temperature
control can be achieved at the different temperature set points. The
transient is not present in both the hardware and MATLAB/Simulink,
and should also influence the temperature control on the set point
temperatures.
It is concluded that digital neuro fuzzy controllers are effective
in dealing with the highly nonlinear characteristics of the temperature
control for the plastic extrusion system. The hardware significantly
decreases at runtimes. The controller provides a quick, accurate set point
tracking with reference temperature. For the different temperature set
points the hardware results data are close to the MATLAB/Simulink
results. The hardware neuro fuzzy controller relay method gives the best
response among all the controllers in experiments.