134
LASER COMMUNICATION SYSTEM by Kuldeep Gangwar (0701431037) Tuhina Oli (0701431084) Nitin Bhardwaj(0701431055) Mukesh Kumar(2801431005) Department of Electronics & Communication Shri Ram Murti Smrak College of Engineering & Technology Shri Ram Murti Puram Bareilly-243202 April,2011 1

2min-3 min

Embed Size (px)

Citation preview

Page 1: 2min-3 min

LASER COMMUNICATION

SYSTEM

by

Kuldeep Gangwar (0701431037)

Tuhina Oli (0701431084)

Nitin Bhardwaj(0701431055)

Mukesh Kumar(2801431005)

Department of Electronics & Communication

Shri Ram Murti Smrak College of Engineering & Technology

Shri Ram Murti Puram

Bareilly-243202

April,2011

1

Page 2: 2min-3 min

LASER COMMUNICATION

SYSTEM

by

Kuldeep Gangwar (0701431037)

Tuhina Oli (0701431084)

Nitin Bhardwaj(0701431055)

Mukesh Kumar(2801431005)

Submitted to Department of Electronics & Communication Engineering

in partial fulfillment of the requirements

for the degree of

Bachelor of Technology

in

Electronics & Communication Engineering

Shri Ram Murti Smarak College of Engineering & Technology

U.P. Technical University

April’ 20112

Page 3: 2min-3 min

TABLE OF CONTENTS

DECLARATION……………………………………………………………...i

CERTIFICATE………………………………………………………………..ii

ACKNOWLEDGEMENT……………………………………………………iii

ABSTRACT…………………………………………………………………..iv

LIST OF TABLES…………………………………………………………….v

LIST OF FIGURES…………………………………………………………..vi

LIST OF SYMBOL………………………………………………………….vii

LIST OF ABBREVIATION…………………………………………………viii

3

Page 4: 2min-3 min

CHAPTER 1- INTRODUCTION……………………………………………..

1.1 INTRODUCTION

1.2 OPERATING PRINCIPELS

CHAPTER 2-IMPLEMENTATION OF PROJECT........................................

2.1 BLOCK DAIGRAM OF SYSTEM

2.2 CIRCUIT DAIGRAM

CHAPTER 3-COMPONENTS…………………………………………………

1.1 COMPONENTS USED

CHAPTER 4-SOFTWARE .................................................................................

1.1 CVAVR

1.2 EXPRESS PCB

CHAPTER 5-DISCRIPTION OF HARDWARE

2.1 MICROCONTROLLER

2.2 LASER DIODE

2.3 PHOTO DIODE

2.4 SEVEN SEGMENT LED

2.5 ELECTRT MIC

2.6 SPEAKER

CHAPTER 3- COMPONENTS USED……………………………………….

3.1 COMPONENT LIST………………………………………………..

3.1.1 POWER SUPPLY………………………………………………..

3.1.2 DIODE……………………………………………………………..

3.1.3 CAPACITOR……………………………………………………….

3.1.4 VOLTAGE REGULATOR……………………………………….

4

Page 5: 2min-3 min

3.1.5 RESISTOR……………………………………………………….

3.1.6 TRANSISTOR…………………………………………………………

3.1.7 CRYSTAL OSCILLATOR………………………………………………

3.2 MATERIAL USED AND PROCEDURE……………………….

3.2.1 PRECAUTIONS AND USES………………………………….

CHAPTER 4- GENERAL DESCRIPTION

4.1 FEATURES……………………………………………………….

4.2 APPLICATION……………………………………………………

CHAPTER 6- CONCLUSSION

6.1 CONCLUSSION…………………………………………………….

6.2 ADVANTAGE………………………………………………………..

APPENDIX A…………………………………………………………….

APPENDIX B……………………………………………………………..

REFERENCES……………………………………………………………..

5

Page 6: 2min-3 min

DECLARATION

I hereby declare that this submission is our own work and that, to the best of our knowledge

and belief , it contains no material previously published or written by another person nor

material which to a substantial extent has been accepted for the award of any other degree or

diploma of the university or other institute of higher learning, except where due acknowledge

has been made in the text.

Signature: Signature:

Name -Kuldeep Gangwar Name: Tuhina Oli

Roll No.:0701431037 Roll No.:0701431084

Date: Date:

Signature: Signature:

Name:Nitin Bharadwaj Name: Mukesh Kumar

Roll No.:0701431055 Roll No.:2801431005

Date: Date:

6

Page 7: 2min-3 min

CERTIFICATE

This is to certify that Project Report entitled “LASER COMMUNICATION SYSTEM”

which is submitted by Kuldeep Gangwar, Tuhina Oli ,Nitin Bhardwaj & Mukesh Kumar in

partial fulfillment of requirement for the award of degree B.Tech in Department of

Electronics & Communication of U.P. Technical University is a record of the candidates’

owes work carried out by them under my supervision. The matter embodied in this thesis is

original and has been submitted for the award of any other degree.

Date: SUPERVISOR

Mr. ALOK KUMAR SENGAR

7

Page 8: 2min-3 min

ACKNOWLEDGEMENT

It gives us a great sense of pleasure to present the report of B.Tech Project undertaken

during B.Tech Final Year. We owe special debt of gratitude to Mr. Alok Kr Sengar,

Department of Electronics & Communication, Shri Ram Murti Smarak College of

Engineering & Technology, Bareilly for his constant support and guidance throughout the

course of our work. His sincerity, thoroughness and perseverance have been a constant

source of inspiration for us. It is only his cognizant efforts that our endeavors have seen light

of the day.

We also take the opportunity to acknowledge the contribution of Mr B.R Dutta, Head

Department of Electronic & Communication, Shri Ram Murti Smarak College of Engineering

& Technology, Bareilly for his full support and assistance during the development of the

project. We also do not miss the opportunity to acknowledge the contribution of all faculty

member of the department for their kind assistance and cooperation during the development

of our project. Last but not the least, we acknowledge our friends for their contribution in the

completion of the project.

Signature: Signature:

Name -Kuldeep Gangwar Name: Tuhina Oli

Roll No.:0701431037 Roll No.:0701431084

Signature: Signature:

Name:Nitin Bharadwaj Name: Mukesh Kumar

Roll No.:0701431055 Roll No.:2801431005

DATE-:

8

Page 9: 2min-3 min

ABSTRACT

In this project we have shown the communication system using a controller of family of

ATMEGA i.e ATMEGA32 . We have shown the concept for transmitting the voice and data

through laser light. In this project we have displayed that how we will modulate the data

either voice or text in the optical format and to transmit it with the help of a laser diode at

transmitter end and to decode it at receiver end.

The project is meant for line of sight application i.e. transmitter & receiver are present at line

of sight distance. Here no physical media is required for transmission and the data is far

more secure and noise free compare to the data travelling in wires or links .Moreover

minimum overheads are required for transmission of data through optical means.

The system is simplex consisting of single transmitter and receiver and air between them

9

Page 10: 2min-3 min

LIST OF TABLE

TABLE PAGE

Table 3.1 Color coding resistor

Table 3.2 Capacitor marking

10

Page 11: 2min-3 min

LIST OF FIGURE

FIGURE PAGE

Figure 1.1 Block Diagram

Figure 2.1 Internal architecture of ATMEGA32

Figure 2.2 Pin diagram

Figure 2.3 Microcontroller versus microprocessor

Figure 2.4 Input/output port

Figure 2.5 Central processing unit

Figure 3.1 Power supply

Figure 3.2 Internal block diagram

Figure 3.3 Connection of RS32 With microcontroller

Figure 3.4 Complete Setup

Figure 4.1 Circuit Diagram of Ttransmitter (voice)

Figure 4.2 Circuit Diagram of Receiver (voice)

Figure 4.3 Circuit Diagram of Transmitter (data)

Figure 4.4 Circuit Diagram of Receiver (data)

Figure 4.5 Circuit Diagram

Figure A Structure and symbol of P-N-P transistor

Figure B (a)P-N-P transistor biasing (b) N-P-N transistor biasing

11

Page 12: 2min-3 min

LIST OF SYMBOLE

Voltage V

Current I

Micro farad µF

Ohm Ώ

Hertz Hz

Not equal ≠

Equal =

Divide ÷

Watt W

Mega M

Kilo K

12

Page 13: 2min-3 min

LIST OF ABBREVIATIONS

1. LED Light emitting diode

2. CMOS Complementary metal oxide semiconductor

3. SMD Semiconductor material devices

4. EPROM Erasable programmable read only memory

5. LED Light emitting diode

6. I/O Port Input/Output Port

7. A/D Convertor Analog to digital convertor

8. CCD Charged coupled device

9. PEECO Perry equipment and engineering company

10. VFC Vibratory feeder corporation

11. PEROM Programmable and erasable read only memory

12. RAM Random access memory

13. ALU Arithmetic and logical unit

14. OTPROM One time programmable read only memory

15. EEROM Electrical erasable read only memory

13

Page 14: 2min-3 min

CHAPTER 1

INTRODUCTION

14

Page 15: 2min-3 min

CHAPTER 1

INTRODUCTION

In this chapter we have introduced our project and its basic working , the thoughts and ideas

regarding project are mentioned here . The project is basically a media free communication

system that uses laser light for carrying the information .

1.1 INTRODUCTION

Laser Communication may prove as a efficient way of communication in near future.the

most advantageous feature of laser communication is minimum amount of overheads it dealt

with. It involves transmission of data in a smart and efficient way. As it do not require any of

the physical media so the burden in system is low but besides other system that are media

free but involves lot of loss & distortion due to scattering interference & multipath it is far

more secure and error free transmission method.

Since there exits some of the shortcomings of every system and this one too is not an

exception.The limitation of the system is that it is valid only for LOS (line of sight distance)

i.e. the transmitter and receiver should be visible to each other only then transmission and

reception will prove fruitful.

Advantageous feature are

Security

Correctness

Less over heads

15

Page 16: 2min-3 min

1.2 OPERATING PRINCIPLE

The system comprising of :-

DIP switch that decides weather we are transmitting data or voice

VOICE DATA

TRANSMITTER TRANSMITTER

-MIC is used -Data provided by pushing switches

-Amplified through IC 741 -values are received in MCU

(pre-amplification)

-Send to push pull amplifier - values are stored in transmitting

(power amplification) buffer

-Rheostat for varying gain -optical signals are transmitted

-Transmission through laser diode laser diode

RECEIVER RECEIVER

-Reception through photo diode - data received through photo diode

-passed through IC 741 -apropriate signals are sensed

-passed through push pull amplifier -respective signals displayed in LED

-Gain is adjusted through rheostat

-Given to speaker

16

Page 17: 2min-3 min

CHAPTER 2

IMPLEMENTING PROJECT

In this chapter we will discuss about how we have implemented the basic ideas which we

