88
A Project Report On ENGINE OIL PURITY INDICTOR Submitted in partial fulfillment of requirements for award of Bachelor of technology In ELECTRONICS AND COMMUNICATION ENGINEERING SUBMITTED BY A.ANURAG SHARMA 08R01A0406 CH.NAGA SAI SRUJAN 08R01A0413 CH.VAMSHI KRISHNA 08R01A0414 Under the guidance of SHAIK BASHA Assistant professor, Department of Electronics and Communication Engineering, CMR Institute of Technology

Automatic Street Lights-1

Embed Size (px)

Citation preview

Page 1: Automatic Street Lights-1

A

Project Report

On

ENGINE OIL PURITY INDICTOR

Submitted in partial fulfillment of requirements for award of

Bachelor of technology

In

ELECTRONICS AND COMMUNICATION ENGINEERING

SUBMITTED BY

A.ANURAG SHARMA 08R01A0406

CH.NAGA SAI SRUJAN 08R01A0413

CH.VAMSHI KRISHNA 08R01A0414

Under the guidance of

SHAIK BASHAAssistant professor,

Department of Electronics and Communication Engineering,

CMR Institute of Technology(Affiliated to JNTU, HYD, AP)Kandlakoya, Medchal, A.P.

(2008-12)

Page 2: Automatic Street Lights-1

ABSTRACT

Purity in engine oil ensures proper working of engine. Degradation in purity will gradually decrease performance of vehicle and further degradation may completely damage engine.To avoid this, engine oil is changed in particular interval of kilometer.

Even in this case some times it happens to change engine oil after degrading in its quality. This situation can be avoided if we can change engine oil basins on its quality rather than kilometers travelled and arbitrary check engine oil purity indication system dynamically.

This project involves optical sensor( IR-PHOTO DIODE pair) to indicate purity level comparator for setting different levels of purity by user to get indicated on purity level.

Micro controller(AT89C2051) is used to collect sensor data an indicate it through LEDs for level of purity

Page 3: Automatic Street Lights-1

INDEX

LIST OF FIGURES

LIST OF TABLES

CONTENT PAGE

NO

CHAPTER 1: INTRODUCTION

CHAPTER 2: POWER SUPPLY

2.1 9V LITHIUM BATTERY

2.1.1 CONNECTERS2.1.2 TECHNICAL SPECIFICATIONS2.1.3 FEATURES OF LITHIUM BATTERY

2.2 RECTIFIERS

2.2.1 HALF WAVE RECTIFICATION2.2.2 FULL WAVE RECTIFICATION2.2.3 PEAK LOSS2.2.4 BRIDGE RECTIFIER2.2.4.1 CURRENT FLOW IN BRIDGE RECTIFIER

2.3 FILTERS

2.3.1 PASSIVE FILTERS2.3.1.1 SINGLE ELEMENT TYPES2.3.1.2 MULTIPLE ELEMENT TYPES2.3.2 ACTIVE FILTERS2.3.2.1 DESIGN OF ACTIVE FILTERS

Page 4: Automatic Street Lights-1

2.4 VOLTAGE REGULATORS2.4.1 ADVANTAGES2.4.2 DISADVANTAGES2.4.3 INDIVIDUAL DEVICES IN THE SERIES

CHAPTER 3: PIC MICROCONTROLLER

3.1 INTRODUCTION TO MICROCONTROLLER3.2 FEATURES OF PIC 16F73

3.2.1 HIGH PERFORMANCE RISC CPU3.2.2 SPECIAL MICROCONTROLLER FEATURES3.2.3 PERIPHERAL FEATURES3.2.4 CMOS TECHNOLOGY

3.3 PIN DIAGRAM3.3.1 PIC16F73 PINOUT DESCRIPTION

3.4 DESCRIPTION OF CONTROLLER3.4.1 POWER-ON RESET (POR)3.4.2 POWER-UP TIMER (PWRT)3.4.3 OSCILLATOR START-UP TIMER (OST)3.4.4 BROWN-OUT RESET (BOR)3.4.5 WATCHDOG TIMER3.4.6 MEMORY ORGANIZATION3.4.6.1 PROGRAM MEMORY ORGANIZATION3.4.6.2 DATA MEMORY ORGANIZATION3.4.7 STATUS REGISTER3.4.8 I/O PORTS3.4.8.1 PORTA AND THE TRISA REGISTER3.4.8.2 PORTB AND THE TRISB REGISTER3.4.8.3 PORTC AND THE TRISC REGISTER3.4.9 TIMER0 MODULE3.4.10 TIMER1 MODULE

Page 5: Automatic Street Lights-1

INTRODUCTION

Nowadays, human has become too busy and he is unable to find time

even to switch the lights wherever not necessary. This can be seen more

effectively in the case of street lights. The present system is like, the street

lights will be switched on in the evening before the sun sets and they are

switched off the next day morning after there is sufficient light on the roads.

But the actual timings for these street lights to be switched on are when there

is absolute darkness. With this, the power will be wasted up to some extent.

This project gives the best solution for electrical power wastage. Also the

manual operation of the lighting system is completely eliminated.

The Project Embedded Automatic Street light control with LDR

Interfacing using PIC 16F73 controller is an interesting project which uses PIC

16F73 controller as its brain. This project is very useful for commercial sign

boards, advertising boards, street lights for automation lighting system. This

system switches on the lights only in darkness. As it works with LDR sensor, no

programming of timings and battery back-up is required. This is a simple, fit

and forget system.

This project uses regulated 5V, 500mA power supply. Unregulated 9V DC

is used. 7805 three terminal voltage regulator is used for voltage regulation.

Bridge type full wave rectifier is used to rectify the AC output of 9V battery.

The original PIC was built to be used with General Instruments’ new 16-

bit CPU, the CP1600. While generally a good CPU, the CP1600 had poor I/O

performance, and the 8-bit PIC was developed in 1975 to improve

performance of the overall system by offloading I/O tasks from the CPU. The

Page 6: Automatic Street Lights-1

PIC used simple microcode stored in ROM to perform its tasks, and although

the term was not used at the time, it shares some common features with RISC

designs. In 1985, General Instruments spun off their microelectronics division

and the new ownership cancelled almost everything which by this time was

mostly out of date. The PIC, however, was upgraded with internal EPROM to

produce a programmable channel controller and today a huge variety of PICs

are available with various on-board peripherals (serial communication

modules, UARTs, motor control kernels, etc.) and program memory from 256

words to 64k words and more (a “word” is one assembly language instruction,

varying from 12, 14 or 16 bits depending on the specific PIC micro family). PIC

and PIC micro are registered trademarks of Microchip Technology.

It is generally thought that PIC stands for Peripheral Interface Controller,

although General Instruments’ original acronym for the initial PIC 1640 and PIC

1650 devices was “Programmable Interface Controller”. A microcontroller

(some times abbreviated µC, uC or MCU) is a small computer on a single

integrated circuit containing a processor core, memory, and programmable

input/output peripherals. Program memory in the form of NOR flash or OTP

ROM is also often included on chip, as well as a typically small amount of RAM.

Microcontrollers are designed for embedded applications; in contrast to the

microprocessors used in the personal computers or other general purpose

applications.

Page 7: Automatic Street Lights-1

PIC16F73

IR sensor

RE Oscillator

Power Supply

LED indictor

TUBE

High Power LEDLCD

BLOCK DIAGRAM OF ENGINE OIL PURITY INDICATING SYSTEM

COMPONENTS:

The major building blocks of this project are:-

1. Power Supply

2. LED Indicator

3. PIC 16F73

4. Oscillator

5. IR Sensor (Infrared Sensor)

6. High Power LED

7. LCD

8. TRANSPARENT TUBE

Page 8: Automatic Street Lights-1

The main technical performance comparison between the LED street light and conventional road light:

Description LED street light Traditional street light

Methods Electric network Electric network

Light source LED High Pressure Sodium Lamp

Color Temperature 3000 – 8000K 2700 – 5000K

Lifespan 50,000 hours 3,000 hours

Power 144W (energy saving>60%)

400W

Actual power consumption

160W 500W

Illumination uniformity

>0.35, Good >0.40, Excellent

Illuminated area Radius>15M, Good Radius>15M, Excellent

Glare control maximum light intensity<65 degree,

Excellent

maximum light intensity<65 degree,

Good

Good fog penetrating ability

Bad fog penetrating ability

Ballast No ballast Need ballast

Environmental Flicker-free, cold light source

Heating, result yellow shell

Fireproof rating

ADVANTAGES & APPLICATIONS:

Page 9: Automatic Street Lights-1

1. High-power LED street lamp with long lifespan.

2. The quality of LED chip, values of light attenuation.

3. LED package quality, Consistency and reliability. LED is cold light source, but the LED semiconductor itself generates heat, so good heat dissipation is the condition for LED lighting.

4. The lifespan of power supply and constant current drive.

5. High energy saving efficiency.

6. It has the features of point light source, high brightness, and narrow-beam output and so on.

7. Have considerable space for technology improvement.

8. Reasonable optical light.

POWER SUPPLY

Page 10: Automatic Street Lights-1

