Sie sind auf Seite 1von 73

DEVELOPMENT OF AN IOT ENVIRONMENTAL AND INDUSTRIAL

MONITORING APPLICATION WITH A NOVEL MIDDLEWARE FOR


SMART CITY MONITORING SYSTEM

CHAPTER 1

INTRODUCTION

A smart city enables the effective utilization of resources and better quality of
services to the citizens. To provide services such as air quality management,
weather monitoring and automation of homes and buildings in a smart city, the
basic parameters are temperature, humidity and CO2. This Project presents a
customised design of an Internet of Things (IoT) enabled environment
monitoring system to monitor temperature, humidity and CO2. In developed
system, data is sent from the transmitter node to the receiver node. The data
received at the receiver node is monitored and recorded in an excel sheet in a
personal computer (PC) through Serial Port Communication.
The IoT has a large role to play in future smart cities.The IoT can be used in
practically all scenarios for public services by governments. Sensor-enabled
devices can help monitor the environmental impact of cities, collect details
about sewers, air quality, and garbage. Such devices can also help monitor
woods, rivers, lakes, and oceans. Many environmental trends are so complex,
that they are difficult to conceptualize. The Internet of Things (IoT) is a recent
communication paradigm that envisions a near future, in which the objects of
everyday life will be equipped with microcontrollers, transceivers for digital
communication, and suitable protocol stacks that will make them able to
communicate with one another and with the users, becoming an integral part of
the Internet.
An embedded system is a special purpose computer system, which is
completely encapsulated by the device it controls. An embedded system has
specific requirement and performs pre-define tasks, unlike a general-purpose
personal computer.

An embedded system is a programmed hardware device. A


programmable hardware chip is the ‘raw material’ and it is programmed with
particular applications. This is to be understood in comparison to older systems
with full functional hardware or system with general purpose hardware and
externally loaded software. Embedded systems are a combination of hardware
and software which facilitates mass production and variety of application

1.1 CHARACTERISTICS OF AN EMBEDDED SYSTEM

 Sophisticated Functionality
 Real-Time Operation
 Low manufacturing Cost
 Low Power Consumption

1.2 FEATURES OF AN EMBEDDED SYSTEM

Real-Time Operation

 Reactive: computations must occur in response to external events


 Correctness is partially a function of time
Small size, low weight

 Hand – held electronics and Transportation application—weight costs money


Safety – critical operation
 Must function correctly and must not function incorrect
1.3 FUTURE OF AN EMBEDDED CONTROL

Intelligent products are used every day – mobile phone, printer,


microwave ovens, water purifier, air conditioner etc.,
New generation embedded controller will include internet connectivity,
RF controller and Bluetooth

1.4 BENEFITS OF EMBEDDED CONTROLLER DESIGN

 Eliminates necessity of complex circuitry


 Smarter products
 Smaller size
 Lower cost
 User friendly
 State of the art technology

CHAPTER 2

EXISTING SYSTEM:

There have been numerous efforts on microclimate monitoring using


Wireless Sensor Network (WSN).the data loss is more in the Wireless
monitoring design. The system deployment cost of the Network design is high.
As of now they are using the monitoring details from the display manually. If
the manual up date will lead the human errors on the measurement data’s.

PROPOSED SYSTEM:

The entire environmental monitoring system will monitor and update


automatically using IoT(Internet of Things ).all the collected data will save the
server end and monitored single end up date, it will reduce the human effort and
error measurements. In our proposed system we are using the CO (Carbon
Monoxide ) ,Temperature ,Humidity and Rain level & Landslide Indication
from single Web link using IoT Technology.

BLOCK DIAGRAM (MULTIPLE ZONE END)

POWER SUPPLY UNIT

PIC16F877A
CARBON MONOXIDE (GAS)
SENSOR MODULE
A RAIN DETECTOR
I
D /
HUMIDITY SENSOR C O
MODULE P
O
R LANDSLIDE
T DETECTION SENSOR
TEMPERATURE SENSOR
S (TILT SENSOR
MODULE
MODULE)

UART

IoT TRANSCEIVER

IoT Data uploading from this server system using


Web server program.
Hardware Requirements:

1. Microcontroller
2. Iot module (ESP8266mcu)
3. Tilt Sensor Module
4. Gas Sensor Module
5. Humidity Sensor Module
6. Rain Detector
7. Temperature Sensor Module
8. Usb To Rs232 Cable

Software Requirements:

1. Pic Compiler
2. Embedded C

Advantages:

1. Air pollution monitoring system and sensor control system

2. Water Quality Measurements Industry(pH and Temperature)

3. Significance & Reliability

4. Environmental Sustainability in Food Industry


2.6 CIRCUIT DIAGRAM

Fig.No.2.2
CHAPTER 3

PIC MICROCONTROLLER

3.1 GENERAL DESCRIPTION ABOUT PIC MICROCONTROLLER

The Microcontroller that has been used for this project is from PIC
series. PIC microcontroller is the first RISC based microcontroller fabricated in
CMOS (complementary metal oxide semiconductor) that uses separate bus for
instruction and data allowing simultaneous access of program and data memory.

The main advantage of CMOS and RISC combination is low power


consumption resulting in a very small chip size with a small pin count. The
main advantage of CMOS is that it has immunity to noise than other fabrication
techniques.

Various microcontrollers offer different kinds of memories. EEPROM,


EPROM, FLASH etc. are some of the memories of which FLASH is the most
recently developed. Technology that is used in pic16F877 is flash technology,
so that data is retained even when the power is switched off. Easy Programming
and Erasing are other features of PIC 16F877.

3.2 CORE FEATURES

 High-performance RISC CPU


 All single cycle instructions except for program branches which are two
cycle
 Operating speed: DC - 20 MHz clock input
DC - 200 ns instruction cycle
 Up to 8K x 14 words of Flash Program Memory,
 Up to 368 x 8 bytes of Data Memory (RAM)
 Up to 256 x 8 bytes of EEPROM data memory
 Direct, indirect, and relative addressing modes
 Power-on Reset (POR)
 Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)
 Watchdog Timer (WDT) with its own on-chip RC Oscillator for reliable
operationProgrammable code-protection
 Power saving SLEEP mode
 Selectable oscillator options
 Low-power, high-speed CMOS EPROM/EEPROM technology
 Fully static design
 In-Circuit Serial Programming (ICSP) via two pins
 Only single 5V source needed for programming capability
 In-Circuit Debugging via two pins
 Processor read/write access to program memory
 Wide operating voltage range: 2.5V to 5.5V
 High Sink/Source Current: 25 mA
 Commercial and Industrial temperature ranges
 Low-power consumption:
< 2mA typical @ 5V, 4 MHz

20mA typical @ 3V, 32 kHz

< 1mA typical standby current

3.3 PERIPHERAL FEATURES


 Timer0: 8-bit timer/counter with 8-bit pre scaler
 Timer1: 16-bit timer/counter with pre scaler, can be incremented during
sleep
Via external crystal/clock
 Timer2: 8-bit timer/counter with 8-bit period registers, prescaler and post
scaler
 Two Capture, Compare, PWM modules