have described in introduction of our project. This chapter deals with block diagram

representation and circuit diagram of project.

2.1 BLOCK DAIGRAM

The block diagram consist Transmitter part , Receiver part and LASER LIGHT system. They

have separate circuitry. The Transmitter and Receiver communicate with each other through

AIR interface .

In data transmission where we make use of ATMEGA32, is interfaced with our laser diode .

While in voice communication we have used a push pull amplifier system for transmission

part.

At receiver side in case of data we have interfaced a 7-segment LED with our

microcontroller and a photo diode.

In voice transmission again a push pull amplifier is being used.

17

Page 18: 2min-3 min

BLOCK DIAGRAM

DIGITAL DATA TRANSMITTER DIGITAL DATA RECEIVER

AUDIO TRANSMITTER

Tx

laser beam

Rx

AUDIO RECEIVER

18

keypad as digital data source

atmega32 as mcu

laser diode as transmitterer

Photo-diode as receiver

Power supply

12V

Pre -amplifier opm741

7 segment display

Atmega32 as MCU

Electrets mic

Push-pull amplifier

Laser diode

speaker Pre -amplifier opm741

Push-pull amplifier

Photo-diode

Pre -amplifier opm741

Electrets mic

Push-pull amplifier

Laser diode

speaker Pre -amplifier opm741

Push-pull amplifier

Photo-diode

Pre -amplifier opm741

Electrets mic

Push-pull amplifier

Laser diode

speaker Pre -amplifier opm741

Push-pull amplifier

Photo-diode

voltage regulator IC7805

Page 19: 2min-3 min

2.2 CIRCUIT DAIGRAM

2.2.1 AUDIO TRANSMITTER PART:

2.2.1 AUDIO RECEIVER PART:

19

Page 20: 2min-3 min

2.2.2 DATA TRANSMITTER PART

2.2.2 DATA RECEIVER PART

20

Page 21: 2min-3 min

FLOW DIAGRAM:

Data Voice

laser beam laser beam

21

start

Data or

voice

10 push switches connected to PORTA

Electret mic

Atmega32 PORTA & C are input port.TXD PIN 15 as transmitter

o/p from PIN15 to laser diode

Preamplifier than power amplifier (push pull amp)

o/p from push pull is given to laser diode

Photodiode as detector

Page 22: 2min-3 min

7 segment LED display

CHAPTER 3

COMPONENETS

22

Photodiode as detector at PIN14 of MCU

ATMEGA32 PORTB as o/p port.

PIN14 receives laser beam data

o/p from PORTB.0-PORTB.6 to 7 segment

Preamplified voice is than power amplified

o/p from push-pull is given to speaker

Page 23: 2min-3 min

CHAPTER 3

COMPONENT

This chapter deals with different components used for implementing the circuitry . this

mainly comprises of resisters, capcitors, transisters, 7-segment display and ICs. This chapter

is most important in regard with project because this chapter specifies the correct value of

different component and their description.

3.1 COMPONENTS USED

Sr. no. Components Quantity

1. Microcontroller ATMEGA32 2

2. Laser Diode 1

3. Photo Diode 1

4. Opamp IC 741 1

5. 7-segment LED 1

6. Resistance(ohm)

100 1

470 1

23

Page 24: 2min-3 min

560 7

1K 1

4 K 4

10 K 7

7. Capacitances

0.1uF 4

33pF 4

220uF 2

8. Potentiometer (1M) 2

9. 7805 Voltage Regulator 2

10. Crystal 4 Mhz 2

11. LED 1

12. Diode IN4007 6

13. Push Switches 9

3.1 LASER DIODE:

Laser, the wonder beam of this century apart from fuelling science fictions stories, is

increasingly becoming a real force in our lives. The term laser is an acronym for Light

Amplification by Stimulated Emission of Radiation or a light amplifier. These days laser

beam has made its diversified characteristic potentialities in different fringes of Science and

Technology.

The laser originally got its finding by Einstein was further developed in 1960's. The magic

behind the laser is its 'coherence'. This term means that the light from a laser is highly

directional and rather than emerging from the source as the characteristic cone of the

flashlight, appears as a sharp straight beam, a sort of clothesline to eternity.

Multifaced application of laser in the development of science and technology made this

wonder beam equally prolific for men and machine. In the developed countries it provided

ease, but in developing countries, still in a process of gaining new dimensions to its

applicability. In India it has been widely in practice in industries, defence, medicine, surgery

and scientific research.

24

Page 25: 2min-3 min

3.1.1 RED LASER DIODE (DL-3149-057)

3.1.1.1 Features

• Short wavelength : 670 nm (Typ.)

• Low threshold current : Ith = 25 mA (Typ.)

• High operating temperature : 5 mW at 60°C

• Small package : ø5.6 mm

3.1.1.2 Applications

• Laser beam printer

• Bar-code scanner

3.1.2 HOW ARE LASER BEAM PRODUCED?

A device that employs the principle of amplification of electromagnetic waves by stimulated

emission of radiation and operates in the infrared, visible, or ultraviolet, region.

Just as an electronic amplifier can be made into an oscillator by feeding appropriately phased

out back into output, so the laser light amplifier can be made into a laser oscillator, which is

really a light source. The stimulated emission can be interpreted well, when atoms, ions, or

molecules absorb energy, they can emit light spontaneously (as in an incandescent lamp) or

they can be stimulated to emit by a light wave. This stimulated emission is the opposite of

absorption., where unexcited matter is stimulated into an excited state by a light wave. If the

accumulated atoms are pumped which are in excited or unexcited state, then an incident light

wave will stimulate more emission than absorption, and there is net amplification of the

incident light beam. This is the way of the laser amplifier functions.

Laser amplifier can be made into the laser oscillator by adjusting suitable mirrors on either

end of the amplifier. These are called resonators. Thus the essential parts of a laser oscillator

are an amplifying medium, a source of pump power, and resonator. Radiation that is directed

straight along the axis bounces back and forth between the mirrors and can remain in the

25

Page 26: 2min-3 min

resonator long enough to build up a strong oscillation. Wave oriented in other directions soon

pass off the edge of the mirrors and are lost-before they are much amplified.

The produced radiation can be coupled out by making one mirror partially transparent, so that

part of the amplified light can emerge through it. The produced wave, like most of the waves

being amplified between the mirrors, travels along the axis and is thus very nearly a plane

wave.

3.1.3 ORIGIN OF LASER BEAM

The idea of laser beam emerged in the late 1950s and began developing the device the early

1960s. The Laser research grew out of earlier studies of microwave amplifying devices called

masers. As a result, early lasers were also called masers. The term MASER stands for

Microwave Amplification by Stimulated Emission of Radiation. A maser is a microwave

amplifier which produces highly directional and coherent microwaves with just one

frequency.

Two United States physicists, Arthur L.Schawlow and O.H. Towns, first proposed the idea of

laser in 1958. Originally laser proposed by Einstein developed in the 60s. In 1961, Ali Javan,

another US physicist, operated the first gas laser. The semiconductor lasers were initially

operated in 1962 by the separate teams of US scientists. The first liquid laser was operated in

1966 by Peter Sorking of United States.

The application of laser mirror was first used in 1969 by the Astronauts on the Apollo II

mission on Moon. It was called laser reflector. Scientists used this device to measure

precisely the distance between the earth and the moon. It was called laser reflector. Scientists

used this device to measure precisely the distance between the earth and the moon. They did

so by measuring the time required by a laser beam to travel to the reflector and back. Laser

applications increases steadily during the 1970s and early 1980's. These days much laser

research involves the development of new kinds of lasers.

3.1.4 LASER COMPARISON WITH CONVENTIONAL LIGHT

SOURCES

In the contrast to lasers, all conventional light sources are basically hot bodies which radiate

by spontaneous emission. The electrons in the tungsten filament of an incadescent lamp are

26

Page 27: 2min-3 min

agitated by and acquire excitation from the high temperature of the filament. Once excited,

they emit light in all directions and revert to a lower energy state, and they soon give up this

excitation energy by radiating it as light. In all the above, spontaneous emission from each

excited electron or atom takes place independently of emission from the others. Thus the

overall wave produced by a conventional light source is a jumble of waves from numerous

individual atoms. The phase of wave emitted by one atom has no relation to the phase emitted

by any other atom. So that the total phase of the light fluctuates randomly from moment to

moment and place to place.

The hot bodies emit more or less equally in all directions radiation whose wavelength

distribution is dictated by the Planack black body radiation curve. For example, the surface of

the sun radiates like a black body at a temperature of about 6000 K, and emits a total of 7

KW/cm2, spread out over all wavelengths and directions. Light from gas lamps can be more

monochromatic but radiation still occurs in all directions. In contrast to this an ideal plane

wave would be highly predictable (coherent). The output of the parallel plate laser described

above is very nearly such plane wave and is, therefore, highly directional.

There are varieties of lasers and their various applicabilities are classified according to their

pumping or (excitation) method. The function of pumping method is to maintain more atoms

in the upper than in the lower state, thereby assuring that (stimulated) absorption (loss

transition). This is called inversion ensure net gain.

3.1.5 TYPES OF LASERS

The various types of lasers and their applications are discussed below, and it is classified

according to their pumping (or excitation) methods. The important lasers which are in

practice in these days are:-

1. Optically pumped lasers

2. Gas discharged lasers

3. Pulsed gas lasers

4. Chemical lasers27

Page 28: 2min-3 min

5. Photo dissociation lasers

6. Nuclear lasers

7. Gas-dynamic lasers

8. Semiconductor lasers

9. Free-electron lasers

10. High-power lasers

3.1.5.1 OPTICALLY PUMPED LASER

Simple method to achieve population inversion is by concentrating light (for example, from a

flash lamp or the sun) onto the amplifying medium. Alternatively lasers may be used to

optically pump other lasers. Molecular lasers, like deuterium cyanide (DCN) are used to lease

powerfully in to fat infrared, operating out to several hundred micrometers wavelength. The

pumping method can be made applicable to pump gas at high pressure to obtain tunability

where other excitation methods would be difficult if not impossible to implement.

Three-and Four-Level Lasers: Many lasers are three-level lasers in which is ground state

atoms are excited by absorption of light to a broad upper energy state, from which they

quickly relax to the emitting state, laser action occurs as they are stimulated to emit radiation

and so return to original ground state. The most suitable thing found for the ground state is

crystalline glass, liquid and gaseous systems, but many possible materials are remained to be

explored. Solid three-level lasers usually make use of ions of a rare-earth element, such as

neodymium, or of a transitional metal, such as a chromium, dispersed in a transition metal

such as chromium dispersed in a transparent crystal or glass.

Majority of rare-earth ion lasers use a fourth level above the ground state. This level serves

as a terminal level for the laser transition, and it is kept empty by rapid non-radioactive