2.1 BATTERY

An electrical battery is one or more electrochemical cells that convert stored chemical energy into electrical energy.

A nine-volt battery, also called a PP3 battery, is shaped as a rounded rectangular prism and has a nominal output of nine volts. Its nominal dimensions are 48 mm × 25 mm × 15 mm.

9V batteries are commonly used in pocket transistor radios, smoke detectors, carbon monoxide alarms, guitar effect units, and radio-controlled vehicle controllers. They are also used as backup power to keep the time in digital clocks and alarm clocks.

Nine-volt alkaline batteries are often constructed of six individual 1.5V LR61 cells enclosed in a wrapper.

These cells are sometimes confused with standard LR8D425 AAAA cells and can be used in their place for some devices, even though they are 3.5 mm shorter.

2.1.1 CONNECTORS

The connector (snap) consists of two connectors: one smaller circular (male) and one larger, typically either hexagonal or octagonal (female). The connectors on the battery are the same as on the connector itself, the smaller one connects to the larger one and vice versa.

2.1.2 TECHNICAL SPECIFICATIONS

The battery has both the positive and negative terminals on one end. The negative terminal is fashioned into a snap fitting which mechanically and electrically connects to a mating terminal on the power connector. The power connector has a similar snap fitting on its positive terminal which mates to the battery. This makes battery polarization obvious since mechanical connection is only possible in one configuration. The clips on the nine-volt battery can be used to connect several nine-volt batteries in series. One problem with this

Page 11: Automatic Street Lights-1

style of connection is that it is very easy to connect two batteries together in a short circuit, which quickly discharges both batteries, generating heat and possibly a fire. Multiple nine volt batteries can be snapped together in series to create higher voltage.

Inside a PP3 there are six cells, either cylindrical alkaline or flat carbon-zinc type, connected in series. Some brands use welded tabs internally to attach to the cells, others press foil strips against the ends of the cells.

Rechargeable NiCd and NiMH batteries have various numbers of 1.2 volt cells. Lithium versions use three 3.2 V cells - there is a rechargeable lithium polymer version. There is also a Hybrid NiMH version that has a very low self-discharge rate (85% of capacity after one year of storage).

Formerly, mercury batteries were made in this size. They had higher capacity than carbon-zinc types, a nominal voltage of 8.4 volts, and very stable voltage output. Once used in photographic and measuring instruments or long-life applications, they are now unavailable due to environmental restrictions.

Battery Life Comparison - Ultralife lithium versus other common 9V battery types

2.1.3 FEATURES OF LITHIUM BATTERY

Page 12: Automatic Street Lights-1

1. Replaces standard 9V radio battery size.

2. Excellent for long life in smoke detectors.

3. 9 Volt, 1200 MilliAmpHour capacity.

4. Twice the power capacity of alkaline, and can last up to four times longer.

5. Extended shelf life of up to ten years.

6. Slightly smaller size than standard 9V,because it has no metal outer jacket.

7. 1/3 lighter in weight than an alkaline.

8. Maximum unit weight is 33.8 grams.

9. Superior hot and cold performance.

10.Operating temperature range: -20° to +60°C (-5° to +140°F).

11. Storage temperature range: -40° to +60°C (-40° to +140°F).

.

2.2 RECTIFIERS

A rectifier is an electrical device that converts alternating current (AC), which periodically reverses direction, to direct current (DC), which is in only one direction, a process known as rectification. Rectifiers have many uses including as components of power supplies and as detectors of radio signals. Rectifiers may be made of solid state diodes, silicon-controlled rectifiers, vacuum tube diodes, mercury arc valves, and other components.

A device which performs the opposite function (converting DC to AC) is known as an inverter.

When only one diode is used to rectify AC (by blocking the negative or positive portion of the waveform), the difference between the term diode and

Page 13: Automatic Street Lights-1

the term rectifier is merely one of usage, i.e., the term rectifier describes a diode that is being used to convert AC to DC. Almost all low power rectifiers comprise a number of diodes in a specific arrangement for more efficiently converting AC to DC than is possible with only one diode. Before the development of silicon semiconductor rectifiers, vacuum tube diodes and copper (I) oxide or selenium rectifier stacks were used. High power rectifiers, such as are used in high-voltage direct current power transmission, now uniformly employ silicon semiconductor devices of various types. These are not diodes (two-layer devices), but rather thyristors and certain more-complicated solid-state switches which effectively function as diodes to pass current in only one direction.

Early radio receivers, called crystal radios, used a "cat's whisker" of fine wire pressing on a crystal of galena (lead sulfide) to serve as a point-contact rectifier or "crystal detector". Rectification may occasionally serve in roles other than to generate direct current per se. For example, in gas heating systems flame rectification is used to detect presence of flame. Two metal electrodes in the outer layer of the flame provide a current path, and rectification of an applied alternating voltage will happen in the plasma, but only while the flame is present to generate it.

2.2.1 HALF WAVE RECTIFICATION

In half wave rectification, either the positive or negative half of the AC wave is passed, while the other half is blocked. Because only one half of the input waveform reaches the output, it is very inefficient if used for power transfer. Half-wave rectification can be achieved with a single diode in a one-phase supply, or with three diodes in a three-phase supply.

Page 14: Automatic Street Lights-1

The output DC voltage of a half wave rectifier can be calculated with the following two ideal equations:

2.2.2 FULL WAVE RECTIFICATION

A full-wave rectifier converts the whole of the input waveform to one of constant polarity (positive or negative) at its output. Full-wave rectification converts both polarities of the input waveform to DC (direct current), and is more efficient. However, in a circuit with a non-center tapped transformer, four diodes are required instead of the one needed for half-wave rectification. Four diodes arranged this way are called a diode bridge or bridge rectifier.

Graetz bridge rectifier: a full-wave rectifier using 4 diodes.

For single-phase AC, if the transformer is center-tapped, then two diodes back-to-back (i.e. anodes-to-anode or cathode-to-cathode) can form a full-wave rectifier. Twice as many windings are required on the transformer secondary to obtain the same output voltage compared to the bridge rectifier above.

Page 15: Automatic Street Lights-1

Full-wave rectifier using a center tap transformer and 2 diodes

A very common vacuum tube rectifier configuration contained one cathode and twin anodes inside a single envelope; in this way, the two diodes required only one vacuum tube. The 5U4 and 5Y3 were popular examples of this configuration.

For three-phase AC, six diodes are used. Typically there are three pairs of diodes, each pair, though, is not the same kind of double diode that would be used for a full wave single-phase rectifier. Instead the pairs are in series (anode to cathode). Typically, commercially available double diodes have four terminals so the user can configure them as single-phase split supply use, for half a bridge, or for three-phase use.

Most devices that generate alternating current (such devices are called alternators) generate three-phase AC. For example, an automobile alternator has six diodes inside it to function as a full-wave rectifier for battery charging applications.

The average and root-mean-square output voltages of an ideal single phase full wave rectifier can be calculated as:

Page 16: Automatic Street Lights-1

Where:

Vdc,Vav - the average or DC output voltage,

Vp - the peak value of half wave,

Vrms - the root-mean-square value of output voltage.

2.2.3 PEAK LOSS

An aspect of most rectification is a loss from the peak input voltage to the peak output voltage, caused by the built-in voltage drop across the diodes (around 0.7 V for ordinary silicon p-n-junction diodes and 0.3 V for Schottky diodes). Half-wave rectification and full-wave rectification using two separate secondary’s will have a peak voltage loss of one diode drop. Bridge rectification will have a loss of two diode drops. This may represent significant power loss in very low voltage supplies. In addition, the diodes will not conduct below this voltage, so the circuit is only passing current through for a portion of each half-cycle, causing short segments of zero voltage to appear between each "hump".

2.2.4 BRIDGE RECTIFIER

The Bridge rectifier is a circuit, which converts an ac voltage to dc voltage using both half cycles of the input ac voltage. The Bridge rectifier circuit is shown in the figure. The circuit has four diodes connected to form a bridge. The ac input voltage is applied to the diagonally opposite ends of the bridge. The load resistance is connected between the other two ends of the bridge.

A bridge rectifier makes use of four diodes in a bridge arrangement to

Page 17: Automatic Street Lights-1

achieve full-wave rectification. This is a widely used configuration, both with individual diodes wired as shown and with single component bridges where the diode bridge is wired internally.

Bridge Rectifier, RC Filter

Bridge Rectifier, LC Filter

2.2.4.1 CURRENT FLOW IN BRIDGE RECTIFIER

Page 18: Automatic Street Lights-1

For both positive and negative swings of the transformer, there is a forward path through the diode bridge. Both conduction paths cause current to flow in the same direction through the load resistor, accomplishing full-wave rectification.

While one set of diodes is forward biased, the other set is reverse biased and effectively eliminated from the circuit.

Page 19: Automatic Street Lights-1

2.3 FILTERS:

Electronic filters are electronic circuits which perform signal processing functions, specifically to remove unwanted frequency components from the signal, to enhance wanted ones, or both. Electronic filters can be:

1. Passive or Active2. Analog or Digital3. High-pass, Low-pass, Band pass, Band-reject (Band reject; Notch), or All-