Capture is 16-bit, max resolution is 12.5 ns,
Compare is 16-bit, max resolution is 200 ns,
PWM max. Resolution is 10-bit
10-bit multi-channel Analog-to-Digital converter

3.4 ARCHITECTURE OF PIC 16F877

The complete architecture of PIC 16F877 is shown in the fig 2.1. Table 2.1
gives details about the specifications of PIC 16F877. Fig 2.2 shows the
complete pin diagram of the IC PIC 16F877.
Fig.3.1 Architecture of PIC16F877

3.5 PIN DIAGRAM


Fig No3.2: Pin Diagram of PIC16F877A

3.6 PIN DESCRIPTION


Table No.3.1
Legend: I = input O = output I/O = input/output P = power

= Not used TTL = TTL input ST = Schmitt Trigger input

NOTE:
1. This buffer is a Schmitt Trigger input when configured as an external
interrupt.

2. This buffer is a Schmitt Trigger input when used in serial programming


mode.

3. This buffer is a Schmitt Trigger input when configured as general purpose


I/O and a TTL input when used in the Parallel Slave Port mode (for interfacing
to a microprocessor bus).

4. This buffer is a Schmitt Trigger input when configured in RC oscillator mode


and a CMOS input otherwise.

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

Additional Information on I/O ports may be found in the IC micro™


Mid-Range Reference Manual.

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

3.7.2. PORTB AND 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. Three pins of
PORTB are multiplexed with the Low Voltage Programming function;
RB3/PGM, RB6/PGC and RB7/PGD. The alternate functions of these pins are
described in the Special Features Section. 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.

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

3.7.4 PORTD AND TRISD REGISTERS

This section is not applicable to the 28-pin devices. PORTD is an 8-bit port with
Schmitt Trigger input buffers. Each pin is individually configurable as an input
or output. PORTD can be configured as an 8-bit wide microprocessor Port
(parallel slave port) by setting control bit PSPMODE (TRISE<4>). In this
mode, the input buffers are TTL.

3.7.5 PORTE AND TRISE REGISTER

PORTE has three pins RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/AN7, which


are individually configurable as inputs or outputs. These pins have Schmitt
Trigger input buffers.

The PORTE pins become control inputs for the microprocessor port
when bit PSPMODE (TRISE<4>) is set. In this mode, the user must make sure
that the TRISE<2:0> bits are set (pins are configured as digital inputs). Ensure
ADCON1 is configured for digital I/O. In this mode the input buffers are TTL.

3.8 MEMORY ORGANISATION

There are three memory blocks in each of the PIC16F877 MUC’s. The program
memory and Data Memory have separate buses so that concurrent access can
occur.
3.8.1 PROGRAM MEMORY ORGANISATION

The PIC16f877 devices have a 13-bit program counter capable of addressing 8K


*14 words of FLASH program memory. 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.8.2 DATA MEMORY ORGANISTION

The data memory is partitioned into multiple banks which contain the General
Purpose Registers and the special functions Registers. Bits RP1 (STATUS<6)
and RP0 (STATUS<5>) are the bank selected bits.

RP1:RP0 Banks

00 0

01 1

10 2

11 3

Table No.3.2

