Vous êtes sur la page 1sur 68

1

1.1 INTRODUCTION
Embedded systems are finding increasing applications not only in domestic areas but also
in areas of industrial automation, automobiles, power electronics, defense and space
equipments. Microcontrollers are the basic building blocks for many embedded systems.
Inspite of revolutionary advances in the field of electronics, microcontrollers play a major
role in the design of embedded control systems during the past two decades. They are
available in 8-bit, 16-bit and 32-bit versions manufactured by a number of leading
companies like Intel, Motorola, Philips, Hitachi, Atmen, Microchip, Dallas, Siemens etc.
They are available in the market with various configurations for different applications.
An embedded system is some combination of computer hardware and software, either
fixed in capability or programmable, that is specifically designed for a particular kind of
application device. Industrial machines , automobiles, medical equipment ,cameras,
household appliances, airplanes, vending machines and toys are among the myriad
possible hosts of an embedded systems. Embedded system that are programmable are
provided with a programming interface, and embedded systems programming is a
specialized occupation.
Certain operating systems or language platforms are tailored for the embedded market,
such as embedded Java and Windows XP Embedded. However, some low-end consumer
products use very inexpensive microprocessors and limited storage, with the application
and operating system both part of single program. The program is written permanently
into the systems memory in the case, rather than being loaded into RAM as programs on
other computer.

1.2 HOW THE DATA IS COLLECTED?
Sensors are used to input the data into the data-logging equipment. Almost any physical
property can be measured with the correct sensor. The data logger collects the data at
regular intervals for the set length of time. There are two categories of sensors:
Digital sensors- These are either on or off i.e. a light gate senses something breaking a
light beam. Such sensors can often be connected directly to a computer as the data output
is already digital.
2

Analog sensor- These measure some physical quantity by converting into a voltage. The
voltage signal is then converted into digital form by an interface and either stored or
transferred directly to computer. The vast majority of sensors are of this type.

1.3 HOW THE DATA IS STORED?
The data that is logged is usually stored in RAM memory or on some form of backing
storage as it is collected. Some data logging equipment is designed to be linked directly to a
computer. This would be suitable if an experiment is taking place in a laboratory for example. If
you want to record data out in the field then battery powered data logging equipment would be
needed that could measure and store the data until the unit is collected. The equipment would
then be connected to a computer so that the data can be downloaded. This data collection
could still be done out in the field if a portable computer was used to collect data.

1.4 HOW THE DATA CAN BE DISPLAYED?
Once downloaded to a computer, the different types of data and are displayed it more
clearly by the hyper terminal.
An embedded system is a special purpose computer system designed to perform one or
few dedicated functions, sometimes with real time computing constraints. It is usually
embedded as a part of complete device including hardware and mechanical parts. In
contrast, a general purpose computer, such as personal computer, can do many different
tasks depending on programming. Embedded system have become very important today
as they control many of the devices we use.
Embedded systems are controlled by one or more main processing cores that is
typically either a microcontroller or a digital signal processor (DSP). The key
characteristic is however being dedicated to handle a particular task, which may require
very powerful processors. Since the embedded system is dedicated to specific tasks,
design engineers can optimize it reducing the size and cost of the product and increasing
the reliability and performance. Some embedded systems are mass-produced, benefiting
from economies of scale.

3

1.5 BLOCK DIAGRAM

FIG 1.1 BLOCK DIAGRAM OF TEMP MONITORING SYSTEM AND TEMPERATURE CONTROLLED FAN
1.5.1 DESCRIPTION OF BLOCK DIAGRAM
LM35 SENSOR

FIG1.2 LM 35 SENSOR

Figure shows the pin configuration of LM35. It is a precision integrated-circuit
centigrade temperature sensor whose output voltage is linearly proportional to the Celsius
(Centigrade) temperature. The sensor can measure temperature in the range of 0 to
100C, i.e., the output of the sensor varies from 0 to 1000 mV.


4

THE LCD

FIG 1.3 LCD
A 162 LCD is used for displaying the temperature. The control lines EN, R/W and RS
of the LCD module are connected to pins RA1, RA2 and RA3 of Port A of the
microcontroller.

PIC16F877A MICROCONTROLLER

FIG 1.4 PIC 16F877A
IC PIC16F877A is an 8-bit microcontroller with 8k14-bit flash program memory, 368
bytes of RAM and many other extra peripherals like ADC, universal synchronous
asynchronous receiver transmitter, master synchronous serial port, timers, compare
capture and pulse-width modulation modules, and analogue comparators.
5

The microcontroller processes the sensor output to compute the temperature in degree
Celsius. The internal ADC of the microcontroller is used to convert the analogue output
of the sensor into its equivalent digital value.
ADC 0804
The ADC 0804 A/D Converter is an 8bit A/D converter that uses successive
approximation to convert the analog inputs to the digital output. The ADC0804 has four
major sections namely the Comparator, the control logic, the digital counter and a 256R
ladder D/A converter. This 256R network consists of a number of resistors of fixed
incremental resistance that produce a representative staircase type waveform based on the
output of the digital counter. The output of the ladder network then enters the comparator
which has the role of comparing the input analog to the analog output of the D/A
Converter.
CRYSTAL OSCILLATOR

FIG 1.5 CRYSTAL OSCILLATOR

A crystal oscillator is an electronic circuit that uses the mechanical resonance of a
vibrating crystal of piezoelectric material to create an electrical signal with a very
precise frequency. The most common type of piezoelectric resonator used is the quartz
crystal, so oscillator circuits designed around them became known as "crystal
oscillators."
Quartz crystals are manufactured for frequencies from a few tens of kilohertz to tens of
megahertz. More than two billion crystals are manufactured annually. Most are used for
consumer devices such as wristwatches, clocks, radios, computers, and cellphones.
6

2.1 ORIGIN OF IDEA
This project is a standalone automatic fan speed controller that controls the speed of an
electric fan according to our requirement. Use of embedded technology makes this closed
loop feedback control system efficient and reliable. Micro controller allows dynamic and
faster control. Liquid crystal display (LCD) makes the system user-friendly. The sensed
temperature and fan speed level values are simultaneously displayed on the LCD panel.
Micro controller is the heart of the circuit as it controls all the functions
2.2 TECHNOLOGY USED
MPLAB IDE is a very powerful software development tool for Microchip products
(microcontrollers). It consists of tools like text editor, cross-assembler, cross-compiler
Hitech C cross compiler is meant for Microchip PIC10/12/16 series of microcontrollers.
There are many definitions of a comfortable indoor environment. It may mean different
things to different people. For some individuals, they look at the practical side before
they consider their haven comfortable and convenient. And one of these factors is the
ability of the space to control and regulate the temperature, thereby making it livable and
conducive to more efficient working conditions in extreme hot summer days or cold
freezing nights.
In addition, they will certainly shorten the lives of our expensive appliances and
electronics which do not thrive in extreme heat condition. The microchips embedded in
our laptop, computer and other gadgets easily break apart in terms of function when
exposed in heat.
Thus, there is an important need, in such conditions, to have our space insulated to
prevent trapping heat inside it.





7

3.1 PROJECT DESCRIPTION
This project is a standalone automatic fan speed controller that controls the speed of an
electric fan according to our requirement. Use of embedded technology makes this closed
loop feedback control system efficient and reliable. Micro controller allows dynamic and
faster control. Liquid crystal display (LCD) makes the system user-friendly. The sensed
temperature and fan speed level values are simultaneously displayed on the LCD panel.
Micro controller is the heart of the circuit as it controls all the functions.
The temperature sensor LM35 senses the temperature and converts it into an electrical
(analog) signal, which is applied to the micro controller through ADC. The analog signal
is converted into digital format by the analog-to-digital converter (ADC). The sensed and
set values of the temperature are displayed on the LCD. The micro controller drives
control relays to control the fan speed with the help of high wattage tagged wire wound
resistor.
3.2 DETAILS OF COMPONENTS
3.2.1 RESISTORS
A resistor is a passive two-terminal electrical component that implements electrical
resistance as a circuit element.
The current through a resistor is in direct proportion to the voltage across the resistor's
terminals. This relationship is represented by Ohm's law:
I=V/R
The ratio of the voltage applied across a resistor's terminals to the intensity of current in
the circuit is called its resistance, and this can be assumed to be a constant (independent
of the voltage) for ordinary resistors working within their ratings.

FIG 3.1 RESISTORS
8

Resistors are common elements of electrical networks and electronic circuits and are
ubiquitous in electronic equipment. Practical resistors can be made of various compounds
and films, as well as resistance wire (wire made of a high-resistivity alloy, such as nickel-
chrome). Resistors are also implemented within integrated circuits, particularly analog
devices, and can also be integrated into hybrid and printed circuits.
3.2.1.1 RESISTOR VALUES-THE RESISTOR COLOUR CODE
The electrical functionality of a resistor is specified by its resistance: common
commercial resistors are manufactured over a range of more than nineorders of
magnitude. When specifying that resistance in an electronic design, the required precision
of the resistance may require attention to themanufacturing tolerance of the chosen
resistor, according to its specific application. The temperature coefficient of the
resistance may also be of concern in some precision applications. Practical resistors are
also specified as having a maximum power rating which must exceed the anticipated
power dissipation of that resistor in a particular circuit: this is mainly of concern in power
electronics applications. Resistors with higher power ratings are physically larger and
may require heat sinks. In a high-voltage circuit, attention must sometimes be paid to the
rated maximum working voltage of the resistor.
The ohm (symbol: ) is the SI unit of electrical resistance, named after Georg Simon
Ohm. An ohm is equivalent to a volt per ampere. Since resistors are specified and
manufactured over a very large range of values, the derived units of milliohm (1 m =
103 ), kilo-ohm (1 k = 103 ), and megohm (1 M = 106 ) are also in common
usage.
The reciprocal of resistance R is called conductance G = 1/R and is measured
in siemens (SI unit), sometimes referred to as a mho. Hence, siemens is the reciprocal of
an ohm: . Although the concept of conductance is often used in circuit
analysis, practical resistors are always specified in terms of their resistance (ohms) rather
than conductance.


