PROJECT REPORT ON MICRO CONTROLLER BASED by xiuliliaofz

VIEWS: 130 PAGES: 35

									                         PROJECT REPORT
                                    ON

    MICRO CONTROLLER BASED
    TEMPERATURE CONTROLLER



                           Under the guidance of
                              G.SWAPNA
  Assistant Professor in Department of Electrical & Electronics Engineering




      Department of Electrical & Electronics Engineering
GOKARAJU RANGARAJU INSTITUTE OF
  ENGINEERING & TECHNOLOGY
             BACHUPALLY, HYDERABAD – 500 090
     (Affiliated to Jawaharlal Nehru Technological University)
                               2011 – 2012
                          PROJECT REPORT
                                   ON

         MICRO CONTROLLER BASED
        TEMPERATURE CONTROLLER




                           SUBMITTED BY



1.    M.SURYA KANTH                           08241A02A8

2.    K.MAYUR KARTHIK                         08241A0276

3.    K.MADAN RAJU                            08241A0287

4.    G.MANOJ KUMAR                           08241A0275




          Department of Electrical & Electronics Engineering
     GOKARAJU RANGARAJU INSTITUTE OF
       ENGINEERING & TECHNOLOGY
               BACHUPALLY, HYDERABAD – 500 090
         (Affiliated to Jawaharlal Nehru Technological University)
                               2011 – 2012
                                PROJECT REPORT
                                           ON

               MICRO CONTROLLER BASED
               TEMPERATURE CONTROLLER

                               CERTIFICATE

             This is to certify that this mini project report entitled “MICRO

CONTROLLER BASED TEMPERATURE CONTROLLER” is the bonafied work

of the following students carried out the project under my supervision.


1.    M.SURYA KANTH                                    08241A02A8

2.    K.MAYUR KARTHIK                                  08241A0276

3.    K.MADAN RAJU                                     08241A0287

4.    G.MANOJ KUMAR                                    08241A0275



                   Submitted in partial fulfillment of the
              requirements of Bachelor Of Technology in
                 Electrical and Electronics Engineering
Guide:
Sri M. CHAKRAVARTHY                      Prof P. M. SHARMA
Associate Professor                      Head of Department
Department of Electrical & Electronics   Department of Electrical & Electronics
GRIET, Bachupally                        GRIET, Bachupally
Hyderabad – 500 090.                     Hyderabad – 500 090.
                         ACKNOWLEDGMENT

      We have great pleasure to convey our gratitude to Prof. Jandhyala N
Murthy, Principal, Gokaraju Rangaraju Institute of Engineering & Technology for
permitting to do the mini project.
      We express our heartiest gratitude and respectful regards to Prof. P. M.
Sharma, Head of the Department of EEE, Gokaraju Rangaraju Institute of
Engineering and Technology for his support and encouragement while doing the
mini project.
      We express our profound sense of gratitude to our internal guide Sri. M.
CHAKRAVARTHY, Associate Professor of EEE department for his valuable
guidance, constructive criticism and consistent enthusiastic interest during the
course of investigation and writing of manuscript that led this work to its
successful completion.
      We regard our sincere thanks to the technical staff that helped us during the
project and made our project successful.
      Last but not the least our special thanks to our Parents and friends for their
support and constant encouragement during the project work



                                                                  M. Suryakanth,

                                                               K. Mayur Karthik,

                                                                 K.Madan Raju,

                                                                G. Manoj Kumar,
  Project Report on
Microcontroller Based
Temperature controller
                     CONTENTS




1. INTRODUCTION

2. FLOW CHART

3. BLOCK DIAGRAM AND EXPLANATION

4. CIRCUIT DIAGRAM

5. HARDWARE DESCRIPTION

     MICROCONTROLLER UNIT
     PID CONTROLLER
     ADC0804

6. SOFTWARE

7. COMPONENTS REQUIRED

8. BIBLIOGRAPHY
                             1. INTRODUCTION



The aim of the project is to design a temperature controller using 8051
microcontroller. It is used in a variety of applications like temperature control of
rooms using equipments like Air conditioners , industrial process temperature
control in medical and other industries.

ELEMENTS OF THE PROJECT:

The project uses the following elements.

   1.   8051 based microcontroller AT89S52
   2.   LM35 temperature sensor
   3.   Analog to Digital converter ADC0804
   4.   Zero crossing reference circuit of the AC line voltage

DESCRIPTION:

The temperature is sensed through the LM35 sensor. The output of the sensor is
converted to voltage and given to A/D converter ADC0804.The voltage equivalent
of temperature is read into the microcontroller through one of its port from the
ADC. The temperature difference is calculated and the error is calculated. This
error is sent to the PID controller algorithm. This algorithm calculates the
necessary firing angle required for controlling the temperature and sent out through
one of its port
 2. FLOWCHART


          Start




      Temperature
 acquisition from LM35
        and ADC


Calculating the firing
angle based on PID
algorithm and zero
crossing reference




 output the pulses
 through pin P2.3




     wait for some time
       giving pulses




              Is
No                      Yes
      the temperature
            set?
       3. BLOCK DIAGRAM




                           LM35
   MICRO
 CONTROLLER
  (AT89C51)               OUTPUT
                          PULSES




   +5V
   UNIT

POWER SUPPLY
4. CIRCUIT DIAGRAM
                    5. HARDWARE DESCRIPTION



                   AT89C51 microcontroller

Introduction:
                     The AT89C51 is a low-power, high-performance CMOS 8-bit
microcomputer with 4K bytes of Flash programmable and erasable read only
memory (PEROM). The device is manufactured using Atmel’s high-denity
nonvolatile memory technology and is compatible with the industry-standard
MCS-51 instruction set and pinout. The on-chip Flash allows the program memory
to be reprogrammed in-system or by a conventional nonvolatile memory
programmer. By combining a versatile 8-bit CPU with Flash on a monolithic chip,
the Atmel AT89C51 is a powerful microcomputer which provides a highly-
flexible and cost-effective solution.
Pin diagram:
Pin description:
Pin No                               Function                                       Name
  1                                                                                  P1.0
  2                                                                                  P1.1
  3                                                                                  P1.2
  4                                                                                  P1.3
                          8 bit input/output port (P1) pins
  5                                                                                  P1.4
  6                                                                                  P1.5
  7                                                                                  P1.6
  8                                                                                  P1.7
  9                            Reset pin; Active high                               Reset
            Input (receiver) for serial
 10                                                RxD                               P3.0
                  communication
          Output (transmitter) for serial
 11                                                 TxD                              P3.1
                  communication
 12            External interrupt 1                 Int0      8 bit input/output     P3.2
 13            External interrupt 2                 Int1        port (P3) pins       P3.3
 14           Timer1 external input                  T0                              P3.4
 15           Timer2 external input                  T1                              P3.5
 16       Write to external data memory            Write                             P3.6
 17      Read from external data memory            Read                              P3.7
 18                                                                                Crystal 2
                      Quartz crystal oscillator (up to 24 MHz)
 19                                                                                Crystal 1
 20                                Ground (0V)                                     Ground
 21                                                                                 P2.0/ A8
 22                                                                                 P2.1/ A9
 23                      8 bit input/output port (P2) pins                         P2.2/ A10
 24                                      /                                         P2.3/ A11
 25       High-order address bits when interfacing with external memory            P2.4/ A12
 26                                                                                P2.5/ A13
 27                                                                                P2.6/ A14
 28                                                                                P2.7/ A15
 29        Program store enable; Read from external program memory                  PSEN
                            Address Latch Enable                                     ALE
 30
                 Program pulse input during Flash programming                        Prog
          External Access Enable; Vcc for internal program executions                 EA
 31
          Programming enable voltage; 12V (during Flash programming)                 Vpp
 32                                                                                P0.7/ AD7
 33                                                                                P0.6/ AD6
 34                       8 bit input/output port (P0) pins                        P0.5/ AD5
 35                                                                                P0.4/ AD4
 36       Low-order address bits when interfacing with external memory             P0.3/ AD3
 37                                                                                P0.2/ AD2
 38                                                                                P0.1/ AD1
 39                                                                                P0.0/ AD0
 40                       Supply voltage; 5V (up to 6.6V)                            Vcc
Block diagram:


         The block diagram of 8051micontroller is shown here:
Pin Description:
Port 0