pass.4. Discrete-time (Sampled) or Continuous-time5. Linear or Non-linear6. Infinite Impulse Response (IIR type) or Finite Impulse Response (FIR

type)

The most common types of electronic filters are linear filters, regardless of other aspects of their design.

The oldest forms of electronic filters are passive analog linear filters, constructed using only resistors and capacitors or resistors and inductors. These are known as RC and RL single-pole filters respectively. More complex multi-pole LC filters have also existed for many years, and their operation is well understood.

Hybrid filters are also possible, typically involving a combination of analog amplifiers with mechanical resonators or delay lines. Other devices such as CCD delay lines have also been used as discrete-time filters. With the availability of digital signal processing, active digital filters have become common.

2.3.1 PASSIVE FILTERS

A passive filter is a kind of electronic filter that is made only from passive elements – in contrast to an active filter, it does not require an external power source (beyond the signal). Since most filters are linear, in most cases, passive filters are composed of just the four basic linear elements

Page 20: Automatic Street Lights-1

– resistors, capacitors, inductors, and transformers. More complex passive filters may involve nonlinear elements, or more complex linear elements, such as transmission lines.

Television signal splitter consisting of a passive high-pass filter (left) and a passive low-pass filter (right). The antenna is connected to the screw terminals to the left of center

A passive filter has several advantages over an active filter:

1. Guaranteed stability2. Passive filters scale better to large signals (tens of amperes, hundreds of

volts), where active devices are often impractical3. No power consumption.4. May be less expensive in discrete designs (unless large coils are

required)5. For linear filters, may be, more linear than filters including active (and

therefore non-linear) elements, depending on components required.

They are commonly used in speaker crossover design (due to the moderately large voltages and currents, and the lack of easy access to power), filters in power distribution networks (due to the large voltages and currents), power supply bypassing (due to low cost, and in some cases, power requirements), as well as a variety of discrete and home brew circuits (for low-cost and simplicity). Passive filters are uncommon in monolithic integrated circuit design, where active devices are inexpensive compared to resistors and capacitors, and inductors are prohibitively expensive. Passive filters are still found, however, in hybrid integrated circuits. Indeed, it may be the desire to

Page 21: Automatic Street Lights-1

incorporate a passive filter that leads the designer to use the hybrid format.

Passive implementations of linear filters are based on combinations of resistors (R), inductors (L) and capacitors (C). These types are collectively known as passive filters, because they do not depend upon an external power supply and they do not contain active components such as transistors.

Inductors block high-frequency signals and conduct low-frequency signals, while capacitors do the reverse. A filter in which the signal passes through an inductor, or in which a capacitor provides a path to ground, presents less attenuation to low-frequency signals than high-frequency signals and is a low-pass filter. If the signal passes through a capacitor, or has a path to ground through an inductor, then the filter presents less attenuation to high-frequency signals than low-frequency signals and is a high-pass filter. Resistors on their own have no frequency-selective properties, but are added to inductors and capacitors to determine the time-constants of the circuit, and therefore the frequencies to which it responds.

The inductors and capacitors are the reactive elements of the filter. The number of elements determines the order of the filter. In this context, an LC tuned circuit being used in a band-pass or band-stop filter is considered a single element even though it consists of two components.

At high frequencies (above about 100 MHz), sometimes the inductors consist of single loops or strips of sheet metal, and the capacitors consist of adjacent strips of metal. These inductive or capacitive pieces of metal are called stubs.

2.3.1.1 SINGLE ELEMENT TYPES

The simplest passive filters, RC and RL filters, include only one reactive element, except hybrid LC filter which is characterized by inductance and capacitance integrated in one element.

L-FILTER

An L filter consists of two reactive elements, one in series and one in

Page 22: Automatic Street Lights-1

parallel.

A low-pass electronic filter realized by an RC circuit

T AND FILTERSπ

Capacitor-input filter

Low-pass π filter

2.3.1.2 MULTIPLE ELEMENT TYPES

Multiple element filters are usually constructed as a ladder network. These can be seen as a continuation of the L, T and π designs of filters. More elements are needed when it is desired to improve some parameter of the

Page 23: Automatic Street Lights-1

filter such as stop-band rejection or slope of transition from pass-band to stop-band.

2.3.2 ACTIVE FILTERS

An active filter is a type of analog electronic filter, distinguished by the use of one or more active components i.e. voltage amplifiers or buffer amplifiers. Typically this will be a vacuum tube, or solid-state (transistor or operational amplifier).

Active filters have three main advantages over passive filters:

1. Inductors can be avoided. Without them, passive filters cannot obtain a high Q (low damping), but inductors are often large and expensive (at low frequencies), may have significant internal resistance, and may pick up surrounding electromagnetic signals.

2. The shape of the response, the Q (quality factor), and the tuned frequency can often be set easily by varying resistors, in some filters one parameter can be adjusted without affecting the others. Variable inductances for low-frequency filters are not practical.

3. The amplifier powering the filter can be used to buffer the filter from the electronic components it drives or is fed from variations in which could otherwise significantly affect the shape of the frequency response.

Active filter circuit configurations (electronic filter topology) include:

1. Sallen and Key, and VCVS filters (low dependency on accuracy of the components)

2. State variable and biquadratic filters3. Dual Amplifier Band pass (DABP)4. Wien notch5. Multiple Feedback Filter6. Fliege (lowest component count for 2 op amp but with good

controllability over frequency and type)

Page 24: Automatic Street Lights-1

7. Akerberg Mossberg (one of the topologies that offer complete and independent control over gain, frequency, and type)

All the varieties of passive filters can also be found in active filters. Some of them are:

1. High-pass filters – attenuation of frequencies below their cut-off points.2. Low-pass filters – attenuation of frequencies above their cut-off points.3. Band-pass filters – attenuation of frequencies both above and below

those they allow to pass.4. Notch filters – attenuation of certain frequencies while allowing all

others to pass.

Combinations are possible, such as notch and high-pass (in a rumble filter where most of the offending rumble comes from a particular frequency). Another example is elliptic filters.

2.3.2.1 DESIGN OF ACTIVE FILTERS

To design filters, the specifications that need to be established include:

The range of desired frequencies (the pass band) together with the shape of the frequency response. This indicates the variety of filter and the center or corner frequencies.

Input and output impedance requirements. These limit the circuit topologies available; for example, most, but not all active filter topologies provide a buffered (low impedance) output. However, remember that the internal output impedance of operational amplifiers, if used, may rise markedly at high frequencies and reduce the attenuation from that expected. Be aware that some high-pass filter topologies present the input with almost a short circuit to high frequencies.

The degree to which unwanted signals should be rejected. o In the case of narrow-band band pass filters, the Q determines the

-3dB bandwidth but also the degree of rejection of frequencies far removed from the center frequency; if these two requirements are in conflict then a staggered-tuning band pass filter may be needed.

o For notch filters, the degree to which unwanted signals at the notch frequency must be rejected determines the accuracy of the

Page 25: Automatic Street Lights-1

components, but not the Q, which is governed by desired steepness of the notch, i.e. the bandwidth around the notch before attenuation becomes small.

o For high-pass and low-pass (as well as band-pass filters far from the center frequency), the required rejection may determine the slope of attenuation needed, and thus the "order" of the filter. A second-order all-pole filter gives an ultimate slope of about 12 dB per octave (40dB/decade), but the slope close to the corner frequency is much less, sometimes necessitating a notch be added to the filter.

The allowable "ripple" (variation from a flat response, in decibels) within the pass band of high-pass and low-pass filters, along with the shape of the frequency response curve near the corner frequency, determine the damping factor (reciprocal of Q). This also affects the phase response, and the time response to a square-wave input. Several important response shapes (damping factors) have well-known names:

o Chebyshev filter – slight peaking/ripple in the pass band before the corner; Q>0.7071 for 2nd-order filters

o Butterworth filter – flattest amplitude response; Q=0.7071 for 2nd-order filters

o Linkwitz–Riley filter – desirable properties for audio crossover applications; Q = 0.5 (critically damped)

o Paynter or transitional Thompson-Butterworth or "compromise" filter – faster fall-off than Bessel; Q=0.639 for 2nd-order filters

o Bessel filter – best time-delay, best overshoot response; Q=0.577 for 2nd-order filters

o Elliptic filter or Cauer filter – add a notch (or "zero") just outside the pass band, to give a much greater slope in this region than the combination of order and damping factor without the notch.

Active filters are implemented using a combination of passive and active (amplifying) components, and require an outside power source. Operational amplifiers are frequently used in active filter designs. These can have high Q factor, and can achieve resonance without the use of inductors. However, their upper frequency limit is limited by the bandwidth of the amplifiers used.

Digital signal processing allows the inexpensive construction of a

Page 26: Automatic Street Lights-1

wide variety of filters. The signal is sampled and an analog-to-digital converter turns the signal into a stream of numbers. A computer program running on a CPU or a specialized DSP (or less often running on a hardware implementation of the algorithm) calculates an output number stream. This output can be converted to a signal by passing it through a digital-to-analog converter. There are problems with noise introduced by the conversions, but these can be controlled and limited for many useful filters. Due to the sampling involved, the input signal must be of limited frequency content or aliasing will occur.