28

Page 29: 2min-3 min

relaxation to the ground state. This means that, relative to three-level systems, a population

inversion is easier to maintain, and therefore such materials require relatively low pumping

light intensity for laser action.

Structure of Pumped lasers: The structure of optically pumped solid-state could be as

simple as a rod of the light-amplifying material with parallel end polished and coated to

produce reflection. The produced radiation can penetrate either through the transparent sides

or the ends. Other structures can be used. The mirrors end can be spherical rather than plane,

with common focal point of the two mirrors lying half way between them.

Structure of Liquid Lasers: The structure of liquid lasers are generally like those of

optically pumped solid-state lasers, except that the liquid is generally contained in a

transparent cell. Some liquid lasers make use of organic dye solutions. The dyes can lase over

a wide range of wavelengths, depending upon the composition and concentration of the dye

solvent. Thus tunability is obtained throughout the visible and up to a wavelength of about

0.9 micrometers.

3.1.5.2 GAS-DISCHARGED LASERS

Gas-discharged laser is another wide-range of lasers which make use of nonequilibrium

process in a gas discharge. At moderately low pressure (of the order of torr or 102 pascals)

and fairly high current, the population of energy levels is far from an equilibrium distribution.

Some levels are populated especially rapidly by the fast electrons in the discharge. Other

levels empty particularly slowly and so accumulate large numbers of excited atoms. Thus

laser action can occur at any wavelength in any of a large number of gases under suitable

circumstances.

For some gases, a continuous discharge, with the use of either direct or radio-frequency

current, gives continuous laser action. Output powers of continuous gas lasers range from less

than 1 microwatt up to about 100 W in the visible region. Wavelengths generated span the

ultraviolet and vision regions and extend beyond 700 micro m with infrared. They thus

provide the first intense sources of radiation in much of the far infrared region of the

spectrum

3.1.5.3 PULSED GAS LASERS

29

Page 30: 2min-3 min

Pulsed gas discharges permit a further departure from equilibrium. Thus pulsed laser action

can be obtained in some additional gases which could not be made to the lase continuously.

In some of them the length of the laser state is filled by stimulated transition from the upper

level, and so introduces absorption at the laser wavelength.

Nitrogen Lasers: It is a self-determining laser, which gives pulses of several nanoseconds

duration with peak powers from tens of kilowatts up to a few megawatts at a wavelength of

337 nm in the ultraviolet region. There are easy to produce and are such used for pumping

tunable dyne lasers throughout the wavelength range from about 350 to 1000mm.

Hydrogen Lasers: Very powerful laser radiation in the vacuum ultraviolet region between

100 to 200 nm can be obtained from short pulse discharges in hydrogen, and in rare gases

such as xenon at high pressure, (High pressure leads to higher power). When the gas pressure

is too high to permit an electric discharge, excitation may be provided by an intense burst of

fast electrons from a small accelerator the so called E beam.

Gases like carbon dioxide, which provide continuous laser action, also can be used to

generate intense pulses of microsecond duration. For this purpose, gas pressure of about 1

atm(105 Pa) are used and the electrical discharge takes place across the diameter of the laser

column, hence the name transverse-electrical-atmosphere (TEA) laser.

3.1.5.4 CHEMICAL LASERS

Chemical lasers can be produced by the energy released in some fast chemical reactions.

Atoms or molecules produced during the reaction are often may be enough atoms or

molecules excited to some particular state for amplification to occur by stimulated emission.

Usually the reacting gases are mixed and then ignited by ultraviolet light or fast-electrons.

Both continuous infrared output and pulses up to several thousand joules of energy have

been obtained in reactions which produce excited hydrogen fluorides molecules.

3.1.5.5 PHOTO DISSOCIATION LASERS

The intense pulses of ultraviolet light can dissociate molecules in such a way as to have

constituent in an excited state capable of sustaining laser action. Iodine compounds are

notably having peak 1.3 micro m pulse powers above 109 W from the excited iodide atoms.

30

Page 31: 2min-3 min

3.1.5.6 NUCLEAR LASERS

In the process of nuclear fusion where the fast moving ions are in excited state are also

produced nuclear lasers. These fusion products excite and ionise the gas atom, and make it

possible to convert directly from nuclear to optical energy.

3.1.5.7 SEMICONDUCTOR LASERS

The excitation produced by using semiconducting materials are known as semiconductors

lasers. The process activates when the free electrons movement begins in the conduction band

stimulated to recombine with holes in the valence band. In recombining the electrons give up

energy corresponding nearly to the band gap. This energy is radiated as a light quantum.

Gallium arsenide is the best suited material to be used. The main features of the suitable

materials producing semiconductor lasers are direct-gap semi conductors. In this kind of

material recombination occurs directly without the emission or absorption of a quantum of

lattice vibrations. A flat junction between p-type and n-type material may be used.

When the current is passed through this junction in the forward direction a large number of

holes and electrons are brought together. This is called recombination and is accompanied by

emission of radiation. A light wave passing along the plane of the junction can be amplified

by stimulating such recombination of electrons and holes. The ends of the semiconducting

crystal provide the mirrors to complete the structure.

Semiconductor lasers can be very small less than 1mm in any direction. They can have

efficiencies higher than 50% (electricity to light). Power densities are high, but the thinness

of the active layer tends to limit the total output power. Even so, maximum continuous power

are comparable with those of other moderate-size lasers.

3.1.5.8 FREE-ELECTRON LASERS

It is laser of its own kind, which converts the kinetic energy in an electron beam to

electromagnetic radiation. Since it is relatively simple to generate electron because with peak

powers of 1010 W, the free-electron laser has the potential for providing high optical power,

and since there are non prescribed energy levels, as in the conventional laser, the free

electrons loses can be operate over a wide frequency range.

31

Page 32: 2min-3 min

3.1.5.9 HIGH POWER, SHORT PULSE LASERS

This kind of laser can be generated by mode-locking techniques. A typical laser without

mode locking normally oscillates simultaneously and independently at several closely spaced

wavelengths. These modes of oscillation can be synchronised so that the peaks of their waves

occur simultaneously at some instant. The result is very short, intense, pulse which quickly

ends as the waves of different frequencies get out of step.

3.1.4 APPLICATIONS OF LASERS

The variety of technological uses for lasers have increased steadily since their finding was

advocated in the 1960s. Among the noticeable applications are those that utilise high-speed

controllability of the tiny focal spot of a laser beam. For example, high speed automatic

scanners identify library cards, skipasses, and supermarket purchases and perform a variety of

functions known as optical processing. Further applications involving high power include

weaponry, laser welding laser surgery, laser fusion and material processing. Optical

communication utilise the laser's high frequency which makes possible high information

capacity. Except for space applications, laser light communications is primarily done through

glass fibres. Fiber optic laser telephone systems are presently in operation in many cities

around the world.

IN COMMUNICATIONS: -

Laser's noticeable applications are those which utilise high-speed controllability of the tiny

focal spot which is the wonder of laser beam.

32

Page 33: 2min-3 min

In recent days application of lasers in communication technologies marked tremendous

successes. Laser can transmit voice messages and television signals. It has great advantages

over ordinary electronic transmitters, such as those used to produce radio and television

signals. For example, a laser operates at a much higher frequency than do electronic

transmitters. The high frequency of laser light enables a laser beam to carry much more

information than radio waves can. Therefore, one of these beams can transmit many

telephone calls and television programmes at the same time.

The specific character of laser is that, it can transmit information with little inference because

it produces a highly directional beam. A laser beam can be directed to fall solely on the

desired laser-receiving equipment because the equipment receives only three beams aimed at

it, so most interference is eliminated. It also has a highly, directional beam which enables it to

serve as an efficient long-distance transmitter. Laser beams, unlike radio waves, spread only

slightly as they travel.

It has been well accepted by the scientists that further advancement of laser beam may

provide excellent communication link with space craft and submerged submarines. Recently

the concept of "Information Highway" to make easy the communication have came into

existence by the utilisation of optical fibre. The two sort of things lasers and optical fibre

made possible to send laser beam carrying communications signals from one relay station to

another through the glass fibre and can travel great distances with little loss of energy or

clarity. Lasers applications are also equally advantageous in other communication devices

including high speed photocopiers and printers compact disk players and some video players.

3.2 RESISTANCE

Resistance is the opposition of a material to the current. It is measured in Ohms (). All

conductors represent a certain amount of resistance, since no conductor is 100% efficient. To

control the electron flow (current) in a predictable manner, we use resistors. Electronic

circuits use calibrated lumped resistance to control the flow of current. Broadly speaking,

resistor can be divided into two groups viz. fixed & adjustable (variable) resistors. In fixed

resistors, the value is fixed & cannot be varied. In variable resistors, the resistance value can

be varied by an adjuster knob. It can be divided into (a) Carbon composition (b) Wire wound

33

Page 34: 2min-3 min

(c) Special type. The most common type of resistors used in our projects is carbon type. The

resistance value is normally indicated by colour bands. Each resistance has four colours, one

of the band on either side will be gold or silver, this is called fourth band and indicates the

tolerance, others three band will give the value of resistance (see table). For example if a

resistor has the following marking on it say red, violet, gold. Comparing these coloured rings

with the colour code, its value is 27000 ohms or 27 kilo ohms and its tolerance is ±5%.

Resistor comes in various sizes (Power rating). The bigger, the size, the more power rating of

1/4 watts. The four colour rings on its body tells us the value of resistor value as given below.

COLOURS CODE

Black-----------------------------------------------------0

Brown----------------------------------------------------1

Red-------------------------------------------------------2

Orange---------------------------------------------------3

Yellow---------------------------------------------------4

Green-----------------------------------------------------5

Blue-------------------------------------------------------6

Violet-----------------------------------------------------7

Grey------------------------------------------------------8

White-----------------------------------------------------9

3.1.1 DIFFERENT TYPES OF RESISTANCES

34

Page 35: 2min-3 min

The first rings give the first digit. The second ring gives the second digit. The third

ring indicates the number of zeroes to be placed after the digits. The fourth ring gives

tolerance (gold ±5%, silver ± 10%, No colour ± 20%). In variable resistors, we have the dial

type of resistance boxes. There is a knob with a metal pointer. This presses over brass pieces

placed along a circle with some space b/w each of them. Resistance coils of different values

are connected b/w the gaps. When the knob is rotated, the pointer also moves over the brass

pieces. If a gap is skipped over, its resistance is included in the circuit. If two gaps are

skipped over, the resistances of both together are included in the circuit and so on.

A dial type of resistance box contains many dials depending upon the range, which it

has to cover. If a resistance box has to read upto 10,000, it will have three dials each having

ten gaps i.e. ten resistance coils each of resistance 10. The third dial will have ten

resistances each of 100. The dial type of resistance boxes is better because the contact