Port 0 is an 8-bit open-drain bi-directional I/O port. As an output port, each pin can
sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as
high impedance inputs.
Port 0 may also be configured to be the multiplexed loworder address/data bus
during accesses to external program and data memory. In this mode P0 has internal
pullups.
Port 0 also receives the code bytes during Flash programming, and outputs the
code bytes during program verification. External pullups are required during
program verification.

Port 1:

Port 1 is an 8-bit bi-directional I/O port with internal pullups. T he Port 1 output
buffers can sink/source four TTL inputs.
When 1s are written to Port 1 pins they are pulled high by the internal pullups
and can be used as inputs. As inputs, Port 1 pins that are externally being pulled
low will source current (IIL) because of the internal pullups.
Port 1 also receives the low-order address bytes during Flash programming and
verification.

Port 2

Port 2 is an 8-bit bi-directional I/O port with internal pull-ups . The Port 2 output
buffers can sink/source four TTL inputs.When 1s are written to Port 2 pins they
are pulled high by the internal pullups and can be used as inputs. As inputs,
Port 2 pins that are externally being pulled low will source current (IIL) because of
the internal pullups.
Port 2 emits the high-order address byte during fetches from external program
memory and during accesses to external data memory that use 16-bit addresses
(MOVX @ DPTR). In this application, it uses strong internal pull-ups when
emitting 1s. During accesses to external data memory that use 8-bit addresses
(MOVX @ RI), Port 2 emits the contents of the P2 Special Function
Register. Port 2 also receives the high-order address bits and some
control signals during Flash programming and verification.

Port 3
Port 3 is an 8-bit bi-directional I/O port with internal pullups. The Port 3 output
buffers can sink/source four TTL inputs.When 1s are written to Port 3 pins they are
pulled high by the internal pullups and can be used as inputs. As inputs, Port 3 pins
that are externally being pulled low will source current (IIL) because of the
pullups.
Port 3 also serves the functions of various special features of the AT89C51 as
listed below:

Port Pin Alternate Functions

P3.0    RXD (serial input port)
P3.1    TXD (serial output port)
P3.2   INT0 (external interrupt 0)
P3.3    INT1 (external interrupt 1)
P3.4    T0 (timer 0 external input)
P3.5    T1 (timer 1 external input)
P3.6    WR (external data memory write strobe)
P3.7    RD (external data memory read strobe)


Port 3 also receives some control signals for Flash programming and verification.

RST
Reset input. A high on this pin for two machine cycles while the oscillator is
running resets the device.

ALE/PROG
Address Latch Enable output pulse for latching the low byte of the address during
accesses to external memory. This pin is also the program pulse input (PROG)
during Flash programming.In normal operation ALE is emitted at a constant rate of
1/6 th the oscillator frequency, and may be used for external timing or clocking
purpose.However one ALE pulse is skipped during each access to external Data
Memory. If desired, ALE operation can be disabled by setting bit 0 of SFR
location 8EH. With the bit set, ALE is active only during a MOVX or MOVC
instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit
has no effect if the microcontroller is in external execution mode.


PSEN
Program Store Enable is the read strobe to external program memory.When the
AT89C51 is executing code from external program memory, PSEN is activated
twice each machine cycle, except that two PSEN activations are skipped during
each access to external data memory.

EA/VPP
External Access Enable. EA must be strapped to GND in order to enable the device
to fetch code from external program memory locations starting at 0000H up to
FFFFH. Note, however, that if lock bit 1 is programmed, EA will be internally
latched on reset.EA should be strapped to VCC for internal program
executions.This pin also receives the 12-volt programming enable voltage(VPP)
during Flash programming, for parts that require 12-volt VPP.

XTAL1
Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.

XTAL2
Output from the inverting oscillator amplifier.

Oscillator Characteristics
XTAL1 and XTAL2 are the input and output, respectively, of an inverting
amplifier which can be configured for use as on-chip oscillator, as shown in
Figure 1. Either a quartz crystal or ceramic resonator may be used. To drive the
device from an external clock source, XTAL2 should be left unconnected while
XTAL1 is driven as shown in Figure 2. There are no requirements on the duty
cycle of the external clock signal, since the input to the internal clocking
circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage
high and low time specifications must be observed.