The transfer function of a filter is the ratio of the output signal to that of the input signal as a function of the complex frequency:

With .

The transfer function of all linear time-invariant filters, when constructed of discrete components, will be the ratio of two polynomials in, i.e. a rational function of. The order of the transfer function will be the highest power of encountered in either the numerator or the denominator.

2.4 VOLTAGE REGULATOR

A voltage regulator is an electrical regulator designed to automatically maintain a constant voltage level. A voltage regulator may be a simple "feed-forward" design or may include negative feedback control loops. It may use an electromechanical mechanism, or electronic components. Depending on the design, it may be used to regulate one or more AC or DC voltages.

Electronic voltage regulators are found in devices such as computer power supplies where they stabilize the DC voltages used by the processor and other elements. In automobile alternators and central power station generator plants, voltage regulators control the output of the plant. In an electric power

Page 27: Automatic Street Lights-1

distribution system, voltage regulators may be installed at a substation or along distribution lines so that all customers receive steady voltage independent of how much power is drawn from the line.

AN ASSORTMENT OF 78XX IC’S:

The 78xx (sometimes LM78xx) is a family of self-contained fixed linear voltage regulator integrated circuits. The 78xx family is commonly used in electronic circuits requiring a regulated power supply due to their ease-of-use and low cost. For ICs within the family, the xx is replaced with two digits, indicating the output voltage (for example, the 7805 has a 5 volt output, while the 7812 produces 12 volts). The 78xx lines are positive voltage regulators: they produce a voltage that is positive relative to a common ground. There is a related line of 79xx devices which are complementary negative voltage regulators. 78xx and 79xx ICs can be used in combination to provide positive and negative supply voltages in the same circuit.

78xx ICs have three terminals and are commonly found in the TO220 form factor, although smaller surface-mount and larger TO3 packages are available. These devices support an input voltage anywhere from a couple of volts over the intended output voltage, up to a maximum of 35 or 40 volts, and typically provide 1 or 1.5 amps of current (though smaller or larger packages may have a lower or higher current rating).

2.4.1 ADVANTAGES

1. 78xx series ICs do not require additional components to provide a constant, regulated source of power, making them easy to use, as well as economical and efficient uses of space. Other voltage regulators may

Page 28: Automatic Street Lights-1

require additional components to set the output voltage level, or to assist in the regulation process. Some other designs (such as a switching power supply) may need substantial engineering expertise to implement.

2. 78xx series ICs have built-in protection against a circuit drawing too much power. They have protection against overheating and short-circuits, making them quite robust in most applications. In some cases, the current-limiting features of the 78xx devices can provide protection not only for the 78xx itself, but also for other parts of the circuit.

2.4.2 DISADVANTAGES

1. The input voltage must always be higher than the output voltage by some minimum amount (typically 2 volts). This can make these devices unsuitable for powering some devices from certain types of power sources (for example, powering a circuit that requires 5 volts using 6-volt batteries will not work using a 7805).

2. As they are based on a linear regulator design, the input current required is always the same as the output current. As the input voltage must always be higher than the output voltage, this means that the total power (voltage multiplied by current) going into the 78xx will be more than the output power provided. The extra input power is dissipated as heat. This means both that for some applications an adequate heat sink must be provided, and also that a (often substantial) portion of the input power is wasted during the process, rendering them less efficient than some other types of power supplies. When the input voltage is significantly higher than the regulated output voltage (for example, powering a 7805 using a 24 volt power source), this inefficiency can be a significant issue.

3. Even in larger packages, 78xx integrated circuits cannot supply as much power as many designs which use discrete components, and are generally inappropriate for applications requiring more than a few amps of current.

Page 29: Automatic Street Lights-1

2.4.3 INDIVIDUAL DEVICES IN THE SERIES

There are common configurations for 78xx ICs, including 7805 (5 volt), 7806 (6 volt), 7808 (8 volt), 7809 (9 volt), 7810 (10 volt), 7812 (12 volt), 7815 (15 volt), 7818 (18 volt), and 7824 (24 volt) versions. The 7805 is common, as its regulated 5 volt supply provides a convenient power source for most TTL components.

Less common are lower-power versions such as the LM78Mxx series (500mA) and LM78Lxx series (100mA) from National Semiconductor. Some devices provide slightly different voltages than usual, such as the LM78L62 (6.2 volts) and LM78L82 (8.2 volts).

Page 30: Automatic Street Lights-1
Page 31: Automatic Street Lights-1
Page 32: Automatic Street Lights-1
Page 33: Automatic Street Lights-1

 

Page 34: Automatic Street Lights-1

PIC MICROCONTROLLER

3.1 INTRODUCTION TO MICROCONTROLLER

Looking back into the history of microcomputers, one would first come across the development of microprocessor i.e. the processing element, and later on the peripheral devices. The three basic elements – the CPU, I/O devices and memory have developed in distinct directions. While the CPU has been the proprietary item, the memory devices fall into general purpose category and I/O devices may be grouped somewhere in between. A microcontroller is a computer on chip device. The design incorporates all off the features found in microprocessor CPU, ALU, PC, SP and registers. It also has added the other features needed to make a complete computer like ROM, RAM, parallel I/O, Serial I/O, counters and clock circuits.

The device is manufactured by Microchip Company. It consists of three timers/counters, two 8-bit, one 16-bit. It also includes two serial communication ports, Universal Synchronous Receive- Transmit (USART), Synchronous Serial Port (SSP). PIC16f73 is a powerful microcontroller which provides which provides a highly flexible and cost-effective solution to many embedded control applications.

3.2 FEATURES OF PIC16F73

3.2.1 HIGH PERFORMANCE RISC CPU

1. Only 35 single word instructions2. All single cycle instructions except for program branches which are

two-cycle3. Operating speed: DC - 20 MHz clock input DC - 200 ns instruction

cycle4. Up to 4K x 14 words of FLASH Program Memory, Up to 192 bytes of

Data Memory 5. Pin out compatible to the PIC16C72B, PIC16F8726. Interrupt capability (up to 11 sources)

Page 35: Automatic Street Lights-1

7. Eight level deep hardware stack8. Direct, Indirect and Relative Addressing modes9. Processor read access to program memory

3.2.2 SPECIAL MICROCONTROLLER FEATURES

1. Power-on Reset (POR)2. Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)3. Watchdog Timer (WDT) with its own on-chip RC oscillator for

reliable operation4. Programmable code protection5. Power saving SLEEP mode6. Selectable oscillator options7. In-Circuit Serial Programming (ICSP) via two pins

3.2.3 PERIPHERAL FEATURES

i. Timer0: 8-bit timer/counter with 8-bit prescalerii. Timer1: 16-bit timer/counter with prescaler, can be incremented

during SLEEP via external crystal/clockiii. Timer2: 8-bit timer/counter with 8-bit period register, prescaler

and postscaleriv. Two Capture, Compare, PWM modules

1. Capture is 16-bit, max. Resolution is 12.5 ns2. Compare is 16-bit, max. Resolution is 200 ns3. PWM max. Resolution is 10-bit

v. 8-bit, up to 8-channel Analog-to-Digital convertervi. Synchronous Serial Port (SSP) with SPI (Master mode) and I2CTM

(Slave)vii. Universal Synchronous Asynchronous Receiver Transmitter (USART)

viii. Brown-out detection circuitry for Brown-out Reset (BOR)

3.2.4 CMOS TECHNOLOGY

1. Low power, high speed CMOS FLASH technology

2. Fully static design

Page 36: Automatic Street Lights-1

3. Wide operating voltage range: 2.0V to 5.5V

4. High Sink/Source Current: 25 mA5. Industrial temperature range6. Low power consumption:7. < 2 mA typical @ 5V, 4 MHz8. 20 μA typical @ 3V, 32 kHz9. < 1 μA typical standby current

 

3.3 PIN DIAGRAM

 

Page 37: Automatic Street Lights-1

3.3.1 PIC16F73 PINOUT DESCRIPTION

There are 28 pins on PIC16F73. Most of them can be used as an IO pin. Others are already for specific functions. These are the pin functions.1. MCLR – to reset the PIC2. RA0 – port A pin 03. RA1 – port A pin 14. RA2 – port A pin 25. RA3 – port A pin 36. RA4 – port A pin 47. RA5 – port A pin 58. VSS – ground9. OSC1 – connect to oscillator10. OSC2 – connect to oscillator11. RC0 – port C pin 0 VDD – power supply12. RC1 – port C pin 113. RC2 – port C pin 214. RC3 – port C pin 315. RC4 - port C pin 416. RC5 - port C pin 517. RC6 - port C pin 618. RC7 - port C pin 719. VSS - ground20. VDD – power supply21. RB0 - port B pin 022. RB1 - port B pin 123. RB2 - port B pin 224. RB3 - port B pin 325. RB4 - port B pin 426. RB5 - port B pin 527. RB6 - port B pin 628. RB7 - port B pin 7

 

Page 38: Automatic Street Lights-1