resistance in this case is small & constant.

3.2 CRYSTAL OSCILLATOR

XTAL1 and XTAL2 are input and output, respectively, of an inverting amplifier which can

be configured for use as an On-chip Oscillator, as shown in Figure 12. Either a quartz

crystal or a ceramic resonator may be used. The CKOPT Fuse selects between two different

Oscillator amplifier modes. When CKOPT is programmed, the Oscillator output

will oscillate will a full rail-to-rail swing on the output. This mode is suitable when operating

35

Page 36: 2min-3 min

in a very noisy environment or when the output from XTAL2 drives a second clock

buffer. This mode has a wide frequency range. When CKOPT is unprogrammed, the

Oscillator has a smaller output swing. This reduces power consumption considerably.

This mode has a limited frequency range and it can not be used to drive other clock

buffers.

Figure . Crystal Oscillator Connections

3.3 MICROPHONE

Microphones, speakers and headphones are components commonly used as the input and

output devices of many circuits. A microphone converts sound waves into electrical signals

that closely follow the waveform of the sound being received. This signal is then amplified

by the circuit and transformed into a sound by a speaker or headphone.  The symbols for

these components are shown in figure.

3.4 LIGHT EMITTING DIODE

Light emitting diode (LED) is basically a P-N junction semiconductor diode particularly

designed to emit visible light. There are infrared emitting LEDs which emit invisible light.

The LEDs are now available in many colours red, green and yellow. A normal LED emits at

36

Page 37: 2min-3 min

2.4V and consumes MA of current. The LEDs are made in the form of flat tiny P-N junction

enclosed in a semi-spherical dome made up of clear coloured epoxy resin. The dome of a

LED acts as a lens and diffuser of light. The diameter of the base is less than a quarter of an

inch. The actual diameter varies somewhat with different makes. The common circuit

symbols for the LED are shown in Fig. It is similar to the conventional rectifier diode symbol

with two arrows pointing out. There are two leads- one for anode and the other for cathode.

LEDs often have leads of dissimilar length and the shorter one is the cathode. All

manufacturers do not strictly adhere this to. Sometimes the cathode side has a flat base. If

there is doubt, the polarity of the diode should be identified. A simple bench method is to use

the ohmmeter incorporating 3-volt cells for ohmmeter function. When connected with the

ohmmeter: one way there will be no deflection and when connected the other way round

there will be a large deflection of a pointer. When this occurs the anode lead is connected to

the negative of test lead and cathode to the positive test lead of the ohmmeter.

If low range (Rxl) of the ohmmeter is used the LED would light up in most cases because the

low range of ohmmeter can pass sufficient current to light up the LED.

Another safe method is to connect the test circuit shown in Fig. 2. Use any two dry cells in

series with a current limiting resistor of 68 to 100 ohms. The resistor limits the forward diode

current of the LED under test to a safe value. When the LED under test is connected to the

test terminals in any way: if it does not light up, reverse the test leads. The LED will now

light up. The anode of the LED is that which is connected to the “A” terminal (positive pole

of the battery). This method is safe, as reverse voltage can never exceed 3 volts in this test.

3.4.1 ELECTRICAL CHARATERISTIC OF LED37

Page 38: 2min-3 min

Electrically, a LED is similar to the conventional diode in that it has relatively low forward

voltage threshold. Once this is exceeded the junction has a low slope resistance and conducts

current readily. An external resistor must limit this current. Forward voltage drew across red

LED is nominally 1.6 V but spread with commercial diodes, it may be as high as 2 volts or

so, while the Green LED drops 2.4V. This difference accounts for use of lower limiting

resistor used with the Green LED.

Another important parameter of the LED is its maximum reverse voltage rating. For typical

Red device it is of the order of 3 volts. But for Green LED it is somewhat higher- 5 to 10

volts. The LED produces light only when a d.c. current is passed in the forward direction and

the amount of light emitted by a LED is proportional to the forward current over a broad

range. It means that light intensity increases in an approximately linear manner with

increasing current.

3.5 POWER SUPPLY

38

Page 39: 2min-3 min

3.6 VOLTAGE REGULATOR

3.6.1 Features

• Output Current up to 1A

• Output Voltages of 5, 6, 8, 9, 10, 12, 15, 18, 24V

• Thermal Overload Protection

• Short Circuit Protection

• Output Transistor Safe Operating Area Protection

3.6.2 Description

The LM78XX series of three terminal positive regulators are available in the TO-220/D-PAK

package and with several fixed output voltages, making them useful in a wide range of

applications. Each type employs internal current limiting, thermal shut down and safe

operating area protection, making it essentially indestructible. If adequate heat sinking is

provided, they can deliver over 1A output current. Although designed primarily as fixed

39

Page 40: 2min-3 min

voltage regulators, these devices can be used with external components to obtain adjustable

voltages and currents.

3.6.3 Internal Block Diagram

3.6.4 ABSOLUTE MAXIMUM RATINGS

3.6.5 ELECTRICAL CHARACTERISTICS (LM7805)

40

Page 41: 2min-3 min

3.6.6 TYPICAL APPLICATIONS

PHOTODIODE

A photodiode is a type of photodetector capable of converting light into either current or

voltage, depending upon the mode of operation. The common, traditional solar cell used to

generate electric solar power is a large area photodiode.

Photodiodes are similar to regular semiconductor diodes except that they may be either

exposed (to detect vacuum UV or X-rays) or packaged with a window or optical fiber

connection to allow light to reach the sensitive part of the device. Many diodes designed for

use specifically as a photodiode will also use a PIN junction rather than the typical PN

junction.

41

Page 42: 2min-3 min

PRINCIPLE OF OPERATION

A photodiode is a PN junction or PIN structure. When a photon of sufficient energy strikes

the diode, it excites an electron, thereby creating a free electron and a (positively charged

electron hole). This mechanism is also known as the photoelectric effect. If the absorption

occurs in the junction's depletion region, or one diffusion length away from it, these carriers

are swept from the junction by the built-in field of the depletion region. Thus holes move

toward the anode, and electrons toward the cathode, and a photocurrent is produced. This

photocurrent is the sum of both the dark current (without light) and the light current, so the

dark current must be minimised to enhance the sensitivity of the device.

Materials

The material used to make a photodiode is critical to defining its properties, because only

photons with sufficient energy to excite electrons across the material's bandgap will produce

significant photocurrents.

Materials commonly used to produce photodiodes include:

MaterialElectromagnetic spectrum

wavelength range (nm)

Silicon 190 – 1100

Germanium 400 – 1700

Indium gallium arsenide 800 – 2600

Lead(II) sulfide <1000 – 3500

Because of their greater bandgap, silicon-based photodiodes generate less noise than

germanium-based photodiodes, but germanium photodiodes must be used for wavelengths

longer than approximately 1 µm.

42

Page 43: 2min-3 min

OPERATIONAL AMPLIFIER

An op amp is a high-gain, direct-coupled differential linear amplifier whose response

characteristics are externally controlled by negative feedback from the output to the input. OP

amps, widely used in computers, can perform mathematical operations such as summing,

integration, and differentiation. OP amps are also used as video and audio amplifiers,

oscillators, etc. in the communication electronics. Because of their versatility op amps are

widely used in all branches of electronics both in digital and linear circuits.

OP amps lend themselves readily to IC manufacturing techniques. Improved IC

manufacturing techniques, the op amp's adaptability, and extensive use in the design of new

equipment have brought the price of IC ops amps from very high to very reasonable levels.

These facts ensure a very substantial role for the IC op amp in electronics.

Fig shows the symbol for an op amp. Note that the operational amplifier has two inputs

marked (-) and (+). The minus input is the inverting input. A signal applied to the minus

terminal will be shifted in phase 180° at the output. The plus input is the non-inverting input.

A signal applied to the plus terminal will appear in the same phase at the output as at the

input. Because of the complexity of the internal circuitry of an op amp, the op amp symbol is

used exclusively in circuit

diagrams.

IC-741

An operational amplifier often referred to as op Amp, is a very high gain high performance

amplifier designed to amplify ac and dc signal voltages. Modern integrated circuit technology

and large-scale production techniques have brought down the prices of such amplifiers within

reach of all amateurs, experimenters and hobbyists. The Op Amp is now used as a basic gain

element, like an elegant transistor, in electronic circuits.

A symbol used to represent an operational amplifier in schematics is shown in fig. The

operational amplifier has two inputs and only one output. One input is called the inverting

input and is denoted by a minus sign. A signal applied to this input appears as an amplified

43

Page 44: 2min-3 min

but phase inverted the signal output. The second input is called a non-inverting input and is

denoted by a plus sign. A signal applied to this input appears at the output as an amplified

signal, which has the same phase as that of the input signal.

The availability of two input terminals simplifies feedback circuitry and makes the

operational amplifier a highly versatile device. If a feedback is applied from the output to the

inverting input terminal, the result is a negative feedback, which gives a stable amplifier with

precisely controlled gain characteristics. On the other hand, if the feedback is applied to the

non-inverting input, the result is positive feedback, which gives oscillators and multivibrator.

Special effects are obtained by combination of both types of feedback.

NEGATIVE FEEDBACK CONTROL

SEVEN SEGMENT DISPLAY

A popular type consists of seven small, bar-shaped LED segment arranged so that depending

on which combinations are energized, the numbers 0 to 9 light up. All the LED cathodes (or

sometimes anodes) are joined to form a common connection. Current limiting resistors are

required (e.g. 270 ohms), preferably one per segment.

44

Page 45: 2min-3 min

Common cathode method of connecting an array of display elements.

ANODE

The main requirements for a suitable LED material are:-

1) It must have on energy gap of appropriate width.

45

Page 46: 2min-3 min

2) Both P and N types must exist, preferably with low resistivities.

3) Efficient radioactive pathways must be present.

Generally, energy gaps greater than or equal to about 2 are required.

Commercial LED materials::

Gallium arsenide (Ga As) doped with Si

Gallium Phosphide (GaP) doped with N & Bi

Gallium arsenide Phosphide (Ga As1-x Px)

Gallium aluminium arsenide (Gax Al1-x As)

CHAPTER 4

MICROCONTROLLER

46

Page 47: 2min-3 min

CHAPTER 4

4.1 FEATURES

1. High-performance, Low-power AVR® 8-bit Microcontroller

2. Advanced RISC Architecture

a. 131 Powerful Instructions – Most Single-clock Cycle Execution

b. 32 x 8 General Purpose Working Registers

c. Fully Static Operation

d. Up to 16 MIPS Throughput at 16 MHz

3. Nonvolatile Program and Data Memories

a. 32K Bytes of In-System Self-Programmable Flash

4. In-System Programming by On-chip Boot Program

5. True Read-While-Write Operation

a. 1024 Bytes EEPROM