9

3.2.1.2. RESISTORS CONNECTED IN SERIES.
In a series configuration, the current through all of the resistors is the same, but the
voltage across each resistor will be in proportion to its resistance. The potential difference
(voltage) seen across the network is the sum of those voltages, thus the total resistance
can be found as the sum of those resistances:


FIG 3.2 RESISTOR IN SERIES
As a special case, the resistance of N resistors connected in series, each of the same
resistance R, is given by NR.
3.2.1.3.RESISTORS CONNECTED IN PARELLEL
Resistors in a parallel configuration are each subject to the same potential difference
(voltage), however the currents through them add. The conductances of the resistors then
add to determine the conductance of the network. Thus the equivalent resistance (R
eq
) of
the network can be computed:

FIG 3.3 RESITORS IN PARALLEL


The parallel equivalent resistance can be represented in equations by two vertical lines
"||" (as in geometry) as a simplified notation. Occasionally two slashes "//" are used
instead of "||", in case the keyboard or font lacks the vertical line symbol. For the case of
two resistors in parallel, this can be calculated using:
10


As a special case, the resistance of N resistors connected in parallel, each of the same
resistance R, is given by R/N.
The standard color code is as follows:
TABLE 3.1 COLOUR CODE DESCRIPTION
Color
Significant
figures
Multiplier Tolerance
Temp.
Coefficient
(ppm/K)
Black 0 10
0
250 U
Brown 1 10
1
1% F 100 S
Red 2 10
2
2% G 50 R
Orange 3 10
3
15 P
Yellow 4 10
4
(5%) 25 Q
Green 5 10
5
0.5% D 20 Z
Blue 6 10
6
0.25% C 10 Z
Violet 7 10
7
0.1% B 5 M
11
















FIG 3.4 COLOUR CODE DESCRIPTION
To distinguish left from right there is a gap between the C and D bands.
band A is first significant figure of component value (left side)
band B is the second significant figure
band C is the decimal multiplier
band D if present, indicates tolerance of value in percent (no band means 20%)
For example, a resistor with bands of yellow, violet, red, and gold will have first digit 4
(yellow in table below), second digit 7 (violet), followed by 2 (red) zeros: 4,700 ohms.
Gray 8 10
8

0.05%
(10%)
A 1 K
White 9 10
9

Gold 10
-1
5% J
Silver 10
-2
10% K
None 20% M

12

Gold signifies that the tolerance is 5%, so the real resistance could lie anywhere
between 4,465 and 4,935 ohms.
Resistors manufactured for military use may also include a fifth band which indicates
component failure rate (reliability).
Tight tolerance resistors may have three bands for significant figures rather than two, or
an additional band indicating temperature coefficient, in units of ppm/K.
All coded components will have at least two value bands and a multiplier; other bands are
optional.
3.2.1.4. POWER RATING OF RESISTORS
when an electrical current passes through a resistor, electrical energy is lost by the
resistor in the form of heat and the greater this current flow the hotter the resistor will get.
This is known as the Resistor Power Rating. Resistors are rated by the value of their
resistance and the power in watts that they can safely dissipate based mainly upon their
size. Every resistor has a maximum power rating which is determined by its physical size
as generally, the greater its surface area the more power it can dissipate safely into the
ambient air or into a heat sink.
Electrical power is the rate in time at which energy is used or consumed (converted into
heat). The standard unit of electrical power is the Watt, symbol W and a resistors power
rating is also given in Watts. As with other electrical quantities, prefixes are attached to
the word "Watt" when expressing very large or very small amounts of resistor power.
Some of the more common of these are:
ELECTRICAL POWER UNITS
TABLE 3.2 ELECTRICAL POWER UNITS
Unit Symbol Value Abbreviation
milliwatt mW 1/1,000th watt 10
-3
W
kilowatt kW 1,000 watts 10
3
W
13

megawatt MW 1,000,000 watts 10
6
W
[ P = V x I ] Power = Volts x Amps
[ P = I
2
x R ] Power = Current
2
x Ohms
[ P = V
2
R ] Power = Volts
2
Ohms

FIG 3.5 RESISTOR WITH 25 WATT RATING
Where:
V is the voltage across the resistor in Volt.
I is in current flowing through the resistor in Amperes.
R is the resistance of the resistor in Ohm's ().
3.2.2 CAPACITORS
Capacitor (originally known as condenser) is a passive two-terminal electrical
component used to store energy in an electric field. The forms of practical capacitors vary
widely, but all contain at least two electrical conductors separated by
a dielectric (insulator); for example, one common construction consists of metal foils
separated by a thin layer of insulating film. Capacitors are widely used as parts
of electrical circuits in many common electrical devices.
When there is a potential difference (voltage) across the conductors, a static electric
field develops across the dielectric, causing positive charge to collect on one plate and
negative charge on the other plate. Energy is stored in the electrostatic field. An ideal
capacitor is characterized by a single constant value, capacitance, measured in farads.
14

This is the ratio of the electric charge on each conductor to the potential difference
between them.