Each bank extends up to 7Fh (1238 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.8.3 EEPROM

EEPROM (electrically erasable, programmable read only memory)


technology supplies Nonvolatile storage of variables to a PIC-controlled device
or instrument. That is variables stored in an EEPROM will remain there even
after power has been turned off and then on again. Some instruments use an
EEPROM to store calibration data during manufacture. In this way, each
instrument is actually custom built, with customization that can be easily
automated. Other instruments use and EEPROM to allow a user to store
several sets of setup information. For an instrument requiring a complicated
setup procedure, this permits a user to retrieve the setup required for any one of
several very Different measurements. Still other devices use an EEPROM in a
way that is transparent To a user, providing backup of setup parameters and
thereby bridging over power outages

The data EEPROM and flash program memory are readable and
writable during normal operation over the entire VDD range. A bulk erase
operation may not be issued from user code (which includes removing code
protection. The data memory is not directly mapped in the register file space.
Instead it is indirectly addressed through the special function registers (SFR).

There are six SFRS used to read and write the program and data EEPROM
memory.

These registers are:

EECON1

EECON2

EEDATA

EEDATH

EEADR

EEADRH

EEDATA holds the 8-bit data for read/write and EEADRR holds the address of
the EEPROM location being accessed.

3.9 TIMERS

There are three timers used Timer 0, Timer1 and Timer2

Timer 0

 8-bit timer/counter
 Software programmable prescaler
 Internal or external clock select
 Readable writable
 Interrupt on overflow
 Edge selects for external clock
Timer 1

 Timer 1 can be used as timer or counter


 It is 16-bit register
 Software programmable prescaler
 Interrupt on overflow
 Readable and writable
 The timer-1 module is a 16-bit timer/counter consisting two 8-bit register
(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. This interrupt can be enabled/disabled by setting/clearing
tmr1 interrupt enable bit tmr1IE.
Timer 2

 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.
 The timer2 module has an 8-bit period register PR2. Timer2 increments from
00h until it match 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
 Timer 2 can be shut off by clearing control bit tmr2on to minimize power
consumption.
 The prescaler and postscaler counters are cleared when any of the following
occurs:
 A write to the tmr2 register
 A write to the t2con register
 An any device reset
 Tmr2 is not cleared when t2con is written
3.10 INTERRUPTS

The Pic16f87x Family has upto 14 Sources of Interrupt. The interrupt control
register (INTCON) records individual interrupt requests in flag bits. IT also has
individual interrupt requests in flag bits. IT also has individual and global
interrupt enables bits.Though some modules may generate multiple interrupts
such as (USART) They have 14 sources.

Additionally if the device has peripheral interrupts, then it will have


registers to enable the peripheral interrupts and registers to hold the interrupt
flag bits

PIE1 PIE2 PIR1 PIR2


Table No.3.3
3.11 OSCILLATOR AND CLOCK CIRCUIT

XTAL1 and XTAL2 are the input and output respectively of an inverting
amplifier which is intended for use as a crystal oscillator in the pierce
configuration, in the frequency range of 1.2 MHz to 12 Mhz. XTAL2 also the
input to the internal clock generator.

To drive the chip with an internal oscillator, one would ground


XTAL1 and XTAL2.

Since the input to the clock generator is dividing by two flip flops there are no
requirements on the duty cycle of the external oscillator signal. However,
minimum high and low times must be observed.

The clock generator divides the oscillator frequency by 2 and provides


a tow phase clock signal to the chip. The phase 1 signal is active during the first
half to each clock period and the phase 2 signals are active during the second
half of each clock period.

CHAPTER 4

4.1 Filter

Integrated circuits (ICs) are made up of sensitive transistors. Most are


rated for 3 to 5 Volts DC although newer ones operate at even lower voltages.
Exceeding that voltage can damage or destroy the IC. Electro Static Discharges
(ESD) from human contact can exceed 10,000 Volts. This section describes
methods for protecting microcontroller inputs.

4.1.1 Static Electricity Input Protection with R/C filtering.

Semiconductors are really fragile critters. If you exceed the maximum


voltage you can burn it out. If the input voltage goes below ground by more
than a few tenths of a volt, the whole IC can latch up in a high current mode and
burn up. Static electricity can build up on the user and then discharge through
your circuit when they touch a switch or other control. Putting some protection
on the inputs can be a good idea.
Figure 10-1 shows a switch configuration similar to that shown in Part
6. Two additional parts are added, R2 and C1. Adding just R2 by itself will
provide some protection. If a voltage spike is applied to the switch the resistor
R2 will limit the current flowing into the input port. Typically R2 will be
between 10 and a few hundred ohms.

Adding C1 will improve protection to the input. A capacitor resists


change in the voltage across it. The capacitor will become charged as current
flows into it. The amount of current will be limited by the value of R2. The
time it takes to charge to the input voltage will increase as the capacitance of C1
and the value of R2 increases. Figure 10-2 shows the voltage across a capacitor
with a step input.

FIG .NO .4.1

Assume that the input voltage Vin and voltage across the capacitor Vc is
zero volts. At some point Vin jumps to the value V. At that instant Vc is still
zero volts. Over time the capacitor will start to charge and if Vin stays at V long
enough, Vc will approach V. The rate Vc approaches V depends on the time
constant (TC).

TC =R*C

Where R is resistance of R in ohms, and C is capacitance of C in Farads. TC is


measured in seconds.

The voltage at time t can be calculated with the following equation:

Vc=V(1-e^(-t/RC))

At a period of 1 TC Vc will reach about 63% of V. At 2 TC the voltage


will reach 63% of the remaining difference between Vc and V, or about 86% of
V, and so on. At 4 * TC Vc will be within 99% of V. Technically Vc will never
reach V, but the difference will be infinitesimal. At some point Vin returns to
zero volts, and the capacitor will discharge at the same rate it charged.

Now consider the situation where Vin is at voltage V for a short period of
time. The capacitor will not have time to charge very much, and Vc will not be
able to approach V. If the length of Vin being high is short compared to TC,
Vc may not get high enough to reach the threshold voltage of the
microcontroller input. The microcontroller will never recognize the input signal
went high.

Let’s get back to our static electricity problem. A static electricity burst
is usually a very short pulse. The RC circuit will limit how high the voltage
will get. A resistor of a couple of hundred ohms and a capacitor of .01 or .1
microfarads will give reasonable protection to the input.
Fig.No.4.2

An RC circuit is also known as a low pass filter. If the period of a signal


is long (low frequency) compared to TC, the signal will pass through reasonably
intact. If the period is short with respect to TC it will be filtered out.

The low pass filter can be used for other purposes. Part 6 mentioned
switch bounce. This is where a mechanical switch will often make and break
contact when it is actuated. Proper values of RC can filter out these spikes.
RC filters are also used for filtering out high frequencies for A/D (Analog to
Digital) converters. Their use in those applications will be covered in a future
installment.

The nature of the signal inputs must be kept in mind when using RC
filtering. Suppose we have a sensor that indicates one revolution of a motor. If
the motor is running fast enough, or if the values of R and C are too high, the
inputs will be filtered out. The voltage at the pin will never reach the switching
threshold and the micro will think the motor is not running.
Looking at the situation from the analog world, an RC circuit has a
frequency at which point ½ of the input voltage is lost. This is also known as the
3dB point. This is known as the cut off frequency, or Fc.

Fc = 1/(2πRC)

The frequency of a signal going through an RC filter must be much less than Fc
for proper operation.

Another characteristic of an RC filter might be important in some


applications. Take a look at Figure 10-2. Suppose that our application requires
the microcontroller to perform some operation very quickly when Vin rises to
V. Further assume that the threshold voltage for determining the input
registering as a 1 or a 0 is at ½ V. It takes nearly 1 full TC for Vc to reach that
voltage. This might be too late for the microcontroller to complete its operation
in time.

Some microcontroller inputs depend on the input signal rising quickly.


Reset pins and edge triggered interrupt lines may not work properly if an RC
circuit slows the rate the signal changes. Consult the microcontroller data sheet
before putting RC networks on these types of microcontroller inputs.

4.2 Transient Suppressor Protection

Special electronic components specifically designed for ESD protection


are available. The go by the name of TVS, MOV, and a large number of trade
names. They are easy to use, and have many advantages over the zener
protection including faster response times and higher energy capacity. Some are
also available as arrays, handling a number of signal lines in a single package.
Figure 10-4 shows a microcontroller input protected by one of these devices.
The schematic symbol may vary depending on the technology of the device.
In normal operation these look like a capacitor. If the applied voltage
reaches the Varistor Voltage, the varistor acts like a switch shorting the signal to
ground. Most types are bidirectional, meaning they will switch on if the
varistor voltage is reached regardless of polarity.

The first data sheet parameter to look for is the Maximum Allowable
Voltage. This must be higher than the normal operating signal voltages.
Otherwise, the normal signal will trip it, possibly preventing the signal from
reaching the threshold voltage. Another key specification is the capacitance.
You will want to use low capacitance suppressors for high frequency signals.
Otherwise, the signal will get filtered out as in the RC filter described earlier.

Another specification is the maximum surge current. The higher this is,
the more abuse the circuit can take, but often at a higher cost, size and
capacitance.Since transient suppressors look like capacitors during normal
operation, you need to consider the same frequency related considerations as if
you had used a regular RC filter. The resistor is optional. Use one between 10
and a few hundred ohms for things like user switches. Leave the resistor off and
use low capacitance types for high frequency signals.

4.3 Rectifier

A rectifier is an electrical device that converts alternating current (AC),


which periodically reverses direction, to direct current (DC), which flows in
only one direction. The process is known as rectification. Physically, rectifiers
take a number of forms, including vacuum tube diodes, mercury-arc valves,
solid-state diodes, silicon-controlled rectifiers and other silicon-based
semiconductor switches. Historically, even synchronous electromechanical
switches and motors have been used. 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".
Rectifiers have many uses, but are often found serving as components of
DC power supplies and high-voltage direct current power transmission systems.
Rectification may serve in roles other than to generate direct current for use as a
source of power. As noted, detectors of radio signals serve as rectifiers. In gas
heating systems flame rectification is used to detect presence of flame.

The simple process of rectification produces a type of DC characterized


by pulsating voltages and currents (although still unidirectional). Depending
upon the type of end-use, this type of DC current may then be further modified
into the type of relatively constant voltage DC characteristically produced by
such sources as batteries and solar cells.

4.3.1 Rectifier devices

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 thyristors or other controlled switching solid-state switches which
effectively function as diodes to pass current in only one direction.

4.3.2 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. Half wave rectifiers
yield a unidirectional but pulsating direct current
Fig.No.4.3

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

4.3.3 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 (see
semiconductors and diode). Four diodes arranged this way are called a diode
bridge or bridge rectifier.
Fig.No.4.4

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.

Fig.No.4.5

4.3.4 Rectifier output smoothing

While half-wave and full-wave rectification suffice to deliver a form of


DC output, neither produces constant-voltage DC. In order to produce steady
DC from a rectified AC supply, a smoothing circuit or filter is required.[2] In its
simplest form this can be just a reservoir capacitor or smoothing capacitor,
placed at the DC output of the rectifier. There will still remain an amount of AC
ripple voltage where the voltage is not completely smoothed.
Fig.No.4.6

Sizing of the capacitor represents a tradeoff. For a given load, a larger


capacitor will reduce ripple but will cost more and will create higher peak
currents in the transformer secondary and in the supply feeding it. In extreme
cases where many rectifiers are loaded onto a power distribution circuit, it may
prove difficult for the AC supply to maintain a correctly shaped sinusoidal
voltage curve.

For a given tolerable ripple the required capacitor size is proportional to


the load current and inversely proportional to the supply frequency and the
number of output peaks of the rectifier per input cycle. The load current and the
supply frequency are generally outside the control of the designer of the rectifier
system but the number of peaks per input cycle can be affected by the choice of
rectifier design.

A half-wave rectifier will only give one peak per cycle and for this and
other reasons is only used in very small power supplies. A full wave rectifier
achieves two peaks per cycle and this is the best that can be done with single-
phase input. For three-phase inputs a three-phase bridge will give six peaks per
cycle and even higher numbers of peaks can be achieved by using transformer
networks placed before the rectifier to convert to a higher phase order.

To further reduce this ripple, a capacitor-input filter can be used. This


complements the reservoir capacitor with a choke (inductor) and a second filter
capacitor, so that a steadier DC output can be obtained across the terminals of
the filter capacitor. The choke presents a high impedance to the ripple current.

A more usual alternative to a filter, and essential if the DC load is very


demanding of a smooth supply voltage, is to follow the reservoir capacitor with
a voltage regulator. The reservoir capacitor needs to be large enough to prevent
the troughs of the ripple getting below the voltage the DC is being regulated to.
The regulator serves both to remove the last of the ripple and to deal with
variations in supply and load characteristics. It would be possible to use a
smaller reservoir capacitor (these can be large on high-current power supplies)
and then apply some filtering as well as the regulator, but this is not a common
strategy. The extreme of this approach is to dispense with the reservoir
capacitor altogether and put the rectified waveform straight into a choke-input
filter. The advantage of this circuit is that the current waveform is smoother and
consequently the rectifier no longer has to deal with the current as a large
current pulse, but instead the current delivery is spread over the entire cycle.
The downside is that the voltage output is much lower – approximately the
average of an AC half-cycle rather than the peak.
4.4 RS232

In telecommunications, RS-232 (Recommended Standard 232) is the traditional


name for a series of standards for serial binary single-ended data and control
signals connecting between a DTE (Data Terminal Equipment) and a DCE
(Data Circuit-terminating Equipment). It is commonly used in computer serial
ports. The standard defines the electrical characteristics and timing of signals,
the meaning of signals, and the physical size and pin out of connectors. The
current version of the standard is TIA-232-F Interface Between Data Terminal
Equipment and Data Circuit-Terminating Equipment Employing Serial Binary
Data Interchange, issued in 1997.

An RS-232 port was once a standard feature of a personal computer for


connections to modems, printers, mice, data storage, un-interruptible power
supplies, and other peripheral devices. However, the limited transmission speed,
relatively large voltage swing, and large standard connectors motivated
development of the universal serial bus which has displaced RS-232 from most
of its peripheral interface roles. Many modern personal computers have no RS-
232 ports and must use an external converter to connect to older peripherals.
Some RS-232 devices are still found especially in industrial machines or
scientific instruments.

Scope of the standard

The Electronic Industries Association (EIA) standard RS-232-C as of 1969


defines:
Electrical signal characteristics such as voltage levels, signaling rate, timing
and slew-rate of signals, voltage withstand level, short-circuit behavior, and
maximum load capacitance.

 Interface mechanical characteristics, pluggable connectors and pin


identification.
 Functions of each circuit in the interface connector.
 Standard subsets of interface circuits for selected telecom applications.

The standard does not define such elements as the character encoding or the
framing of characters, or error detection protocols. The standard does not define
bit rates for transmission, except that it says it is intended for bit rates lower
than 20,000 bits per second. Many modern devices support speeds of 115,200
bit/s and above. RS 232 makes no provision for power to peripheral devices.

Details of character format and transmission bit rate are controlled by the serial
port hardware, often a single integrated circuit called a UART that converts data
from parallel to asynchronous start-stop serial form. Details of voltage levels,
slew rate, and short-circuit behavior are typically controlled by a line driver that
converts from the UART's logic levels to RS-232 compatible signal levels, and
a receiver that converts from RS-232 compatible signal levels to the UART's
logic levels.

Limitations of the standard

Because the application of RS-232 has extended far beyond the original purpose
of interconnecting a terminal with a modem, successor standards have been
developed to address the limitations. Issues with the RS-232 standard include.
 The large voltage swings and requirement for positive and negative
supplies increases power consumption of the interface and complicates
power supply design. The voltage swing requirement also limits the upper
speed of a compatible interface.
 Single-ended signaling referred to a common signal ground limits the
noise immunity and transmission distance.
 Multi-drop connection among more than two devices is not defined.
While multi-drop "work-arounds" have been devised, they have
limitations in speed and compatibility.
 Asymmetrical definitions of the two ends of the link make the assignment
of the role of a newly developed device problematic; the designer must
decide on either a DTE-like or DCE-like interface and which connector
pin assignments to use.
 The handshaking and control lines of the interface are intended for the
setup and takedown of a dial-up communication circuit; in particular, the
use of handshake lines for flow control is not reliably implemented in
many devices.
 No method is specified for sending power to a device. While a small
amount of current can be extracted from the DTR and RTS lines, this is
only suitable for low power devices such as mice.
 The 25-way connector recommended in the standard is large compared to
current practice.
Role in modern personal computers

RS-232 has mostly been replaced in personal computers by USB for local
communications. Compared with RS-232, USB is faster, uses lower voltages,
and has connectors that are simpler to connect and use. However, USB is
limited by standard to no more than 5 meters of cable, thus favoring RS-232
when longer distances are needed. Both standards have software support in
popular operating systems. USB is designed to make it easy for device drivers
to communicate with hardware. However, there is no direct analog to the
terminal programs used to let users communicate directly with serial ports. USB
is more complex than the RS-232 standard because it includes a protocol for
transferring data to devices. This requires more software to support the protocol
used. RS-232 only standardizes the voltage of signals and the functions of the
physical interface pins. Serial ports of personal computers are also sometimes
used to directly control various hardware devices, such as relays or lamps, since
the control lines of the interface can be easily manipulated by software. This is
not feasible with USB, which requires some form of receiver to decode the
serial data.

As an alternative, USB docking ports are available which can provide


connectors for a keyboard, mouse, one or more serial ports, and one or more
parallel ports. Corresponding device drivers are required for each USB-
connected device to allow programs to access these USB-connected devices as
if they were the original directly connected peripherals. Devices that convert
USB to RS-232 may not work with all software on all personal computers and
may cause a reduction in bandwidth along with higher latency.

Personal computers may use a serial port to interface to devices such as


uninterruptible power supplies. In some cases, serial data is not exchanged, but
the control lines are used to signal conditions such as loss of power or low
battery alarms.

Many fields (for example, laboratory automation, surveying) provide a


continued demand for RS-232 I/O due to sustained use of very expensive but
aging equipment. It is often far cheaper to continue to use RS-232 than it is to
replace the equipment. Additionally, modern industrial automation equipment,
such as PLCs, VFDs, servo drives, and CNC equipment are programmable via
RS-232. Some manufacturers have responded to this demand: Toshiba re-
introduced the DE-9M connector on the Tecra laptop.

Serial ports with RS-232 are also commonly used to communicate to


headless systems such as servers, where no monitor or keyboard is installed,
during boot when operating system is not running yet and therefore no network
connection is possible. An RS-232 serial port can communicate to some
embedded systems such as routers as an alternative to network mode of
monitoring.

Standard details

In RS-232, user data is sent as a time-series of bits. Both synchronous and


asynchronous transmissions are supported by the standard. In addition to the
data circuits, the standard defines a number of control circuits used to manage
the connection between the DTE and DCE. Each data or control circuit only
operates in one direction, that is, signaling from a DTE to the attached DCE or
the reverse. Since transmit data and receive data are separate circuits, the
interface can operate in a full duplex manner, supporting concurrent data flow
in both directions. The standard does not define character framing within the
data stream, or character encoding.

Voltage Level
Fig.No.4.7

The RS-232 standard defines the voltage levels that correspond to logical
one and logical zero levels for the data transmission and the control signal lines.
Valid signals are plus or minus 3 to 15 volts; the ±3 V range near zero volts is
not a valid RS-232 level. The standard specifies a maximum open-circuit
voltage of 25 volts: signal levels of ±5 V, ±10 V, ±12 V, and ±15 V are all
commonly seen depending on the power supplies available within a device. RS-
232 drivers and receivers must be able to withstand indefinite short circuit to
ground or to any voltage level up to ±25 volts. The slew rate, or how fast the
signal changes between levels, is also controlled.

For data transmission lines (TxD, RxD and their secondary channel
equivalents) logic one is defined as a negative voltage, the signal condition is
called marking, and has the functional significance. Logic zero is positive and
the signal condition is termed spacing. Control signals are logically inverted
with respect to what one sees on the data transmission lines. When one of these
signals is active, the voltage on the line will be between +3 to +15 volts. The
inactive state for these signals is the opposite voltage condition, between −3 and
−15 volts. Examples of control lines include request to send (RTS), clear to
send (CTS), data terminal ready (DTR), and data set ready (DSR).

Because the voltage levels are higher than logic levels typically used by
integrated circuits, special intervening driver circuits are required to translate
logic levels. These also protect the device's internal circuitry from short circuits
or transients that may appear on the RS-232 interface, and provide sufficient
current to comply with the slew rate requirements for data transmission.

Because both ends of the RS-232 circuit depend on the ground pin being
zero volts, problems will occur when connecting machinery and computers
where the voltage between the ground pin on one end, and the ground pin on the
other is not zero. This may also cause a hazardous ground loop. Use of a
common ground limits RS-232 to applications with relatively short cables. If the
two devices are far enough apart or on separate power systems, the local ground
connections at either end of the cable will have differing voltages; this
difference will reduce the noise margin of the signals. Balanced, differential,
serial connections such as USB, RS-422 and RS-485 can tolerate larger ground
voltage differences because of the differential signaling

Unused interface signals terminated to ground will have an undefined


logic state. Where it is necessary to permanently set a control signal to a defined
state, it must be connected to a voltage source that asserts the logic 1 or logic 0
level. Some devices provide test voltages on their interface connectors for this
purpose.

Connectors
RS-232 devices may be classified as Data Terminal Equipment (DTE) or
Data Communication Equipment (DCE); this defines at each device which
wires will be sending and receiving each signal. The standard recommended but
did not make mandatory the D-subminiature 25 pin connector. In general and
according to the standard, terminals and computers have male connectors with
DTE pin functions, and modems have female connectors with DCE pin
functions. Other devices may have any combination of connector gender and
pin definitions. Many terminals were manufactured with female terminals but
were sold with a cable with male connectors at each end; the terminal with its
cable satisfied the recommendations in the standard.

Presence of a 25 pin D-sub connector does not necessarily indicate an


RS-232-C compliant interface. For example, on the original IBM PC, a male D-
sub was an RS-232-C DTE port (with a non-standard current loop interface on
reserved pins), but the female D-sub connector was used for a parallel
Centronics printer port. Some personal computers put non-standard voltages or
signals on some pins of their serial ports.

The standard specifies 20 different signal connections. Since most devices use
only a few signals, smaller connectors can often be used.
Fig.No.4.8
4.5 Transformer

A transformer is a device that transfers electrical energy from one circuit


to another through inductively coupled conductors—the transformer's coils. A
varying current in the first or primary winding creates a varying magnetic flux
in the transformer's core and thus a varying magnetic field through the
secondary winding. This varying magnetic field induces a varying electromotive
force (EMF), or "voltage", in the secondary winding. This effect is called
inductive coupling.

If a load is connected to the secondary, current will flow in the secondary


winding, and electrical energy will be transferred from the primary circuit
through the transformer to the load. In an ideal transformer, the induced voltage
in the secondary winding (Vs) is in proportion to the primary voltage (Vp) and
is given by the ratio of the number of turns in the secondary (Ns) to the number
of turns in the primary (Np) as follows:

By appropriate selection of the ratio of turns, a transformer thus enables an


alternating current (AC) voltage to be "stepped up" by making Ns greater than
Np, or "stepped down" by making Ns less than Np.
In the vast majority of transformers, the windings are coils wound around
a ferromagnetic core, air-core transformers being a notable exception.

Transformers range in size from a thumbnail-sized coupling transformer


hidden inside a stage microphone to huge units weighing hundreds of tons used
to interconnect portions of power grids. All operate on the same basic
principles, although the range of designs is wide. While new technologies have
eliminated the need for transformers in some electronic circuits, transformers
are still found in nearly all electronic devices designed for household ("mains")
voltage. Transformers are essential for high-voltage electric power transmission,
which makes long-distance transmission economically practical.

Basic principles
The transformer is based on two principles: first, that an electric current
can produce a magnetic field (electromagnetism) and second that a changing
magnetic field within a coil of wire induces a voltage across the ends of the coil
(electromagnetic induction). Changing the current in the primary coil changes
the magnetic flux that is developed. The changing magnetic flux induces a
voltage in the secondary coil.

Fig.No. 4.9
An ideal transformer is shown in the adjacent figure. Current passing through
the primary coil creates a magnetic field. The primary and secondary coils are
wrapped around a core of very high magnetic permeability, such as iron, so that
most of the magnetic flux passes through both the primary and secondary coils.
If a load is connected to the secondary winding, the load current and voltage
will be in the directions indicated, given the primary current and voltage in the
directions indicated (each will be alternating current in practice).

Induction law

The voltage induced across the secondary coil may be calculated from
Faraday's law of induction, which states that:
where Vs is the instantaneous voltage, Ns is the number of turns in the
secondary coil and Φ is the magnetic flux through one turn of the coil. If the
turns of the coil are oriented perpendicularly to the magnetic field lines, the flux
is the product of the magnetic flux density B and the area A through which it
cuts. The area is constant, being equal to the cross-sectional area of the
transformer core, whereas the magnetic field varies with time according to the
excitation of the primary. Since the same magnetic flux passes through both the
primary and secondary coils in an ideal transformer,[34] the instantaneous
voltage across the primary winding equals

Taking the ratio of the two equations for Vs and Vp gives the basic
equation[35] for stepping up or stepping down the voltage

Np/Ns is known as the turns ratio, and is the primary functional


characteristic of any transformer. In the case of step-up transformers, this may
sometimes be stated as the reciprocal, Ns/Np. Turns ratio is commonly
expressed as an irreducible fraction or ratio: for example, a transformer with
primary and secondary windings of, respectively, 100 and 150 turns is said to
have a turns ratio of 2:3 rather than 0.667 or 100:150.

Ideal power equation


If the secondary coil is attached to a load that allows current to flow,
electrical power is transmitted from the primary circuit to the secondary circuit.
Ideally, the transformer is perfectly efficient. All the incoming energy is
transformed from the primary circuit to the magnetic field and into the
secondary circuit. If this condition is met, the input electric power must equal
the output power:

giving the ideal transformer equation

This formula is a reasonable approximation for most commercial built


transformers today.
If the voltage is increased, then the current is decreased by the same
factor. The impedance in one circuit is transformed by the square of the turns
ratio.[34] For example, if an impedance Zs is attached across the terminals of
the secondary coil, it appears to the primary circuit to have an impedance of
(Np/Ns)2Zs. This relationship is reciprocal, so that the impedance Zp of the
primary circuit appears to the secondary to be (Ns/Np)2Zp.
CHAPTER 5

SENSORS

5.1.Liquid Crystal Display


The most commonly used Character based LCDs are based on Micro controller
or other. In this section, we will discuss about character based LCDs, their
interfacing with various microcontrollers, various interfaces (8-bit/4-bit),
programming, special stuff and tricks you can do with these simple looking
LCDs which can give a new look to your application.
PIN DESCRIPTION
The most commonly used LCDs found in the market today are 1 Line, 2 Line or
4 Line LCDs which have only 1 controller and support at most of 80 characters,
whereas LCDs supporting more than 80 characters make use of two
controllers.Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller
has 16 Pins (two pins are extra in both for back-light LED connections). Pin
description is shown in the table below.
Pin diagram

Pin No. Name Description


Pin no. 1 VSS Power supply (GND)
Pin no. 2 VCC Power supply (+5V)
Pin no. 3 VEE Contrast adjust
0 = Instruction input
Pin no. 4 RS
1 = Data input
0 = Write to LCD
module
Pin no. 5 R/W
1 = Read from LCD
module
Pin no. 6 EN Enable signal
Pin no. 7 D0 Data bus line 0 (LSB)
Pin no. 8 D1 Data bus line 1
Pin no. 9 D2 Data bus line 2
Pin no. 10 D3 Data bus line 3
Pin no. 11 D4 Data bus line 4
Pin no. 12 D5 Data bus line 5
Pin no. 13 D6 Data bus line 6
Pin no. 14 D7 Data bus line 7 (MSB)

DDRAM - DISPLAY DATA RAM


Display data RAM (DDRAM) stores display data represented in 8-bit character
codes. Its extended capacity is 80 X 8 bits, or 80 characters. The area in display
data RAM (DDRAM) that is not used for display can be used as general data
RAM. So whatever you send on the DDRAM is actually displayed on the LCD.
For LCDs like 1x16, only 16 characters are visible, so whatever you write after
16 chars is written in DDRAM but is not visible to the user.
CGROM - CHARACTER GENERATOR ROM
Now you might be thinking that when you send an ASCII value to DDRAM,
the answer is CGROM. The character generator ROM generates 5 x 8 dot or 5 x
10 dot character patterns from 8-bit character codes (see Figure 5 and Figure 6
for more details). It can generate 208 5 x 8 dot character patterns and 32 5 x 10
dot character patterns. User defined character patterns are also available by
mask-programmed ROM.
CGRAM - CHARACTER GENERATOR RAM
As clear from the name, CGRAM area is used to create custom characters in
LCD. In the character generator RAM, the user can rewrite character patterns by
program. For 5 x 8 dots, eight character patterns can be written, and for 5 x 10
dots, four character patterns can be written. Later in this section will explain
how to use CGRAM area to make custom character and also making animations
to give nice effects to your application.
BF - BUSY FLAG
Busy Flag is an status indicator flag for LCD. When we send a command or
data to the LCD for processing, this flag is set (i.e BF =1) and as soon as the
instruction is executed successfully this flag is cleared (BF = 0). This is helpful
in producing and exact amount of delay. For the LCD processing.To read Busy
Flag, the condition RS = 0 and R/W = 1 must be met and The MSB of the LCD
data bus (D7) act as busy flag. When BF = 1 means LCD is busy and will not
accept next command or data and BF = 0 means LCD is ready for the next
command or data to process.
Instruction register (IR) AND Data register (DR)
There are two 8-bit registers in controller Instruction and Data register.
Instruction register corresponds to the register where you send commands to
LCD e.g LCD shift command, LCD clear, LCD address etc. and Data register is
used for storing data which is to be displayed on LCD.

5.2 TILT SENSOR DESCRIPTION


A tilt sensor is an instrument that is used for measuring the tilt in multiple axes
of a reference plane. Tilt sensors measure the tilting position with reference to
gravity, and are used in numerous applications. It allows you to detect
orientation or inclination. They are small, inexpensive, low-power and easy-to-
use. Their simplicity makes them popular for toys, gadgets and appliances. They
are referred to as "mercury switches", "tilt switches" or "rolling ball sensors".
PRODUCT DESCRIPTION The tilt sensor is a component that can detect the
tilting of an object. However it is only the equivalent to a pushbutton activated
through a different physical mechanism. This type of sensor is the
environmental-friendly version of a mercury-switch. These sensors consist of a
rolling ball with a conductive plate beneath them. When the sensor gets power,
the rolling ball falls to the bottom of the sensor to form an electrical connection.
When the sensor is tilted, the rolling ball doesn’t fall to the bottom so that the
current cannot flow the two end terminals of the sensor. When the device gets
power and is in its upright position, then the rolling ball settle at the bottom of
the sensor to form an electrical connection between the two end terminals of the
sensor If the circuit gets tilted so that the rolling ball doesn’t settle at the bottom
of the sensor with the electrical conduction path, then the circuit becomes open

FEATURES
 Power supply: Up to 24V, switching less than 5mA
 Size: Cylindrical, 4mm (0.16") diameter & 12mm (0.45") long.
 Sensitivity range: > +-15 degrees Lifetime: 50,000+ cycles (switches)
APPLICATIONS
 To monitor the angle at which a mobile phone or tablet is held for the
auto-rotate function To detect the position of hand-held game systems
and in game controllers
 To monitor laser levels and seismic activity
 Measuring the "look angle" of a satellite antenna towards a satellite.
5.3 GAS SENSOR MQ-3
GENERAL DESCRIPTION In current technology scenario, monitoring of
gases produced is very important. From home appliances such as air
conditioners to electric chimneys and safety systems at industries monitoring of
gases is very crucial. Gas sensors spontaneously react to the gas present, thus
keeping the system updated about any alterations that occur in the concentration
of molecules at gaseous state. The gas sensor module consists of a steel
exoskeleton under which a sensing element is housed. This sensing element is
subjected to current through connecting leads. This current is known as heating
current through it, the gases coming close to the sensing element get ionized and
are absorbed by the sensing element. This changes the resistance of the sensing
element which alters the value of the current going out of it. The connecting
leads of the sensor are thick so that sensor can be connected firmly to the circuit
and sufficient amount of heat gets conducted to the inside part. They are casted
from copper and have tin plating over them.
PRODUCT DESCRIPTION MQ-3 gas sensor is designed with sensitive
material of Alcohol, which with lower conductivity in clean air. When the target
combustible gas exists, the sensor’s conductivity is higher. Signal conditioning
circuit is used to convert the change of conductivity to correspond output signal
with the input gas concentration. MQ-3 gas sensor has high sensitivity to
alcohol, Propane and other combustible steam, it is with low cost and suitable
for different application. The MQ-3 gas module is mounted on a pcb board
which has an operating voltage of 5VDC. The sensor output values can be get
by means of both analog and digital.
FEATURES
Analog and Digital output
 Good sensitivity to Alcohol in wide range
 Operation voltage: 5VDC
 Simple drive circuit
 Long life and low cost
APPLICATIONS
Domestic gas leakage detector
 Industrial Combustible gas detector
 Portable gas detector

5.3 TEMPERATURE SENSOR

GENERAL DESCRIPTION The LM35 series are precision integrated-circuit


temperature devices with an output voltage linearly-proportional to the
Centigrade temperature. The LM35 device has an advantage over linear
temperature sensors calibrated in Kelvin, as the user is not required to subtract a
large constant voltage from the output to obtain convenient Centigrade scaling.
The LM35 device does not require any external calibration or trimming to
provide typical accuracies of ±¼°C at room temperature and ±¾°C over a full
−55°C to 150°C temperature range. The low-output impedance, linear output,
and precise inherent calibration of the LM35 device makes interfacing to
readout or control circuitry especially easy.

PRODUCT ESCRIPTION LM35 is a precision IC temperature sensor with its


output proportional to the temperature (in oC). The sensor circuitry is sealed
and therefore it is not subjected to oxidation and other processes. With LM35,
temperature can be measured more accurately than with a thermistor. It also
possess low self heating and does not cause more than 0.1 oC temperature rise
in still air. The device is used with single power supplies, or with plus and
minus supplies. As the LM35 device draws only 60 µA from the supply, it has
very low self-heating of less than 0.1°C in still air. The LM35 device is rated to
operate over a −55°C to 150°C temperature range.

FEATURES

Calibrated Directly in Celsius (Centigrade)

 Linear + 10-mV/°C Scale Factor

 0.5°C Ensured Accuracy (at 25°C)

 Rated for Full −55°C to 150°C Range

 Suitable for Remote Applications

APPLICATIONS
Power Supplies

 Battery Management

 HVAC

 Appliances

RAIN DETECTOR

GENERAL DESSRIPTION This rain detector will give you a heads-up the
instant it starts to rain, hopefully giving you time to close windows and bring in
possessions. The batterypowered circuit draws virtually no current when the
sensor is dry and the current consumption is low when the buzzer is activated so
a couple of AA cells will last a long time. Alternately, a molded power supply
with a simple voltage regulator to drop the voltage to 3 volts could be used. The
circuit is basically a handy flasher circuit that operates well on only 3 volts
using ordinary silicon transistors. When the circuit is triggered, the buzzer is
pulsed about once per second for a very short time, giving it a "dripping water"
sound which seems appropriate.

PRODUCT DESCRIPTION Water is basic need in every one’s life. Saving


and proper usage of water is very important. Here is an easy method which will
give the alarm when there is rain, so that we can make some actions and save
the rain water. The rain detector is suitable for outdoor use. The sensing part of
the probe is an etched area which consists of three carbon electrodes separated
by a waterproof resin. The sensing area is smooth to allow water droplets to run
off more easily. A slower, longer beep may be had by increasing the 1 uF
capacitor. The 10 k resistor may be increased for a longer beep time without
decreasing the beep rate but at some point the circuit will cease to function
properly, depending on the gain of the transistors.
FEATURES Uses reliable electrolyte measurement principle. Detects both
rain and snow. Operating voltage: 5V DC. Output voltage: 5v Output:
Analog Adjustable sensitivity and switching behaviour

 APPLICATIONS Agriculture and horticulture monitoring and Automation.


Control of ventilation and skylights. Automatic operation of shutters and
awnings. Weather stations.

CHAPTER 6

SOFTWARE

6.1 CCS C Compiler Details

Intelligent and highly optimized CCS C compilers contain Standard C


operators and Built-in Function libraries that are specific to PIC registers,
providing developers with a powerful tool for accessing device hardware
features from the C language level. Standard C preprocessors, operators and
statements can be combined with hardware specific directives and CCS
provided built-in functions and example libraries to quickly develop
applications incorporating leading edge technologies such as capacitive touch,
wireless and wired communication, motion and motor control and energy
management.

Device Specific Optimization and Initialization

Device specific include files contain all the information the compiler needs to
optimize code generation for the specific PIC® MCU.

 Op-code length
 Memory size
 Pin functionality
 Memory banking
 Peripheral resources
 Hardware stack size

This detailed information enables the compiler to make intelligent decisions


regarding code optimization at the sub family and device level, generating
denser code than would be possible if the compiler treated all devices within a
Microchip PIC® family the same. Learn how an optimizing C compiler can
save you money.

The device specific include files also initialize device registers and
peripherals, relieving developers from the tedium of studying data sheets to
learn register map details, flag settings, etc.
The compiler can handle in-line or separate functions, as well as parameter
passing in re-usable registers. Transparent to the user, the compiler handles calls
across pages automatically and analyzes program structure and call tree
processes to optimize RAM and ROM Usage. Additional features include:

 Efficient function implementation allows call trees deeper than the


hardware stack.
 Automatic linking handles multiple code pages.
 Assembly code may be inserted anywhere in the source and may
reference C variables.
 Function Overloading allows for several functions with the same name,
but differences in number and type of parameters.
 Default Parameters can be used in a function if arguments are not used in
a call.
 The compiler generates all startup and clean up code for interrupt
functions as well as identifying the correct interrupt function to be called.
 Reference parameters may be used to improve code readability and in-
line function efficiency.
 Variable Number Of Parameters in a function.
 Relocatable Objects / Multiple Compilation Unit (IDE Only)
 Automatic #fuses Configuration
 Function recursion for PIC24 and dsPIC® DSC devices
Built-In Functions Provide Direct Access to PIC® MCU Hardware

The CCS compiler contains over 307 built-in functions that simplify access
to hardware while producing efficient and highly optimized code. Functions are
included for device hardware features such as:

 Timers & PWM modules


 A/D converters
 On-chip data EEPROM
 LCD controllers
 External memory busses
 And much more…
 Specify microcontroller clock speed with a PRAGMA, allowing built-in
functions to generate precision delays in microseconds or milliseconds
with DELAY_US() and DELAY_MS()
 Setup and read values from on-chip A/D converterswith SETUP_ADC()
and READ_ADC()
 Enhanced oscillator control for selection from multiple clock sources,
PLL and power saving options
 Set PWM duty cycle with SET_PWM_DUTY
 Drive the internal PIC® LCD controller with LCD_LOAD(),
LCD_SYMBOL()
 Maintain tri-state registers with INPUT() and OUTPUT_HIGH
 Use compiler directives to specify if tri-state registers are refreshed on
every I/O or if the I/O is as fast as possible
 Map registers to C variables with #BIT, #BYTE and #WORD
 Interface codec chips to dsPIC® DSCs with Data Converter Interface
(DCI) peripheral support for I2S and AC '97 16-bit and 20-bit protocols

6.2 Arithmetic Libraries Speed up Code Development

Why recreate the wheel coding your own arithmetic functions in assembly or
C? Standard C math libraries are supplied with the CCS compiler.

 1, 8, 16 and 32-bit integer types and 32-bit floating point are supported
for all devices
 48 and 64-bit integer types and 64-bit floating point for PIC24 and dsPIC
DSC devices
 The compiler also has the ability to represent decimal numbers using a
new data type, the fixed point decimal.
 Fixed point decimal gives you decimal representation, but at integer
speed. This gives you a phenomenal speed boost over using float.
 DSP in-line assembly is supported for your most performance critical
code.

Quickly Implement Industry Standard Protocols

Built-in functions, include files, interrupts, and code examples help you to
quickly "get on the bus". Serial buses such as I2C™ and SPI™, CAN, ECAN
and USB interfaces and RS232 communications protocols are fully supported
by the CCS compiler and development kits.

 Powerful built-in libraries for interface and communication such as #USE


SPI(), #USE I2C() and #USE RS232() make it easy to define multiple
I2C and RS232 ports
 Hardware transceiver used when possible, but for all other occasions the
compiler generates a software serial transceiver.
 Serial I/O functions allow standard functions such as GETC() and
PRINTF() to be used for RS-232 like I/O.
 #USE RS232() offers options to specify a maximum wait time for getc.

Optimized String Handling Delivers Up to 18% Code Size Reductions

String compression for 7-bit ASCII strings has been implemented for
Microchip's 14-bit opcode PIC12 and PIC16 families. Studies conducted by
CCS show that string functions that used to take 2,300 bytes of ROM to
implement now consume as little as 1,884, a savings of 18%

Strings can be used in switch statements, making it much easier developers


to perform string comparisons. Comparisons that can take many individual
string handling function calls to implement with other compilers can be handled
directly in the switch statement, resulting in tighter and more maintainable
source code and a smaller ROM footprint.

 Variable Length Constant Strings


 Formatted printf allows easy formatting and display in HEX or decimal.
 Efficient Bit Oriented Code
 Standard one bit type (Short Int) permits the compiler to generate very
efficient bit oriented code.
 Bit Arrays
 Efficient Data Structures Mapped into Program Memory
 Flexible constant data structure handling allows the compiler to handle
lookup tables that are virtually unlimited in size. This is of particular
interest to developers using large lookup tables for trigonometric
functions or storing FPGA configuration memory images in on-chip
MCU memory.
 Constants (including strings and arrays) are saved in program memory
 DSP performance can be enhanced by manually assigning variables to
data spaces for faster access with preprocessor directives

6.3 Extensive Source Code Driver Library

CCS provides an extensive source code library of drivers to aid in driver


development for your target hardware.
 Source code drivers included for LCD modules, keypads, 24xx and 94xx
serial EEPROM, X10, DS1302 and NJU6355 real time clocks, Dallas
touch memory devices, DS2223 and PCF8570, LTC1298 and PCF8591
A/D converters, temperature sensors, digital pots, I/O expander and much
more.
 133 ready-to-run programs included

Microchip Enhanced Mid-Range core architecture support

The CCS code optimizing C compiler supports up to 56K instructions and


4K RAM for these new 14-bit opcode devices. The Enhanced Mid-Range core's
16-level hardware stack is supported by the compiler's 16-level call stack,
reducing the number of inlined system functions that must be coded. Built-in
system functions are provided for all of the enhanced peripherals including A/D
converters and comparators, SPI and I2C serial buses, PWM, mTouch™. non-
volatile memory, op-amp and LCD drive.

External Memory Support

The compiler contains features to simplify using external memory chips.

 Addressmod Capability To Create User Defined Address Spaces In


Memory Device
 Generation Of Multiple HEX Files For Chips With External Memory
Multiple Compilation Units

IDE includes support for separately compiling source code files and then
linking them together for the final build. The PCW IDE has tools to easily
define the units, figure out what units need to recompiled on a build and
automatically calling the linker.
Fig.No.6.1

C Aware Editor

PCW includes a full-featured C aware Windows editor. The editor has color
syntax highlighting, tab control, bookmarks, context sensitive help and searches
for matching } or ). The IDE allows easy access to the call tree, symbol map
and other helpful screens. It also includes a direct interface to device
programmers and debuggers.
Fig.No.6.2

New Project Wizard

New Project Wizard generates an initial .H and .C file for your project based on
some standard forms that you fill out. Some forms include helpful information
such as: interactively calculating and showing the timer options for you based
on your clocks, allocating pins for device drivers and setting up pin names.
Fig.No.6.3

Project Navigation by File

A navigation bar shows all project related files. This allows for quickly opening
or compiling a file from the navigation bar. The navigation bar can even be used
to track non-C files associated with the project such as project documentation
files.
Fig.No.6.4

Project Navigation by Identifier

Another navigation bar shows all project functions and identifiers. Double click
on an identifier to move the editor cursor to the location where the identifier is
declared.
Fig.No.6.5

Special Viewers

Special viewers include quick and easy access to data sheets, valid fuses and
interrupts for devices, a hex file disassembler, COD file interpreter and an
advanced source/list file compare. Shown to the right is just the file/compare.
Fig.No.6.6

C-Metrics Calculator

The compiler evaluates the code cyclomatic and computational complexity


using the McCable and Halstead Complexity measures. The derived
Maintainability Index gives a good insight into the structural and textual
complexity of the source code.
Fig.No.6.7

Special Function Register Reference

The PCW IDE allows the viewing of all SFR's for a given part and has the
ability to generate custom .h files with the register and bit definitions for
specific functions.
Fig.No.6.8

Automatic Documentation Generator

The compiler recognizes comments that have specially marked tags as


containing information that should be exported for program documentation. The
compiler associated comments with variables and functions plus the compiler
accumulates information on its own about functions, variables and types. The
new documentation generator uses a user generated template in .RTF format
and merges in the project information from the source files and generates a
.RTF output file as source code documentation.
Fig.No.6.9

Ability to Generate Customized Include

Files with SFR Definitions

Automatically generate a custom include file according to the device parameters


you need.
Fig.No.6.10
Device Selector

The device selector makes it easy to find parts with the right number of pins,
memory and other criteria. Grids can be sorted by any column or easily printed.
Individual rows can selected to find more details on the part and to check
distributor price and availability.

Fig.No.6.11

Das könnte Ihnen auch gefallen