3.4 DESCRIPTION OF CONTROLLER

Power-on Reset (POR), Power-up Timer (PWRT),Oscillator Start-up Timer (OST), Brown-out Reset (BOR), and Parity Error Reset (PER)

 

The reset logic is used to place the device into a known state. The source of the reset can be determined by using the device status bits. The reset logic is designed with features that reduce system cost and increase system reliability.

Devices differentiate between various kinds of reset:

a) Power-on Reset (POR)

b) MCLR reset during normal operation

c) MCLR reset during SLEEP

d) WDT reset during normal operation

e) Brown-out Reset (BOR)

Most registers are unaffected by a reset their status is unknown on POR and unchanged by all other resets. The other registers are forced to a "reset state" on Power-on Reset, MCLR, WDT reset, Brown-out Reset and on MCLR reset during SLEEP.

The on-chip parity bits that can be used to verify the contents of program memory. Most registers are not affected by a WDT wake-up, since this is viewed as the resumption of normal operation. Status bits TO, PD, POR and BOR.are set or cleared differently in different reset situations. These bits are used in software to determine the nature of the reset. All new devices will have a noise filter in the MCLR reset path to detect and ignore small pulses.

              

Page 39: Automatic Street Lights-1

3.4.1 POWER-ON RESET (POR)

A Power-on Reset pulse is generated on-chip when VDD rise is detected. To take advantage of the POR, just tie the MCLR pin directly (or through a resistor) to VDD. This will eliminate external RC components usually needed to create a Power-on Reset. A minimum rise time for VDD is required.

When the device exits the reset condition (begins normal operation), the device operating parameters (voltage, frequency, temperature, etc.) must be within their operating ranges, and otherwise the device will not function correctly.

3.4.2 POWER-UP TIMER (PWRT)

The Power-up Timer provides a nominal 72 ms delay on Power-on Reset (POR) or Brown-out Reset (BOR).The Power-up Timer operates on a dedicated internal RC oscillator. The device is kept in reset as long as the PWRT is active. The PWRT delay allows VDD to rise to an acceptable level. The Power-up Timer should always be enabled when Brown-out Reset is enabled. The polarity of the Power-up Timer configuration bit is now PWRTE = 0 for enabled, while the initial definition of the bit was PWRTE = 1 for enabled. Since all new devices will use the PWRTE = 0 for enabled, the text will describe the operation for such devices. The power-up time delay will vary from device to device due to VDD, temperature, and process variations.

3.4.3 OSCILLATOR START-UP TIMER (OST)

The Oscillator Start-Up Timer (OST) provides a 1024 oscillator cycle delay (from OSC1 input) after the PWRT delay is over. This ensures that the crystal oscillator or resonator has started and is stable. The OST time-out is invoked only for XT, LP and HS modes and only on Power-on Reset, Brown-out Reset, or wake-up from SLEEP.

The OST counts the oscillator pulses on the OSC1/CLKIN pin. The counter only starts incrementing after the amplitude of the signal reaches the oscillator input thresholds. This delay allows the crystal oscillator or resonator to

Page 40: Automatic Street Lights-1

stabilize before the device exits the OST delay. The length of the time-out is a function of the crystal/resonator frequency.

For low frequency crystals this start-up time can become quite long. That is because the time it takes the low frequency oscillator to start oscillating is longer than the power-up timer's delay. So the time from when the power-up timer times-out, to when the oscillator starts to oscillate is a dead time.There is no minimum or maximum time for this dead time (TDEADTIME).

Tosc1 = time for the crystal oscillator to react to an oscillation level detectable by the

Oscillator Start-up Timer (OST).

TOST = 1024TOSC.

 3.4.4 BROWN-OUT RESET (BOR):

On-chip Brown-out reset circuitry places the device into reset when the device voltage falls below a trip point (BVDD). This ensures that the device does not continue program execution outside the valid operation range of the device. Brown-out resets are typically used in AC line applications or large battery applications where large loads may be switched in (such as automotive), and cause the device voltage to temporarily fall below the specified operating minimum.

The BODEN configuration bit can disable (if clear/programmed) or enable (if set) the Brown-out Reset circuitry. The Power-up Timer will now be invoked and will keep the chip in reset an additional 72 ms. If VDD drops below BVDD while the Power-up Timer is running, the chip will go back into Reset and the Power-up Timer will be re-initialized. Once VDD rises above BVDD, the Power-up Timer will again start a 72 ms time delay. With the BODEN bit set, all voltages below BVDD will hold the device in the reset state. This includes during the power-up sequence.

3.4.5  WATCHDOG TIMER (WDT)

During normal operation, a WDT time-out generates a device RESET. If the device is in SLEEP mode, a WDT time-out causes the device to wake-up and continue with normal operation, this is known as a WDT wake-up. The WDT

Page 41: Automatic Street Lights-1

can be permanently disabled by clearing the WDTE configuration bit. The postscaler assignment is fully under software control, i.e., it can be changed "on the fly" during program execution.

3.4.6 MEMORY ORGANIZATION

There are two memory blocks in each of these PICmicro MCUs. The Program Memory and Data Memory have separate buses so that concurrent access can occur .The Program Memory can be read internally by user code.

3.4.6.1 PROGRAM MEMORY ORGANIZATION

The PIC16F7X devices have a 13-bit program counter capable of addressing an 8K word x 14-bit program memory space. The PIC16f73 device has 4K words. Accessing a location above the physically implemented address will cause a wraparound. The RESET Vector is at 0000h and the Interrupt Vector is at 0004h.

3.4.6.2 DATA MEMORY ORGANIZATION

The Data Memory is partitioned into multiple banks, which contain the General Purpose Registers and the Special Function Registers. Bits RP1 (STATUS<6>) and RP0 (STATUS<5>) are the bank select bits.

Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are reserved for the Special Function Registers. Above the Special Function Registers are General Purpose Registers, implemented as static RAM. All implemented banks contain Special Function Registers. Some frequently used Special Function Registers from one bank may be mirrored in another bank for code reduction and quicker access.

3.4.7 STATUS REGISTER

The STATUS register contains the arithmetic status of the ALU, the RESET status and the bank select bits for data memory.

Page 42: Automatic Street Lights-1

The STATUS register can be the destination for any instruction, as with any other register. If the STATUS register is the destination for an instruction that affects the Z, DC, or C bits, then the write to these three bits is disabled. These bits are set or cleared according to the device logic. Furthermore, the TO and PD bits are not writable, therefore, the result of an instruction with the STATUS register as destination may be different than intended.

For example, CLRF STATUS will clear the upper three bits and set the Z bit. It is recommended, therefore, that only BCF, BSF, SWAPF and MOVWF instructions are used to alter the STATUS register, because these instructions do not affect the Z, C, or DC bits from the STATUS register. For other instructions not affecting any status bits, see the "Instruction Set Summary".

 

Bit 7 IRP: Register Bank Select bit (used for indirect addressing)

1 = Bank 2, 3 (100h - 1FFh)

0 = Bank 0, 1 (00h - FFh)

Bit 6-5 RP1:RP0: Register Bank Select bits (used for direct addressing)

11 = Bank 3 (180h - 1FFh)

10 = Bank 2 (100h - 17Fh)

01 = Bank 1 (80h - FFh)

00 = Bank 0 (00h - 7Fh)

Each bank is 128 bytes

Bit 4 TO: Time-out bit

1 = after power-up, CLRWDT instruction, or SLEEP instruction

Page 43: Automatic Street Lights-1

0 = A WDT time-out occurred

Bit 3 PD: Power-down bit

1 = after power-up or by the CLRWDT instruction

0 = by execution of the SLEEP instruction

Bit 2 Z: Zero bit

1 = the result of an arithmetic or logic operation is zero

0 = the result of an arithmetic or logic operation is not zero

Bit 1 DC: Digit carry/borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions)

1 = A carry-out from the 4th low order bit of the result occurred

0 = No carry-out from the 4th low order bit of the result

Bit 0 C: Carry/borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions)

1 = A carry-out from the Most Significant bit of the result occurred

0 = No carry-out from the Most Significant bit of the result occurred

3.4.8 I/O PORTS

Some pins for these I/O ports are multiplexed with an alternate function for the peripheral features on the device. In general, when a peripheral is enabled, that pin may not be used as a general purpose I/O pin.

3.4.8.1 PORTA AND THE TRISA REGISTER

PORTA is a 6-bit wide, bi-directional port. The corresponding data direction register is TRISA. Setting a TRISA bit (= '1') will make the corresponding PORTA pin an input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISA bit (= '0') will make the corresponding PORTA pin an output (i.e., put the contents of the output latch on the selected pin).

Page 44: Automatic Street Lights-1

Reading the PORTA register reads the status of the pins, whereas writing to it will write to the port latch. All write operations are read-modify-write operations. Therefore, a write to a port implies that the port pins are read; the value is modified and then written to the port data latch.

Pin RA4 is multiplexed with the Timer0 module clock input to become the RA4/T0CKI pin. The RA4/T0CKI pin is a Schmitt Trigger input and an open drain output. All other PORTA pins have TTL input levels and full CMOS output drivers.