b. 2K Byte Internal SRAM

6. Peripheral Features

a. Two 8-bit Timer/Counters

47

Page 48: 2min-3 min

b. One 16-bit Timer/Counter

c. Real Time Counter with Separate Oscillator

d. Four PWM Channels

e. 8-channel, 10-bit ADC

7. 8 Single-ended Channels

a. Byte-oriented Two-wire Serial Interface

b. Programmable Serial USART

c. Master/Slave SPI Serial Interface

d. Programmable Watchdog Timer with Separate On-chip Oscillator

e. On-chip Analog Comparator

8. Special Microcontroller Features

a. External and Internal Interrupt Sources

b. Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down,

Standby and Extended Standby.

9. I/O and Packages

a. 32 Programmable I/O Lines

b. 40-pin PDIP

10. Operating Voltages

a. 2.7 - 5.5V for ATmega32L

b. 4.5 - 5.5V for ATmega32

11. Speed Grades

a. 0 - 8 MHz for ATmega32L

b. 0 - 16 MHz for ATmega32

12. Power Consumption at 1 MHz, 3V, 25°C for ATmega32L

a. Active: 1.1 mA

b. Idle Mode: 0.35 mA

c. Power-down Mode: < 1 μA

4.2 PIN CONFIGURATIONS

48

Page 49: 2min-3 min

4.3 BLOCK DIAGRAM

49

Page 50: 2min-3 min

4.4 OVERVIEW

50

Page 51: 2min-3 min

The ATmega32 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced

RISC architecture. By executing powerful instructions in a single clock cycle, the

ATmega32 achieves throughputs approaching 1 MIPS per MHz allowing the system

designer to optimize power consumption versus processing speed.

The AVR core combines a rich instruction set with 32 general purpose working registers.

All the 32 registers 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 ATmega32 provides the following features: 32K bytes of In-System Programmable

Flash Program memory with Read-While-Write capabilities, 1024 bytes EEPROM, 2K

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. In Standby

mode, the crystal/resonator Oscillator is running while the rest of the device is sleeping.

This allows very fast start-up combined with low-power consumption. In Extended

51

Page 52: 2min-3 min

Standby mode, both the main Oscillator and the Asynchronous Timer continue to run.

The device is manufactured using Atmel’s high density nonvolatile memory technology.

The On-chip ISP Flash allows the program memory to be reprogrammed in-system

through an SPI serial interface, by a conventional nonvolatile memory programmer, or

by an On-chip Boot program running on the AVR core. By combining an 8-bit RISC CPU

with In-System Self-Programmable Flash on a monolithic chip, the Atmel ATmega32 is

a powerful microcontroller that provides a highly-flexible and cost-effective solution to

many embedded control applications.

4.5 PIN DESCRIPTIONS

VCC Digital supply voltage.

GND 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 B also serves the functions of various special features of the ATmega32.

PORT C (PC7..PC0)52

Page 53: 2min-3 min

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.

PORT D (PD7..PD0)

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 ATmega32.

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. 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.

53

Page 54: 2min-3 min

4.5.1 Digital Input Output Port

So let’s start with understanding the functioning of AVR. We will first discuss about I/O Ports. Again I remind you that I will be using and writing about Atmega-32. Let’s first have a look at the Pin configuration of Atmega-32.

You can see it has 32 I/O (Input/Output) pins grouped as A, B, C & D with 8 pins in each group. This group is called as PORT.

PA0 - PA7 (PORTA)

PB0 - PB7 (PORTB)

PC0 - PC7 (PORTC)

PD0 - PD7 (PORTD)

Notice that all these pins have some function written in bracket. These are additional function that pin can perform other than I/O. Some of them are.

ADC (ADC0 - ADC7 on PORTA)

UART (Rx,Tx on PORTD)

TIMERS (OC0 - OC2)

SPI (MISO, MOSI, SCK on PORTB)

External Interrupts (INT0 - INT2)

 4.5.2 Registers

All the configurations in microcontroller is set through 8 bit (1 byte) locations in RAM (RAM is a bank of memory bytes) of the microcontroller called as Registers. All the functions are mapped to its locations in RAM and the value we set at that location that is at that Register configures the functioning of microcontroller. There are total 32 x 8bit registers in Atmega-16. As Register size of this microcontroller is 8 bit, it called as 8 bit microcontroller.

4.5.3  I/O Ports:

Input Output functions are set by Three Registers for each PORT.

DDRX ----> Sets whether a pin is Input or Output of PORTX.

PORTX ---> Sets the Output Value of PORTX.

PINX -----> Reads the Value of PORTX.

54

Page 55: 2min-3 min

4.5.4 DDRX (Data Direction Register)

First of all we need to set whether we want a pin to act as output or input. DDRX register sets this. Every bit corresponds to one pin of PORTX. Let’s have a look on DDRA register.

Bit 7 6 5 4 3 2 1 0

PIN PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0

Now to make a pin act as I/O we set its corresponding bit in its DDR register.

To make Input set bit 0

To make Output set bit 1

If I write DDRA = 0xFF (0x for Hexadecimal number system) that is setting all the bits of DDRA to be 1, will make all the pins of PORTA as Output.

Similarly by writing DDRD = 0x00 that is setting all the bits of DDRD to be 0, will make all the pins of PORTD as Input.

Now let’s take another example. Consider I want to set the pins of PORTB as shown in table,

PORT-B PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0

Function Output Output Input Output Input Input Input Output

DDRB 1 1 0 1 0 0 0 1

For this configuration we have to set DDRB as 11010001 which in hexadecimal isD1. So we will write DDRB=0xD1

Summary

DDRX -----> to set PORTX as input/output with a byte.

DDRX.y ---> to set yth pin of PORTX as input/output with a bit (works only with CVAVR).

 4.5.5 PORTX (PORTX Data Register)

This register sets the value to the corresponding PORT. Now a pin can be Output or Input. So let’s discuss both the cases.

55

Page 56: 2min-3 min

Output Pin

If a pin is set to be output, then by setting bit 1 we make output High that is +5V and by setting bit 0 we make output Low that is 0V.

Let’s take an example. Consider I have set DDRA=0xFF, that is all the pins to be Output. Now I want to set Outputs as shown in table,

PORT-A PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0

ValueHigh(+5V)

High(+5V)

Low(0V) Low(0V) Low(0V)High(+5V)

High(+5V)

Low(0V)

PORTA 1 1 0 0 0 1 1 0

For this configuration we have to set PORTA as 11000110 which in hexadecimal isC6. So we will write PORTA=0xC6;

 Input Pin

If a pin is set to be input, then by setting its corresponding bit in PORTX register will make it as follows,

Set bit 0 ---> Tri-Stated

Set bit 1 ---> Pull Up

Tristated means the input will hang (no specific value) if no input voltage is specified on that pin.

Pull Up means input will go to +5V if no input voltage is given on that pin. It is basically connecting PIN to +5V through a 10K Ohm resistance.

Summary

PORTX ----> to set value of PORTX with a byte.

PORTX.y --> to set value of yth pin of PORTX with a bit (works only with CVAVR).

 

56

Page 57: 2min-3 min

4.5.6 PINX (Data Read Register)

This register is used to read the value of a PORT. If a pin is set as input then corresponding bit on PIN register is,

0 for Low Input that is V < 2.5V

1 for High Input that is V > 2.5V (Ideally, but actually 0.8 V - 2.8 V is error zone !)

For an example consider I have connected a sensor on PC4 and configured it as an input pin through DDR register. Now I want to read the value of PC4 whether it is Low or High. So I will just check 4th bit of PINC register.

We can only read bits of the PINX register; can never write on that as it is meant for reading the value of PORT.

Summary

PINX ----> Read complete value of PORTX as a byte.

PINX.y --> Read yth pin of PORTX as a bit (works only with CVAVR).

4.5.7 A SMALL NOTE ABOUT “DELAY”

C has inbuilt libraries which contain many pre-built functions. One such function is “Delay”, which introduces a time delay at a particular step. To invoke it in your program, you need to add the following line at the beginning of your code:

#include<delay.h>;

Thereafter, it can be used in the program by adding the following line:

delay_ms(X);

Where X is the time delay you wish to introduce at that particular step in milliseconds.

57

Page 58: 2min-3 min

4.6 ARCHITECTURAL OVERVIEW

In order to maximize performance and parallelism, the AVR uses a Harvard architecture

– with separate memories and buses for program and data. Instructions in the program

memory are executed with a single level pipelining. While one instruction is being executed,

the next instruction is pre-fetched from the program memory. This concept

enables instructions to be executed in every clock cycle. The program memory is In-

System Reprogrammable Flash memory.

The fast-access Register File contains 32 x 8-bit general purpose working registers with

a single clock cycle access time. This allows single-cycle Arithmetic Logic Unit (ALU)

operation. In a typical ALU operation, two operands are output from the Register File,

the operation is executed, and the result is stored back in the Register File – in one

clock cycle.

Six of the 32 registers can be used as three 16-bit indirect address register pointers for

58

Page 59: 2min-3 min

Data Space addressing – enabling efficient address calculations. One of the these

address pointers can also be used as an address pointer for look up tables in Flash Program

memory. These added function registers are the 16-bit X-, Y-, and Z-register,

described later in this section.

The ALU supports arithmetic and logic operations between registers or between a constant

and a register. Single register operations can also be executed in the ALU. Afteran arithmetic

operation, the Status Register is updated to reflect information about the

result of the operation.

Program flow is provided by conditional and unconditional jump and call instructions,

able to directly address the whole address space. Most AVR instructions have a single

16-bit word format. Every program memory address contains a 16- or 32-bit instruction.

Program Flash memory space is divided in two sections, the Boot program section and

the Application Program section. Both sections have dedicated Lock bits for write and

read/write protection. The SPM instruction that writes into the Application Flash memory

section must reside in the Boot Program section.

During interrupts and subroutine calls, the return address Program Counter (PC) is

stored on the Stack. The Stack is effectively allocated in the general data SRAM, and

consequently the Stack size is only limited by the total SRAM size and the usage of the

SRAM. All user programs must initialize the SP in the reset routine (before subroutines

or interrupts are executed). The Stack Pointer SP is read/write accessible in the I/O

space. The data SRAM can easily be accessed through the five different addressing

modes supported in the AVR architecture.

The memory spaces in the AVR architecture are all linear and regular memory maps.

A flexible interrupt module has its control registers in the I/O space with an additional

global interrupt enable bit in the Status Register. All interrupts have a separate interrupt

vector in the interrupt vector table. The interrupts have priority in accordance with their

interrupt vector position. The lower the interrupt vector address, the higher the priority.

The I/O memory space contains 64 addresses for CPU peripheral functions as Control

Registers, SPI, and other I/O functions. The I/O Memory can be accessed directly, or as

the Data Space locations following those of the Register File, $20 - $5F.