Idle Mode
In idle mode, the CPU puts itself to sleep while all the onchip peripherals remain
active. The mode is invoked by software. The content of the on-chip RAM and all
the special functions registers remain unchanged during this mode. The idle mode
can be terminated by any enabled interrupt or by a hardware reset. It should be
noted that when idle is terminated by a hard ware reset, the device normally
resumes program execution, from where it left off, up to two machine cycles
before the internal reset algorithm takes control.

XTAL oscillator connection:
Note:

        C1, C2 = 30 pF ± 10 pF for Crystals
               = 40 pF ± 10 pF for Ceramic Resonators

Power-down Mode
In the power-down mode, the oscillator is stopped, and the instruction that invokes
power-down is the last instruction executed. The on-chip RAM and Special
Function Registers retain their values until the power-down mode is
terminated. The only exit from power-down is a hardware reset. Reset redefines
the SFRs but does not change the on-chip RAM. The reset should not be activated
before VCC is restored to its normal operating level and must be held active long
enough to allow the oscillator to restart and stabilize.

Ratings

 Under steady state (non-transient) conditions, IOL must be externally limited as
follows:

          Maximum IOL per port pin:      10 mA
          Maximum IOL per 8-bit port:
                          Port 0:        26 mA
                          Ports 1, 2, 3: 15 mA
          Maximum total IOL for all
                          output pins: 71 mA

          Minimum VCC for Power-down is 2V.


PID CONTROLLER
A proportional–integral–derivative controller is a generic control loop feedback
mechanism controller widely used in industrial control systems – a PID is the most
commonly used feedback controller. A PID controller calculates an "error" value
as the difference between a measured process variable and a desired setpoint. The
controller attempts to minimize the error by adjusting the process control inputs.

The PID controller algorithm involves three separate constant parameters, and is
accordingly sometimes called three-term control:

   1. The Proportional term , P
   2. The Integral term , I and
   3. The Derivative term , D

    Heuristically, these values can be interpreted in terms of time:

      P depends on the present error,
      I on the accumulation of past errors, and
      D is a prediction of future errors, based on current rate of change.
The weighted sum of these three actions is used to adjust the process via a control
element such as the position of a control valve or the power supply of a heating
element.

In the absence of knowledge of the underlying process, a PID controller is the best
controller . By tuning the three parameters in the PID controller algorithm, the
controller can provide control action designed for specific process requirements.
The response of the controller can be described in terms of the responsiveness of
the controller to an error, the degree to which the controller overshoots the set
point and the degree of system oscillation.

Some applications may require using only one or two actions to provide the
appropriate system control. This is achieved by setting the other parameters to
zero. A PID controller will be called a PI, PD, P or I controller in the absence of
the respective control actions. PI controllers are fairly common, since derivative
action is sensitive to measurement noise, whereas the absence of an integral term
may prevent the system from reaching its target value due to the control action.
The PID control scheme is named after its three correcting terms, whose sum
constitutes the manipulated variable . The proportional, integral, and derivative
terms are summed to calculate the output of the PID controller. Defining u(t) as the
controller output, the final form of the PID algorithm is:




where

        Kp: Proportional gain, a tuning parameter
        Ki: Integral gain, a tuning parameter
        Kd: Derivative gain, a tuning parameter
        e: Error = SP − PV
        t: Time or instantaneous time

Proportional term

The proportional term makes a change to the output that is proportional to the
current error value. The proportional response can be adjusted by multiplying the
error by a constant Kp, called the proportional gain.

The proportional term is given by:
           Plot of PV vs time, for three values of Kp (Ki and Kd held constant)

A high proportional gain results in a large change in the output for a given change
in the error. If the proportional gain is too high, the system can become unstable .In
contrast, a small gain results in a small output response to a large input error, and a
less responsive or less sensitive controller. If the proportional gain is too low, the
control action may be too small when responding to system disturbances. Tuning
theory and industrial practice indicate that the proportional term should contribute
the bulk of the output change.

A pure proportional controller will not always settle at its target value, but may
retain a steady-state error. Specifically, drift in the absence of control, such as
cooling of a furnace towards room temperature, biases a pure proportional
controller. If the drift is downwards, as in cooling, then the bias will be below the
set point, hence the term "droop".