Other PORTA pins are multiplexed with analog inputs and analog VREF input. The operation of each pin is selected by clearing/setting the control bits in the ADCON1 register (A/D Control Register1).

The TRISA register controls the direction of the RA pins, even when they are being used as analog inputs. The user must ensure the bits in the TRISA register are maintained set, when using them as analog inputs.

3.4.8.2 PORTB AND THE TRISB REGISTER

PORTB is an 8-bit wide, bi-directional port. The corresponding data direction register is TRISB. Setting a TRISB bit (= '1') will make the corresponding PORTB pin an input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISB bit (= '0') will make the corresponding PORTB pin an output (i.e., put the contents of the output latch on the selected pin).

Each of the PORTB pins has a weak internal pull-up. A single control bit can turn on all the pull-ups. This is performed by clearing bit RBPU (OPTION_REG<7>). The weak pull-up is automatically turned off when the port pin is configured as an output. The pull-ups are disabled on a Power-on Reset.

Four of the PORTB pins (RB7:RB4) have an interrupt-on-change feature. Only pins configured as inputs can cause this interrupt to occur (i.e., any RB7:RB4 pin configured as an output is excluded from the interrupt-on-change comparison). The input pins (of RB7:RB4) are compared with the old value latched on the last read of PORTB. The "mismatch" outputs of RB7:RB4 are

Page 45: Automatic Street Lights-1

ORed together to generate the RB Port Change Interrupt with flag bit RBIF (INTCON<0>).

This interrupt can wake the device from SLEEP. The user, in the Interrupt Service Routine, can clear the interrupt in the following manner:

a) Any read or write of PORTB. This will end the mismatch condition.

b) Clear flag bit RBIF.

A mismatch condition will continue to set flag bit RBIF Reading PORTB will end the mismatch condition and allow flag bit RBIF to be cleared. The interrupt-on-change feature is recommended for wake-up on key depression operation and operations where PORTB is only used for the interrupt-on-change feature. Polling of PORTB is not recommended while using the interrupt-on-change feature.

This interrupt on mismatch feature, together with software configurable pull-ups on these four pins, allow easy interface to a keypad and make it possible for wake-up on key depression.RB0/INT is an external interrupt input pin and is configured using the INTEDG bit (OPTION_REG<6>).RB0/INT.

3.4.8.3 PORTC AND THE TRISC REGISTER

PORTC is an 8-bit wide, bi-directional port. The corresponding data direction register is TRISC. Setting a TRISC bit (= '1') will make the corresponding PORTC pin an input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISC bit (= '0') will make the corresponding PORTC pin an output (i.e., put the contents of the output latch on the selected pin).PORTC is multiplexed with several peripheral functions .PORTC pins have Schmitt Trigger input buffers.

When enabling peripheral functions, care should be taken in defining TRIS bits for each PORTC pin. Some peripherals override the TRIS bit to make a pin an output, while other peripherals override the TRIS bit to make a pin an input. Since the TRIS bit override is in effect while the peripheral is enabled, read-modify-write instructions (BSF, BCF, and XORWF) with TRISC as destination should be avoided.

Page 46: Automatic Street Lights-1

3.4.9 TIMER0 MODULE

The Timer0 module timer/counter has the following features:

• 8-bit timer/counter

• Readable and writable

• 8-bit software programmable prescaler

• Internal or external clock select

• Interrupt on overflow from FFh to 00h

• Edge select for external clock

Timer0 operation is controlled through the OPTION_REG register. Timer mode is selected by clearing bit T0CS (OPTION_REG<5>). In Timer mode, the Timer0 module will increment every instruction cycle (without prescaler).If the TMR0 register is written, the increment is inhibited for the following two instruction cycles. The user can work around this by writing an adjusted value to the TMR0 register.

Counter mode is selected by setting bit T0CS (OPTION_REG<5>). In Counter mode, Timer0 will increment, either on every rising or falling edge of pin RA4/T0CKI. The incrementing edge is determined by the Timer0 Source Edge Select bit T0SE (OPTION_REG<4>). Clearing bit T0SE selects the rising edge. The prescaler is mutually exclusively shared between the Timer0 module and the Watchdog Timer. The prescaler is not readable or writable.

3.4.10 TIMER1 MODULE

The Timer1 module is a 16-bit timer/counter consisting of two 8-bit registers (TMR1H and TMR1L), which are readable and writable. The TMR1 Register pair (TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. The TMR1 Interrupt, if enabled, is generated on overflow, which is latched in interrupt flag bit TMR1IF (PIR1<0>). This interrupt can be enabled/disabled by setting/clearing TMR1 interrupt enable bit TMR1IE (PIE1<0>).

Page 47: Automatic Street Lights-1

Timer1 can operate in one of two modes:

• As a timer

• As a counter

The operating mode is determined by the clock select bit, TMR1CS (T1CON<1>).In Timer mode, Timer1 increments every instruction cycle. In Counter mode, it increments on every rising edge of the external clock input.Timer1 can be enabled/disabled by setting/clearing control bit TMR1ON (T1CON<0>).Timer1 also has an internal "RESET input”. This RESET can be generated by either of the two CCP modules as the special event trigger. When the Timer1 oscillator is enabled (T1OSCEN is set), the RC1/T1OSI/CCP2 and RC0/T1OSO/T1CKI pins become inputs. That is, the TRISC<1:0> value is ignored and these pins read as '0'.

3.4.11 TIMER2 MODULE

 

                             Timer2 is an 8-bit timer with a prescaler and a postscaler. It can be used as

the PWM time-base for the PWM mode of the CCP module(s). The TMR2 register is

readable and writable, and is cleared on any device RESET.The input clock (FOSC/4) has a

prescale option of 1:1,1:4 or 1:16, selected by control bits T2CKPS1:T2CKPS0

(T2CON<1:0>).The Timer2 module has an 8-bit period register, PR2.Timer2 increments

from 00h until it matches PR2 and then resets to 00h on the next increment cycle. PR2 is a

readable and writable register. The PR2 register is initialized to FFh upon RESET. The match

output of TMR2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive)

to generate a TMR2 interrupt (latched in flag bit

TMR2IF, (PIR1<1>)).Timer2 can be shut-off by clearing control bit TMR2ON

(T2CON<2>) to minimize power consumption.

 CAPTURE/COMPARE/PWM MODULES(CCP):

                              Each Capture/Compare/PWM (CCP) module contains a 16-bit register

which can operate as a:

Page 48: Automatic Street Lights-1

• 16-bit Capture register

• 16-bit Compare register

• PWM Master/Slave Duty Cycle register

                             Both the CCP1 and CCP2 modules are identical in operation, with the

exception being the operation of the special event trigger.In the following sections, the

operation of a CCP module is described with respect to CCP1. CCP2 operates the same as

CCP1, except where noted.

CCP1 Module

                             Capture/Compare/PWM Register1 (CCPR1) is comprised of two 8-bit

registers: CCPR1L (low byte) and CCPR1H (high byte). The CCP1CON register controls the

operation of CCP1. The special event trigger is generated by a compare match and will clear

both TMR1H and TMR1L registers.

CCP2 Module

                              Capture/Compare/PWM Register1 (CCPR1) is comprised of two 8-bit

registers: CCPR1L (low byte) and CCPR1H (high byte). The CCP2CON register controls the

operation of CCP2. The special event trigger is generated by a compare match; it will clear

both TMR1H and TMR1L registers, and start an A/D conversion (if the A/D module is

enabled).

SSP Module

                                     The Synchronous Serial Port (SSP) module is a serial interface useful

for communicating with other peripheral or microcontroller devices. These peripheral devices

may be Serial EEPROMs, shift registers, display drivers, A/D converters, etc. The SSP

module can operate in one of two modes:

• Serial Peripheral Interface (SPI)

• Inter-Integrated Circuit (I2C)

Page 49: Automatic Street Lights-1

SPI Mode                            

SPI mode allows 8 bits of data to be synchronously transmitted and received simultaneously.

To accomplish communication, typically three pins are used:

• Serial Data Out (SDO) RC5/SDO

• Serial Data In (SDI) RC4/SDI/SDA

• Serial Clock (SCK) RC3/SCK/SCL

Additionally, a fourth pin may be used when in a Slave mode of operation:

• Slave Select (SS) RA5/SS/AN4

                                  When initializing the SPI, several options need to be specified. This is

done by programming the appropriate control bits in the SSPCON register (SSPCON<5:0>)

and SSPSTAT<7:6>. These control bits allow the following

to be specified:

• Master mode (SCK is the clock output)

• Slave mode (SCK is the clock input)

• Clock Polarity (IDLE state of SCK)

• Clock edge (output data on rising/falling edge of

SCK)

• Clock Rate (Master mode only)

• Slave Select mode (Slave mode only)

SSP I2 C Operation

                                   The SSP module in I2C mode, fully implements all slave

Page 50: Automatic Street Lights-1

functions, except general call support, and provides interrupts on START and STOP bits in

hardware to facilitate firmware implementations of the master functions. The SSP module