59

Page 60: 2min-3 min

4.7 ALU – Arithmetic Logic Unit

The high-performance AVR ALU operates in direct connection with all the 32 general

purpose working registers. Within a single clock cycle, arithmetic operations between

general purpose registers or between a register and an immediate are executed. The

ALU operations are divided into three main categories – arithmetic, logical, and bit-

functions.

Some implementations of the architecture also provide a powerful multiplier

supporting both signed/unsigned multiplication and fractional format. See the “Instruction

Set” section for a detailed description.

4.8 GENERAL PURPOSE REGISTER FILE

The Register File is optimized for the AVR Enhanced RISC instruction set. In order to

achieve the required performance and flexibility, the following input/output schemes are

supported by the Register File:

• One 8-bit output operand and one 8-bit result input

• Two 8-bit output operands and one 8-bit result input

• Two 8-bit output operands and one 16-bit result input

• One 16-bit output operand and one 16-bit result input

60

Page 61: 2min-3 min

4.9 STATUS REGISTER

The Status Register contains information about the result of the most recently executed

arithmetic instruction. This information can be used for altering program flow in order to

perform conditional operations. Note that the Status Register is updated after all ALU

operations, as specified in the Instruction Set Reference. This will in many cases

remove the need for using the dedicated compare instructions, resulting in faster and

more compact code.

The Status Register is not automatically stored when entering an interrupt routine and

restored when returning from an interrupt. This must be handled by software.

The AVR Status Register – SREG – is defined as:

• Bit 7 – I: Global Interrupt Enable

The Global Interrupt Enable bit must be set for the interrupts to be enabled. The individual

interrupt enable control is then performed in separate control registers. If the Global

Interrupt Enable Register is cleared, none of the interrupts are enabled independent of

the individual interrupt enable settings. The I-bit is cleared by hardware after an interrupt

has occurred, and is set by the RETI instruction to enable subsequent interrupts. The Ibit

can also be set and cleared by the application with the SEI and CLI instructions, as

described in the instruction set reference.

• Bit 6 – T: Bit Copy Storage

The Bit Copy instructions BLD (Bit LoaD) and BST (Bit STore) use the T-bit as source or

destination for the operated bit. A bit from a register in the Register File can be copied

into T by the BST instruction, and a bit in T can be copied into a bit in a register in the

Register File by the BLD instruction.61

Page 62: 2min-3 min

• Bit 5 – H: Half Carry Flag

The Half Carry Flag H indicates a half carry in some arithmetic operations. Half Carry is

useful in BCD arithmetic. See the “Instruction Set Description” for detailed information.

• Bit 4 – S: Sign Bit, S = N ⊕ V

The S-bit is always an exclusive or between the Negative Flag N and the Two’s Complement

Overflow Flag V. See the “Instruction Set Description” for detailed information.

• Bit 3 – V: Two’s Complement Overflow Flag

The Two’s Complement Overflow Flag V supports two’s complement arithmetics. See

the “Instruction Set Description” for detailed information.

• Bit 2 – N: Negative Flag

The Negative Flag N indicates a negative result in an arithmetic or logic operation. See

the “Instruction Set Description” for detailed information.

• Bit 1 – Z: Zero Flag

The Zero Flag Z indicates a zero result in an arithmetic or logic operation.

4.10 THE X-REGISTER, Y-REGISTER AND Z-REGISTER

The registers R26..R31 have some added functions to their general purpose usage.

These registers are 16-bit address pointers for indirect addressing of the Data Space.

The three indirect address registers X, Y, and Z are defined as described in Figure.

62

Page 63: 2min-3 min

In the different addressing modes these address registers have functions as fixed

displacement, automatic increment, and automatic decrement

4.11 STACK POINTER

The Stack is mainly used for storing temporary data, for storing local variables and for

storing return addresses after interrupts and subroutine calls. The Stack Pointer Register

always points to the top of the Stack. Note that the Stack is implemented as growing

from higher memory locations to lower memory locations. This implies that a Stack

PUSH command decreases the Stack Pointer.

The Stack Pointer points to the data SRAM Stack area where the Subroutine and Interrupt

Stacks are located. This Stack space in the data SRAM must be defined by the

program before any subroutine calls are executed or interrupts are enabled. The Stack

Pointer must be set to point above $60. The Stack Pointer is decremented by one when

data is pushed onto the Stack with the PUSH instruction, and it is decremented by two

when the return address is pushed onto the Stack with subroutine call or interrupt. The

Stack Pointer is incremented by one when data is popped from the Stack with the POP

instruction, and it is incremented by two when data is popped from the Stack with return

from subroutine RET or return from interrupt RETI.

The AVR Stack Pointer is implemented as two 8-bit registers in the I/O space. The number

of bits actually used is implementation dependent. Note that the data space in some

implementations of the AVR architecture is so small that only SPL is needed. In this

case, the SPH Register will not be present.

63

Page 64: 2min-3 min

4.12 INSTRUCTION EXECUTION TIMING

This section describes the general access timing concepts for instruction execution. The

AVR CPU is driven by the CPU clock clkCPU, directly generated from the selected clock

source for the chip. No internal clock division is used.

Figure shows the parallel instruction fetches and instruction executions enabled by the

Harvard architecture and the fast-access Register File concept. This is the basic pipelining

concept to obtain up to 1 MIPS per MHz with the corresponding unique results for

functions per cost, functions per clocks, and functions per power-unit.

Figure The Parallel Instruction Fetches and Instruction Executions

Figure shows the internal timing concept for the Register File. In a single clock cycle

an ALU operation using two register operands is executed, and the result is stored back

to the destination register.

Figure Single Cycle ALU Operation

64

Page 65: 2min-3 min

4.13 RESET AND INTERRUPT

Handling

The AVR provides several different interrupt sources. These interrupts and the separate

reset vector each have a separate program vector in the program memory space. All

interrupts are assigned individual enable bits which must be written logic one together

with the Global Interrupt Enable bit in the Status Register in order to enable the interrupt.

Depending on the Program Counter value, interrupts may be automatically disabled

when Boot Lock bits BLB02 or BLB12 are programmed. This feature improves software

security. See the section “Memory Programming” on page 254 for details.

The lowest addresses in the program memory space are by default defined as the Reset

and Interrupt Vectors. The complete list of vectors is shown in “Interrupts” on page 42.

The list also determines the priority levels of the different interrupts. The lower the

address the higher is the priority level. RESET has the highest priority, and next is INT0

– the External Interrupt Request 0. The Interrupt Vectors can be moved to the start of

the Boot Flash section by setting the IVSEL bit in the General Interrupt Control Register

(GICR). Refer to “Interrupts” on page 42 for more information. The Reset Vector can

also be moved to the start of the boot Flash section by programming the BOOTRST

fuse, see “Boot Loader Support – Read-While-Write Self-Programming” on page 242.

When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts

are disabled. The user software can write logic one to the I-bit to enable nested interrupts.

All enabled interrupts can then interrupt the current interrupt routine. The I-bit is

automatically set when a Return from Interrupt instruction – RETI – is executed.

There are basically two types of interrupts. The first type is triggered by an event that

sets the Interrupt Flag. For these interrupts, the Program Counter is vectored to the

actual Interrupt Vector in order to execute the interrupt handling routine, and hardware

clears the corresponding Interrupt Flag. Interrupt Flags can also be cleared by writing a

logic one to the flag bit position(s) to be cleared. If an interrupt condition occurs while the

corresponding interrupt enable bit is cleared, the Interrupt Flag will be set and remembered

until the interrupt is enabled, or the flag is cleared by software. Similarly, if one or

65

Page 66: 2min-3 min

more interrupt conditions occur while the Global Interrupt Enable bit is cleared, the

corresponding Interrupt Flag(s) will be set and remembered until the global interrupt enable

bit is set, and will then be executed by order of priority.

The second type of interrupts will trigger as long as the interrupt condition is present.

These interrupts do not necessarily have Interrupt Flags. If the interrupt condition disappears

before the interrupt is enabled, the interrupt will not be triggered.

When the AVR exits from an interrupt, it will always return to the main program and execute

one more instruction before any pending interrupt is served.

Note that the Status Register is not automatically stored when entering an interrupt routine,

nor restored when returning from an interrupt routine. This must be handled by

software.

When using the CLI instruction to disable interrupts, the interrupts will be immediately

disabled. No interrupt will be executed after the CLI instruction, even if it occurs

simultaneously with the CLI instruction.

4.14 AVR ATMEGA32 MEMORIES

This section describes the different memories in the ATmega32. The AVR architecture

has two main memory spaces, the Data Memory and the Program Memory space. In

addition, the ATmega32 features an EEPROM Memory for data storage. All three memory

spaces are linear and regular.

4.14.1 IN-SYSTEM REPROGRAMMABLE FLASH PROGRAM MEMORY

The ATmega32 contains 32K bytes On-chip In-System Reprogrammable Flash memory

for program storage. Since all AVR instructions are 16 or 32 bits wide, the Flash is organized

as 16K x 16. For software security, the Flash Program memory space is divided

into two sections, Boot Program section and Application Program section.

The Flash memory has an endurance of at least 10,000 write/erase cycles. The

ATmega32 Program Counter (PC) is 14 bits wide, thus addressing the 16K program

memory locations. The operation of Boot Program section and associated Boot Lock

bits for software protection are described in detail in “Boot Loader Support – Read-

66

Page 67: 2min-3 min

While-Write Self-Programming” on page 242. “Memory Programming” on page 254

containsa detailed description on Flash Programming in SPI, JTAG, or Parallell

Programming mode.

Constant tables can be allocated within the entire program memory address space (see

the LPM – Load Program Memory Instruction Description).

Timing diagrams for instruction fetch and execution are presented in “Instruction Execution

Timing” on page 11.

4.14.2 SRAM DATA MEMORY

Figure 9 shows how the ATmega32 SRAM Memory is organized.

The lower 2144 Data Memory locations address the Register File, the I/O Memory, and

the internal data SRAM. The first 96 locations address the Register File and I/O Memory,

and the next 2048 locations address the internal data SRAM.

The five different addressing modes for the data memory cover: Direct, Indirect with

Displacement,Indirect, Indirect with Pre-decrement, and Indirect with Post-increment. In

the Register File, registers R26 to R31 feature the indirect Addressing Pointer

67

Page 68: 2min-3 min

Registers.The direct addressing reaches the entire data space.

The Indirect with Displacement mode reaches 63 address locations from the base

address given by the Y- or Z-register.

When using register indirect addressing modes with automatic pre-decrement and

postincrement,the address registers X, Y, and Z are decremented or incremented.

The 32 general purpose working registers, 64 I/O Registers, and the 2048 bytes of internal

data SRAM in the ATmega32 are all accessible through all these addressing modes.