Droop is an inherent defect of purely proportional control. Droop may be mitigated
by adding a compensating bias term or corrected by adding an integral term.

Integral term

The contribution from the integral term is proportional to both the magnitude of the
error and the duration of the error. The integral in a PID controller is the sum of the
instantaneous error over time and gives the accumulated offset that should have
been corrected previously. The accumulated error is then multiplied by the integral
gain (Ki) and added to the controller output.
The integral term is given by:




           Plot of PV vs time, for three values of Ki (Kp and Kd held constant)

The integral term accelerates the movement of the process towards setpoint and
eliminates the residual steady-state error that occurs with a pure proportional
controller. However, since the integral term responds to accumulated errors from
the past, it can cause the present value to overshoot the setpoint value.

Derivative term

The derivative of the process error is calculated by determining the slope of the
error over time and multiplying this rate of change by the derivative gain Kd. The
magnitude of the contribution of the derivative term to the overall control action is
termed the derivative gain, Kd.

The derivative term is given by:
The derivative term slows the rate of change of the controller output. Derivative
control is used to reduce the magnitude of the overshoot produced by the integral
component and improve the combined controller-process stability.




             Plot of PV vs time, for three values of Kd (Kp and Ki held constant)

However, the derivative term slows the transient response of the controller. Also,
differentiation of a signal amplifies noise and thus this term in the controller is
highly sensitive to noise in the error term, and can cause a process to become
unstable if the noise and the derivative gain are sufficiently large. Hence an
approximation to a differentiator with a limited bandwidth is more commonly
used.

Stability

If the PID controller parameters i.e. the gains of the proportional, integral and
derivative terms are chosen incorrectly, the controlled process input can be
unstable, i.e. its output diverges, with or without oscillation, and is limited only by
saturation or mechanical breakage.So the parameters are tuned for a given system
and these parameters are used for the controller.

PID controller implementation in this project :-

   1. The set value(SV) is programmed in the microcontroller program and the
      temperature of the device i.e. current value(CV) of temperature is sensed
      using temperature sensor LM35 and sent into the microcontroller.
   2. The error value is generated as per the relation
                 Error Value(EV)=Set value (SV) – Current value (CV)

   3. The tuned parameters of the PID controller are loaded in the program i.e.,
      Kp,Kd,Ki values.
   4. The controller,then calculates the proportional ,integral and derivative terms
   5. At each stage of the terms,the saturation conditions are checked.
   6. The output of the controller is used to generate the firing pulses to the
      switching device say triac or mosfets,which controls the power input to the
      device ,thus controlling the temperature of the device.



                                   ADC0804
Description:

  The ADC0804 is CMOS 8-Bit, successive-approximation A/D converter which
use a modified potentiometric ladder and are designed to operate with the 8080A
control bus via three-state outputs. These converters appear to the processor as
memory locations or I/O ports, and hence no interfacing logic is required.
The differential analog voltage input has good commonmode- rejection and
permits offsetting the analog zero-inputvoltage value. In addition, the voltage
reference input can be adjusted to allow encoding any smaller analog voltage span
to the full 8 bits of resolution.

Features:

       Conversion Time < 100 us

           Easy Interface to Most Microprocessors

           Will Operate in a “Stand Alone” Mode

           Works with Bandgap Voltage References

           TTL Compatible Inputs and Outputs

            0V to 5V Analog Voltage Input Range (Single + 5V Supply)
Pin Diagram:




Pin Description:

    It contains 20 pins. They are:
CS:
    CS stand for chip select. It is active low pin.
RD:
    RD stands for read. It is also active low pin. It is used to get the converted
data out of the ADC0804 chip. It is also referred to as output enable.
WR:
     WR stands for write. It is active low pin. When WR makes a low to high
transition, ADC starts converting the analog input value of Vin to an 8bit digital
number.
CLK IN and CLK R:
      CLK IN is an input pin connected to an external clock source when an external
clock is used for timing. For the internal clock generator both pins are connected
to a capacitor and a resistor. Clock frequency is given by
              F=(1/1.1*R*C)
INTR:
       INTR stands for interrupt. It is active low pin.
Vin (+) and Vin (-):
       These are the differential analog inputs. Vin(-) connected to ground. Vin (+)
pin used as an analog input to be converted to digital.
Vcc:
      This is the +5 volt power supply. It is also used as a reference voltage when
