Professional Documents
Culture Documents
INTRODUCTION
CHAPTER 1
INTRODUCTION
a straight line with the saline bottle in between, at the point representing the preset saline level. The
presence of saline water, in a full bottle, refracts the emitted radiation, thus generating no output at
the IR detector. When the saline level falls below the preset value; the emitted IR radiation causes a
photoelectric current from the detector. The detector output is an analog quantity which is made to
drive a switching NPN transistor BC107 to get a binary output from the collector of the transistor.
This digital output is fed to the pin 23 of the PIC micro controller, corresponding to port bit 4. The
signal is processed and the saline status is displayed on the screen. In case of the saline becoming
empty the annunciation systems are activated.
CHAPTER 2
HARDWARE COMPONENT
CHAPTER 2
HARDWARE COMPONENT
2.1 RESISTOR
Electrical resistance is a measure of the degree to which an object opposes an electric current
through it. The SI unit of electrical resistance is the ohm. Its reciprocal quantity is electric
conductance measured in seimens. Electrical resistance shares some conceptual parallels with the
mechanical notion of friction.
V
R
where V is the voltage (or potential difference) across the wire in volts, I is the current through the
wire in amperes, and R, in ohms, is a constant called the resistance in fact this is only a
simplification of the original Ohm's law Materials that obey this law over a certain voltage or current
range are said to be ohmic over that range. An ideal resistor obeys the law across all frequencies and
amplitudes of voltage or current. Superconducting materials at very low temperatures have zero
resistance. Insulators (such as air, diamond, or other non-conducting materials) may have extremely
high (but not infinite) resistance, but break down and admit a larger flow of current under
sufficiently high voltage.
Where
l is the length of the conductor, measured in meters.
A is the cross-sectional area, measured in square meters.
(Greek: rho) is the electric sensitivity s(also called specific electrical resistance) of the
material, measured in ohm meter. Resistivity is a measure of the material's ability to oppose
the flow of electric current.
For practical reasons, almost any connections to a real conductor will almost certainly mean the
current density is not totally uniform. However, this formula still provides a good approximation for
long thin conductors such as wires.
10
2.4.2 AC resistance
If a wire conducts high-frequency alternating current then the effective cross sectional area of the
wire is reduced. This is because of the skin effect. This formula applies to isolated conductors. In a
conductor close to others, the actual resistance is higher because of the proximity effect.
What do resistors do?
Resistors limit current. In a typical application, a resistor is connected in series with an LED:
Enough current flows to make the LED light up, but not so much that the LED is damaged. Later in
this Chapter, you will find out how to calculate a suitable value for this resistor. The 'box' symbol for
a fixed resistor is popular in the UK and Europe. A 'zigzag' symbol is used in America and Japan:
Resistors are used with transducers to make sensor subsystems. Transducers are electronic
components, which convert energy from one form into another, where one of the forms of energy is
11
electrical. A light dependent resistor, or LDR, is an example of an input transducer. Changes in the
brightness of the light shining onto the surface of the LDR result in changes in its resistance. As will
be explained later, an input transducer is most often connected along with a resistor to make a circuit
called a potential divider. Most electronic circuits require resistors to make them work properly and
it is obviously important to find out something about the different types of resistor available, and to
be able to choose the correct resistor value, in
, or M
Number
Colour
Black
Brown
Red
Orange
Yellow
Green
Blue
Violet
How can the value of a resistor be worked out from the colours of the bands? Each colour represents
a number according to the following scheme: The first band on a resistor is interpreted as the FIRST
DIGIT of the resistor value. For the resistor shown below, the first band is yellow, so the first digit is
4:
12
The second band gives the SECOND DIGIT. This is a violet band, making the second digit 7. The
third band is called the MULTIPLIER and is not interpreted in quite the same way. The multiplier
tells you how many noughts you should write after the digits you already have. A red band tells you
to add 2 noughts. The value of this resistor is therefore 4700 ohms, that is, 4700
, or 4.7
. Work
through this example again to confirm that you understand how to apply the colour code given by
the first three bands. The remaining band is called the TOLERANCE band. This indicates the
percentage accuracy of the resistor value. Most carbon film resistors have a gold-coloured tolerance
band, indicating that the actual resistance value is with + or - 5% of the nominal value. Other
tolerance colours are:
Tolerance
Colour
1%
Brown
2%
Red
5%
Gold
10%
Silver
2.6 CAPACITORS
can store energy in the electric field between a pair of closely-spaced conductors (called 'plates').
When voltage is applied to the capacitor, electric charges of equal magnitude, but opposite polarity,
build up on each plate. Capacitors are used in electrical circuits as energy-storage devices. They can
also be used to differentiate between high-frequency and low-frequency signals and this makes them
useful in electronic filters. Capacitors are occasionally referred to as condensers. This is now
considered an antiquated term. A capacitor consists of two conductive electrodes, or plates, separated
by an insulator.
2.7 Capacitance
When electric charge accumulates on the plates, an electric field is created in the region between the
plates that is proportional to the amount of accumulated charge. This electric field creates a potential
difference V = Ed between the plates of this simple parallel-plate capacitor. The capacitor's
capacitance (C) is a measure of the amount of charge (Q) stored on each plate for a given potential
difference or voltage (V) which appears between the plates:
In SI units, a capacitor has a capacitance of one farad when one coulomb of charge is stored due to
one volt applied potential difference across the plates. Since the farad is a very large unit, values of
capacitors are usually expressed in microfarads (F), nanofarads (nF), or picofarads (pF).The
capacitance is proportional to the surface area of the conducting plate and inversely proportional to
the distance between the plates. It is also proportional to the permittivity of the dielectric (that is,
14
non-conducting) substance that separates the plates. The capacitance of a parallel-plate capacitor is
given by:
Where is the permittivity of the dielectric, A is the area of the plates and d is the spacing between
them.
The electrons within dielectric molecules are influenced by the electric field, causing the molecules
to rotate slightly from their equilibrium positions. The air gap is shown for clarity; in a real
15
capacitor, the dielectric is in direct contact with the plates. Capacitors also allow AC current to flow
and block DC current.
16
17
It is such a capacitor which is used for high voltage DC&AC on medium loss and medium accuracy
of capacitance stability. Wrapping thin layer of aluminum with the layers of tissue paper makes it
and to remove the moisture from paper, thin layer of wax is used on it. In the matellised paper
capacitor, metal film is used in place of aluminum for electrodes. The value of paper capacitor is
generally in between 0.001 microfarad to 0.2 microfarad. Their voltage capacity is maximum up to
100 V. now- a- days; polyester plastic film is used on the tissue paper in the paper capacitors.
18
2.11 TRANSISTORS
19
2.11.2 Introduction
Modern transistors are divided into two main categories: bipolar junction transistors (BJTs) and field
effect transistors (FETs). Application of current in BJTs and voltage in FETs between the input and
common terminals increases the conductivity between the common and output terminals, thereby
controlling current flow between them. The transistor characteristics depend on their type. In analog
circuits, transistors are used in amplifiers, (direct current amplifiers, audio amplifiers, radio
frequency amplifiers), and linear regulated power supplies. Transistors are also used in digital
circuits where they function as electronic switches, but rarely as discrete devices, almost always
being incorporated in monolithic Integrated Circuits. Digital circuits include logic gates, random
access memory (RAM), microprocessors, and digital signal processors (DSPs).
20
2.12 Types
2.12.1 Transistors are categorized by:
Maximum operating frequency: low, medium, high, radio frequency (RF), microwave (The
maximum effective frequency of a transistor is denoted by the term ft., an abbreviation for
"frequency of transition".
Application: switch, general purpose, audio, high voltage, super-beta, matched pair
Physical packaging: through hole metal, through hole plastic, surface mount, ball grid array,
power modules.
There are mainly two types of transistor (i) NPN (ii) PNP
Both types are shown in figure, with their symbols for representation. The centre section is called the
base, one of the outside sections-the emitter and the other outside section-the collector. The direction
of the arrowhead gives the direction of the conventional current with the forward bias on the emitter.
The conventional flow is opposite in direction to the electron flow.
A switching amplifier or class-D amplifier is a power amplifier where the active devices (especially
in the output stage) are operated in on/off mode (i.e., as switches). The term "Class-D" is often
assumed to mean "digital" amplifier. The quantization of the output signal implies sampling like that
done in A/D conversion, but such amplifiers' input and output signals are still analog. Output stages
such as those used in pulse generators are examples of class D amplifiers. However, the term mostly
applies to devices intended to reproduce signals with a bandwidth well below the switching
frequency. These amplifiers use pulse width modulation (PWM), pulse density modulation
(sometimes referred to as pulse frequency modulation) or more advanced forms of modulation such
as Sigma delta modulation (see for example Analog Devices AD1990 Class-D audio power
22
amplifier). The input signal is converted to a sequence of pulses whose average value is directly
proportional to the amplitude of the signal at that time.
2.14 OSCILLATOR
Oscillators may be classified by name, such as Armstrong, Hartley, Colpitts, or by the manner in
which dc power is applied. An oscillator, in which dc power is supplied to the transistor through the
tank circuit, or a portion of the tank circuit, is said to be SERIES FED. An oscillator, which receives
its dc power for the transistor through a path separate and parallel to the tank circuit, is said to be
PARALLEL FED OR SHUNT FED. The construction depends on the characteristics of the oscillator
circuit the designer is interested in.
shape, elasticity, and the speed of sound in the material. High-frequency crystals are typically cut in
the shape of a simple, rectangular plate.
Or,
24
Where s is the complex frequency (s = j), s is the series resonant frequency in radians per second
and p is the parallel resonant frequency in radians per second. Adding additional capacitance across
a crystal will cause the parallel resonance to shift downward. This can be used to adjust the
frequency at which a crystal oscillator oscillates. Crystal manufacturers normally cut and trim their
crystals to have a specified resonant frequency with a known 'load' capacitance added to the crystal.
For example, a 6 pF 32 kHz crystal has a parallel resonance frequency of 32,768 Hz when a 6.0 pF
capacitor is placed across the crystal. Without this capacitance, the resonance frequency is higher
than 32,768 Hz.
2.15 LED
LEDs produce more light per watt than do incandescent bulbs; this is useful in battery
powered or energy-saving devices.
26
LEDs can emit light of an intended color without the use of color filters that traditional
lighting methods require. This is more efficient and can lower initial costs.
The solid package of an LED can be designed to focus its light. Incandescent and fluorescent
sources often require an external reflector to collect light and direct it in a usable manner.
When used in applications where dimming is required, LEDs do not change their color tint as
the current passing through them is lowered, unlike incandescent lamps, which turn yellow.
LEDs are ideal for use in applications that are subject to frequent on-off cycling, unlike
fluorescent lamps that burn out more quickly when cycled frequently.
2.15.3 Technology
27
28
Color
Wavelength
[nm]
Voltage [V]
Semiconductor Material
> 760
V < 1.9
Red
Orange
Yellow
Blue
Violet
Purple
multiple types
Infrared
Green
29
White
diamond (C)
Aluminium nitride (AlN)
3.1 < V < 4.4 Aluminium gallium nitride (AlGaN)
Aluminium gallium indium nitride (AlGaInN)
(down to 210 nm[27])
Blue LEDs
Blue LEDs are based on the wide band gap semiconductors GaN (gallium nitride) and InGaN
(indium gallium nitride). They can be added to existing red and green LEDs to produce the
impression of white light, though white LEDs today rarely use this principle. The first blue LEDs
were made in 1971 by Jacques Pankove (inventor of the gallium nitride LED) at RCA Laboratories.]
However, these devices had too little light output to be of much practical use. In the late 1980s, key
breakthroughs in GaN epitaxial growth and p-type doping by Isamu Akasaki and Hiroshi Amano
(Nagoya, Japan) ushered in the modern era of GaN-based optoelectronic devices. Building upon this
30
foundation, in 1993 high brightness blue LEDs were demonstrated through the work of Shuji
Nakamura at Nichia Corporation. Wavelengths down to 210 nm were obtained in laboratories using
aluminium nitride.While not an LED as such, an ordinary NPN bipolar transistor will emit violet
light if its emitter-base junction is subjected to non-destructive reverse breakdown. This is easy to
demonstrate by filing the top off a metal-can transistor (BC107, 2N2222 or similar) and biasing it
well above emitter-base breakdown ( 20 V) via a current-limiting resistor.
LEDs are currently more expensive, price per lumen, on an initial capital cost basis, than
more conventional lighting technologies. The additional expense partially stems from the
relatively low lumen output and the drive circuitry and power supplies needed.
LEDs typically cast light in one direction at a narrow angle compared to an incandescent or
fluorescent lamp of the same lumen level.
The spectrum of some white LEDs differs significantly from a black-body radiator, such as
the sun or an incandescent light.
At present the spectrum of emitted light from white LEDs falls outside the natural range
provided by incandescent bulbs, making them less suited for domestic lighting.
2.16.1 Diodes
31
Diode schematic symbol. Conventional current can flow from the anode to the cathode, but not the
other way around.Most modern diodes are based on semiconductor p-n junctions. In a p-n diode,
conventional current flows from the p-type side (the anode) to the n-type side (the cathode), but not
in the opposite direction. Another type of semiconductor diode, the Schottky diode, is formed from
the contact between a metal and a semiconductor rather than by a p-n junction. A semiconductor
diode's current-voltage, or I-V, characteristic curve is described to the behavior of the so-called
depletion layer or depletion zone which exists at the p-n junction between the differing
semiconductors. When a p-n junction is first created, conduction band (mobile) electrons from the
N-doped region diffuse into the P-doped region where there is a large population of holes (places for
electrons in which no electron is present) with which the electrons "recombine". When a mobile
32
electron recombines with a hole, the hole vanishes and the electron is no longer mobile. Thus, two
charge carriers have vanished. The region around the p-n junction becomes depleted of charge
carriers and thus behaves as an insulator.
33
reverse conduction will cease very abruptly (as in a step waveform). SRDs can therefore provide
very fast voltage transitions by the very sudden disappearance of the charge carriers.
to lock quickly, replacing older designs that took a long time to warm up and lock. A PLL is faster
than a FLL, but prone to integer harmonic locking (if one attempts to lock to a broadband signal).
They also enabled tunable oscillators in early discrete tuning of radios, where a cheap and stable, but
fixed-frequency
2.16.15 Photodiodes
Semiconductors are subject to optical charge carrier generation and therefore most are packaged in
light blocking material. If they are packaged in materials that allow light to pass, their
photosensitivity can be utilized. Photodiodes can be used as solar cells, and in photometry.
36
37
2.17 RELAYS
To 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
38
installed in partitions, which may be often moved as needs change. They may also be
controlled by room occupancy detectors in an effort to conserve energy,
To perform logic functions. For example, the Boolean AND function is realised by
connecting NO relay contacts in series, the OR function by connecting NO contacts in
parallel.
2.18 TRANSFORMER
A transformer is a device that transfers energy from one electrical circuit to another by magnetic
coupling without requiring relative motion between its parts. A transformer comprises two or more
coupled windings, and, in most cases, a magnetic core to concentrate magnetic flux. A voltage
applied to one winding creates a time-varying magnetic flux in the core, which induces a voltage in
the other windings. Varying the relative number of turns in the windings determines the ratio of their
voltages, thus transforming the voltage from one circuit to another.
magnitude to the measured terminal voltages. In accordance with Faraday's law of induction, they
are proportional to the rate of change of flux:
and
Where:
and
and
are the time derivatives of the flux linking the primary and secondary
windings.
All flux produced by the primary winding also links the secondary, and so
, from which
The ratio of primary to secondary voltage is therefore the same as the ratio of the number of turns
alternatively, that the volts-per-turn is the same in both windings.
40
Classifications
Transformers are adapted to numerous engineering applications and may be classified in many ways:
By cooling type (air cooled, oil filled, fan cooled, water cooled, etc.)
However, transformers are components of the systems that perform all these functions.
Large, specially constructed power transformers are used for electric arc furnaces used in
steelmaking.
Rotating transformers are designed so that one winding turns while the other remains
stationary. A common use was the video head system as used in VHS and Beta video tape
players. These can pass power or radio signals from a stationary mounting to a rotating
mechanism, or radar antenna.
Transformer-like device is used for position measurement. See linear variable differential
transformer.
Some rotary transformers are used to couple signals between two parts which rotate in
relation to each other.
Intelligent, with built-in Hitachi HD44780 compatible LCD controller and RAM providing simple
interfacing 61 x 15.8 mm viewing area 5 x 7 dot matrix format for 2.96 x 5.56 mm characters, plus
cursor line Can display 224 different symbols Low power consumption (1 mA Typical) Powerful
command set and user-produced characters TTL and CMOS compatible Connector for standard 0.1pitch pin headersumeric LCD Module
2.19.3 Keypad
A keypad is a set of buttons arranged in a block which usually bear digits and other symbols but not
a complete set of alphabetical letters. If it mostly contains numbers then it can also be called a
numeric keypad. Keypads are found on many alphanumeric keyboards and on other devices such as
calculators, combination locks and telephones which require largely numeric input.
2.19.5 A calculator
By convention, the keys on calculator-style keypads are arranged such that 123 is on the bottom row.
In contrast, a telephone keypad has the 123 keys at the top. It also has buttons labeled * (star) and #
(octothorpe, number sign, "pound" or "hash") either side of the zero. Most of the keys also bear
letters which have had several auxiliary uses, such as remembering area codes or whole telephone
numbers.
44
Keypads are a part of mobile phones that are replaceable and sit on a sensor board. Some multimedia
mobile phones have a small joystick which has a cap to match the keypad.
2.19.6 EEPROM
EEPROM (electrically erasable programmable read-only memory) is user-modifiable read-only
memory (ROM) that can be erased and reprogrammed (written to) repeatedly through the application
of higher than normal electrical voltage. Unlike EPROM chips, EEPROMs do not need to be
removed from the computer to be modified. However, an EEPROM chip has to be erased and
reprogrammed in its entirety, not selectively. It also has a limited life - that is, the number of times it
can be reprogrammed is limited to tens or hundreds of thousands of times. In an EEPROM that is
frequently reprogrammed while the computer is in use, the life of the EEPROM can be an important
design consideration.
45
typically has its own set of OP-Code Instructions to map to different functions. Some of the common
operations on SPI EEPROM devices are:
Write Enable (WREN)
Write Disable (WRDI)
Read Status Register (RDSR)
Write Status Register (WRSR)
Read Data (READ)
Write Data (WRITE)
Other operations supported by some EEPROM devices are:
Program
Sector Erase
Chip Erase commands
and
electrical tests (only the passivation layer need to be added), and held in inventory. This means
that ROM can be
programmed
late in
two weeks.
both
used to
instructions and data. Program instructions and data are stored in a common main
memory. When such a controller addresses main memory, it first fetches an instruction, and then
47
instruction. The
two separate
fetches
slows
up
the
controller's operation.
on the data bus. Once the current instruction is complete, the next
instruction is ready to go. This pre-fetch theoretically allows for much faster execution than VonNeumann architecture, but there is some added silicon complexity.
2.20.2.3 CISC
Almost all of today's microcontrollers are based on the CISC (Complex Instruction Set Computer)
concept. The typical CISC microcontroller has well over 80 instructions, many of them very
powerful and very specialized for specific control tasks. It is quite common for the instructions to all
behave quite differently. Some might only operate on certain address spaces or registers and others
might only recognize certain addressing modes. The advantages of the CISC architecture are that
many of the instructions are macro-like, allowing the programmer to use one instruction in place of
many simpler instructions.
2.20.2.4 RISC
The industry
trend for
designs. This is beginning to spill over into the microcontroller market. By implementing fewer
instructions, the chip designed is able to dedicate some of the precious
performance enhancing features The benefits of RISC design simplicity are a smaller chip, smaller
pin count, and very low power consumption.
48
2.20.2.5 SISC
Actually a microcontroller is by definition a Reduced Instruction Set
opinion).
now come with a mind boggling array of features that aid the control engineer - watchdog timers,
sleep/wakeup modes, power management, powerful I/O channels, and so on. By keeping
instruction
the
these features can be added, while maintaining the economy of the microcontroller
( because of its
economics) for small Amounts of memory that hold a limited number of parameters that May
have to be changed from time to time. This type of memory is relatively slow, and the number
of erase/write cycles allowed in its lifetime is limited.
keep
to be
reprogrammed in the
that it
controls.
One
engine
from
the
system
volatile program memory on the engine's microcontroller allows the engine controller program
to be modified
for such
factors
Reprogramming
up. Almost
during
as engine aging and changing emissions control laws (or even to fix bugs).
of
every
the
hardware supported it, you could remotely upgrade your modem from V fast to V.34, or incorporate
new features such as voice control or a digital answering machine.
protected
against
unauthorized snooping (reverse engineering, modifications, piracy, etc.). This is only an option on
OTPs and Windowed devices. On Masked ROM devices, security is not needed - the only way
50
be to
rip
microcontrollers, and 5
Volts is very easy to do in a car, most microcontrollers have only supported 4.5 - 5.5 V operation. In
the recent past, as consumer goods are beginning to drive major Segments of the microcontroller
market, and as consumer goods Become portable and lightweight, the requirement for 3 volt (and
lower) microcontrollers
has
to
operate
at
the market
today
lower voltage =
properly at
the
operating voltage (Vcc) is lower than the brownout voltage. The device is held in reset and will
remain in reset when Vcc stays below the Brownout voltage. The device will
resume execution
(from reset) after Vcc has risen above the brownout Voltage.
2.21.8 Idle/Halt/Wakeup
The device can be placed into IDLE/HALT mode by software control. In both
conditions the state of the microcontroller remains. RAM is not cleared and any outputs are not
changed. The terms idle and halt often have different definitions, depending on the manufacturer.
What some call idle, others may call halt, and vice versa. It can be confusing, so check the data
sheet for the device in question to be sure.
51
The Multi-Input Wake up (MIWU) feature is used to return (wakeup) the microcontroller from either
HALT or IDLE modes. Alternately MIWU may also be used to generate up to 8 edge selectible
external interrupts. The user can select whether the
A UART (Universal Asynchronous Receiver Transmitter) is a serial port adapter for asynchronous serial
communications.
2.22.1 USART
A synchronous serial port doesn't require start/stop bits and can Operate at much higher clock rates than
an
asynchronous serial port. Used to communicate with high speed devices such as memory servers,
display drivers, additional A/D ports, etc. Can also be used to implement a simple microcontroller
network.
52
The I2C bus is a simple 2 wire serial interface developed by Philips. It was developed for 8 bit
applications and is widely used in consumer electronics, automotive and industrial applications. In
addition to microcontrollers, several peripherals also exist that support the I2C bus. The I2C bus is a two
line, multi-master, multi-slave network Interface with collision detection. Up to 128 devices can exist O
the network and they can be spread out over 10 meters. Each node (microcontroller or peripheral) may
initiate a message, and then transmit or receive data.
Converts an external analog signal (typically relative to voltage) and converts it to a digital
representation. Microcontrollers that have this
feature
can
be
used for
instrumentation,
environmental data logging, or any application that lives in an analog world successive approximation
A/D converters. This is the most common type of A/D and is used in the majority of microcontrollers.
In this technique, the converter figures out each bit at a time (most significant first) and finds if the next
step is higher or lower.
Digital
changed to the analog output of (50/256 * 5Volts) = .9765625V on an 8-bit / 5 Volt system.
Often used as a digital-to-analog conversion technique. A pulse train is generated and regulated with
a low-pass filter to generate a voltage proportional to the duty cycle.
53
A pulse accumulator is an event counter. Each pulse increments the pulse accumulator register,
recording the number of times this event has occurred.
2.22.9 Comparator
One or more standard comparators can sometimes be placed on a microcontroller die. These
comparators operate much like standard comparators however the input and output signals are
available on the microcontroller bus.
quantity
pressure temperature, voltage , current, air and water flow are always analog entities. They
can be
digitized
for
storage
sensing continuously varying information, shaping and converting it for the efficiency of digital
processing and transmission.
2.23 Interrupts
2.23.1 Polling
Polling is not really a "feature"-it's what you have to do if your
have interrupts. Polling is a software technique whereby the controller continually asks a peripheral
54
if it needs servicing. The peripheral sets a flag when it has data ready for transferring to the
controller, which the controller notices on its next poll.
2.22.2 Interrupts
Rather
than
have the
(timers
/ UARTS
microcontroller
A/Ds /
continually
asking
peripherals
finding most of the time they do not), a more efficient method is to have the peripherals tell
the
controller
normal
of an
peripheral,
then
to
the controller
peripherals
can
be
carrying
out
its
response
advantage of
software overhead (of continually asking peripherals if they have any data ready).
is
that
you
interrupts
it out means
disabling
benefit of maskable
can turn off a particular interrupts (for example a UART) during some
time critical task. Then, those particular interrupts will be ignored thus allowing the microcontroller
to deal with the task at hand. Most microcontrollers (as well as most microprocessors) have some
type of Global Interrupt Enable (GIE).
the
to see which peripheral has caused the interrupt to occur. This can
between the interrupt happening and the time the service routine
55
is entered, depends on how the system designer sets up their ranking In ROM location 01F8 01F9 (2bytes x 8 bits = 16bit address) the system designer enters the ROM location of where they
want the service routine (of the Timer T0 underflow) to be. And so on for the rest of the addresses.
arbitration
and
priority - These are two of the most misused words when it comes to
between
them.
Priority
is
and
not
is
not
Priority. Lets see if we can sort out the differences. Arbitration - If you look at the above chart of
the COP888CG, you May
They do
have rank, but they are not prioritized. What happens is that (in an arbitration scheme)
think the interrupts are prioritized because they have some ranking.
GIE
is
that all future interrupts will be delayed until the GIE is set. The GIE becomes set only if
the system designer sets it in service routines, or on a RETI (Return from Interrupt).
that
prevents
operating correctly. If the program fails to reset the watchdog at some predetermined
interval, a
hardware reset will be initiated. The bug may still exist, but at least the system has a way recover.
This is especially useful for unattended systems.
thing a
2.23 Monitor
A monitor is a program installed in the microcontroller which provides
debug capabilities. Typical capabilities of a
basic
development and
setting breakpoints, and single-stepping through code. Some simple monitors only
allow basic functions such as memory inspection, and the more sophisticated
57
tangible stimuli. This breakthrough product is dubbed the MIL-WOMF ("Whoa, outta my face")
transducer.
58
Chapter 3
SOFTWARE REQUIREMENT
59
Chapter 3
SOFTWARE REQUIREMENT
3.1 CODE VISION AVR:Code Vision AVR is a C cross compiler, Integrated Development Environment and Automatic
Program generator designed for Atmel AVR family of microcontrollers. The program is designed to
run under the Widows 98,200, XP and Vista 32 bit operating system. The C cross compiler
implements all the elements of the ANSI C language, as allowed by the AVR architecture with some
features added to take advantage of specificity of the AVR architecture and the embedded system
needs. The combined COFF file can be C source level debugged with variable watching using the
Atmel AVR studio debugger. The Integrated Development Environment (IDE) has built in AVR chip
in system programmer software that enables the automatically transfer of the program to the
microcontroller chip after the successful compilation/assembly. The In-system programmer software
is designed to work in conjunction with the Atmel STK500 and other development boards. For
debugging embedded systems, which employee serial communication, the IDE has a built in
terminal.
Besides the standard C libraries, the Code Vision AVR compiler has dedicated libraries for: Alphanumeric LCD modules.
National semiconductor LM75 sensor.
Power management.
Delays.
Gray code conversion.
Code Vision AVR also contains the Code Wizard AVR Automatic program generator, that allows us
to write, in a matter of minutes, all the code needed for implementing the following functions: External memory access setup.
Chip reset source identification.
Input/output port initialization.
External interrupt initialization.
Timers/counters initializations.
Watchdog timer initialization.
Analog comparator initialization.
ADC initialization.
Two wire interface initialization.
60
In Code Vision AVR we write the required coding of our project. The steps involved in this process
are explained below:-
3.2 Working with projects:- The project groups the source file(s) and compiler setting that we
use for a building a particular program.
3.3 1- Creating a New Project: - We can create a new project using the File New menu
command by pressing the specified button on the toolbar. A dialog box appears, in which we must
select File Type Project and press OK button.
61
If we select NO then the Create New Project dialog window will open. We must specify the new
Project file name and its location.
toolbar button.
2-Opening an Existing Project:- We can open an existing project file using the File| Open
menu command. An Open dialog window appears.
62
Chapter 4
MICROCONTROLLER AT mega 16
63
Chapter 4
MICROCONTROLLER AT mega 16
The AVR core combines a rich instruction set with 32 general purpose working registers. All the
32registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent
registers to be accessed in one single instruction executed in one clock cycle. The resulting
architecture is more code efficient while achieving throughputs up to ten times faster than
conventional CISC microcontrollers.
The ATmega16A provides the following features: 16K bytes of In-System Programmable Flash
Program memory with Read-While-Write capabilities, 512 bytes EEPROM, 1K byte SRAM, 32
general purpose I/O lines, 32 general purpose working registers, a JTAG interface for Boundary
scan, On-chip Debugging support and programming, three flexible Timer/Counters with compare
modes, Internal and External Interrupts, a serial programmable USART, a byte oriented Two-wire
Serial Interface, an 8-channel, 10-bit ADC with optional differential input stage with programmable
gain (TQFP package only), a programmable Watchdog Timer with Internal Oscillator, an SPI serial
port, and six software selectable power saving modes. The Idle mode stops the CPU while allowing
the USART, Two-wire interface, A/D Converter, SRAM, Timer/Counters, SPI port, and interrupt
system to continue functioning. The Power-down mode saves the register contents but freezes the
Oscillator, disabling all other chip functions until the next External Interrupt or Hardware Reset. In
Power-save mode, the Asynchronous Timer continues to run, allowing the user to maintain a timer
base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the CPU and all
I/O modules except Asynchronous Timer and ADC, to minimize switching noise during ADC
conversions.
4.1 Features
High-performance, Low-power AVR 8-bit Microcontroller
64
Interface
Peripheral Features
Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode
Real Time Counter with Separate Oscillator
Four PWM Channels
8-channel, 10-bit ADC
8 Single-ended Channels
7 Differential Channels in TQFP Package Only
2 Differential Channels with Programmable Gain at 1x, 10x, or 200x
Byte-oriented Two-wire Serial Interface
65
66
VCC
Digital supply voltage.
GND
67
Ground.
Port A (PA7:PA0)
Port A serves as the analog inputs to the A/D Converter. Port A also serves as an 8-bit bi-directional
I/O port, if the A/D Converter is not used. Port pins can provide internal pull-up resistors (selected
for each bit). The Port A output buffers have symmetrical drive characteristics with both high sink
and source capability. When pins PA0 to PA7 are used as inputs and are externally pulled low, they
will source current if the internal pull-up resistors are activated. The Port A pins are tri-stated when a
reset condition becomes active, even if the clock is not running.
Port B (PB7:PB0)
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port B output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if
the clock is not running.
Port C (PC7:PC0)
Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port C output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port C pins are tri-stated when a reset condition becomes active, even if
the clock is not running. If the JTAG interface is enabled, the pull-up resistors on pins PC5 (TDI).
Port D (PD7:PD0)
68
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The
Port D output buffers have symmetrical drive characteristics with both high sink and source
capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up
resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if
the clock is not running. Port D also serves the functions of various special features of the
ATmega16A.
RESET
Reset Input. A low level on this pin for longer than the minimum pulse length will generate a reset,
even if the clock is not running. The minimum pulse length is given in. Shorter pulses are not
guaranteed to generate a reset.
XTAL1
Input to the inverting Oscillator amplifier and input to the internal clock operating circuit.
XTAL2
Output from the inverting Oscillator amplifier.
AVCC
AVCC is the supply voltage pin for Port A and the A/D Converter. It should be externally connected
to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a
low-pass filter.
AREF
AREF is the analog reference pin for the A/D Converter.
69
Chapter 5
EXPRESS PCB SOFTWARE
70
Chapter 5
EXPRESS PCB SOFTWARE
There are different tools available for making circuit schematic, simulation, circuit layout
etc. Electronic design automation (EDA) is the category of tools for designing and producing
electronic systems ranging from printed circuit boards (PCBs) to integrated circuits. This is
sometimes referred to as ECAD (Electronic Computer-Aided Design) or just CAD.
&Symbol
Manger. Begin
your
schematic by placing the components. Select the parts from the Component and Symbol Manager
Dialog box. Express SCH includes a large library with hundreds of component symbols (ICs,
resistors, capacitors) that we can use to draw our electronic circuits. Check Component and
click Insert to schematic. After doing with all necessary components click done.
Step 2: Position the components. Drag each component to the desired location on the page. The snap
to grid feature makes it easy to neatly align the symbols. If all of the components do not fit on a
single page, add additional sheets. All the sheets of a schematic are linked together and saved in one
file.
71
72
5.2 Procedure for Making Layout of Circuit:Step1: Linking schematic to PCB Select the Component - Component Manager. Begin your layout
by adding the components. Select the parts from the Component Manager dialog box.
Step 2: Position the Components - Drag each component to the desired location on your board. The
Snap to grid feature makes it easy to neatly align the parts.
73
74
Step 3: Link the schematic to the PCB. File - Link schematic to the PCB Add the Traces (Place a
trace). Now add each trace by clicking on the pin of a component and dragging the trace to another
pin. If you link your schematic file to the PCB, then the Express PCB program highlights the
pins that should be wired together in blue by clicking highlight net connections.
75
Chapter 6
PROGRAM
76
Chapter 6
PROGRAM
/*******************************************************
This program was created by the
CodeWizardAVR V3.17 Evaluation
Automatic Program Generator
Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date
: 3/24/2015
Author :
Company :
Comments:
Chip type
: ATmega16A
Program type
: Application
AVR Core Clock frequency: 8.000000 MHz
Memory model
: Small
External RAM size
: 0
Data Stack size
: 256
*******************************************************/
#include <io.h>
#include <stdlib.h>
#include <delay.h>
// Alphanumeric LCD functions
#include <alcd.h>
// Declare your global variables here
// Voltage Reference: AREF pin
#define ADC_VREF_TYPE ((0<<REFS1) | (0<<REFS0) | (0<<ADLAR))
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | ADC_VREF_TYPE;
// Delay needed for the stabilization of the ADC input voltage
77
delay_us(10);
// Start the AD conversion
ADCSRA|=(1<<ADSC);
// Wait for the AD conversion to complete
while ((ADCSRA & (1<<ADIF))==0);
ADCSRA|=(1<<ADIF);
return ADCW;
}
void main(void)
{ float a,b,c,d,E;
int X=0;
char ch[10];
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In
Bit1=In Bit0=In
DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) |
(0<<DDA2) | (0<<DDA1) | (0<<DDA0);
// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) |
(0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);
// Port B initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In
Bit1=In Bit0=In
DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) |
(0<<DDB2) | (0<<DDB1) | (0<<DDB0);
// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) |
(0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);
// Port C initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In
Bit1=In Bit0=In
DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) |
(0<<DDC2) | (0<<DDC1) | (0<<DDC0);
// State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) |
(0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);
// Port D initialization
// Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In
Bit1=In Bit0=In
78
a=read_adc(0);
itoa(a,ch);
lcd_puts(ch);
delay_ms(100);
lcd_clear();
delay_ms(100);
}
else
{lcd_putsf(" HUMIDITY");
PORTD.6=0;
b=read_adc(0);
itoa(a,ch);
delay_ms(100);
lcd_puts(ch);
delay_ms(100);
lcd_clear();
delay_ms(100);
}
}
if(PIND.0==0 && PIND.1==1 && PIND.2==0)
{
lcd_clear();
delay_ms(100);
lcd_putsf(" TEMPRATURE SENSOR
DEVICE: ON");
delay_ms(100);
c=read_adc(0);
d=c-485;
ftoa(d,3,ch);
lcd_puts(ch);
delay_ms(100);
lcd_clear();
c=read_adc(1);
lcd_clear();
delay_ms(100);
if(d>40)
{
lcd_clear();
X=X+1;
lcd_putsf("TEMPERATURE INCREASING");
PORTD.6=1;
delay_ms(100);
lcd_clear();
lcd_putsf("COOLING ON");
delay_ms(100);
82
lcd_clear();
c=read_adc(0); //use of adc0 interchanging method
d=c/10-15;
ftoa(d,3,ch);
lcd_puts(ch);
delay_ms(100);
lcd_clear();
delay_ms(100);
if(X==1)
{ PORTD.4=1;
lcd_putsf("CALLING......");
delay_ms(200);
PORTD.4=0;
lcd_clear();
}
}
else
{lcd_putsf(" TEMPERATURE");
PORTD.4=0;
c=read_adc(0);
d=c/10-15;
ftoa(d,3,ch);
delay_ms(100);
lcd_puts(ch);
delay_ms(100);
lcd_clear();
delay_ms(100);
PORTD.6=0;
lcd_putsf("COOLING OFF");
delay_ms(100);
lcd_clear();
}
}
if(PIND.0==0 && PIND.1==0 && PIND.2==1)
{
lcd_clear();
delay_ms(100);
lcd_putsf(" GAS SENSOR
DEVICE: ON");
delay_ms(100);
b=read_adc(2);
itoa(b,ch);
lcd_puts(ch);
lcd_clear();
delay_ms(100);
83
if(b>900)
{
lcd_clear();
lcd_putsf("GAS LEVEL INCREASING:");
PORTD.5=1;
b=read_adc(2);
itoa(b,ch);
lcd_puts(ch);
delay_ms(100);
lcd_clear();
delay_ms(100);
}
else
{lcd_putsf("
GAS");
PORTD.5=0;
b=read_adc(2);
itoa(b,ch);
delay_ms(100);
lcd_puts(ch);
delay_ms(100);
lcd_clear();
delay_ms(100);
}
}
if(PIND.0==0 && PIND.1==0 && PIND.2==0 && PIND.3==1)
{
lcd_clear();
delay_ms(100);
lcd_putsf(" PIZZO SENSOR
DEVICE: ON");
delay_ms(100);
E=read_adc(3);
E=1000-E;
itoa(E,ch);
lcd_puts(ch);
lcd_clear();
delay_ms(100);
if(E>900)
{
lcd_clear();
lcd_putsf("PRESSURE LEVEL
PORTD.7=1;
E=read_adc(3);
E=1000-E;
itoa(E,ch);
lcd_puts(ch);
delay_ms(100);
84
INCREASING:");
lcd_clear();
delay_ms(100);
}
else
{lcd_putsf("
PRESSURE");
PORTD.7=0;
E=read_adc(3);
E=1000-E;
itoa(E,ch);
delay_ms(100);
lcd_puts(ch);
delay_ms(100);
lcd_clear();
delay_ms(100);
}
}
} }
85
REFRENCE
WEBSITE REFRENCES
a) www.efymag.com
b) www.geocities.com
c) www.microchip.com
d) www.alldatasheets.com
e) www.wikipedia.com
BOOK REFRENCES
a) Microcontroller (D.S.YADAV)
b) Microprocessor Architecture Program And Application (R.S. GAONKAR)
c) Digital Fundamentals (THOMAS. I. FLAYD)
d) Microcontroller & Embedded System (SAMPATH. K. VENKATESH)
e) Microcontrollers Theory and Application (AJAY. V. DESSHMUKH)
f) Electronics for U (magazine) EFY
g) Digital Design (MORRIS MANO)
h) Microcontroller (P. RAJA)
86