FIG 3.6 CAPACITORS
The capacitance is greatest when there is a narrow separation between large areas of
conductor, hence capacitor conductors are often called plates, referring to an early means
of construction. In practice, the dielectric between the plates passes a small amount
of leakage current and also has an electric field strength limit, resulting in a breakdown
voltage, while the conductors and leads introduce an undesired inductance and resistance.
Capacitors are widely used in electronic circuits for blocking direct current while
allowing alternating current to pass, in filter networks, for smoothing the output of power
supplies, in the resonant circuits that tune radios to particular frequencies, in electric
power transmission systems for stabilizing voltage and power flow, and for many other
purposes.
3.2.3.DIODES
In electronics, a diode is a two-terminal electronic component with asymmetric transfer
characteristic, with low (ideally zero) resistance to current flow in one direction, and high
(ideally infinite) resistance in the other. A semiconductor diode, the most common type
today, is a crystalline piece of semiconductor material with a p-n junction connected to
two electrical terminals. A vacuum tube diode, now used only in some high-power
technologies and by enthusiasts, is a vacuum tube with two electrodes, a plate (anode)
and filament (cathode).
The most common function of a diode is to allow an electric current to pass in one
direction (called the diode's forward direction), while blocking current in the opposite
15

direction (the reverse direction). Thus, the diode can be viewed as an electronic version
of a check valve. This unidirectional behavior is called rectification, and is used to
convert alternating current to direct current, including extraction of modulation from
radio signals in radio receiversthese diodes are forms of rectifiers.

FIG3 .7 DIODES
However, diodes can have more complicated behavior than this simple onoff action.
Semiconductor diodes begin conducting electricity only if a certain threshold voltage or
cut-in voltage is present in the forward direction (a state in which the diode is said to
be forward-biased). The voltage drop across a forward-biased diode varies only a little
with the current, and is a function of temperature; this effect can be used as a temperature
sensor or voltage reference.
Semiconductor diodes' nonlinear currentvoltage characteristic can be tailored by varying
the semiconductor materials and introducing impurities into (doping) the materials. These
are exploited in special-purpose diodes that perform many different functions. For
example, diodes are used to regulate voltage (Zener diodes), to protect circuits from high
voltage surges (avalanche diodes), to electronically tune radio and TV receivers (varactor
diodes), to generate radio frequency oscillations (tunnel diodes, Gunn diodes, IMPATT
diodes), and to produce light (light emitting diodes). Tunnel diodes exhibit negative
resistance, which makes them useful in some types of circuits.
Diodes were the first semiconductor electronic devices. The discovery
of crystals' rectifying abilities was made by German physicist Ferdinand Braun in 1874.
The first semiconductor diodes, called cat's whisker diodes, developed around 1906, were
made of mineral crystals such as galena. Today most diodes are made of silicon, but
other semiconductors such as germanium are sometimes used.
16


3.2.3.1 P-N JUNCTION DIODE
A pn junction is formed at the boundary between a p-type and n-
type semiconductor created in a single crystal of semiconductor by doping, for example
by ion implantation, diffusion of dopants, or by epitaxy (growing a layer of crystal doped
with one type of dopant on top of a layer of crystal doped with another type of dopant). If
two separate pieces of material were used, this would introduce a grain boundary between
the semiconductors that severely inhibits its utility by scattering the electrons and holes.

FIG 3.8 P-N JUNCTION DIODE
PN junctions are elementary "building blocks" of most semiconductor electronic
devices such as diodes, transistors, solar cells, LEDs, andintegrated circuits; they are the
active sites where the electronic action of the device takes place. For example, a common
type of transistor, the bipolar junction transistor, consists of two pn junctions in series,
in the form npn or pnp.


17

FORWARD BIAS
In forward bias, the p-type is connected with the positive terminal and the n-type is
connected with the negative terminal.
With a battery connected this way, the holes in the P-type region and the electrons in the
N-type region are pushed toward the junction. This reduces the width of the depletion
zone. The positive charge applied to the P-type material repels the holes, while the
negative charge applied to the N-type material repels the electrons. As electrons and
holes are pushed toward the junction, the distance between them decreases. This lowers
the barrier in potential. With increasing forward-bias voltage, the depletion zone
eventually becomes thin enough that the zone's electric field cannot counteract charge
carrier motion across the pn junction, as a consequence reducing electrical resistance.
The electrons that cross the pn junction into the P-type material (or holes that cross into
the N-type material) will diffuse in the near-neutral region. Therefore, the amount of
minority diffusion in the near-neutral zones determines the amount of current that may
flow through the diode.
Although the electrons penetrate only a short distance into the P-type material, the
electric current continues uninterrupted, because holes (the majority carriers) begin to
flow in the opposite direction. The total current (the sum of the electron and hole
currents) is constant in space, because any variation would cause charge buildup over
time (this is Kirchhoff's current law). The flow of holes from the P-type region into the
N-type region is exactly analogous to the flow of electrons from N to P (electrons and
holes swap roles and the signs of all currents and voltages are reversed).

FIG 3.9 FORWARD AND REVERSE BIAS


18

REVERSE BIAS
Reverse-bias usually refers to how a diode is used in a circuit. If a diode is reverse-
biased, the voltage at the cathode is higher than that at the anode. Therefore, no current
will flow until the diode breaks down. Connecting the P-type region to
the negative terminal of the battery and the N-type region to the positive terminal
corresponds to reverse bias. The connections are illustrated in the following diagram:
Because the p-type material is now connected to the negative terminal of the power
supply, the 'holes' in the P-type material are pulled away from the junction, causing the
width of the depletion zone to increase. Likewise, because the N-type region is connected
to the positive terminal, the electrons will also be pulled away from the junction.
Therefore, the depletion region widens, and does so increasingly with increasing reverse-
bias voltage. This increases the voltage barrier causing a high resistance to the flow of
charge carriers, thus allowing minimal electric current to cross the pn junction. The
increase in resistance of the pn junction results in the junction behaving as an insulator.
The strength of the depletion zone electric field increases as the reverse-bias voltage
increases. Once the electric field intensity increases beyond a critical level, the pn
junction depletion zone breaks down and current begins to flow, usually by either
the Zener or the avalanche breakdown processes. Both of these breakdown processes are
non-destructive and are reversible, as long as the amount of current flowing does not
reach levels that cause the semiconductor material to overheat and cause thermal damage.

FIG 3.10 V-I CHARACTERISTICS OF P-N JUNCTION DIODE
19


This effect is used to one's advantage in Zener diode regulator circuits. Zener diodes have
a certain low breakdown voltage. A standard value for breakdown voltage is for
instance 5.6 V. This means that the voltage at the cathode can never be more than 5.6 V
higher than the voltage at the anode, because the diode will break down and therefore
conduct if the voltage gets any higher. This in effect regulates the voltage over the
diode.
Another application where reverse biased diodes are used is in Varicap diodes. The width
of the depletion zone of any diode changes with voltage applied. This varies the
capacitance of the diode. For more information, refer to the Varicap article.
3.2.4 VOLTAGE REGULATOR
A voltage regulator is designed to automatically maintain a constant voltage level. A
voltage regulator may be a simple "feed-forward" design or may include negative
feedback control loops. It may use an electromechanical mechanism, or electronic
components. Depending on the design, it may be used to regulate one or
more AC or DC voltages.

FIG 3.11 VOLTAGE REGULATOR
20

Electronic voltage regulators are found in devices such as computer power
supplies where they stabilize the DC voltages used by the processor and other elements.
In automobile alternators and central power station generator plants, voltage regulators
control the output of the plant. In an electric power distribution system, voltage regulators
may be installed at a substation or along distribution lines so that all customers receive
steady voltage independent of how much power is drawn from the line.
3.2.5 TRANSFORMER
A transformer is a power converter that transfers electrical energy from one circuit to
another through inductively coupled conductorsthe transformer's coils. A
varying current in the primary winding creates a varying magnetic flux in the
transformer's core and thus a varying magnetic field through the secondary winding. This
varying magnetic field induces a varying electromotive force (EMF) secondary
winding.This effect is called inductive coupling.

FIG 3.12 TRANSFORMER
If a load is connected to the secondary winding, current will flow in this winding, and
electrical energy will be transferred from the primary circuit through the transformer to
the load. In an ideal transformer, the induced voltage in the secondary winding (V
s
) is in
proportion to the primary voltage (V
p
) and is given by the ratio of the number of turns in
the secondary (N
s
) to the number of turns in the primary (N
p
) as follows:

By appropriate selection of the ratio of turns, a transformer thus enables an alternating
current (AC) voltage to be "stepped up" by making N
s
greater than N
p
, or "stepped down"
21

by making N
s
less than N
p
. The windings are coils wound around a ferromagnetic
core, air-core transformers being a notable exception.
Transformers range in size from a thumbnail-sized coupling transformer hidden inside a
stage microphone to huge units weighing hundreds of tons used in power stations, or to
interconnect portions of power grids. All operate on the same basic principles, although
the range of designs is wide. While new technologies have eliminated the need for
transformers in some electronic circuits, transformers are still found in nearly all
electronic devices designed for household ("mains") voltage. Transformers are essential
for high-voltage electric power transmission, which makes long-distance transmission
economically practical.
The transformer is based on two principles: first, that an electric current can produce
a magnetic field (electromagnetism) and second that a changing magnetic field within a
coil of wire induces a voltage across the ends of the coil (electromagnetic induction).
Changing the current in the primary coil changes the magnetic flux that is developed. The
changing magnetic flux induces a voltage in the secondary coil.
An ideal transformer is shown in the adjacent figure. Current passing through the primary
coil creates a magnetic field. The primary and secondary coils are wrapped around
a core of very high magnetic permeability, such as iron, so that most of the magnetic flux
passes through both the primary and secondary coils. If a load is connected to the
secondary winding, the load current and voltage will be in the directions indicated, given
the primary current and voltage in the directions indicated (each will be alternating
current in practice).
3.2.5.1 INDUCTION LAW
The voltage induced across the secondary coil may be calculated from Faraday's law of
induction, which states that:

where V
s
is the instantaneous voltage, N
s
is the number of turns in the secondary coil and
is the magnetic flux through one turn of the coil. If the turns of the coil are oriented
22

perpendicularly to the magnetic field lines, the flux is the product of the magnetic flux
density B and the area A through which it cuts. The area is constant, being equal to the
cross-sectional area of the transformer core, whereas the magnetic field varies with time
according to the excitation of the primary. Since the same magnetic flux passes through
both the primary and secondary coils in an ideal transformer, the instantaneous voltage
across the primary winding equals

Taking the ratio of the two equations for V
s
and V
p
gives the basic equation for stepping
up or stepping down the voltage

N
p
/N
s
is known as the turns ratio, and is the primary functional characteristic of any
transformer. In the case of step-up transformers, this may sometimes be stated as the
reciprocal, N
s
/N
p
. Turns ratio is commonly expressed as an irreducible fraction or ratio:
for example, a transformer with primary and secondary windings of, respectively, 100
and 150 turns is said to have a turns ratio of 2:3 rather than 0.667 or 100:150.
3.2.5.2 IDEAL POWER EQUATION
If the secondary coil is attached to a load that allows current to flow, electrical power is
transmitted from the primary circuit to the secondary circuit. Ideally, the transformer is
perfectly efficient. All the incoming energy is transformed from the primary circuit to
the magnetic field and into the secondary circuit. If this condition is met, the
input electric power must equal the output power:

giving the ideal transformer equation

23

This formula is a reasonable approximation for most commercial built transformers
today.

FIG 3.13 E-I LAMINATIONS OF TRANSFORMER
If the voltage is increased, then the current is decreased by the same factor. The
impedance in one circuit is transformed by the square of the turns ratio. For example, if
an impedance Z
s
is attached across the terminals of the secondary coil, it appears to the
primary circuit to have an impedance of (N
p
/N
s
)
2
Z
s
. This relationship is reciprocal, so that
the impedance Z
p
of the primary circuit appears to the secondary to be (N
s
/N
p
)
2
Z
p
.
The physical limitations of the practical transformer may be brought together as an
equivalent circuit model (shown below) built around an ideal lossless transformer. Power
loss in the windings is current-dependent and is represented as in-series
resistances R
p
and R
s
. Flux leakage results in a fraction of the applied voltage dropped
without contributing to the mutual coupling, and thus can be modeled as reactances of
each leakage inductance X
p
and X
s
in series with the perfectly coupled region.
Iron losses are caused mostly by hysteresis and eddy current effects in the core, and are
proportional to the square of the core flux for operation at a given frequency. Since the
core flux is proportional to the applied voltage, the iron loss can be represented by a
resistance R
C
in parallel with the ideal transformer.
A core with finite permeability requires a magnetizing current I
m
to maintain the mutual
flux in the core. The magnetizing current is in phase with the flux. Saturation effects
cause the relationship between the two to be non-linear, but for simplicity this effect
24

tends to be ignored in most circuit equivalents. With a sinusoidal supply, the core flux
lags the induced EMF by 90 and this effect can be modeled as a magnetizing reactance
(reactance of an effective inductance) X
m
in parallel with the core loss
component, R
c
. R
c
and X
m
are sometimes together termed the magnetizing branch of the
model. If the secondary winding is made open-circuit, the current I
0
taken by the
magnetizing branch represents the transformer's no-load current.
The secondary impedance R
s
and X
s
is frequently moved (or "referred") to the primary
side after multiplying the components by the impedance scaling factor (N
p
/N
s
)
2
.

FIG 3.14 WORKING OF TRANSFORMER
The resulting model is sometimes termed the "exact equivalent circuit", though it retains
a number of approximations, such as an assumption of linearity.
[53]
Analysis may be
simplified by moving the magnetizing branch to the left of the primary impedance, an
implicit assumption that the magnetizing current is low, and then summing primary and
referred secondary impedances, resulting in so-called equivalent impedance.
The parameters of equivalent circuit of a transformer can be calculated from the results of
two transformer tests: open-circuit test and short-circuit test.
3.3 MICROCONTROLLER
A microcontroller (sometimes abbreviated C, uC or MCU) is a small computer on a
single integrated circuit containing a processor core, memory, and
programmable input/output peripherals. Program memory in the form of NOR
flash or OTP ROM is also often included on chip, as well as a typically small amount
25

of RAM. Microcontrollers are designed for embedded applications, in contrast to
the microprocessors used in personal computers or other general purpose applications.
Microcontrollers are used in automatically controlled products and devices, such as
automobile engine control systems, implantable medical devices, remote controls, office
machines, appliances, power tools, toys and other embedded systems. By reducing the
size and cost compared to a design that uses a separate microprocessor, memory, and
input/output devices, microcontrollers make it economical to digitally control even more
devices and processes. Mixed signal microcontrollers are common, integrating analog
components needed to control non-digital electronic systems.
Some microcontrollers may use four-bit words and operate at clock rate frequencies as
low as 4 kHz, for low power consumption (milliwatts or microwatts). They will generally
have the ability to retain functionality while waiting for an event such as a button press or
other interrupt; power consumption while sleeping (CPU clock and most peripherals off)
may be just nanowatts, making many of them well suited for long lasting battery
applications. Other microcontrollers may serve performance-critical roles, where they
may need to act more like a digital signal processor (DSP), with higher clock speeds and
power consumption.
Microcontrollers usually contain from several to dozens of general purpose input/output
pins (GPIO). GPIO pins are software configurable to either an input or an output state.
When GPIO pins are configured to an input state, they are often used to read sensors or
external signals. Configured to the output state, GPIO pins can drive external devices
such as LEDs or motors.
Many embedded systems need to read sensors that produce analog signals. This is the
purpose of the analog-to-digital converter (ADC). Since processors are built to interpret
and process digital data, i.e. 1s and 0s, they are not able to do anything with the analog
signals that may be sent to it by a device. So the analog to digital converter is used to
convert the incoming data into a form that the processor can recognize. A less common
feature on some microcontrollers is a digital-to-analog converter (DAC) that allows the
processor to output analog signals or voltage levels.
26

In addition to the converters, many embedded microprocessors include a variety of timers
as well. One of the most common types of timers is the Programmable Interval
Timer (PIT). A PIT may either count down from some value to zero, or up to the capacity
of the count register, overflowing to zero. Once it reaches zero, it sends an interrupt to the
processor indicating that it has finished counting. This is useful for devices such as
thermostats, which periodically test the temperature around them to see if they need to
turn the air conditioner on, the heater on, etc.
A dedicated Pulse Width Modulation (PWM) block makes it possible for the CPU to
control power converters, resistive loads, motors, etc., without using lots of CPU
resources in tight timer loops.
Universal Asynchronous Receiver/Transmitter (UART) block makes it possible to
receive and transmit data over a serial line with very little load on the CPU. Dedicated
on-chip hardware also often includes capabilities to communicate with other devices
(chips) in digital formats such as IC and Serial Peripheral Interface (SPI).
3.3.1 PIC MICROCONTROLLER
PIC is a family of modified Harvard architecture microcontrollers made by Microchip
Technology, derived from the PIC1650[1][2][3] originally developed by General
Instrument's Microelectronics Division. The name PIC initially referred to "Peripheral
Interface Controller.
PICs are popular with both industrial developers and hobbyists alike due to their low
cost, wide availability, large user base, extensive collection of application notes,
availability of low cost or free development tools, and serial programming (and re-
programming with flash memory) capability. They are also commonly used in
educational programming as they often come with the easy to use 'pic logicator' software.
The PIC architecture is characterized by its multiple attributes:
Separate code and data spaces (Harvard architecture).
A small number of fixed length instructions
Most instructions are single cycle execution (2 clock cycles, or 4 clock cycles in 8-bit
models), with one delay cycle on branches and skips.
27

One accumulator (W0), the use of which (as source operand) is implied (i.e. is not
encoded in the opcode).
All RAM locations function as registers as both source and/or destination of math and
other functions.
A hardware stack for storing return addresses
A fairly small amount of addressable data space (typically 256 bytes), extended through
banking.
Data space mapped CPU, port, and peripheral registers.
The program counter is also mapped into the data space and writable (this is used to
implement indirect jumps).
There is no distinction between memory space and register space because the RAM
serves the job of both memory and registers, and the RAM is usually just referred to as
the register file or simply as the registers.
3.3.1.1 DATA SPACE (RAM)
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 varies depending on device series, and all PIC devices have
some banking mechanism to extend addressing to additional memory. Later series of
devices feature move instructions which can cover the whole addressable space,
independent of the selected bank. In earlier devices, any register move had to be achieved
via the accumulator.
To implement indirect addressing, a "file select register" (FSR) and "indirect register"
(INDF) are used. A register number is written to the FSR, after which reads from or
writes to INDF will actually be to or from the register pointed to by FSR. Later devices
extended this concept with post- and pre- increment/decrement for greater efficiency in
accessing sequentially stored data. This also allows FSR to be treated almost like a stack
pointer (SP).
External data memory is not directly addressable except in some high pin count PIC18
devices.

28

3.3.1.2 CODE SPACE
The code space is generally implemented as ROM, EPROM or flash ROM. In general,
external code memory is not directly addressable due to the lack of an external memory
interface. The exceptions are PIC17 and select high pin count PIC18 devices.
3.3.1.3 WORD SIZE
All PICs handle (and address) data in 8-bit chunks. However, the unit of addressability of
the code space is not generally the same as the data space. For example, PICs in the
baseline (PIC12) and mid-range (PIC16) families have program memory addressable in
the same word size as the instruction width, i.e. 12 or 14 bits respectively. In contrast, in
the PIC18 series, the program memory is addressed in 8-bit increments (bytes), which
differs from the instruction width of 16 bits.
In order to be clear, the program memory capacity is usually stated in number of (single
word) instructions, rather than in bytes.
3.3.1.4 STACKS
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 changed with the 18 series
devices.
Hardware support for a general purpose parameter stack was lacking in early series, but
this greatly improved in the 18 series, making the 18 series architecture more friendly to
high level language compilers.
3.3.1.5 INSTRUCTION SET
A PIC's instructions vary from about 35 instructions for the low-end PICs to over 80
instructions for the high-end PICs. The instruction set includes instructions to perform a
variety of operations on registers directly, the accumulator and a literal constant or the
accumulator and a register, as well as for conditional execution, and program branching
Some operations, such as bit setting and testing, can be performed on any numbered
register, but bi-operand arithmetic operations always involve W (the accumulator),
writing the result back to either W or the other operand register. To load a constant, it is
necessary to load it into W before it can be moved into another register. On the older
29

cores, all register moves needed to pass through W, but this changed on the "high end"
cores.
PIC cores have skip instructions which are used for conditional execution and branching.
The skip instructions are 'skip if bit set' and 'skip if bit not set'. Because cores before
PIC18 had only unconditional branch instructions, conditional jumps are implemented by
a conditional skip (with the opposite condition) followed by an unconditional branch.
Skips are also of utility for conditional execution of any immediate single following
instruction.
The 18 series implemented shadow registers which save several important registers
during an interrupt, providing hardware support for automatically saving processor state
when servicing interrupts.
In general, PIC instructions fall into 5 classes:
Operation on working register (WREG) with 8-bit immediate ("literal") operand.
E.g. movlw (move literal to WREG), andlw (AND literal with WREG). One instruction
peculiar to the PIC isretlw, load immediate into WREG and return, which is used with
computed branches to produce lookup tables.
Operation with WREG and indexed register. The result can be written to either the
Working register (e.g. addwf reg,w). or the selected register (e.g. addwf reg,f).
Bit operations. These take a register number and a bit number, and perform one of 4
actions: set or clear a bit, and test and skip on set/clear. The latter are used to perform
conditional branches. The usual ALU status flags are available in a numbered register so
operations such as "branch on carry clear" are possible.
Control transfers. Other than the skip instructions previously mentioned, there are only
two: goto and call.
A few miscellaneous zero-operand instructions, such as return from subroutine,
and sleep to enter low-power mode.
3.3.1.6 PERFORMANCE
The architectural decisions are directed at the maximization of speed-to-cost ratio. The
PIC architecture was among the first scalar CPU designs,[citation needed] and is still
among the simplest and cheapest. The Harvard architecturein which instructions and
30

data come from separate sourcessimplifies timing and microcircuit design greatly, and
this benefits clock speed, price, and power consumption.
The PIC instruction set is suited to implementation of fast lookup tables in the program
space. Such lookups take one instruction and two instruction cycles. Many functions can
be modeled in this way. Optimization is facilitated by the relatively large program space
of the PIC (e.g. 4096 14-bit words on the 16F690) and by the design of the instruction
set, which allows for embedded constants. For example, a branch instruction's target may
be indexed by W, and execute a "RETLW" which does as it is named - return with literal
in W.
Interrupt latency is constant at three instruction cycles. External interrupts have to be
synchronized with the four clock instruction cycle, otherwise there can be a one
instruction cycle jitter. Internal interrupts are already synchronized. The constant
interrupt latency allows PICs to achieve interrupt driven low jitter timing sequences. An
example of this is a video sync pulse generator. This is no longer true in the newest PIC
models, because they have a synchronous interrupt latency of three or four cycles.
3.3.1.7 ADVANTAGES
The PIC architectures have these advantages:
Small instruction set to learn.
RISC architecture
Built in oscillator with selectable speeds
Easy entry level, in circuit programming plus in circuit debugging PICKit units available
for less than $50
Inexpensive microcontrollers
Wide range of interfaces including IC, SPI, USB, USART, A/D, programmable
comparators, PWM, LIN, CAN, PSP, and Ethernet
3.3.1.8 LIMITATIONS
The PIC architectures have these limitations:
One accumulator Register-bank switching is required to access the entire RAM of many
devices
31

Operations and registers are not orthogonal; some instructions can address RAM
and/or immediate constants, while others can only use the accumulator
The following stack limitations have been addressed in the PIC18 series, but still apply
to earlier cores:
The hardware call stack is not addressable, so preemptive task switching cannot be
implemented
Software-implemented stacks are not efficient, so it is difficult to generate reentrant code
and support local variables
With paged program memory, there are two page sizes to worry about: one for CALL and
GOTO and another for computed GOTO (typically used for table lookups). For example,
on PIC16, CALL and GOTO have 11 bits of addressing, so the page size is 2048
instruction words. For computed GOTOs, where you add to PCL, the page size is 256
instruction words. In both cases, the upper address bits are provided by the PCLATH
register. This register must be changed every time control transfers between pages.
PCLATH must also be preserved by any interrupt handler
3.4 PIC 16F877A
The 16F877A is one of the most popular PIC microcontrollers and it's easy to see why - it
comes in a 40 pin DIP pinout and it has many internal peripherals.
The 40 pins make it easier to use the peripherals as the functions are spread out over the
pins.One of the main advantages is that each pin is only shared between two or three
functions so its easier to decide what the pin function (other devices have up to 5
functions for a pin).
3.4.1 ARCHITECTURE
Harvard computer model
Separate memories for program and data. Each with its own busses
The major advantage with this architecture is that while an instruction is being executed
the next one can be fetched.
The execution speed is doubled The memory of this chip which was referred to earlier is
its data memory
32

Its program memory has 14 bits in each location
All instructions fit in one program memory location
An instruction is in other words completely defined with a number between 0x0000 and
0x3FFF
Data memory data bus has 8 wires and address bus has 9 wires
Program memory data bus has 14 wires and address bus has 13 wires
A Register is the same as a memory location
An assembler is a program which translates assembly code into machine code and writes
this code in an output file. This output file has the extension *.HEX.
Every instruction in PIC16F877 is represented by a 14 bit binary number. If the
instruction involves a move to or from a data memory location the address of this
memory location will be contained in the instruction.
The PIC16F877 has 35 different instructions.
3.4.2 FEATURES
High-performance RISC CPU
All single cycle instructions except for program branches which are 2 cycle
Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle
Up to 8K x 14 words of Flash Program Memory
Up to 256 x 8 bytes of EEPROM data memory
Pin out compatible to the PIC16C73/74/76/77
Interrupt capability -up to 14 internal/external
Eight level deep hardware stack
Direct, indirect, and relative addressing modes
Power-on Reset (POR)
Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)
Watchdog Timer (WDT) with its own on-chip RC Oscillator for reliable operation
Programmable code-protection
Power saving SLEEP mode
Selectable oscillator options
Low-power, high-speed CMOS EPROM/EEPROM technology
33

Fully static design
In-Circuit Serial Programming (ICSP) via two pins
Only single 5V source needed for programming capability
In-Circuit Debugging via two pin
Processor read/write access to program memory
Wide operating voltage range: 2.5V to 5.5V
High Sink/Source Current: 25 mA
Commercial and Industrial temperature ranges
3.4.3 PIN DIAGRAM OF PIC 16F877A

FIG 3.15 PIN DIAGRAM OF PIC 16F877A

34

3.4.4 PIN DESCRIPTION
TABLE 3.3 PIN DESCRIPTION OF PIC 16F877A

3.5 ADC 0804
The ADC 0804 A/D Converter is an 8bit A/D converter that uses successive
approximation to convert the analog inputs to the digital output. The basic block diagram
of the function of the successive approximation A/D Converter is shown in the figure
above. The ADC0804 has four major sections namely the Comparator, the control logic,
the digital counter and a 256R ladder D/A converter. For any analog input, the control
35

logic will trigger the digital counter to start incrementing from zero count and these
digital values are converted to analog form through a 256R ladder network. This 256R
network consists of a number of resistors of fixed incremental resistance that produce a
representative staircase type waveform based on the output of the digital counter. The
output of the ladder network then enters the comparator which has the role of comparing
the input analog to the analog output of the D/A Converter. When the staircase wave
form exceeds the input voltage, the comparator sends a signal to the control logic to stop
counting. The value of the digital counter at the time when the comparator sends the 'stop
count' signal is the digital representation of the input voltage.
Analog to digital converters find huge application as an intermediate device to convert
the signals from analog to digital form. These digital signals are used for further
processing by the digital processors. Various sensors like temperature, pressure, force etc.
convert the physical characteristics into electrical signals that are analog in nature.
ADC0804 is a very commonly used 8-bit analog to digital convertor. It is a single
channel IC, i.e., it can take only one analog signal as input. The digital outputs vary from
0 to a maximum of 255. The step size can be adjusted by setting the reference voltage at
pin9. When this pin is not connected, the default reference voltage is the operating
voltage, i.e., Vcc. The step size at 5V is 19.53mV (5V/255), i.e., for every 19.53mV rise
in the analog input, the output varies by 1 unit. To set a particular voltage level as the
reference value, this pin is connected to half the voltage. For example, to set a reference
of 4V (Vref), pin9 is connected to 2V (Vref/2), thereby reducing the step size to 15.62mV
(4V/255).

FIG 3.16 ADC 0804
36


ADC0804 needs a clock to operate. The time taken to convert the analog value to digital
value is dependent on this clock source. An external clock can be given at the Clock IN
pin. ADC 0804 also has an inbuilt clock which can be used in absence of external clock.
A suitable RC circuit is connected between the Clock IN and Clock R pins to use the
internal clock.
TABLE 3.4 PIN DESCRIPTION OF ADC 0804
Pin No Function Name
1 Activates ADC; Active low Chip select
2 Input pin; High to low pulse brings the data from internal registers to the
output pins after conversion
Read
3 Input pin; Low to high pulse is given to start the conversion Write
4 Clock Input pin; to give external clock. Clock IN
5 Output pin; Goes low when conversion is complete Interrupt
6 Analog non-inverting input Vin(+)
7 Analog inverting Input; normally ground Vin(-)
8 Ground(0V) Analog Ground
9 Input pin; sets the reference voltage for analog input Vref/2
10 Ground(0V) Digital Ground
11
8 bit digital output pins
D7
12 D6
13 D5
14 D4
15 D3
16 D2
17 D1
18 D0
19 Used with Clock IN pin when internal clock source is used Clock R
20 Supply voltage; 5V Vcc

3.6 TEMPERATURE SENSOR LM 35
The LM35 series are precision integrated-circuit temperature sensors, whose output
voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus
37

has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not
required to subtract a large constant voltage from its output to obtain convenient
Centigrade scaling. The LM35 does not require any externalcalibration or trimming to
provide typical accuracies of 14Cat room temperature and 34C over a full 55 to
+150Ctemperature range. Low cost is assured by trimming andcalibration at the wafer
level. The LM35s low output impedance, linear output, and precise inherent calibration
makeinterfacing to readout or control circuitry especially easy. Itcan be used with single
power supplies, or with plus andminus supplies. As it draws only 60 A from its supply,
it hasvery low self-heating, less than 0.1C in still air. The LM35 israted to operate over a
55 to +150C temperature range,while the LM35C is rated for a 40 to +110C range
(10with improved accuracy). The LM35 series is available packaged in hermetic TO-
46 transistor packages, while theLM35C, LM35CA, and LM35D are also available in the
plastic TO-92 transistor package. The LM35D is also available in an 8-lead surface
mount small outline package and aplastic TO-220 package.
LM35 is a precision IC temperature sensor with its output proportional to the
temperature (in
o
C). The sensor circuitry is sealed and therefore it is not subjected to
oxidation and other processes. With LM35, temperature can be measured more
accurately than with a thermistor. It also possess low self heating and does not cause
more than 0.1
o
C temperature rise in still air.
The operating temperature range is from -55C to 150C. The output voltage varies by
10mV in response to every
o
C rise/fall in ambient temperature, i.e., its scale factor is
0.01V/
o
C.

FIG 3.17 LM 35
38

TABLE 3.5 PIN DESCRIPTION OF LM 35
Pin No Function Name
1 Supply voltage; 5V (+35V to -2V) Vcc
2 Output voltage (+6V to -1V) Output
3 Ground (0V) Ground

FEATURES
Calibrated directly in Celsius (Centigrade).
Linear + 10.0 mV/C scale factor.
0.5C accuracy guaranteeable (at +25C).
Rated for full -55 to +150C range.
Suitable for remote applications.
Low cost due to wafer-level trimming.
Operates from 4 to 30 volts.
Less than 60 A current drain.
Low self-heating, 0.08C in still air.
Nonlinearity only C typical.
Low impedance output, 0.1 [Ohm] for 1 mA load
3.7 RELAY
A relay is an electrically operated switch. Many relays use an electromagnet to operate a
switching mechanism mechanically, but other operating principles are also used. Relays
are used where it is necessary to control a circuit by a low-power signal (with complete
electrical isolation between control and controlled circuits), or where several circuits
must be controlled by one signal. The first relays were used in long distance telegraph
circuits, repeating the signal coming in from one circuit and re-transmitting it to another.
Relays were used extensively in telephone exchanges and early computers to perform
logical operations.
39

A type of relay that can handle the high power required to directly control an electric
motor or other loads is called a contactor. Solid-state relays control power circuits with
no moving parts, instead using a semiconductor device to perform switching. Relays with
calibrated operating characteristics and sometimes multiple operating coils are used to
protect electrical circuits from overload or faults; in modern electric power systems these
functions are performed by digital instruments still called "protective relays".
A simple electromagnetic relay consists of a coil of wire wrapped around a soft iron core,
an iron yoke which provides a low reluctance path for magnetic flux, a movable
iron armature, and one or more sets of contacts (there are two in the relay pictured). The
armature is hinged to the yoke and mechanically linked to one or more sets of moving
contacts. It is held in place by a spring so that when the relay is de-energized there is an
air gap in the magnetic circuit. In this condition, one of the two sets of contacts in the
relay pictured is closed, and the other set is open. Other relays may have more or fewer
sets of contacts depending on their function. The relay in the picture also has a wire
connecting the armature to the yoke. This ensures continuity of the circuit between the
moving contacts on the armature, and the circuit track on the printed circuit board (PCB)
via the yoke, which is soldered to the PCB.

FIG 3.18 RELAY
APPLICATIONS
Relays are used to and for:
Amplify a digital signal, switching a large amount of power with a small operating
power. Some special cases are:
40

A telegraph relay, repeating a weak signal received at the end of a long wire.
Controlling a high-voltage circuit with a low-voltage signal, as in some types
of modems or audio amplifiers.
Controlling a high-current circuit with a low-current signal, as in the starter solenoid of
an automobile.
Detect and isolate faults on transmission and distribution lines by opening and
closing circuit breakers (protection relays).
Isolate the controlling circuit from the controlled circuit when the two are at different
potentials, for example when controlling a mains-powered device from a low-voltage
switch. The latter is often applied to control office lighting as the low voltage wires are
easily installed in partitions, which may be often moved as needs change. They may also
be controlled by room occupancy detectors to conserve energy.
Logic functions. For example, the boolean AND function is realised by connecting
normally open relay contacts in series, the OR function by connecting normally open
contacts in parallel. The change-over or Form C contacts perform the XOR (exclusive or)
function. Similar functions for NAND and NOR are accomplished using normally closed
contacts. The Ladder programming language is often used for designing relay
logic networks.
The application of Boolean Algebra to relay circuit design was formalized by Claude
Shannon in A Symbolic Analysis of Relay and Switching Circuits
Early computing. Before vacuum tubes and transistors, relays were used as logical
elements in digital computers. See electro-mechanical computers such as ARRA
(computer), Harvard Mark II, Zuse Z2, and Zuse Z3.
Safety-critical logic. Because relays are much more resistant than semiconductors to
nuclear radiation, they are widely used in safety-critical logic, such as the control panels
of radioactive waste-handling machinery.
Time delay functions. Relays can be modified to delay opening or delay closing a set of
contacts. A very short (a fraction of a second) delay would use a copper disk between the
armature and moving blade assembly. Current flowing in the disk maintains magnetic
field for a short time, lengthening release time. For a slightly longer (up to a minute)
delay, a dashpot is used. A dashpot is a piston filled with fluid that is allowed to escape
41

slowly. The time period can be varied by increasing or decreasing the flow rate. For
longer time periods, a mechanical clockwork timer is installed.
Vehicle battery isolation. A 12v relay is often used to isolate any second battery in cars,
4WDs, RVs and boats.
Switching to a standby power supply.
3.8 LCD
The LCD is a much more informative output device than a single LED. The LCD is a
display that can easily show characters on its screen. LCDs range in size, price and
configuration, from having a couple of lines to large displays. Some are even very
specifically designed for a single application, having only that ability to display set
graphics. We will be usng an LCD that has the ability to display four (4) lines of
characters that has a 20 character line length. This is quite sufficient to show quite a bit of
information. Another popular LCD has 2 lines and 16 characters per line.

FIG 3.19 LCD
Just like the microcontroller, the LCD has a row of 8 pins to serve as its port. The pins
that serve as its port is D0, D1, D2, D3, D4, D5, D6 and D7. These pins are generally
used to pass information into the LCD, but it can also be set to pass information back to
the microcontroller. I know, you are probably thinking, "but Patrick (that's me) told me
this is an output device?!?". Well, sure, it is, but from time to time, it will need to inform
you of its state (if it is busy or not). Two types of information can be passed through
these pins: data to display on the LCD screen, or control information that is used to do
things such as clearing the screen, controlling the cursor position, turning the display on
or off, etc. These data pins are connected to the pins of the desired port on the
microcontroller. For example, if you wanted the LCD to be connected to PORTB, the D0
would be connected to Pin0 of Port B, and: D1-PortB Pin1, D2-PortB Pin2, D3-PortB
42

Pin3, D4-PortB Pin4, D5-PortB Pin5, D6-PortB Pin6 and D7-PortB Pin7. This way, there
is a pin to pin consistency, and if you pass a character in the form of a hexadecimal
number, the LCD will receive it in the proper way. If not, there will unexpected results,
unless you use a unique form of byte structure, but don't let that get in your way.
TABLE 3.6 PIN DESCRIPTION OF LCD
Pin
No
Function Name
1 Ground (0V) Ground
2 Supply voltage; 5V (4.7V 5.3V) Vcc
3 Contrast adjustment; through a variable resistor

V
EE

4 Selects command register when low; and data register when
high
Register
Select
5 Low to write to the register; High to read from the register Read/write
6 Sends data to data pins when a high to low pulse is given Enable
7
8-bit data pins
DB0
8 DB1
9 DB2
10 DB3
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight V
CC
(5V) Led+
16 Backlight Ground (0V) Led-



43

3.9 REGULATED POWER SUPPLY
A regulated power supply is an embedded circuit, or stand alone unit, the function of
which is to supply a stable voltage (or less often current), to a circuit or device that must
be operated within certain power supply limits. The output from the regulated power
supply may be alternating or unidirectional, but is nearly always DC (Direct Current).
The type of stabilization used may be restricted to ensuring that the output remains within
certain limits under various load conditions, or it may also include compensation for
variations in its own supply source. The latter is much more common today.
D.C. variable bench supply (a bench power supply usually refers to a power
supply capable of supplying a variety of output voltages useful for bench

FIG 3.20 REGULATED POWER SUPPLY
testing electronic circuits, possibly with continuous variation of the output voltage, or just
some preset voltages; a laboratory (lab) power supply normally implies an accurate bench
power supply, while a balanced or tracking power supply refers to twin supplies for use
when a circuit requires both positive and negative supply rails).

44

3.10 ULN 2003
ULN2003 is a high voltage and high current Darlington array IC. It contains seven open
collector darlington pairs with common emitters. A darlington pair is an arrangement of
Two bipolar transistors.
ULN2003 belongs to the family of ULN200X series of ICs. Different versions of this
family interface to different logic families. ULN2003 is for 5V TTL, CMOS logic
devices. These ICs are used when driving a wide range of loads and are used as relay
drivers, display drivers, line drivers etc. ULN2003 is also commonly used while
driving Stepper Motors. Refer Stepper Motor interfacing using ULN2003.
Each channel or darlington pair in ULN2003 is rated at 500mA and can withstand peak
current of 600mA. The inputs and outputs are provided opposite to each other in the pin
layout. Each driver also contains a suppression diode to dissipate voltage spikes while
driving inductive loads. The schematic for each driver is given below:

FIG 3.21 ULN 2003

45

TABLE 3.7 PIN DESCRIPTION OF ULN 2003
Pin No Function Name
1 Input for 1
st
channel Input 1
2 Input for 2
nd
channel Input 2
3 Input for 3
rd
channel Input 3
4 Input for 4
th
channel Input 4
5 Input for 5
th
channel Input 5
6 Input for 6
th
channel Input 6
7 Input for 7
th
channel Input 7
8 Ground (0V) Ground
9 Common free wheeling diodes Common
10 Output for 7
th
channel Output 7
11 Output for 6
th
channel Output 6
12 Output for 5
th
channel Output 5
13 Output for 4
th
channel Output 4
14 Output for 3
rd
channel Output 3
15 Output for 2
nd
channel Output 2
16 Output for 1
st
channel Output 1



3. 11 PRINTED CIRCUIT BOARD (PCB)
A printed circuit board, or PCB, is used to mechanically support and electrically
connect electronic components using conductive pathways, tracks or signal
traces etched from copper sheets laminated onto a non-conductive substrate. It is also
46

referred to as printed wiring board(PWB) or etched wiring board. Printed circuit
boards are used in virtually all but the simplest commercially produced electronic
devices.
A PCB populated with electronic components is called a printed circuit
assembly (PCA), printed circuit board assembly or PCB Assembly(PCBA). In
informal use the term "PCB" is used both for bare and assembled boards, the context
clarifying the meaning.
Alternatives to PCBs include wire wrap and point-to-point construction. PCBs must
initially be designed and laid out, but become cheaper, faster to make, and potentially
more reliable for high-volume production since production and soldering of PCBs can be
automated. Much of the electronics industry's PCB design, assembly, and quality control
needs are set by standards published by the IPC organization.

FIG 3.22 PCB LAYOUT
3.11.1 PATTERNING (ETCHING)
The majority of printed circuit boards today are made from purchased laminate material
with copper already applied to both sides. The unwanted copper is removed by various
47

methods leaving only the desired copper traces, this is called subtractive. PCB's can also
be produced using an additive method where traces are adding to the bare substrate this is
a complex process of multiple electroplating steps. The advantage of the additive method
is less pollution of the environment. The PCB manufacturing method primarily depends
on whether it is for production volume or sample/prototype quantities. Double-sided
boards or multi-layer boards use plated-through holes, called vias, to connect traces on
different layers of the PWB.
Chemical etching is usually done with ammonium persulfate or ferric chloride. For PTH
(plated-through holes), additional steps of electroless deposition are done after the holes
are drilled, then copper is electroplated to build up the thickness, the boards are screened,
and plated with tin/lead. The tin/lead becomes the resist leaving the bare copper to be
etched away.
The simplest method, used for small-scale production and often by hobbyists, is
immersion etching, in which the board is submerged in etching solution such as ferric
chloride. Compared with methods used for mass production, the etching time is long.
Heat and agitation can be applied to the bath to speed the etching rate. In bubble etching,
air is passed through the etchant bath to agitate the solution and speed up etching. Splash
etching uses a motor-driven paddle to splash boards with etchant; the process has become
commercially obsolete since it is not as fast as spray etching. In spray etching, the etchant
solution is distributed over the boards by nozzles, and recirculated by pumps. Adjustment
of the nozzle pattern, flow rate, temperature, and etchant composition gives predictable
control of etching rates and high production rates.
As more copper is consumed from the boards, the etchant becomes saturated and less
effective; different etchants have different capacities for copper, with some as high as 150
grams of copper per litre of solution. In commercial use, etchants can be regenerated to
restore their activity, and the dissolved copper recovered and sold. Small-scale etching
requires attention to disposal of used etchant, which is corrosive and toxic due to its metal
content.
The etchant removes copper on all surfaces exposed by the resist. "Undercut" occurs
when etchant attacks the thin edge of copper under the resist; this can reduce conductor
widths and cause open-circuits. Careful control of etch time is required to prevent
48

undercut. Where metallic plating is used as a resist, it can "overhang" which can cause
short-circuits between adjacent traces when closely spaced. Overhang can be removed by
wire-brushing the board after etching.

3.11.2 LAMINATION
"Multi layer" printed circuit boards have trace layers inside the board. One way to make a
4-layer PCB is to use a two-sided copper-clad laminate, etch the circuitry on both sides,
then laminate to the top and bottom prepreg and copper foil. Lamination is done by
placing the stack of materials in a press and applying pressure and heat for a period of
time. This results in an inseparable one piece product. It is then drilled, plated, and etched
again to get traces on top and bottom layers. Finally the PCB is covered with solder
mask, marking legend, and a surface finish may be applied. Multi-layer PCB's allow for
much higher component density.
3.11.3 DRILLING
Holes through a PCB are typically drilled with small-diameter drill bits made of solid
coated tungsten carbide. Coated tungsten carbide is recommended since many board
materials are very abrasive and drilling must be high RPM and high feed to be cost
effective. Drill bits must also remain sharp so as not to mar or tear the traces. Drilling
with high-speed-steel is simply not feasible since the drill bits will dull quickly and thus
tear the copper and ruin the boards. The drilling is performed by automated drilling
machines with placement controlled by a drill tape or drill file. These computer-generated
files are also called numerically controlled drill (NCD) files or "Excellon files". The drill
file describes the location and size of each drilled hole. These holes are often filled with
annular rings (hollow rivets) to create vias. Vias allow the electrical and thermal
connection of conductors on opposite sides of the PCB.
When very small vias are required, drilling with mechanical bits is costly because of high
rates of wear and breakage. In this case, the vias may be evaporated by lasers. Laser-
drilled vias typically have an inferior surface finish inside the hole. These holes are
called micro vias.
It is also possible with controlled-depth drilling, laser drilling, or by pre-drilling the
individual sheets of the PCB before lamination, to produce holes that connect only some
49

of the copper layers, rather than passing through the entire board. These holes are
called blind vias when they connect an internal copper layer to an outer layer, or buried
vias when they connect two or more internal copper layers and no outer layers.
The hole walls for boards with 2 or more layers can be made conductive and then
electroplated with copper to form plated-through holes. These holes electrically connect
the conducting layers of the PCB. For multilayer boards, those with 3 layers or more,
drilling typically produces a smear of the high temperature decomposition products of
bonding agent in the laminate system. Before the holes can be plated through, this smear
must be removed by a chemical de-smear process, or by plasma-etch. The de-smear
process ensures that a good connection is made to the copper layers when the hole is
plated through. On high reliability boards a process called etch-back is performed
chemically with a potassium permanganate based etchant or plasma.The etch-back
removes resin and the glass fibers so that the copper layers extend into the hole and as the
hole is plated become integral with the deposited copper.
3.11.4 PROTECTION AND PACKAGING
PCBs intended for extreme environments often have a conformal coating, which is
applied by dipping or spraying after the components have been soldered. The coat
prevents corrosion and leakage currents or shorting due to condensation. The earliest
conformal coats were wax; modern conformal coats are usually dips of dilute solutions of
silicone rubber, polyurethane, acrylic, or epoxy. Another technique for applying a
conformal coating is for plastic to be sputtered onto the PCB in a vacuum chamber. The
chief disadvantage of conformal coatings is that servicing of the board is rendered
extremely difficult.
Many assembled PCBs are static sensitive, and therefore must be placed in antistatic
bags during transport. When handling these boards, the user must be grounded (earthed).
Improper handling techniques might transmit an accumulated static charge through the
board, damaging or destroying components. Even bare boards are sometimes static
sensitive. Traces have become so fine that it's quite possible to blow an etch off the board
(or change its characteristics) with a static charge. This is especially true on non-
traditional PCBs such as MCMs and microwave PCBs.
50

3. 12 SOLDERING
Soldering is a process in which two or more metal items are joined together by melting
and flowing a filler metal (solder) into the joint, the filler metal having a lower melting
point than the workpiece. Soldering differs from welding in that soldering does not
involve melting the work pieces. In brazing, the filler metal melts at a higher temperature,
but the workpiece metal does not melt. Formerly nearly all solders contained lead, but
environmental concerns have increasingly dictated use of lead-free alloys for electronics
and plumbing purposes.

FIG 2.23 SOLDERING PROCESS
Soldering operations can be performed with hand tools, one joint at a time, or en
masse on a production line. Hand soldering is typically performed with a soldering
iron, soldering gun, or a torch, or occasionally a hot-air pencil. Sheetmetal work was
traditionally done with "soldering coppers" directly heated by a flame, with sufficient
stored heat in the mass of the soldering copper to complete a joint; torches or electrically-
heated soldering irons are more convenient. All soldered joints require the same elements
of cleaning of the metal parts to be joined, fitting up the joint, heating the parts, applying
flux, applying the filler, removing heat and holding the assembly still until the filler metal
has completely solidified. Depending on the nature of flux material used, cleaning of the
joints may be required after they have cooled.
Each alloy has characteristics that work best for certain applications, notably strength and
conductivity, and each type of solder and alloy has different melting temperatures. The
term silver solder likewise denotes the type of solder that is used. Some soft solders are
51


FIG 3.24 SOLDER IRON
"silver bearing" alloys used to solder silver-plated items. Lead based solders should not
be used on precious metals because the lead dissolves the metal and disfigures it.
3. 12. 1SOLDER
Solder is a fusible metal alloy used to join together metal workpieces and having a
melting point below that of the workpiece(s).
Soft solder is typically thought of when solder or soldering is mentioned, with a typical
melting range of 90 to 450 C (190 to 840 F).It is commonly used
in electronics and plumbing, and when manually applied is often done so using
a soldering iron or soldering gun. Alloys that melt between 180 and 190 C (360 and
370 F) are the most commonly used. Soldering performed using alloys with melting
point above 450 C (840 F) is called 'hard soldering', 'silver soldering', or brazing.

FIG 3.25 SOLDER
For certain proportions an alloy becomes eutectic and melts at a single temperature; non-
eutectic alloys have markedly different solidus and liquidus temperature, and within that
range they exist as a paste of solid particles in a melt of the lower-melting phase. In
electrical work, if the joint is disturbed in the pasty state before it has solidified totally, a
52

poor electrical connection may result; use of eutectic solder reduces this problem. The
pasty state of a non-eutectic solder can be exploited in plumbing as it allows molding of
the solder during cooling, e.g. for ensuring watertight joint of pipes, resulting in a so-
called 'wiped joint'.
For electrical and electronics work solder wire is available in a range of thicknesses for
hand-soldering, and with cores containing flux. It is also available as a paste or as a
preformed foil shaped to match the workpiece, more suitable for mechanized mass-
production. Alloys of lead and tin were universally used in the past, and are still
available; they are particularly convenient for hand-soldering. Lead-free solder,
somewhat less convenient for hand-soldering, is often used to avoid the environmental
effect of lead.
Plumbers often use bars of solder, much thicker than the wire used for electrical
applications. Jewelers often use solder in thin sheets which they cut into snippets.
The word solder comes from the Middle English word soudur, via Old
French solduree and soulder, from the Latin solidare, meaning "to make solid".
With the reduction of the size of circuit board features, the size of interconnects shrinks
as well. Current densities above 10
4
A/cm
2
are often achieved
and electromigration becomes a concern. At such current densities the Sn63Pb37 solder
balls form hillocks on the anode side and voids on the cathode side; the increased content
of lead on the anode side suggests lead is the primary migrating species.
Contact with molten solder can cause 'solder embrittlement' of materials, a type of liquid
metal embrittlement
3.12.2 IMPURITIES IN SOLDERS
Impurities usually enter the solder reservoir by dissolving the metals present in the
assemblies being soldered. Dissolving of process equipment is not common as the
materials are usually chosen to be insoluble in solder.
Aluminium little solubility, causes sluggishness of solder and dull gritty appearance
due to formation of oxides. Addition of antimony to solders forms Al-Sb intermetallics
that are segregated into dross.
53

Antimony added intentionally, up to 0.3% improves wetting, larger amounts slowly
degrade wetting.
Arsenic forms thin intermetallics with adverse effects on mechanical properties, causes
dewetting of brass surfaces
Cadmium causes sluggishness of solder, forms oxides and tarnishes
Copper most common contaminant, forms needle-shaped intermetallics, causes
sluggishness of solders, grittiness of alloys, decreased wetting
Gold easily dissolves, forms brittle intermetallics, contamination above 0.5% causes
sluggishness and decreases wetting. Lowers melting point of tin-based solders. Higher-tin
alloys can absorb more gold without embrittlement.
[46]

Iron forms intermetallics, causes grittiness, but rate of dissolution is very low; readily
dissolves in lead-tin above 427 C.
[10]

Nickel causes grittiness, very little solubility in Sn-Pb
Phosphorus forms tin and lead phosphides, causes grittiness and dewetting, present in
electroless nickel plating
Silver often added intentionally, in high amounts forms intermetallics that cause
grittiness and formation of pimples on the solder surface
Sulphur forms lead and tin sulfides, causes dewetting
Zinc in melt forms excessive dross, in solidified joints rapidly oxidizes on the surface;
zinc oxide is insoluble in fluxes, impairing repairability; copper and nickel barrier layers
may be needed when soldering brass to prevent nickel migration to the surface
3.12.3 SOLDER RESIST
Areas that should not be soldered may be covered with "solder resist" (solder mask). One
of the most common solder resists used today is called LPI (liquid photoimageable).
[20]

A photo sensitive coating is applied to the surface of the PWB, then exposed to light
through the solder mask image film, and finally developed where the unexposed areas are
washed away. Dry film solder mask is similar to the dry film used to image the PWB for
plating or etching. After being laminated to the PWB surface it is imaged and develop as
LPI. Once common but no longer commonly used because of its low accuracy and
54

resolution is to screen print epoxy ink. Solder resist also provides protection from the
environment.
3.12.4 DESOLDERING
In electronics, desoldering is the removal of solder and components from
a circuit for troubleshooting, for repair purposes, component replacement, and to salvage
components. Electronic components are often mounted on a circuit board, and it is
usually desirable to avoid damaging the circuit board, surrounding components, and the
component being removed.
Specialized tools, materials, and techniques have been devised to aid in the desoldering
process.
Desoldering requires application of heat to the solder joint and removing the molten
solder so that the joint may be separated. Desoldering may be required to replace a
defective component, to alter an existing circuit, or to salvage components for re-use. Use
of too high a temperature or heating for too long may damage components or destroy the
bond between a printed circuit trace and the board substrate. Techniques are different for
through-hole and surface-mounted components.
3.12.4.1 DESOLDERING PUMP
A desoldering pump, colloquially known as a solder sucker, is a manually-operated
device which is used to remove solder from a printed circuit board. There are two types:
the plunger style and bulb style.
[1]
(An electrically-operated pump for this purpose would
usually be called a vacuum pump.)

FIG 3.27 DESOLDERING PUMP
55

The plunger type has a cylinder with a spring-loaded piston which is pushed down and
locks into place. When triggered by pressing a button, the piston springs up, creating
suction that sucks the solder off the soldered connection. The bulb type creates suction by
squeezing and releasing a rubber bulb.
The pump is applied to a heated solder connection, then operated to suck the solder away.
3.12.5 APPLICATIONS
Soldering is used in plumbing, in electronics and metalwork from flashing to jewelry.
Soldering provides reasonably permanent but reversible connections between copper
pipes in plumbing systems as well as joints in sheet metal objects such as food cans, roof
flashing, rain gutters and automobile radiators.
Jewelry components, machine tools and some refrigeration and plumbing components are
often assembled and repaired by the higher temperature silver soldering process. Small
mechanical parts are often soldered or brazed as well. Soldering is also used to join
lead came and copper foil in stained glasswork. It can also be used as a semi-permanent
patch for a leak in a container or cooking vessel.
Electronic soldering connects electrical wiring and electronic components to printed
circuit boards (PCBs).
Each type of solder offers advantages and disadvantages. Soft solder is so called because
of the soft lead that is its primary ingredient.Soft soldering uses the lowest temperatures
but does not make a strong join and is unsuitable for mechanical load-bearing
applications. It is also unsuitable for high-temperature applications as it softens and
melts. Silver soldering, as used by jewelers, machinists and in some plumbing
applications, requires the use of a torch or other high-temperature source, and is much
stronger than soft soldering. Brazing provides the strongest joint but also requires the
hottest temperatures to melt the filler metal, requiring a torch or other high temperature
source and darkened goggles to protect the eyes from the bright light produced by the
white-hot work. It is often used to repair cast-iron objects, wrought-iron furniture, etc.
Each alloy has characteristics that work best for certain applications, notably strength and
conductivity, and each type of solder and alloy has different melting temperatures. The
term silver solder likewise denotes the type of solder that is used. Some soft solders are
56

"silver bearing" alloys used to solder silver-plated items. Lead based solders should not
be used on precious metals because the lead dissolves the metal and disfigures it.
3.13 SOFTWARE USED
3.13.1 MPLAB IDE v8.83
MPLAB X IDE is a software program that runs on a PC (Windows, Mac OS,
Linux) to develop applications for Microchip microcontrollers and digital signal
controllers. It is called an Integrated Development Environment (IDE), because it
provides a single integrated environment to develop code for embedded
microcontrollers.
MPLAB X Integrated Development Environment brings many changes to the PIC
microcontroller development tool chain. Unlike previous versions of MPLAB which
were developed completely in-house, MPLAB X is based on the open source

FIG 3.27 MP LAB IDE HOLOGRAM
NetBeans IDE from Oracle. Taking this path has allowed us to add many frequently
requested features very quickly and easily while also providing us with a much more
extensible architecture to bring you even more new features in the future. It also provides
57

many new features that will be especially beneficial to users of our 16-bit and 32-bit
families where programs can grow to be extremely complex.
MPLAB X IDE provides an extensive list of features to help enhance your productivity
while developing and debugging applications on any device from the PIC microcontroller
product family. However, as with any feature-rich program, it can be a challenge to learn
to use all of its capabilities or even to find out what all of those capabilities are. The goal
of this site is to help you to discover and learn how to use the many available features that
are sure to simplify and enhance your development activities.
STEPS
Open MPLAB IDE. Open the tutorial via File->Open Workspace->browse to the location
of the tutorial and open the workspace.
Before you can compile the project the correct compiler tools and library locations must
be selected.
Selecting the required compiler tools is done as in the following:
Project -> Select Language Toolsuite (See the dialog box below and follow the steps)
1From the Active Toolsuite pull-down menu, select Microchip C30 Toolsuite. This
toolsuite
includes the compiler, assembler and linker that will be used.
In the Toolsuite Contents block, select MPLAB ASM30 Assembler (pic30-as.exe).In the
Location block, click browse and navigate to:
C:\...\Microchip\mplabc30\v3.30c\bin\pic30-as.exe
In the Toolsuite Contents block, select MPLAB C30 C Compiler (pic30-gcc.exe).
In the Location block, click browse and navigate to:
C:\...\Microchip\mplabc30\v3.30c\bin\pic30-gcc.exe
In the Toolsuite Contents block, select MPLAB LINK 30 Object Linker (pic30-Id.exe)
In the Location block, click browse and navigate to:
C:\...\Microchip\mplabc30\v3.30c\bin\pic30-ld.exe
58


FIG 3.28 MP LAB IDE TOOLKIT
Close the selection language toolsuite by clicking ok.
To enable the libraries downloaded in the above go to Project->Build Options->
Project->Directories. Select "Include search path" in the dropdown. Enter the path to the
libraries. Eg. C:\Projects\E-pucks\Libraries.
Add the same under "Assembler include search path"
The last thing to do before compilation is correcting the reference to the linker file. Right
click the p30f6014A.gld file under Linker Script below the *.c, *.h and assembly files in
the left bottom of the MPLAB workspace and correct the reference to:
C:\...\Microchip\mplabc30\v3.25\Support\dsPIC30F\gld\ to find p30f6014a.gld
During the first compilation MPLAB IDE will probably notify you that the compiler files
have been moved since last compilation. You should use the MPLAB IDE selected
locations.
Click ok.
You should now be ready to compile the project. Go to project -> Build All, press ctrl +
F10 or click the icon with the two arrows pointing downwards.

59


FIG 3.29 MP LAB IDE TOOLSUIT








60

RESULT
Temperature controller can be done by using Electronic circuit, microprocessor,
microcontroller. Now microcontroller is advanced among all other circuits, therefore we
are using microcontroller for temperature controlling.
In this project, microcontroller PIC 16F877A forms the processing part, which firstly
receives data from ADC. ADC receives data from the temperature sensor. Then
microcontroller PIC 16F877A performs the comparison of current temperature and set
temperature as per the logic of program for which microcontroller had already been
programmed. The result obtained from the above operation is given through the output
port of PIC 16F877A to LCD display of relevant data and generated pulses as per the
program which is further fed to the driver circuit to obtain the desired output of the fan.











61

CONCLUSION AND FUTURE SCOPE
Depending on the temperature, the speed of the fan is controlled. It would be better if we
control the AC fan, the only consideration to be taken is the current capacity of the relay.
The operation of the system is perfect.
The project can be used at home.
The project can be used at industry.
FURTHER DEVELOPMENT
We can monitor more parameters like humidity, light and at the same time control them.
We can send this data to remote location using mobile or internet.












62

APPENDIX
#include<htc.h>
#define _XTAL_FREQ 8000000
#define setbit(address,bitx) (address |= (1<<bitx))
#define clearbit(address,bitx) (address &=~(1<<bitx))
#define adcdata PORTB
#define sendlcd PORTD
#define lcont PORTC
#define rs 0
#define rw 1
#define en 2
#define rd 4
#define wr 3
#define intr 2
#define fan 3
void convert(unsigned char);
void lcdcommand(unsigned char);
void lcddata(unsigned char);

63

void main() {
unsigned char adcval;
TRISD = 0X00;
TRISC = 0X00;
TRISB = 0XFF;
TRISA = 0X00;
PORTB = 0XFF;
setbit(PORTA,rd);
setbit(PORTA,wr);
setbit(PORTA,intr);
while(1)
{
clearbit(PORTA,wr);
setbit(PORTA,wr);
while(PORTA&(1<<intr));
{
clearbit(PORTA,rd);
adcval = adcdata;
convert(adcval);
64

setbit(PORTA,rd);
}
}
if(adcval>25)
{
setbit(PORTC,fan);
}
}
void convert(unsigned char z)
{
unsigned int a,b,c;
a=z/100;
z=(z-(a*100));
b=z/10;
c=(z-(b*10));
lcdcommand(0x38);
lcdcommand(0x0c);
lcdcommand(0x01);
lcdcommand(0x06);
65

lcdcommand(0x80);
lcddata('T');
lcddata('E');
lcddata('M');
lcddata('P');
lcddata('_');
lcdcommand(0x85);
lcddata(a+0x30);
lcddata(b+0x30);
lcddata(c+0x30);
lcddata('c');
aa:goto aa;
}
void lcdcommand(unsigned char com)
{
sendlcd =com;
clearbit(lcont,rs); //rs =0
clearbit(lcont,rw); //rw =0
setbit(lcont,en); //en =1
66

__delay_ms(1);
clearbit(lcont,en); //en =0
__delay_ms(1);
__delay_us(67);
}
void lcddata(unsigned char value)
{
sendlcd = value;
setbit(lcont,rs); //rs =1
clearbit(lcont,rw); //rw =0
setbit(lcont,en); //en =1
__delay_ms(1);
clearbit(lcont,en); //en =0
__delay_ms(1);
}



67

COST EVALUATION OF COMPONENTS USED IN THE
PROJECT
COMPONENTS COST
MICROCONTROLLER PIC
16F877A
160
ADC 0804 124
16*2 LCD DISPLAY 180
CRYSTAL OSCILLATOR
20MHz
15
CAPACITORS 2
RESISTORS 1
VOLTAGE REGULATOR 7805 12
TEMPERATURE SENSOR
LM35
80
MAX IC(ULN 2003) 24
TRANSFORMER 60
DIODE 4
RELAY 18
IC BASE 20
PCB 30
CONNECTING WIRES 10
FAN
SOLDER 20

68

REFERENCES
www.eprints.usq.edu.au
www.google.com
www.howstuffworks.com
www.wikipedia.com
www.microchip.com
www.howstuffworks.com

Vous aimerez peut-être aussi