the pin9 is open.
Vref:
It is also used as reference voltage. It is used to implement analog input voltages
other than 0 to 5V.
D0-D7:
These are the digital data output pins. These access the converted data when
CS=0 and RD is forced to low.
AGND and DGND:
            These are the input pins providing the ground for both analog and
digital signals. AGRD connected to the ground of Vin. DGRD connected to ground
of Vcc.

Serial Communication:

The serial communication is done through the microcontroller with a baud rate of
9600bps , one start bit , one stop bit and no parity bit.
The null configuration used is shown below
                               6. SOFTWARE


#include<reg51.h>

#include<stdio.h>

unsigned int p,firing;

unsigned long int k;

unsigned char setvalue=80;

unsigned char value;

sbit rd=P2^0;

sbit wr=P2^1;

sbit intr=P2^2;

sbit out=P2^3;

sbit rled=P2^4;

sfr mydata=0x90;

void pid(char);

void external0() interrupt 0

{

unsigned int i,j;

for(j=0;j<p;j++)

for(i=0;i<71;i++);

{
}

out=1;

k++;

out=0;

}

void serial(unsigned char value1)

{

TMOD=0x20;

TH1=0xFD;

SCON=0x52;

TR1=1;

//printf("\nTemperature - ");

{

SBUF=value1;

while(TI==0);

TI=0;

}

}

void delay(void)

{

unsigned int a,b;

for(a=0;a<20;a++)
for(b=0;b<1000;b++)

{

}

}

void adc(void)

{

char a,d1,d2,d3;

mydata=0xff;

rd=1;

wr=1;

intr=1;

wr=0;

wr=1;

while(intr==1);

rd=0;

value=mydata;

a=value;

rd=1;

d3=(value/100)+48;

if(d3!=0)

serial(d3);

delay();
d1=(value/10)+48;

serial(d1);

delay();

d2=(value%10)+48;

serial(d2);

delay();

printf("\nTemperature - ");

pid(a);

}

void pid(char a)

{

float kp=150,kd=.06,ki=3;

float pterm,iterm,dterm,error,pre_error=0,accerror,pid_out;

unsigned int firing_min=500,firing_max=9500;

error=setvalue-a;

pterm=kp*error;

if(pterm>32767)

pterm=32767;

if(pterm<-32768)

pterm=-32768;

accerror=error+pre_error;

if(accerror>32767)
accerror=32767;

if(accerror<-32768)

accerror=-32768;

iterm=ki*accerror;

if(iterm>32767)

iterm=32767;

if(iterm<-32768)

iterm=-32768;

dterm=kd*error;

pid_out=pterm+iterm+dterm;

pre_error=error;

if(pid_out>32767)

pid_out=32767;

if(pid_out<0)

pid_out=0;

firing=10000-pid_out;

if(firing>firing_max)

firing=firing_max;

if(firing<firing_min)

firing=firing_min;

printf("\n %d   %d",firing,setvalue-a);

}
void main(void)

{

k=0;

adc();

p=firing/1000;

IE=0x81;

IT0=1;

if(k>1000)

{

EA=0;

k=0;

adc();

p=firing/1000;

k++;

IE=0x81;

IT0=1;

}

else

{



}

}
          7. COMPONENTS REQUIRED




1. Micro Controller                  89c51         1 No

2. Crystal Oscillator                11.0592 MHz   1 No

3. Temperature sensor                LM35          1 No

4. Analog to Digital converter       ADC0804       1 No

5. Serial voltage level converter    MAX232        1 No

6. Resistors                         10 kΩ         4 Nos

7. Capacitors                        33pF          2 Nos

8. Miscellaneous Components:

         Regulated Power Supply of 5V

         Circuit Connecting Board

         Connecting Wires
                  8. BIBLIOGRAPHY




1. The 8051 Micro controller and Embedded Systems


               - Muhammad Ali Mazidi & Janice Gillispie Mazidi


2. Micro controllers Theory and Applications


               - Ajay V. Deshmukh


3. Google Books


4. www.wikipedia.org


5. www.8051.com


6. www.8052.com


7. www.datasheetcatalogue.com
TEMPERATURE CONTROLLER HARDWARE KIT

								
To top