The Register File is described in “General Purpose Register File” on page 9.

4.15 POWER MANAGEMENT AND SLEEP MODES

Sleep modes enable the application to shut down unused modules in the MCU, thereby

saving power. The AVR provides various sleep modes allowing the user to tailor the

power consumption to the application’s requirements.

To enter any of the six sleep modes, the SE bit in MCUCR must be written to logic one

and a SLEEP instruction must be executed. The SM2, SM1, and SM0 bits in the

MCUCR Register select which sleep mode (Idle, ADC Noise Reduction, Power-down,

Power-save, Standby, or Extended Standby) will be activated by the SLEEP instruction.

68

Page 69: 2min-3 min

If an enabled interrupt occurs while the MCU is in a sleep mode, the MCU wakes up. The

MCU is then halted for four cycles in addition to the start-up time, it executes the interrupt

routine, and resumes execution from the instruction following SLEEP. The contents of the

Register File and SRAM are unaltered when the device wakes up from sleep. If a Reset

occurs during sleep mode, the MCU wakes up and executes from the Reset Vector.

4.15.1 IDLE MODE

When the SM2..0 bits are written to 000, the SLEEP instruction makes the MCU enter

Idle mode, stopping the CPU but allowing SPI, USART, Analog Comparator, ADC, Twowire

Serial Interface, Timer/Counters, Watchdog, and the interrupt system to continue

operating. This sleep mode basically halts clkCPU and clkFLASH, while allowing the other

clocks to run.

Idle mode enables the MCU to wake up from external triggered interrupts as well as

internal ones like the Timer Overflow and USART Transmit Complete interrupts. If

wake-up from the Analog Comparator interrupt is not required, the Analog Comparator

can be powered down by setting the ACD bit in the Analog Comparator Control and Status

Register – ACSR. This will reduce power consumption in Idle mode. If the ADC is

enabled, a conversion starts automatically when this mode is entered.

4.15.2 ADC NOISE REDUCTION MODE

When the SM2..0 bits are written to 001, the SLEEP instruction makes the MCU enter

ADC Noise Reduction mode, stopping the CPU but allowing the ADC, the External

Interrupts,

the Two-wire Serial Interface address watch, Timer/Counter2 and the Watchdog

to continue operating (if enabled). This sleep mode basically halts clkI/O, clkCPU, and clk-

FLASH, while allowing the other clocks to run.

This improves the noise environment for the ADC, enabling higher resolution measurements.

If the ADC is enabled, a conversion starts automatically when this mode is

entered. Apart form the ADC Conversion Complete interrupt, only an External Reset, a

Watchdog Reset, a Brown-out Reset, a Two-wire Serial Interface Address Match Interrupt,

69

Page 70: 2min-3 min

a Timer/Counter2 interrupt, an SPM/EEPROM ready interrupt, an External level

interrupt on INT0 or INT1, or an external interrupt on INT2 can wake up the MCU from

ADC Noise Reduction mode.

4.15.3 POWER-DOWN MODE

When the SM2..0 bits are written to 010, the SLEEP instruction makes the MCU enter

Power-down mode. In this mode, the External Oscillator is stopped, while the External

interrupts, the Two-wire Serial Interface address watch, and the Watchdog continue

operating (if enabled). Only an External Reset, a Watchdog Reset, a Brown-out Reset, a

Two-wire Serial Interface address match interrupt, an External level interrupt on INT0 or

INT1, or an External interrupt on INT2 can wake up the MCU. This sleep mode basically

halts all generated clocks, allowing operation of asynchronous modules only.

Note that if a level triggered interrupt is used for wake-up from Power-down mode, the

changed level must be held for some time to wake up the MCU.

When waking up from Power-down mode, there is a delay from the wake-up condition

occurs until the wake-up becomes effective. This allows the clock to restart and become

stable after having been stopped. The wake-up period is defined by the same CKSEL

fuses that define the reset time-out period.

4.15.4 POWER-SAVE MODE

When the SM2..0 bits are written to 011, the SLEEP instruction makes the MCU enter

Power-save mode. This mode is identical to Power-down, with one exception:

If Timer/Counter2 is clocked asynchronously, i.e., the AS2 bit in ASSR is set,

Timer/Counter2 will run during sleep. The device can wake up from either Timer Overflow

or Output Compare event from Timer/Counter2 if the corresponding

Timer/Counter2 interrupt enable bits are set in TIMSK, and the Global Interrupt Enable

bit in SREG is set.

If the Asynchronous Timer is NOT clocked asynchronously, Power-down mode is

recommended

instead of Power-save mode because the contents of the registers in the Asynchronous Timer

should be considered undefined after wake-up in Power-save70

Page 71: 2min-3 min

mode if AS2 is 0.

This sleep mode basically halts all clocks except clkASY, allowing operation only of

asynchronous

modules, including Timer/Counter2 if clocked asynchronously.

4.15.5 STANDBY MODE

When the SM2..0 bits are 110 and an external crystal/resonator clock option is selected,

the SLEEP instruction makes the MCU enter Standby mode. This mode is identical to

Power-down with the exception that the Oscillator is kept running. From Standby mode,

the device wakes up in six clock cycles.

4.15.6 EXTENDED STANDBY MODE

When the SM2..0 bits are 111 and an external crystal/resonator clock option is selected,

the SLEEP instruction makes the MCU enter Extended Standby mode. This mode is

identical to Power-save mode with the exception that the Oscillator is kept running.

From Extended Standby mode, the device wakes up in six clock cycles.

4.16 WATCHDOG TIMER

If the Watchdog Timer is not needed in the application, this module should be turned off.

If the Watchdog Timer is enabled, it will be enabled in all sleep modes, and hence,

always consume power. In the deeper sleep modes, this will contribute significantly to

the total current consumption.

71

Page 72: 2min-3 min

CHAPTER 5

SOFTWARE USED

72

Page 73: 2min-3 min

5.1 EXPRESS PCB

This software is use to design the PCB . The circuit daigarm obtain in our project is shown

below.

5.2 Code Vision AVR (CVAVR)

An IDE has following functions:

Preprocessing Compilation

Assembly

Linking

Object Translation

Text Editor

If we just use compiler and linker independently we still need to get a text editor. So combining everything will actually mess things up. So the best way is to get Software which has it all. That’s called an Integrated Development Environment, in short IDE.

I consider Code-Vision-AVR to be the best IDE for getting started with AVR programming on Windows XP, Vista. It has a very good Code Wizard which generate codes automatically !

73

Page 74: 2min-3 min

You need not mess with the assembly words. So in all my tutorials I will be using CVAVR. You can download evaluation version for free which has code size limitation but good enough for our purpose.

For all my examples I will be using Atmega-32 as default microcontroller because it very easily available and is powerful enough with sufficient number of pins and peripherals we use. You can have a look on the datasheet of Atmega-32 in the datasheet section.

Let’s take a look on the software. The main window looks like following,

Now click on File ---> New --->Project

A pop up window will come asking whether you want to use Code Wizard AVR, obviously select yes because that is the reason we are using CVAVR !

Now have a look on this Wizard. It has many tabs where we can configure PORTS, TIMERS, LCD, ADC etc. I am explaining some of them

74

Page 75: 2min-3 min

CHIP:

Select the chip for which you are going to write the program. Then select the frequency at which Chip is running. By default all chips are set on Internal Oscillator of 1 MHz so select 1 MHz if that is the case. If you want to change the running clock frequency of the chip then you have to change its fuse bits (I will talk more about this in fuse bits section).

 

 

 

 

 

PORT:

PORT is usually a collection of 8 pins.

From this tab you can select which pin you want to configure as output and which as input. It basically writes the DDR and PORT register through this setting. Registers are basically RAM locations which configure various peripherals of microcontroller and by changing value of these registers we can change the function it is performing. I will talk more about registers later. All the details are provided in the datasheet.

75

Page 76: 2min-3 min

So you can configure any pin as output or input by clicking the box.

For Atmega-32 which has 4 Ports we can see 4 tabs each corresponding to one Port. You can also set initial value of the Pins you want to assign. or if you are using a pin as input then whether you want to make it as pull-up or tristated, again I will talk in details about these functions later.

Similarly using this code wizard you can very easily configure all the peripherals on the Atmega.

Now for generating code just go to File ---->Generate, Save and Exit (of the code wizard)

Now it will ask you name and location for saving three files. Two being project files and one being the .C file which is your program. try to keep same names of all three files to avoid confusion. By default these files are generated in C:\CVAVR\bin

The generated program will open in the text editor. Have a look it has some declarations like PORT, DDR, TCCR0 and many more. These are all registers which configures various functions of Atmega and by changing these value we make different functions. All the details about the registers are commented just below them. Now go down and find following infinite while loop there. We can start writing our part of program just before the while loop. And as for most of the applications we want microcontroller to perform the same task forever we put our part of code in the infinite while loop provided by the code wizard !

while (1){// Place your code here

};}

See how friendly this code wizard is, all the work (configuring registers) automatically done and we don’t even need to understand and go to the details about registers too !

Now we want to generate the hex file, so first compile the program. Either press F9 or go to Project--->Compile.

It will show compilation errors if any. If program is error free we can proceed to making of hex file. So either press Shift+F9 or go to Project---->Make. A pop up window will come with information about code size and flash usage etc.

So the machine file is ready now ! It is in the same folder where we saved those 3 files.

76

Page 77: 2min-3 min

CHAPTER 6

CODING

77

Page 78: 2min-3 min

TRANSMITTER PROGRAMMING IN ATMEGA32

Chip type : ATmega32

Program type : Application

AVR Core Clock frequency: 4.000000 MHz

Memory model : Small

External RAM size : 0

Data Stack size : 512

*****************************************************/

#include <mega32.h>

// Standard Input/Output functions

#include <stdio.h>

// Declare your global variables here

void main(void)