implements the standard mode specifications as well as 7-bit and 10-bit addressing.Two pins

are used for data transfer. These are the RC3/SCK/SCL pin, which is the clock (SCL), and

the RC4/SDI/SDA pin, which is the data (SDA). The user must

configure these pins as inputs or outputs through the TRISC<4:3> bits.

                 The SSP module functions are enabled by setting SSP enable bit SSPEN

(SSPCON<5>).The SSPCON register allows control of the I2C operation. Four mode

selection bits (SSPCON<3:0>) allow one of the following I2C modes to be selected:

• I2C Slave mode (7-bit address)

• I2C Slave mode (10-bit address)

• I2C Slave mode (7-bit address), with START and STOP bit interrupts enabled to     

  support Firmware Master mode

• I2C Slave mode (10-bit address), with START and STOP bit interrupts enabled to support

Firmware Master mode

• I2C START and STOP bit interrupts enabled to support Firmware Master mode, Slave is

IDLE Selection of any I2C mode with the SSPEN bit set, forces the SCL and SDA pins to be

open drain, provide these pins are programmed to inputs by setting the appropriate TRISC

bits. Pull-up resistors must be provided externally to the SCL and SDA pins for proper

operation of the I2C module.

Universal Synchronous Asynchronous Receiver Transmitter(USART):

                                 The Universal Synchronous Asynchronous Receiver Transmitter

(USART) module is one of the two serial I/O modules. (USART is also known as a Serial

Communications Interface or SCI.) The USART can be configured as a full duplex

asynchronous system that can communicate with peripheral devices, such as CRT terminals

and personal computers, or it can be configured as a half duplex synchronous system that can

communicate with peripheral devices, such as A/D or D/A integrated

Page 51: Automatic Street Lights-1

circuits, serial EEPROMs, etc.

The USART can be configured in the following modes:

• Asynchronous (full duplex)

• Synchronous - Master (half duplex)

• Synchronous - Slave (half duplex)

                                  Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be set in order to

configure pins RC6/TX/CK and RC7/RX/DT as the Universal Synchronous Asynchronous

Receiver Transmitter.

 

USART Asynchronous Mode:

                                 In this mode, the USART uses standard non-return-to-zero (NRZ) format

(one START bit, eight or nine data bits, and one STOP bit). The most common data format is

8-bits. An on-chip, dedicated, 8-bit baud rate generator can be used to derive standard baud

rate frequencies from the oscillator. The USART transmits and

receives the LSb first. The USART's transmitter and receiver are functionally independent,

but use the same data format and baud rate. The baud rate generator

produces a clock, either x16 or x64 of the bit shift rate, depending on bit BRGH

(TXSTA<2>). Parity is not supported by the hardware, but can be implemented in

software (and stored as the ninth data bit). Asynchronous mode is stopped during SLEEP.

Asynchronous mode is selected by clearing bit SYNC (TXSTA<4>).

The USART Asynchronous module consists of the following important elements:

• Baud Rate Generator

• Sampling Circuit

Page 52: Automatic Street Lights-1

• Asynchronous Transmitter

• Asynchronous Receiver

USART Synchronous Master Mode:

                           In Synchronous Master mode, the data is transmitted in a half-duplex

manner (i.e., transmission and reception do not occur at the same time). When transmitting

data,the reception is inhibited and vice versa. Synchronous mode is entered by setting bit

SYNC (TXSTA<4>). In addition, enable bit SPEN (RCSTA<7>) is set in order to configure

the RC6/TX/CK and RC7/RX/DT I/O pins to CK (clock) and DT (data) lines, respectively.

The Master mode indicates that the processor transmits the

master clock on the CK line. The Master mode is entered by setting bit  CSRC(TXSTA<7>).

USART Synchronous Slave Mode:

                        Synchronous Slave mode differs from the Master mode, in that the shift clock

is supplied externally at the RC6/TX/CK pin (instead of being supplied internally in Master

mode). This allows the device to transfer or receive data while in SLEEP mode. Slave mode

is entered by clearing bit CSRC (TXSTA<7>).

Analog to Digital Converter(A/D) Module:

                            The 8-bit analog-to-digital (A/D) converter module has five inputs for the

PIC16f73.The A/D allows conversion of an analog input signal to a corresponding 8-bit

digital number.The output of the sample and hold is the input into the converter, which

generates the result via successive  approximation.The analog reference voltage is software

selectable to either the device's positive supply voltage (VDD), or the voltage level on the

RA3/AN3/VREF pin.The A/D converter has a unique feature of being able to operate while

the device is in SLEEP mode. To operate in SLEEP, the A/D conversion clock must be

derived from the A/D's internal RC oscillator. The A/D module has three registers. These

registers are:

• A/D Result Register ((ADRES)

• A/D Control Register 0 (ADCON0)

Page 53: Automatic Street Lights-1

• A/D Control Register 1 ((ADCON1)

The ADCON0 register controls the operation of the A/D module. The ADCON1 register,

configures the functions of the port pins. The port pins can be configured as analog inputs

(RA3 can also be a voltage reference), or as digital I/O.

Instruction Set:

 

                          The PIC16 instruction set is highly orthogonal and is comprised of three

basic categories:

• Byte-oriented operations

• Bit-oriented operations

• Literal and control operations

                           Each PIC16 instruction is a 14-bit word divided into an opcode, which

specifies the instruction type and one or more operands, which further specify the operation

of the instruction.

                           For byte-oriented instructions, 'f' represents a file register designator and 'd'

represents a destination designator.The file register designator specifies which file register is

to be used by the instruction.The destination designator specifies where the result of the

operation is to be placed. If 'd' is zero, the result is placed in the W register. If 'd' is one, the

result is placed in the file register specified in the instruction.

                          For bit-oriented instructions, 'b' represents a bit field designator, which

selects the bit affected by the operation,while 'f' represents the address of the file in which the

bit is located.

                          For literal and control operations, 'k' represents an eight- or eleven-bit

constant or literal value One instruction cycle consists of four oscillator periods;for an

oscillator frequency of 4 MHz, this gives a normal instruction execution time of 1 μs. All

instructions are executed within a single instruction cycle, unless a conditional test is true, or

Page 54: Automatic Street Lights-1

the program counter is changed as a result of an instruction. When this occurs, the execution

takes two instruction cycles, with the second cycle executed as a NOP.All instruction

examples use the format '0xhh' to represent a hexadecimal number, where 'h' signifies a

hexadecimal digit.

                           For example, a "clrf PORTB" instruction will read PORTB, clear all the data

bits, then write the result back to PORTB. This example would have the unintended

result that the condition that sets the RBIF flag would be cleared for pins configured as inputs

and using the PORTB interrupt-on-change feature

CRYSTAL OSCILLATOR

Jump to: navigation, search

A miniature 4 MHz quartz crystal enclosed in a hermetically sealed HC-49/US package, used as the resonator in a crystal oscillator.

A crystal oscillator is an electronic oscillator circuit that uses the mechanical resonance of a vibrating crystal of piezoelectric material to

create an electrical signal with a very precise frequency. This frequency is commonly used to keep track of time (as in quartz wristwatches), to provide a stable clock signal for digital integrated circuits, and to stabilize frequencies for radio transmitters and receivers. The most

Page 55: Automatic Street Lights-1

common type of piezoelectric resonator used is the quartz crystal, so oscillator circuits designed around them became known as "crystal oscillators."

Quartz crystals are manufactured for frequencies from a few tens of kilohertz to tens of megahertz. More than two billion (2×109) crystals are manufactured annually. Most are used for consumer devices such as wristwatches, clocks, radios, computers, and cellphones. Quartz crystals are also found inside test and measurement equipment, such as counters, signal generators, and oscilloscopes.

Operation

A crystal is a solid in which the constituent atoms, molecules, or ions are packed in a regularly ordered, repeating pattern extending in all three spatial dimensions.

Almost any object made of an elastic material could be used like a crystal, with appropriate transducers, since all objects have natural resonant frequencies of vibration. For example, steel is very elastic and has a high speed of sound. It was often used in mechanical filters before quartz. The resonant frequency depends on size, shape, elasticity, and the speed of sound in the material. High-frequency crystals are typically cut in the shape of a simple, rectangular plate. Low-frequency crystals, such as those used in digital watches, are typically cut in the shape of a tuning fork. For applications not needing very precise timing, a low-cost ceramic resonator is often used in place of a quartz crystal.

When a crystal of quartz is properly cut and mounted, it can be made to distort in an electric field by applying a voltage to an electrode near or on the crystal. This property is known as piezoelectricity. When the field is removed, the quartz will generate an electric field as it returns to its previous shape, and this can generate a voltage. The result is that a quartz crystal behaves like a circuit composed of an inductor, capacitor and resistor, with a precise resonant frequency. (See RLC circuit.)

Quartz has the further advantage that its elastic constants and its size change in such a way that the frequency dependence on temperature can be very low. The specific characteristics will depend on the mode of vibration and the angle at which the quartz is cut (relative to its crystallographic axes).[7] Therefore, the resonant frequency of the plate, which depends on its size, will not change much, either. This means that a quartz clock, filter or oscillator will remain accurate. For critical applications the quartz oscillator is mounted in a temperature-controlled container, called a crystal oven, and can also be mounted on shock absorbers to prevent perturbation by external mechanical vibrations.

Page 57: Automatic Street Lights-1

Schematic symbol and equivalent circuit for a quartz crystal in an oscillator

A quartz crystal can be modeled as an electrical network with a low impedance (series) and a high impedance (parallel) resonance point spaced closely together. Mathematically (using the Laplace transform) the impedance of this network can be written as:

or,

where s is the complex frequency (s = jω), ωs is the series resonant frequency in radians per second and ωp is the parallel resonant frequency in radians per second.

Adding additional capacitance across a crystal will cause the parallel resonance to shift downward. This can be used to adjust the frequency at which a crystal oscillates. Crystal manufacturers normally cut and trim their crystals to have a specified resonance frequency with a known 'load' capacitance added to the crystal. For example, a crystal intended for a  6 pF load has its specified parallel resonance frequency when a 6.0 pF capacitor is placed across it. Without this capacitance, the resonance frequency is higher.

Temperature effects

A crystal's frequency characteristic depends on the shape or 'cut' of the crystal. A tuning fork crystal is usually cut such that its frequency over temperature is a parabolic curve centered around 25 °C. This means that a tuning fork crystal oscillator will resonate close to its target frequency at room temperature, but will slow down when the temperature either increases or decreases from room temperature. A common parabolic coefficient for a 32 kHz tuning fork crystal is −0.04 ppm/°C².

In a real application, this means that a clock built using a regular 32 kHz tuning fork crystal will keep good time at room temperature, lose 2 minutes per year at 10 degrees Celsius above (or below) room temperature and lose 8 minutes per year at 20 degrees Celsius above (or below) room temperature due to the quartz crystal.

Commonly used crystal frequenciesMain article: Crystal oscillator frequencies

Page 58: Automatic Street Lights-1

Crystal oscillator circuits are often designed around relatively few standard frequencies, such as 3.579545 MHz, 4.433619 MHz, 10 MHz, 14.318182 MHz, 17.734475 MHz, 20 MHz, 33.33 MHz, and 40 MHz. The popularity of the 3.579545 MHz crystals is due to low cost since they are used for NTSC color television receivers. Using frequency dividers, frequency multipliers and phase locked loop circuits, it is practical to derive a wide range of frequencies from one reference frequency. 14.318182 MHz (four times 3.579545 MHz) is used in computer video displays to generate a bitmapped video display for NTSC color monitors, such as the CGA used with the original IBM PC. (The IBM PC used 14.318182 MHz, divided by three, as its 4.77 MHz clock source, using one crystal for two purposes.) The 4.433619 MHz and 17.734475 MHz values are used in PAL color television equipment and devices intended to produce PAL signals.

Crystals can be manufactured for oscillation over a wide range of frequencies, from a few kilohertz up to several hundred megahertz. Many applications call for a crystal oscillator frequency conveniently related to some other desired frequency, so hundreds of standard crystal frequencies are made in large quantities and stocked by electronics distributors.

SENSORS

1. LIGHT DEPENDENT RESISTOR

2. INFRARED SENSOR (IR SENSOR)

LIGHT DEPENDENT RESISTOR :

The symbol for a photoresistor[1]

Page 59: Automatic Street Lights-1

A light dependent resistor

A photoresistor or light dependent resistor (LDR) is a resistor whose resistance decreases with increasing incident light intensity. It can also be referred to as a photoconductor.

A photoresistor is made of a high resistance semiconductor. If light falling on the device is of high enough frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electron (and its hole partner) conduct electricity, thereby lowering resistance.

A photoelectric device can be either intrinsic or extrinsic. An intrinsic semiconductor has its own charge carriers and is not an efficient semiconductor, e.g. silicon. In intrinsic devices the only available electrons are in the valence band, and hence the photon must have enough energy to excite the electron across the entire bandgap. Extrinsic devices have impurities, also called dopants, added whose ground state energy is closer to the conduction band; since the electrons do not have as far to jump, lower energy photons (i.e., longer wavelengths and lower frequencies) are sufficient to trigger the device. If a sample of silicon has some of its

Page 60: Automatic Street Lights-1

atoms replaced by phosphorus atoms (impurities), there will be extra electrons available for conduction. This is an example of an extrinsic semiconductor.

Applications

Photoresistors come in many different types. Inexpensive cadmium sulfide cells can be found in many consumer items such as camera light meters, street lights, clock radios, alarms, and outdoor clocks.

They are also used in some dynamic compressors together with a small incandescent lamp or light emitting diode to control gain reduction.

Lead sulfide (PbS) and indium antimonide (InSb) LDRs (light dependent resistor) are used for the mid infrared spectral region. Ge:Cu photoconductors are among the best far-infrared detectors available, and are used for infrared astronomy and infrared spectroscopy.

INFRARED SENSOR (IR SENSOR):

LIGHT EMITTING DIODE (LED) :

LED is very useful for electronics products. It is used as an indicator for power

availability, indicator for success execution of any processes, indicator for any alarm or

failure and so on. Without LED, electronics products cannot inform user for any action that

need to be take and cannot inform any successful execution.

LED has variety of size and color. Red, blue, green and yellow LED is the most

common. The shape also varies from square, rectangle and circular.

LED is normally being interface with microcontroller. 5 volt is required to turn on

LED and normally 220 ohm resistor is required as a safety to avoid the LED blown.

Page 61: Automatic Street Lights-1

LED consists of two legs. One of the legs with flag must be connected to ground and the

other must be connected to 5 volt.

LEDs are surely one of the most commonly used elements in electronics. LED is an

abbreviation for 'Light Emitting Diode'. When choosing a LED, several parameters should be

looked at: diameter, which is usually 3 or 5 mm (millimeters), working current which is

usually about 10mA (It can be as low as 2mA for LEDs with high efficiency - high light

output), and color of course, which can be red or green though there are also orange, blue,

yellow..

LEDs must be connected around the correct way, in order to emit light and the

current-limiting resistor must be the correct value so that the LED is not damaged or  burn

out (overheated). The positive of the supply is taken to the anode, and the cathode goes to the

negative or ground of the project (circuit). In order to identify each lead, the cathode is the

shorter lead and the LED "bulb" usually has a cut or "flat" on the cathode side. Diodes will

emit light only if current is flowing from anode to cathode. Otherwise, its PN junction is

reverse biased and current won't flow. In order to connect a LED correctly, a resistor must be

added in series that to limit the amount of current through the diode, so that it does not burn

out. The value of the resistor is determined by the amount of current you want to flow

through the LED. Maximum current flow trough LED was defined by manufacturer.

To determine the value of the dropper-resistor, we need

to know the value of the supply voltage. From this we

subtract the characteristic voltage drop of a LED. This

value will range from 1.2v to 1.6v depending on the

color of the LED. The answer is the value of Ur. Using

this value and the current we want to flow through the

LED (0.002A to 0.01A) we can work out the value of

the resistor from the formula R=Ur/I. 

LEDs are connected to a microcontroller in two ways. One is to switch them on with logic

zero, and other to switch them on with logic one. The first is called NEGATIVE logic and the

other is called POSITIVE logic. The next diagram shows how to connect POSITIVE logic.

Since POSITIVE logic provides a voltage of +5V to the diode and dropper resistor, it will

Page 62: Automatic Street Lights-1

emit light each time a pin of port B is provided with a logic 1. The other way is to connect all

anodes to +5V and to deliver logical zero to cathodes.

CUSTOM COMPUTER SERVICE(CCS)

CCS Compiler Screen Shot

Page 63: Automatic Street Lights-1

Compiler Screen Shot while Compilation

Page 64: Automatic Street Lights-1

Programmer software screen shot

Page 65: Automatic Street Lights-1

Progarmmer software screen shot while chip select

Page 66: Automatic Street Lights-1

How to Load Hex File into PIC Controller

Once the C program code has been compiled, the hex file will be generated in the same

folder as the C code. This hex file is needed to be loaded into the PIC using PIC programmer. Topwin

is one of the programmers available in the market at a very cheap cost.

To use the Topwin programmer we need software from Microchip called MPLAB. MPLAB is

Page 67: Automatic Street Lights-1

free software from Microchip. This software can be downloaded from Microchip web site.

After MPLAB install ion on the PC, open the MPLAB application by double click on the MPLAB

icon. From the MPLAB menu on the top find select programmer and choose Topwin. Click on Enable

Programmer. MPLAB will activate Topwin. However make sure Topwin programmer already

connected to the serial COM1 on the PC and its power turn on before running MPLAB software.

Go to setting and select device. Choose PIC controller number as a device say for example

“PIC16F72”. Then select configuration. Choose HS for the Oscillator.

Now go to file and import the hex file to be downloaded into the PIC. Place the PIC chip into

the programmer socket and click on WRITE at the Topwin task.

The hex file will be downloaded into the PIC chip. The MPLAB IDE will respond with SUCCESFUL

LOADED HEX FILE.

Now the PIC controller can be transferred into the real circuit board for testing.

CODE :