{

// Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTA=0x00;

78

Page 79: 2min-3 min

DDRA=0x00;

// Port B initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTB=0x00;

DDRB=0x00;

// Port C initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTC=0x00;

DDRC=0x00;

// Port D initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTD=0x00;

DDRD=0x00;

// Timer/Counter 0 initialization

// Clock source: System Clock

// Clock value: Timer 0 Stopped

// Mode: Normal top=FFh

// OC0 output: Disconnected

TCCR0=0x00;

79

Page 80: 2min-3 min

TCNT0=0x00;

OCR0=0x00;

// Timer/Counter 1 initialization

// Clock source: System Clock

// Clock value: Timer1 Stopped

// Mode: Normal top=FFFFh

// OC1A output: Discon.

// OC1B output: Discon.

// Noise Canceler: Off

// Input Capture on Falling Edge

// Timer1 Overflow Interrupt: Off

// Input Capture Interrupt: Off

// Compare A Match Interrupt: Off

// Compare B Match Interrupt: Off

TCCR1A=0x00;

TCCR1B=0x00;

TCNT1H=0x00;

TCNT1L=0x00;

ICR1H=0x00;

ICR1L=0x00;

OCR1AH=0x00;

OCR1AL=0x00;

80

Page 81: 2min-3 min

OCR1BH=0x00;

OCR1BL=0x00;

// Timer/Counter 2 initialization

// Clock source: System Clock

// Clock value: Timer2 Stopped

// Mode: Normal top=FFh

// OC2 output: Disconnected

ASSR=0x00;

TCCR2=0x00;

TCNT2=0x00;

OCR2=0x00;

// External Interrupt(s) initialization

// INT0: Off

// INT1: Off

// INT2: Off

MCUCR=0x00;

MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization

TIMSK=0x00;

// USART initialization

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Receiver: On

81

Page 82: 2min-3 min

// USART Transmitter: On

// USART Mode: Asynchronous

// USART Baud Rate: 9600

UCSRA=0x00;

UCSRB=0x18;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x19;

// Analog Comparator initialization

// Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off

ACSR=0x80;

SFIOR=0x00;

DDRA=0x00; //portA is made as input port

DDRC=0x00; //portC is made as input port

while (1)

{

if(PINA==01H)

putchar(0); //zero is stored in transmitter buffer register

else if(PINA==02)

putchar(1); //one is stored in transmitter buffer register

82

Page 83: 2min-3 min

else if(PINA==04)

putchar(2); //two is stored in transmitter buffer register

else if(PINA==08)

putchar(3); //thre is stored in transmitter buffer register

else if(PINA==10)

putchar(4); //four is stored in transmitter buffer register

else if(PINA==20)

putchar(5); //five is stored in transmitter buffer register

else if(PINA==40)

putchar(6); //six is stored in transmitter buffer register

else if(PINA==80)

putchar(7); //seven is stored in transmitter buffer register

else if(PINC==01)

putchar(8); //eight is stored in transmitter buffer register

else if(PINC==02)

putchar(9); //nine is stored in transmitter buffer register

}

}

RECEIVER PROGRAMMING OF ATMEGA32

#include <mega32.h> // Standard Input/Output functions

#include <stdio.h> // Declare your global variables here

83

Page 84: 2min-3 min

void main(void)

{

int i; // Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTA=0x00;

DDRA=0x00;

// Port B initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTB=0x00;

DDRB=0x00;

// Port C initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTC=0x00;

DDRC=0x00;

// Port D initialization

// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

84

Page 85: 2min-3 min

PORTD=0x00;

DDRD=0x00;

// Timer/Counter 0 initialization

// Clock source: System Clock

// Clock value: Timer 0 Stopped

// Mode: Normal top=FFh

// OC0 output: Disconnected

TCCR0=0x00;

TCNT0=0x00;

OCR0=0x00;

// Timer/Counter 1 initialization

// Clock source: System Clock

// Clock value: Timer1 Stopped

// Mode: Normal top=FFFFh

// OC1A output: Discon.

// OC1B output: Discon.

// Noise Canceler: Off

// Input Capture on Falling Edge

// Timer1 Overflow Interrupt: Off

// Input Capture Interrupt: Off

// Compare A Match Interrupt: Off

85

Page 86: 2min-3 min

// Compare B Match Interrupt: Off

TCCR1A=0x00;

TCCR1B=0x00;

TCNT1H=0x00;

TCNT1L=0x00;

ICR1H=0x00;

ICR1L=0x00;

OCR1AH=0x00;

OCR1AL=0x00;

OCR1BH=0x00;

OCR1BL=0x00;

// Timer/Counter 2 initialization

// Clock source: System Clock

// Clock value: Timer2 Stopped

// Mode: Normal top=FFh

// OC2 output: Disconnected

ASSR=0x00;

TCCR2=0x00;

TCNT2=0x00;

OCR2=0x00;

// External Interrupt(s) initialization

// INT0: Off

86

Page 87: 2min-3 min

// INT1: Off

// INT2: Off

MCUCR=0x00;

MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization

TIMSK=0x00;

// USART initialization

// Communication Parameters: 8 Data, 1 Stop, No Parity

// USART Receiver: On

// USART Transmitter: On

// USART Mode: Asynchronous

// USART Baud Rate: 9600

UCSRA=0x00;

UCSRB=0x18;

UCSRC=0x86;

UBRRH=0x00;

UBRRL=0x19;

// Analog Comparator initialization

// Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off

ACSR=0x80;

SFIOR=0x00;

87

Page 88: 2min-3 min

DDRB=0xFF; // port B is mabe as o/p port

PORTB=0x00;

while (1)

{

i=getchar(); // RECEIVE THE DATA IN RECEIVER BUFFER

if(i==0)

{PORTB=0x3F;

} // CODE OF ZERO FOR 7 SEGMENT DISPLAY

else if(i==1)

{PORTB=0x06; // CODE OF ONE FOR 7 SEGMENT DISPLAY

}

else if(i==2)

{PORTB=0x5B; // CODE OF TWO FOR 7 SEGMENT DISPLAY

}

else if(i==3)

{PORTB=0x4F; // CODE OF THREE FOR 7 SEGMENT DISPLAY

}

else if(i==4)

{PORTB=0x66; // CODE OF FOUR FOR 7 SEGMENT DISPLAY

}

else if(i==5)

{PORTB=0x6D; // CODE OF FIVE FOR 7 SEGMENT DISPLAY

88

Page 89: 2min-3 min

}

else if(i==6)

{PORTB=0x7D; // CODE OF SIX FOR 7 SEGMENT DISPLAY

}

else if(i==7)

{PORTB=0x07; // CODE OF SEVEN FOR 7 SEGMENT DISPLAY

}

else if(i==8)

{PORTB=0x7F; // CODE OF EIGHT FOR 7 SEGMENT DISPLAY

}

else if(i==9)

{PORTB=0x67; // CODE OF NINE FOR 7 SEGMENT DISPLAY

}

}

}

89

Page 90: 2min-3 min

CHAPTER 7

CONCLUSION

90

Page 91: 2min-3 min

4.1 CONCLUSION

The conclusion is that-

With the help of laser a new means of communication “LASER COMMUNICATION” can

be developed apart from conventional methods.

Moreover the system is far more reliable ,compatible with new technologies & easy to

handle

The only limitation it have is LOS (Line Of Sight) is required between transmitter & receiver

and this limitation would be shortly overcome in near future with the development of

powerful & strong lasers.

91

Page 92: 2min-3 min

APPENDIX A

THE TRANSISTOR

A transistor is semi conductor device consisting of three regions separated by two P-N

junctions. The three regions are Base, Emitter & Collector. The base may be of N- type or P-

type. The emitter and collector have same impurities but different from that of base. Thus if

base is of N- type then emitter and collector are of P- type then transistor is called P-N-P

transistor and vice versa transistor is called N-P-N transistor. The base is made thin and

number density of majority carriers is always less than emitter and collector. The base

provides junction for proper interaction between emitter and collector. Electrons are majority

charge carriers in N- region and in P-region, holes are the majority charge carriers. Thus two

types of charge carriers are involved in current flow through N-P-N or P-N-P transistor.

SYMBOLS FOR TRANSISTORS:

In schematic symbols, the emitter is always represented by an arrow indicating the direction

of conventional current in the device. In case of N-P-N transistor arrow points away from

base and in case of P-N-P transistor it points towards base. When transistor is used in circuit,

emitter - base junction is always forward biased while base - collector junction is always

reverse biased.

92

Page 93: 2min-3 min

Figure a Structure and symbol of P-N-P transistor

BIASING OF TRANSISTOR :

The two junctions can be biased in four different ways:

Both junctions may be forward biased. It causes large current to flow across junctions.

Transistor is to be operated in “SATURATION REGION”.

Both junctions may be reversed biased. It causes very small current to flow across

junctions. Transistor is to be operated in “CUT OFF REGION”.

E-B junction is forward biased and C-B junction is reverse biased. The transistor is

said to be operated in “ACTIVE REGION”. Most of the transistors work in this

region.

E-B junction is reversed biased and C-B junction is forward biased. The transistor is

said to be operated in “INVERTED MODE”.

Figure b (a) P-N-P transistor biasing (b) N-P-N transistor biasing

93

Page 94: 2min-3 min

APPENDIX B

THE LED

A light-emitting diode (LED) is a semiconductor light source. The LED is based on the

semiconductor diode. When a diode is forward biased (switched on), electrons are able to

recombine with holes within the device, releasing energy in the form of photons. This effect

is called electroluminescence and the color of the light (corresponding to the energy of the

photon) is determined by the energy gap of the semiconductor. An LED is usually small in

area (less than 1 mm2), and integrated optical components are used to shape its radiation

pattern and assist in reflection. LEDs present many advantages over the incandescent light

sources including lower energy consumption, longer lifetime, improved robustness, smaller

size, faster switching, and greater durability and reliability. However, they are relatively

expensive and require more precise current and heat management than traditional light

sources. Current LED products for general lighting are more expensive to buy than

fluorescent lamp sources of comparable output.

94

Page 95: 2min-3 min

Figure. Current conduction

Like a normal diode, the LED consists of a chip of semiconducting material doped with

impurities to create a p-n junction. As in other diodes, current flows easily from the p-side, or

anode, to the n-side, or cathode, but not in the reverse direction. Charge-carriers—electrons

and holes—flow into the junction from electrodes with different voltages. When an electron

meets a hole, it falls into a lower energy level, and releases energy in the form of a photon.

The wavelength of the light emitted, and therefore its color, depends on the band gap energy

of the materials forming the p-n junction. In silicon or germanium diodes, the electrons and

holes recombine by a non-radiative transition which produces no optical emission, because

these are indirect band gap materials. The materials used for the LED have a direct band gap

with energies corresponding to near-infrared, visible or near-ultraviolet light.

LED development began with infrared and red devices made with gallium arsenide.

Advances in materials science have made possible the production of devices with ever-

shorter wavelengths, producing light in a variety of colors.

LEDs are usually built on an n-type substrate, with an electrode attached to the p-type layer

deposited on its surface. P-type substrates, while less common, occur as well. Many

commercial LEDs, especially GaN/InGaN, also use sapphire substrate.

Most materials used for LED production have very high refractive indices. This means that

much light will be reflected back into the material at the material/air surface interface.

95

Page 96: 2min-3 min

Therefore Light extraction in LEDs is an important aspect of LED production, subject to

much research and development. Infrared wavelength is greater than about 760 nm.

REFERENCES

http://en.wikipedia.org

http://en.extremeelectronics.co.in

http://www.avrtutor.com/tutorial.html

http://www.cmosexod.com/micro_uart.htm l

http://www.best-microcontroller-projects.com/hardware-interrupt.html

96