Sie sind auf Seite 1von 69

Low Power Wireless Sensor Network

For Building Monitoring


Abstract
Analysis of the stability of the building is a needed measurement
process for all buildings in the cities. Periodic monitoring of the structure for
such damage is therefore a key step in rationally planning the maintenance
needed to guarantee an adequate level of safety and serviceability. However,
in order for the installation of a permanently installed sensing system in
buildings to be economically viable, the sensor modules must be wireless to
reduce installation costs, must operate with a low power consumption to
reduce servicing costs of replacing batteries, and use low cost sensors that
can be mass produced such as MEMS sensors.

Existing System
There is no proper system for measuring the stability of the buildings hence we go for the
proposed system.

Scope of the project:


This project is designed to sense the shaking of the building using MEMS accelerometer and
send the data to PC. PC monitors the stability of the building.

Proposed System
In this project we have MEMS accelerometer to sense the shaking of the building which
in sends to the microcontroller which in turn sends to the monitoring section through Zigbee
wireless technology. Here we have three sections, the two floor sections has PIC microcontroller,
Zigbee device and MEMS accelerometer. The monitoring section has PC and a Zigbee wireless
device, which will collect the data from the floor sections and analyze the stability of the
building.

Block Diagram
Floor 1:
2.4GHZ

MEMS Accelerometer
PIC
Micro
Controller
LCD

Floor 2:
2.4GHZ

MEMS Accelerometer
PIC
Micro
Controller

LCD

Monitoring Section:

2.4GHZ

PC with .Net

No. of Units:
1. Power supply unit
The supply of 5V DC given to the system, which is converted from 230V AC supply.
Firstly, the step down transformer used here is for converting the 230V AC into 12V AC. The
microcontroller will support only the DC supply, so the AC supply is converted to DC using the
bridge rectifier. The output of the rectifier will have ripples so we are using the 2200uf capacitor
for filtering those ripples. The output from the filter is given to the 7805 voltage regulator, which
will convert the 12V DC into 5V DC. The output from the regulator will be filtered using the
1000uf capacitor, so the pure 5V DC is getting as the output from the power supply unit.

2. Microcontroller Unit
2. PIC 16F877A Microcontroller:
The PIC16F877A CMOS FLASH-based 8-bit microcontroller is upward compatible with
the PIC16C5x, PIC12Cxxx and PIC16C7x devices. It features 200 ns instruction execution, 256
bytes of EEPROM data memory, self programming, an ICD, 2 Comparators, 8 channels of 10-bit

Analog-to-Digital (A/D) converter, 2 capture/compare/PWM functions, a synchronous serial port


that can be configured as either 3-wire SPI or 2-wire I2C bus, a USART, and a Parallel Slave
Port. This microcontroller module monitors the vibration of the building and send through the
ZigBee module.

3. Communication Unit

ZIGBEE module
Node 1 and Node 2 Zigbee transmit the vibration parameters. Monitoring section receives

that parameter and monitor through the PC.


MEMS Accelerometer
Micro electromechanical systems (MEMS) measure vibration and moments in the
building.

4. Display Unit
LCD
A liquid crystal display (LCD) is a flat panel display, electronic visual display, or video
display that uses the light modulating properties of liquid crystals (LCs). LCDs do not emit
light directly. Here the LCD is used to display the condition of the Building.

PC
PC is used to monitor the building status and intimate the status to the human.

5. Software Unit
Software is used to compile the coding of the desired application for the corresponding
embedded system.

MPLAB IDE:
MPLAB IDE (Integrated Development Environment) is used for editing, compiling codes
as well as simulating them using an inbuilt simulator.
MPLAB X Integrated Development Environment brings many changes to the PIC
microcontroller development tool chain. Unlike previous versions of MPLAB which were
developed completely in-house, MPLAB X is based on the open source Net Beans IDE from
Oracle. Taking this path has allowed us to add many frequently requested features very quickly

and easily while also providing us with a much more extensible architecture to bring you even
more new features in the future.
Given

Input and Expected output:

Power Supply Unit:


In the power supply unit the 230V AC is converted into 5V DC.

Given Input:
230V AC supply is given as the input to the power supply unit.

Expected Output:
The 5V DC supply is getting as the output from the power supply unit.

Microcontroller Unit
PIC 16F877A Microcontroller:
Given input
The floor 1 and floor 2 MEMS is the input of the microcontroller.

Expected output
Zigbee device transmit information to the control unit.

Display unit
LCD:
Given input
The microcontroller gives input to the LCD module.

Expected output

The details of the floor status are displayed in LCD.

Communication unit
Zigbee:
Given input
ZigBee device receive information from the floor 1 and floor 2.

Expected output
Zigbee device transmit information from the PIC to the control section.

PC:
Given input
Zigbee is given as input to the PC to monitor the data.

Expected output
The control signal is given to the microcontroller via Zigbee.

Block Diagram Description:


Power Supply for 8051 Microcontroller
This section describes how to generate +5V DC power supply

The power supply section is the important one. It should deliver constant output regulated
power supply for successful working of the project. A 0-12V/1 mA transformer is used for this
purpose. The primary of this transformer is connected in to main supply through on/off switch&
fuse for protecting from overload and short circuit protection. The secondary is connected to the
diodes to convert 12V AC to 12V DC voltage. And filtered by the capacitors, which is further
regulated to +5v, by using IC 7805.

PIC Microcontroller:

Analog Applications:
10-bit, up to 8-channel Analog-to-Digital Converter (A/D), Brown-out Reset (BOR), Analog Comparator
module with, Two analog comparators

Programmable on-chip voltage reference (VREF) module,

Programmable input multiplexing from device inputs and internal voltage reference, Comparator outputs
are externally accessible

High-Performance RISC CPU:


Only 35 single-word instructions to learn, 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, Pinout compatible to other 28-pin or 40/44-pin PIC16CXXX and
PIC16FXXX microcontrollers

Peripheral Details:
Timer0: 8-bit timer/counter with 8-bit prescaler, Timer1: 16-bit timer/counter with prescaler, can be
incremented during Sleep via external crystal/clock, Timer2: 8-bit timer/counter with 8-bit period register,
prescaler and postscaler, 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 Synchronous Serial Port
(SSP) with SPI (Master mode) and I2C (Master/Slave), Universal Synchronous Asynchronous Receiver
Transmitter (USART/SCI) with 9-bit address detection, Parallel Slave Port (PSP) 8 bits wide with
external RD, WR and CS controls (40/44-pin only), Brown-out detection circuitry for Brown-out Reset
(BOR).

Special Microcontroller Applications:


100,000 erase/write cycle Enhanced Flash program memory typical, 1,000,000 erase/write cycle Data
EEPROM memory typical, Data EEPROM Retention > 40 years, Self-reprogrammable under software
control, In-Circuit Serial Programming via two pins, Single-supply 5V In-Circuit Serial Programming
Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation Programmable code
protection, Power saving Sleep mode, Selectable oscillator options, In-Circuit Debug (ICD) via two pins.

CMOS Technology:
Low-power, high-speed Flash/EEPROM technology, Fully static design, Wide operating voltage range
(2.0V to 5.5V), Commercial and Industrial temperature ranges, Low-power consumption.

Power Supply for PIC 16F877A Microcontroller


This section describes how to generate +5V DC power supply

The power supply section is the important one. It should deliver constant
output regulated power supply for successful working of the project. A 0-12V/1 mA
transformer is used for this purpose.
The primary of this transformer is connected in to main supply through on/of
switch& fuse for protecting from overload and short circuit protection. The
secondary is connected to the diodes to convert 12V AC to 12V DC voltage. And
filtered by the capacitors , Which is further regulated to +5v, by using IC 7805.

INTRODUCTION OF PIC16F877A:
The PIC16F877A CMOS FLASH-based 8-bit microcontroller is upward compatible with
the PIC16C5x, PIC12Cxxx and PIC16C7x devices. It features 200 ns instruction
execution, 256 bytes of EEPROM data memory, self programming, an ICD, 2

Comparators, 8 channels of 10-bit Analog-to-Digital (A/D) converter, 2


capture/compare/PWM functions, a synchronous serial port that can be configured
as either 3-wire SPI or 2-wire I2C bus, a USART, and a Parallel Slave Port.

Microchip PIC16F877A Microcontroller


Features:
High-Performance RISC CPU

Operating speed: 20 MHz, 200 ns instruction cycle

Operating voltage: 4.0-5.5V

Industrial temperature range (-40 to +85C)

15 Interrupt Sources

35 single-word instructions

All single-cycle instructions except for program branches (two-cycle)

Special Microcontroller Features

Flash Memory: 14.3 Kbytes (8192 words)

Data SRAM: 368 bytes

Data EEPROM: 256 bytes

Self-reprogrammable under software control

In-Circuit Serial Programming via two pins (5V)

Watchdog Timer with on-chip RC oscillator

Programmable code protection

Power-saving Sleep mode

Selectable oscillator options

In-Circuit Debug via two pins

Peripheral Features

33 I/O pins; 5 I/O ports

Timer0: 8-bit timer/counter with 8-bit prescaler

Timer1: 16-bit timer/counter with prescaler


o

Can be incremented during Sleep via external crystal/clock

Timer2: 8-bit timer/counter with 8-bit period register, prescaler and


postscaler

Two Capture, Compare, PWM modules

16-bit Capture input; max resolution 12.5 ns

16-bit Compare; max resolution 200 ns

10-bit PWM

Synchronous Serial Port with two modes:


o

SPI Master

I2C Master and Slave

USART/SCI with 9-bit address detection

Parallel Slave Port (PSP)


o

8 bits wide with external RD, WR and CS controls

Brown-out detection circuitry for Brown-Out Reset

Analog Features

10-bit, 8-channel A/D Converter

Brown-Out Reset

Analog Comparator module


o

2 analog comparators

Programmable on-chip voltage reference module

Programmable input multiplexing from device inputs and internal VREF

Pin

Comparator outputs are externally accessible


diagram:

Memory of the PIC16F877 divided into 3 types of memories:

Program Memory - A memory that contains the program(which we had


written), after we've burned it. As a reminder, Program Counter executes
commands stored in the program memory, one after the other.

Data Memory This is RAM memory type, which contains a special registers
like SFR (Special Faction Register) and GPR (General Purpose Register). The
variables that we store in the Data Memory during the program are deleted
after we turn of the micro.
These two memories have separated data buses, which makes the access to
each one of them very easy.

Data EEPROM (Electrically Erasable Programmable Read-Only


Memory) - A memory that allows storing the variables as a result of burning
the written program.

Each one of them has a diferent role. Program Memory and Data Memory two
memories that are needed to build a program, and Data EEPROM is used to save

data after the microcontroller is turn of.


Program Memory and Data EEPROM they are non-volatile memories, which store the
information even after the power is turn of. These memories called Flash Or
EEPROM. In contrast, Data Memory does not save the information because it needs
power in order to maintain the information stored in the chip.

PIC16F87XA Program Memory


The PIC16F87XA devices have a 13-bit program counter capable of addressing an
8K word x 14 bit program memory space. This memory is used to store the program
after we burn it to the microcontroller. The PIC16F876A/877A devices have 8K words
x 14 bits of Flash program memory that can be electrically erased and
reprogrammed. Each time we burn program into the micro, we erase an old
program and write a new one.

PIC16F876A/877A program memory map and stack

Program Counter (PC) keeps track of the program execution by holding the address
of the current instruction. It is automatically incremented to the next instruction
during the current instruction execution.
The PIC16F87XA family has an 8-level deep x 13-bit wide hardware stack. The stack
space is not part of either program or data space and the stack pointer is not
readable or writable. In the PIC microcontrollers, this is a special block of RAM
memory used only for this purpose.
The CALL instruction is used to jump to a subroutine, which must be terminated with
the RETURN instruction. CALL has the address of the first instruction in the
subroutine as its operand. When the CALL instruction is executed, the destination
address is copied to the PC. The PC is PUSHed onto the stack when a CALL
instruction is executed, or an interrupt causes a branch. The stack is POPed in the
event of a RETURN, RETLW or a RETFIE instruction execution.
The stack operates as a circular bufer. This means that after the stack has been
PUSHed eight times, the ninth push overwrites the value that was stored from the
first push. The tenth push overwrites the second push (and so on).
Each time the main program execution starts at address 0000 - Reset Vector. The
address 0004 is reserved for the interrupt service routine (ISR).
If we plan to use an interrupt, our program will begin after the Interrupt Vector; and
if not we can start to write from the beginning of the Reset Vector.
Some of the memory is divided into the pages that are designed for write/burn the
program into them; the remaining memory (Stack, Interrupt Vector, and Reset
Vector) is hardware registers.
Attention!
Program Memory is divided into the pages, where the program is stored. Data
Memory is divided into the banks. The banks are located inside the RAM, where the
special registers and the data located.

PIC16F87XA Data Memory Organization


The data memory is partitioned into multiple banks which contain the General
Purpose Registers and the Special Function Registers. Number of banks may vary
depending on the microcontroller; for example, micro PIC16F84 has only two banks.

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. While program is being executed, it is working with the particular
bank. The default bank is BANK0.
To access a register that is located in another bank, one should access it inside the program.
There are special registers which can be accessed from any bank, such as STATUS register.

PIC16F876A/877A register file map


In order to start programming and build automated system, there is no need to study all the
registers of the memory map, but only a few most important ones:

STATUS register changes/moves from/between the banks

PORT registers assigns logic values (0/1) to the ports

TRIS registers - data direction register (input/output)

You can learn about other registers at a later stage or as needed.


STATUS register

In most cases, this register is used to switch between the banks (Register Bank Select), but also
has other capabilities.

PIC STATUS register


With the help of three left bits (IRP, RP1, and RP0) one can control the transition between the
banks:

IRP - Register Bank Select bit, used for indirect addressing method.

RP1:RP0: - Register Bank Select bits, used for direct addressing method.

To distinguish between the two methods, at this point, the will use the definition of fundamental
concepts. Later on, the two methods will be studied in detail.
When the IRP Equal to 0, the program will work with banks 0, 1.
When the IRP Equal to 1, the program will work with banks 2, 3.
The following table demonstrates, which of the Banks the program is working with, based on the
selection of the RP0 and RP1 bits:
RP1:RP0

BANK

00

01

10

11

An example of using STATUS register and Register Bank Select bit:


1. bsf STATUS, 5 ; Change to Bank 1
2. clrf TRISB ; Set PORTB as output

3. bcf STATUS, 5 ; Change to Bank 0

In the first line, we are in changing/setting the 5th bit, RP0, in the STATUS register to 1, and
thus, base on the table we are switching/selecting Bank 1. After PortB was set as output in the
second line, we switched back to Bank 0 by in changing/setting the 5th bit, RP0, in the STATUS
register to 0, in the third line.
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
An example of using STATUS register and Carry/borrow bit:
1. Movlw 200
2. Addwf 100, 0

In this example, we are assigning value of 200 to the W (working) register. Then, we are adding
the value of 100 and the W register together. The result is stored in W register and should be 300
(200+100).
However, the maximum value is 256, resulting in carry out. The C (bit 0) of the STATUS register
becomes 1 (C = 1). Register W will contain the reminder: 44.
DC: Digit carry/borrow bit (ADDWF, ADDLW,SUBLW,SUBWF instructions) (for borrow,
the polarity is reversed)
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
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
The bits 3 and 4 are used with WDT - Watchdog Timer.
PD: Power-down bit
1 = After power-up or by the CLRWDT instruction
0 = By execution of the SLEEP instruction
TO: Time-out bit
1 = After power-up, CLRWDT instruction or SLEEP instruction
0 = A WDT time-out occurred
PORT register

The role of the PORT register is to receive the information from an external source (e.g. sensor)
or to send information to the external elements (e.g. LCD). The 28-pin devices have 3 I/O ports,
while the 40/44-pin devices, like PIC16F877, have 5 I/O ports located in the BANK 0.
1. PORTA is a 6-bit wide, bidirectional port. The corresponding data direction
register is TRISA.
Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input.
Clearing a TRISA bit (= 0) will make the corresponding PORTA pin an output.
2. PORTB is an 8-bit wide, bidirectional port. The corresponding data direction
register is TRISB.
Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input.
Clearing a TRISB bit (= 0) will make the corresponding PORTB pin an output.
3. PORTC is an 8-bit wide, bidirectional port. The corresponding data direction
register is TRISC.
Setting a TRISC bit (= 1) will make the corresponding PORTC pin an input.
Clearing a TRISC bit (= 0) will make the corresponding PORTC pin an output.
4. PORTD is an 8-bit port with Schmitt Trigger input bufers. Each pin is
individually configurable as an input or output.
5. 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 bufers.

Pin diagram of PIC16F877A


We can control each port by using an assigned address of specific port, but there is much easier
way to control the port. We are allowed to use the names of the ports without considering their
addresses.
For example:
# define SWITCH PORTA, 0
We define a variable named SWITCH, which received a value of bit number 0 of the PORTA.
Usually we define the ports at the beginning of the program, and then we use only the given
names.

TRIS register

The TRIS register is data direction register which defines if the specific bit or whole port will be
an input or an output. Each PORT has its own TRIS register. Here's a map of the locations:

BANK0

BANK1

PORTA

TRISA

PORTB

TRISB

PORTC

TRISC

PORTD

TRISD

PORTE

TRISE

The default mode of each TRIS is input. If you want to set a specific port as exit you must
change the state of the TRIS to 0.
Keep in mind: to change a specific port to an output, one should first move to the BANK1, make
the change, and then return to BANK0. The default state of the banks is BANK0.
The running program is working only with one bank at all time. If not set otherwise, then as
stated, the default bank is BANK0. Part of the registers located inside BANK0, and some are not.
When we need to access a register that is not located inside BANK0, we are required to switch
between the banks.
For example, the access to PORT registers is done inside BANK0. However, to change port from
an input to an output and vice versa, we need to access TRIS register that is located inside
BANK1. From the moment we moved to the BANK1, the program will always work with
BANK1; at this time, to access registers inside BANK0, we will have to return to the situation in
which our program will work with BANK0.
Direct and Indirect addressing

Direct Addressing: Using this method we are accessing the registers directly by detecting
location inside Data Memory from Opcode and by selecting the bank using bits RP1 and RP0 of
the STATUS register.
Indirect Addressing: To implement indirect addressing, a File Select Register (FSR) and indirect
register (INDF) are used. In addition, when using this method we choose bank using bit IRP of
the STATUS register. Indirect addressing treated like a stack pointer, allowing much more
efficient work with a number of variables. INDF register is not an actual register (it is a virtual
register that is not found in any bank).
Dont be confused! There is SFR (Special Function Register) - special registers of RAM, and
there is FSR (File Select Register).

The following figure shows the two addressing methods:

Pin diagram of PIC16F877A


To the left you can see the direct addressing method, where the bank selection is made by RP bits
and the referencing is made directly from memory Opcode by using the variable name.
To the right you can see the indirect addressing method, where the bank selection is made by IRP
bit and accessing the variable by pointer FSR.

Lets explore the differences between the 2 methods:


We want to assign number 5 to the variable TEMP located at address 0X030. In the first row of
each example, we will define the variable TEMP at the address 0X030.
Example of direct addressing:
1. TEMP Equ 0x030
2. Movlw 5
3. Movwf TEMP

It's easy to understand, that direct addressing method means working directly with the variables.
In the second line we put the number 5 into the working register W, and in the line 3, the content
of the W passes to the TEMP variable.

Example of indirect addressing:


1. TEMP Equ 0x030
2. Movlw 0x030
3. Movwf FSR
4. Movlw 5
5. Movwf INDF

In the second line, we put a value into the W register. In the third line, the value passes to the
FSR register, and from this moment FSR points to the address of the TEMP variable. In the
fourth line, the number 5 passes to the W register, and in the fifth line, we move the contents of
W register (which is 5) to the INDF. In fact INDF performs the following: it takes the number 5
and puts it in the address indicated by FSR register.

PIC16F87XA Data EEPROM


The data EEPROM and Flash program memory is readable and writable during normal operation
(over the full VDD range). This memory is not directly mapped in the register file space. Instead,
it is indirectly addressed through the Special Function Registers.
There are six SFRs used to read and write to this memory:
1. EECON1
2. EECON2
3. EEDATA
4. EEDATH
5. EEADR
6. EEADRH

When interfacing to the data memory block, EEDATA holds the 8-bit data for read/write and
EEADR holds the address of the EEPROM location being accessed. These devices have 128 or
256 bytes of data EEPROM (depending on the device), with an address range from 00h to FFh.
On devices with 128 bytes, addresses from 80h to FFh are unimplemented.
A few important points about Data EEPROM memory:

It lets you save data DURING programming

The data is saved during the burning process

You can read the data memory during the programming and use it

The use is made possible with the help of SFR

At this point there is no need to learn how to use this memory with special registers, because
there are functions (writing and reading) that are ready.

Write to DATA EEPROM

To write to an EEPROM data location, the user must first write the address to the EEADR
register and the data to the EEDATA register. Then the user must follow a specific write
sequence to initiate the write for each byte.
BSF STATUS, RP1 ;
BSF STATUS, RP0 ; Bank 3
BTFSC EECON1, WR ;Wait for write
GOTO $-1 ;to complete
BCF STATUS, RP0 ;Bank 2
MOVF DATA_EE_ADDR, W ;Data Memory
MOVWF EEADR ;Address to write
MOVF DATA_EE_DATA, W ;Data Memory Value
MOVWF EEDATA ;to write
BSF STATUS, RP0 ;Bank 3
BCF EECON1, EEPGD ;Point to DATA memory
BSF EECON1, WREN ;Enable writes
BCF INTCON, GIE ;Disable INTs.
MOVLW 55h ;
MOVWF EECON2 ;Write 55h
MOVLW AAh ;
MOVWF EECON2 ;Write AAh
BSF EECON1, WR ;Set WR bit to begin write

BSF INTCON, GIE ;Enable INTs


BCF EECON1, WREN ;Disable writes

Read DATA EEPROM


To read a data memory location, the user must write the address to the EEADR
register, clear the EEPGD control bit (EECON1<7>) and then set control bit RD
(EECON1<0>). The data is available in the very next cycle in the EEDATA register;
therefore, it can be read in the next instruction. EEDATA will hold this value until
another read or until it is written to by the user (during a write operation).
BSF STATUS, RP1 ;
BCF STATUS, RP0 ; Bank 2
MOVF DATA_EE_ADDR, W ; Data Memory
MOVWF EEADR ; Address to read
BSF STATUS, RP0 ; Bank 3
BCF EECON1, EEPGD ; Point to Data memory
BSF EECON1, RD ; EE Read
BCF STATUS, RP0 ; Bank 2
MOVF EEDATA, W ; W = EEDATA
Both of these functions are provided by the manufacturer. There is a required
sequence in order to write/read to/from the memory; that process can be performed
independently, but it is better to use ready functions of Microchip.

PIC Timer0:
Many times, we plan and build systems that perform various processes that depend
on time.
Simple example of this process is the digital wristwatch. The role of this electronic
system is to display time in a very precise manner and change the display every
second (for seconds), every minute (for minutes) and so on.
To perform the steps we've listed, the system must use a timer, which needs to be
very accurate in order to take necessary actions. The clock is actually a core of any
electronic system.
In this PIC timer module tutorial we will study the existing PIC timer modules. The
microcontroller PIC16F877 has 3 diferent timers:

PIC Timer0

PIC Timer1

PIC Timer2

We can use these timers for various important purposes. So far we used delay
procedure to implement some delay in the program, that was counting up to a
specific value, before the program could be continued. "Delay procedure" had two
disadvantages:

we could not say exactly how long the Delay procedure was in progress

we could not perform any further steps while the program executes the
"delay procedure"

Now, using Timers we can build a very precise time delays which will be based on
the system clock and allow us to achieve our desired time delay well-known in
advance.
In order for us to know how to work with these timers, we need to learn some things
about each one of them. We will study each one separately.

PIC Timer0
The Timer0 module timer/counter has the following features:

8-bit timer/counter

Readable and writable

8-bit software programmable prescaler

Internal (4 Mhz) or external clock select

Interrupt on overflow from FFh to 00h

Edge select (rising or falling) for external clock

Lets explain the features of PIC Timer0 we have listed above:


Timer0 has a register called TMR0 Register, which is 8 bits of size.
We can write the desired value into the register which will be increment as the

program progresses. Frequency varies depending on the Prescaler. Maximum value


that can be assigned to this register is 255.
TMR0IF - TMR0 Overflow Interrupt Flag bit.
The TMR0 interrupt is generated when the TMR0 register overflows from FFh to 00h.
This overflow sets bit TMR0IF (INTCON<2>). You can initialize the value of this
register to what ever you want (not necessarily "0").
We can read the value of the register TMR0 and write into. We can reset its value at
any given moment (write) or we can check if there is a certain numeric value that
we need (read).
Prescaler - Frequency divider.

1:2

1:4

1:8

1:16

1:32

1:64

1:128

1:256

The structure of the OPTION_REG register


We perform all the necessary settings with OPTION_REG Register. The size of the
register is 8 bits.

Initializing the OPTION_REG register


The following is an example how we can initialize the OPTION_REG:
1. PSA=0; // Prescaler is assigned to the Timer0 module

2. PS0=1; // Prescaler rate bits


3. PS1=1; // are set to 111
4. PS2=1; // which means divide by 256
5. TOSE=0; // rising edge
6. TOCS=0; // Internal instruction cycle clock

Block diagram of the PIC Timer0 / WDT prescaler

PIC TIMER0 block diagram

Calculating Count, Fout, and TMR0 values


If using INTERNAL crystal as clock, the division is performed as follow:

PIC TIMER0 formula for internal clock

Fout Output frequency after the division.


Tout The Cycle Time after the division.
4 - The division of the original clock (4 MHz) by 4, when using internal crystal as
clock (and not external oscillator).
Count - A numeric value to be placed to obtain the desired output frequency - Fout.
(256 - TMR0) - The number of times in the timer will count based on the register
TMR0.

An example of INTERNAL crystal as clock


Suppose we want to create a delay of 0.5 second in our program using Timer0.
What is the value of Count?
Calculation:
First, lets assume that the frequency division by the Prescaler will be 1:256.
Second, lets set TMR0=0. Thus:

Formula to calculate Cout using Timer0


If using EXTERNAL clock source (oscillator), the division is performed as follow:

PIC TIMER0 formula for external clock


In this case there is no division by 4 of the original clock. We use the external
frequency as it is.

An example of EXTERNAL clock source (oscillator):

What is the output frequency - Fout, when the external oscillator is 100kHz and Count=8?
Calculation:
First, lets assume that the frequency division by the Prescaler will be 1:256. Second, lets set
TMR0=0. Thus:

Formula to calculate Fout for Timer0

PIC Timer1:
The Timer1 module, timer/counter, has the following features:

16-bit timer/counter consisting of two 8-bit registers (TMR1H and TMR1L)

readable and writable

8-bit software programmable prescaler

Internal (4 Mhz) or external clock select

Interrupt on overflow from FFFFh to 0000h

Lets explain the features of PIC Timer1 we have listed above:


Timer1 has a register called TMR1 register, which is 16 bits of size.
Actually, the TMR1 consists of two 8-bits registers:

TMR1H

TMR1L

It increments from 0000h to the maximum value of 0xFFFFh (or 0 b1111 1111 1111
1111 or 65,535 decimal). 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>).


You can initialize the value of this register to what ever you want (not necessarily
"0").
TMR1IF TMR1 overflow Interrupt Flag bit.

This flag marks the end of ONE cycle count. The flag need to be reset in the
software if you want to do another cycle count. We can read the value of the
register TMR1 and write into. We can reset its value at any given moment (write) or
we can check if there is a certain numeric value that we need (read).
Prescaler Frequency divider.
We can use Prescaler for further division of the system clock. The size of the register
is 2-bit only, so you can make four diferent division. The options are:

1:1

1:2

1:4

1:8

You can choose whether to use an internal system clock (crystal) or external
oscillator that can be connected to a pin RC0.

The structure of the T1CON register


We perform all the necessary settings with T1CON register. As we can see, the size
of the register is 8 bits. Lets explore the relevant bits:

Initializing the T1CON register


The following is an example how we can initialize the T1CON register:

1. TMR1ON=1; // the timer is enable


2. TMR1CS=0; // internal clock source
3. T1CKPS0=0; // Prescaler value set to 00
4. T1CKPS1=0; // which means 1:1 (no division)
Or you can set all the T1CON register at once as follows:
T1CON=0b00000001;

Block diagram of the PIC Timer1

PIC TIMER1 block diagram

Calculating Count, Fout, and Timer1 values

If using INTERNAL crystal as clock, the division is performed as follow:

PIC TIMER1 formula for internal clock


Fout The output frequency after the division.
Tout The Cycle Time after the division.
4 - The division of the original clock (4 MHz) by 4, when using internal crystal as clock (and not

external oscillator).
Count - A numeric value to be placed to obtain the desired output frequency - Fout.
(256 - TMR1) - The number of times in the timer will count based on the register TMR0.
If using EXTERNAL clock source (oscillator), the division is performed as follow:

PIC TIMER1 formula for external clock


Simple example and calculation of how to use TIMER1:

Suppose we want to create a delay of 2 second in the our program using Timer1. What is the
value of Count?
Calculation:
First, lets assume that the frequency division by the Prescaler will be 1:1. Second, lets set
TMR1=0, which means the TMR1 will count 65,536 times. Thus:

Formula to calculate Cout for Timer1

PIC Timer2:
The Timer2 module has the following features:
two 8-bit registers (TMR2 and PR2)
readable and writable
prescaler and a postscaler
connected only to an internal clock - 4 MHz crystal
Interrupt on overflow
Lets explain the features we have listed above:

Timer2 has 2 count registers: TMR2 and PR2. The size of each registers is 8-bit in
which we can write numbers from 0 to 255. The TMR2 register is readable and
writable and is cleared on any device Reset. PR2 is a readable and writable register
and initialized to FFh upon Reset.
Register TMR2 is used to store the initial count value (the value from which it
begins to count). Register PR2 is used to store the ending count value (the
maximum value we need/want to reach). ie: using Timer2 we can determine the
started count value, the final count value, and the count will be between these two
values. The Timer2 increments from 00h until it matches PR2 and then resets to 00h
on the next increment cycle.
Prescaler and Postscaler - Timer2 is an 8-bit timer with a prescaler and a
postscaler. Each allows to make additional division of the frequency clock source.
Prescaler divides the frequency clock source BEFORE the counting take place at the
register TMR2, thus the counting inside the TMR2 register is performed based on the
divided frequency clock source by the Prescaler
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>)).
Postscaler divides the frequency that comes out of the Comparator again for the
last time.
TIMER2 Prescaler and Postscaler

TMR2IF - TMR2 to PR2 Match Interrupt Flag bit.


Comparator Compares the value of the register TMR2 and the maximum value of

the register PR2.


TMR2 The register in which the initial count value is written.
PR2 The register in which the final or the maximum count value is written.
We perform all the necessary settings with T2CON Register The structure of the
T2CON register:

As we can see, the size of the register is 8 bits. Lets explore the relevant bits:
T2CKPS1:T2CKPS0: Timer2 Clock Prescale Select bits
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>).

00 = Prescaler is 1
01 = Prescaler is 4
1x = Prescaler is 16

TMR2ON: Timer2 On bit


Timer2 can be shut-of by clearing control bit, TMR2ON (T2CON<2>), to minimize
power consumption.
1 = Timer2 is on
0 = Timer2 is of

TOUTPS3:TOUTPS0: Timer2 Output Postscale Select bits


The match output of TMR2 goes through a 4-bit postscaler (which gives a 1:1 to
1:16 scaling inclusive selected by control bits TOUTPS3:TOUTPS0 (T2CON<6:3>).
0000
0001
0010
1111

=
=
=
=

1:1 postscale
1:2 postscale
1:3 postscale
1:16 postscale

The following is an example how we can initialize the T2CON register:


1. TMR2ON=1; // the timer is enable
2. T2CKPS0=0; // Prescaler 1:1
3. T2CKPS1=0;
4. TOUTPS0=1; // Postscaler 1:16
5. TOUTPS0=1;
6. TOUTPS0=1;
7. TOUTPS0=1;

Or you can set all the T2CON register at once as follows:


T2CON=0b01111100;

TIMER2 BLOCK DIAGRAM

How to calculate the required values of the TIMER2:

Fout The output frequency after the division.


Tout The Cycle Time after the division.
4 - The division of the original clock (4 MHz) by 4, when using internal crystal as
clock (and not external oscillator).
Count - A numeric value to be placed to obtain the desired output frequency - fout.
(PR2 TMR2) - The number of times the counter will count.
Simple example and calculation of how to use TIMER2:
Suppose we want to create a delay of 1 second in the our program using Timer2.
What is the value of Count?
Calculation:
First, lets assume that the frequency division by the Prescaler will be 1:1 and
Postscaler will be 1:16. Second, lets set TMR1=0 and PR2=255. Thus:

Introduction to Serial communication with PIC16F877


microcontroller
In this tutorial we will study the communication component USART (Universal
Synchronous Asynchronous Receiver Transmitter) located within the PIC. It is a
universal communication component (Synchronous/Asynchronous), which can be
used as transmitter or as receiver. We will look at:

serial and parallel communications

synchronous and asynchronous communications

how to enable serial communication - TXSTA and RCSTA registers

An example of 8-bit transmission

An example of 9-bit transmission

how to calculate the value being placed in the SPBRG register

USART Transmit and Receive block diagrams

Max323 Driver/Receiver

the implementation of the PIC serial communication (C program and a video)

We will show how to set USART in order to allow communication between PIC to PIC
or between PIC to a personal computer. We will start with the definition of media
concepts. There are two options to diferentiate when speaking about transmission
of information on the transmission lines:

serial communication

parallel communication

In order to understand what serial communication is, and emphasize the diference
between serial communication and parallel communication, lets take a look at the
following example:
We have a multi-bit word, and we want to transmit it from one computer to the
second computer.
Using the serial communication:
When using the serial communication we transmit the multi-bit word bit after bit
(when at any given moment only one bit will pass).

Transmitting the word 10011101 using serial communication.


Using the parallel communication:
When using the parallel communication, however, the number of bits will be transmitted at once
from one computer to the second computer.

Transmitting the word 10011101 using parallel communication.


In addition to the serial and parallel communications, there are 2 types of
communication we will explore:

Synchronous communication

Asynchronous communication

Synchronous communication

When using the synchronous communication the information is transmitted from


the transmitter to the receiver:

in sequence

bit after bit

with fixed baud rate

and the clock frequency is transmitted along with the bits

That means that the transmitter and the receiver are synchronized between them
by the same clock frequency. The clock frequency can be transmitted along with the
information, while it is encoded in the information itself, or in many cases there is
an additional wire for the clock.
This type of communication is faster compare to the asynchronous communication
since it is "constantly transmitting the information, with no stops.
Asynchronous communication

When using the asynchronous communication - the transmitter and the receiver refraining to
transmit long sequences of bits because there isn't a full synchronization between the transmitter,
that sends the data, and the receiver, that receives the data.
In this case, the information is divided into frames, in the size of byte. Each one of
the frame has:

Start bit marks the beginning of a new frame.

Stop bit marks the end of the frame.

Frames of information must not necessarily be transmitted at equal time space,


since they are independent of the clock.

Enabling Serial Communication


To communicate with external components such as computers or microcontrollers,
the PIC micro uses a component called USART - Universal Synchronous
Asynchronous Receiver Transmitter. This component can be configured as:

a Full-Duplex asynchronous system that can communicate with peripheral


devices, such as CRT terminals and personal computers

a Half-Duplex synchronous system that can communicate with peripheral


devices, such as A/D or D/A integrated circuits, serial EEPROMs, etc.

To enable the serial communication with PIC micro we must set diferent parameters
within two registers: (click the links for the explanation of each bit)
1. TXSTA - Transmit Status and Control Register

2. RCSTA - Receive Status and Control Register

Display unit
Liquid crystal displays:

The LCD standard requires 3 control lines and 8 I/O lines for the data bus.
8 data pins D7:D0
Bi-directional data/command pins.
Alphanumeric characters are sent in ASCII format.

RS: Register Select


RS = 0 -> Command Register is selected
RS = 1 -> Data Register is selected

R/W: Read or Write


0 -> Write, 1 -> Read

E: Enable (Latch data)


Used to latch the data present on the data pins.
A high-to-low edge is needed to latch the data.

The 8 data lines are connected to PORT 1 of 8051 microcontroller. The three control
lines( RS,RW and EN ) are connected to PORT 3.5,3.6 and 3.7 respectively.

ZIGBEE
ZigBee is a wireless technology developed as an open global standard to address the
unique needs of low-cost, low-power, wireless sensor networks. The standard takes full
advantage of the IEEE 802.15.4 physical radio specification and operates in unlicensed bands
worldwide at the following frequencies: 2.4002.484 GHz, 902-928 MHz and 868.0868.6 MHz
1. The power levels (down from 5v to 3.3v) to power the Zigbee module.
2. The communication lines (TX, RX, DIN and DOUT) to the appropriate voltages.

The Zigbee module acts as both transmitter and receiver. The Rx and Tx pins of ZIGBEE are
connected to Tx and Rx of 8051 microcontroller respectively. The datas from microcontroller is
serially transmitted to Zigbee module via UART port. Then Zigbee transmits the data to another
Zigbee. The datas from Zigbee transmitted from Dout pin. The Zigbee from other side receives
the data via Din pin.

ZigBee module. The 1 coin, shown for size reference, is


about 23 mm in diameter.ZigBee is a specification for a
suite of high level communication protocols using small,

low-power digital radios based on the IEEE 802.15.4-2003


standard for wireless personal area networks (WPANs),
such as wireless headphones connecting with cell phones
via short-range radio. The technology defined by the
ZigBee specification is intended to be simpler and less
expensive than other WPANs, such as Bluetooth. ZigBee
is targeted at radio-frequency (RF) applications that
require a low data rate, long battery life, and secure
networking.
TheZigBeePlatform

Application Profile

ZigBee Stack

IEEE 802.15.4

Compliant
Platform

Overview
ZigBee is a low-cost, low-power, wireless mesh networking proprietary
standard. The low cost allows the technology to be widely deployed in
wireless control and monitoring applications, the low power-usage
allows longer life with smaller batteries, and the mesh networking
provides high reliability and larger range.
The ZigBee Alliance, the standards body that defines ZigBee, also
publishes application profiles that allow multiple OEM vendors to create
interoperable products. The current list of application profiles either
published or in the works are:
Home Automation
ZigBee Smart Energy
Commercial Building Automation
Telecommunication Applications
Personal, Home, and Hospital Care
Toys
The relationship between IEEE 802.15.4 and ZigBee is similar to that
between IEEE 802.11 and the Wi-Fi Alliance. The ZigBee 1.0
specification was ratified on 14 December 2004 and is available to
members of the ZigBee Alliance. Most recently, the ZigBee 2007
specification was posted on 30 October 2007. The first ZigBee
Application Profile, Home Automation, was announced 2 November
2007.

ZigBee operates in the industrial, scientific and medical (ISM) radio


bands; 868 MHz in Europe, 915 MHz in the USA and Australia, and
2.4 GHz in most jurisdictions worldwide. The technology is intended to
be simpler and less expensive than other WPANs such as Bluetooth.
ZigBee chip vendors typically sell integrated radios and microcontrollers
with between 60K and 128K flash memory, such as the Jennic JN5148,
the Freescale MC13213, the Ember EM250 and the Texas Instruments
CC2430. Radios are also available stand-alone to be used with any
processor or microcontroller. Generally, the chip vendors also offer the
ZigBee software stack, although independent ones are also available.
Because Zigbee can activate (go from sleep to active mode) in 15 msec
or less, the latency can be very low and devices can be very
responsive particularly compared to Bluetooth wake-up delays, which
are typically around three seconds. Because Zigbees can sleep most of
the time, average power consumption can be very low, resulting in long
battery life.
The first stack release is now called Zigbee 2004. The second stack
release is called Zigbee 2006, and mainly replaces the MSG/KVP
structure used in 2004 with a "cluster library". The 2004 stack is now
more or less obsolete.
Zigbee 2007, now the current stack release, contains two stack profiles,
stack profile 1 (simply called ZigBee), for home and light commercial
use, and stack profile 2 (called ZigBee Pro). ZigBee Pro offers more
features, such as multi-casting, many-to-one routing and high security
with Symmetric-Key Key Exchange (SKKE), while ZigBee (stack
profile 1) offers a smaller footprint in RAM and flash. Both offer full
mesh networking and work with all ZigBee application profiles.

ZigBee 2007 is fully backward compatible with ZigBee 2006 devices: A


ZigBee 2007 device may join and operate on a ZigBee 2006 network
and vice versa. Due to differences in routing options, ZigBee Pro
devices must become non-routing ZigBee End-Devices (ZEDs) on a
ZigBee 2006 or ZigBee 2007 network, the same as ZigBee 2006 or
ZigBee 2007 devices must become ZEDs on a ZigBee Pro network. The
applications running on those devices work the same, regardless of the
stack profile beneath them.
ZigBee/IEEE 802.15.4 - General Characteristics:
Dual PHY (2.4GHz and 868/915 MHz)
Data rates of 250 kbps (@2.4 GHz), 40 kbps (@ 915
MHz), and 20 kbps (@868 MHz)
Optimized for low duty-cycle applications (<0.1%)
CSMA-CA channel access Yields high throughput and
low latency for low duty cycle devices like sensors
and controls
Low power (battery life multi-month to years)
Multiple topologies: star, peer-to-peer, mesh
Addressing space of up to:
- 18,450,000,000,000,000,000 devices (64 bit IEEE
address)
- 65,535 networks
Optional guaranteed time slot for applications
requiring low latency

Fully hand-shaked protocol for transfer reliability


Range: 50m typical (5-500m based on environment)

ZigBee/IEEE802.15.4 - Typical Traffic Types Addressed


Periodic data
Application defined rate (e.g., sensors)
Intermittent data
Application/external stimulus defined rate (e.g., light
switch)
Repetitive low latency data

ARCHITECTURE:
Though WPAN implies a reach of only a few meters, 30
feet in the case of ZigBee, the network will have several
layers, so designed as to enable intrapersonal
communication within the network, connection to a
network of higher level and ultimately an uplink to the
Web.

The ZigBee Standard has evolved standardized sets of


solutions, called layers'. These layers facilitate the
features that make ZigBee very attractive: low cost, easy
implementation, reliable data transfer, short-range
operations, very low power consumption and adequate
security features.
1. Network and Application Support layer :
The network layer permits growth of network sans high
power transmitters. This layer can handle huge numbers
of nodes. This level in the ZigBee architecture includes
the ZigBee Device Object (ZDO), user-defined application
profile(s) and the Application Support (APS) sub-layer.
The APS sub-layer's responsibilities include maintenance
of tables that enable matching between two devices and
communication among them, and also discovery, the
aspect that identifies other devices that operate in the
operating space of any device.
The responsibility of determining the nature of the device
(Coordinator / FFD or RFD) in the network, commencing
and replying to binding requests and ensuring a secure
relationship between devices rests with the ZDO (Zigbee
Define Object). The user-defined application refers to the
end device that conforms to the ZigBee Standard.

2. Physical (PHY) layer :

The IEEE802.15.4 PHY physical layer accommodates high


levels of integration by using direct sequence to permit
simplicity in the analog circuitry and enable cheaper
implementations.
3. Media access control (MAC) layer :
The IEEE802.15.4 MAC media access control layer permits
use of several topologies without introducing complexity
and is meant to work with large numbers of devices.

DEVICE TYPES
There are three diferent ZigBee device types that
operate on these layers in any self-organizing application
network.
These devices have 64-bit IEEE addresses, with option to
enable shorter addresses to reduce packet size, and work
in either of two addressing modes star and peer-to-peer.

1. The ZigBee coordinator node : There is one, and


only one, ZigBee coordinator in each network to act as
the router to other networks, and can be likened to the
root of a (network) tree. It is designed to store
information about the network.
2. The full function device FFD : The FFD is an
intermediary router transmitting data from other devices.
It needs lesser memory than the ZigBee coordinator
node, and entails lesser manufacturing costs. It can
operate in all topologies and can act as a coordinator.
3. The reduced function device RFD : This device is
just capable of talking in the network; it cannot relay data
from other devices. Requiring even less memory, (no
flash, very little ROM and RAM), an RFD will thus be
cheaper than an FFD. This device talks only to a network
coordinator and can be implemented very simply in star
topology.
TRAFFIC TYPES
ZigBee/IEEE 802.15.4 addresses three typical traffic
types. IEEE 802.15.4 MAC can accommodate all the
types.
1. Data is periodic. The application dictates the rate, and
the sensor activates, checks for data and deactivates.
2. Data is intermittent. The application, or other stimulus,
determines the rate, as in the case of say smoke
detectors. The device needs to connect to the network

only when communication is necessitated. This type


enables optimum saving on energy.
3. Data is repetitive, and the rate is fixed a priori.
Depending on allotted time slots, called GTS (guaranteed
time slot), devices operate for fixed durations.
ZigBee employs either of two modes, beacon or non-beacon to enable
the to-and-fro data traffic. Beacon mode is used when the coordinator
runs on batteries and thus offers maximum power savings, whereas the
non-beacon mode finds favour when the coordinator is mains-powered.
In the beacon mode, a device watches out for the coordinator's beacon
that gets transmitted at periodically, locks on and looks for messages
addressed to it. If message transmission is complete, the coordinator
dictates a schedule for the next beacon so that the device goes to sleep';
in fact, the coordinator itself switches to sleep mode.
While using the beacon mode, all the devices in a mesh network know
when to communicate with each other. In this mode, necessarily, the
timing circuits have to be quite accurate, or wake up sooner to be sure
not to miss the beacon. This in turn means an increase in power
consumption by the coordinator's receiver, entailing an optimal increase
in costs.

Figure 1: Beacon Network Communication [ZigBee: 'Wireless Control


That Simply Works']
The non-beacon mode will be included in a system where devices are
asleep' nearly always, as in smoke detectors and burglar alarms. The
devices wake up and confirm their continued presence in the network at
random intervals.
On detection of activity, the sensors spring to attention', as it were, and
transmit to the ever-waiting coordinator's receiver (since it is mainspowered). However, there is the remotest of chances that a sensor finds
the channel busy, in which case the receiver unfortunately would miss a
call'.

Figure 2: Non-Beacon Network Communication [ZigBee: 'Wireless


Control That Simply Works']

TECHNOLOGY COMPARISONS
The Why ZigBee question has always had an implied, but never quite
worded follower phrase when there is Bluetooth. A comparative
study of the two can be found in ZigBee: 'Wireless Control That Simply
Works' .
The bandwidth of Bluetooth is 1 Mbps, ZigBee's is one-fourth of this
value. The strength of Bluetooth lies in its ability to allow
interoperability and replacement of cables, ZigBee's, of course, is low
costs and long battery life.
In terms of protocol stack size, ZigBee's 32 KB is about one-third of the
stack size necessary in other wireless technologies (for limited capability
end devices, the stack size is as low as 4 KB).
Most important in any meaningful comparison are the
diverse application areas of all the diferent wireless
technologies. Bluetooth is meant for such target areas as
wireless USB's, handsets and headsets, whereas ZigBee is
meant to cater to the sensors and remote controls market
and other battery operated products.
In a gist, it may be said that they are neither
complementary standards nor competitors, but just
essential standards for diferent targeted applications.
The earlier Bluetooth targets interfaces between PDA and
other device (mobile phone / printer etc) and cordless
audio applications.

The IEEE 802.15.4based ZigBee is designed for remote


controls and sensors, which are very many in number, but
need only small data packets and, mainly, extremely low
power consumption for (long) life. Therefore they are
naturally diferent in their approach to their respective
application arenas.

ZIGBEE CHARACTERISTICS
The focus of network applications under the IEEE 802.15.4 / ZigBee
standard include the features of low power consumption, needed for only
two major modes (Tx/Rx or Sleep), high density of nodes per network,
low costs and simple implementation.
These features are enabled by the following characteristics:
2.4GHz and 868/915 MHz dual PHY modes. This represents three
license-free bands: 2.4-2.4835 GHz, 868-870 MHz and 902-928 MHz.
The number of channels allotted to each frequency band is fixed at
sixteen (numbered 11-26), one (numbered 0) and ten (numbered 1-10)
respectively. The higher frequency band is applicable worldwide, and
the lower band in the areas of North America, Europe, Australia and
New Zealand .
Low power consumption, with battery life ranging from months to
years. Considering the number of devices with remotes in use at present,
it is easy to see that more numbers of batteries need to be provisioned
every so often, entailing regular (as well as timely), recurring
expenditure. In the ZigBee standard, longer battery life is achievable by

either of two means: continuous network connection and slow but sure
battery drain, or intermittent connection and even slower battery drain.
Maximum data rates allowed for each of these frequency bands are
fixed as 250 kbps @2.4 GHz, 40 kbps @ 915 MHz, and 20 kbps @868
MHz.
High throughput and low latency for low duty-cycle applications
(<0.1%)
Channel access using Carrier Sense Multiple Access with Collision
Avoidance (CSMA - CA)
Addressing space of up to 64 bit IEEE address devices, 65,535
networks
50m typical range
Fully reliable hand-shaked data transfer protocol.
Different topologies as illustrated below: star, peer-to-peer, mesh

Figure 2: ZigBee Topologies

Licensing
For non-commercial purposes, the ZigBee specification is available free
to the general public. An entry level membership in the ZigBee Alliance,
called Adopter, provides access to the as-yet unpublished specifications
and permission to create products for market using the specifications.
The click through license on the ZigBee specification requires a
commercial developer to join the ZigBee Alliance. "No part of this
specification may be used in development of a product for sale without
becoming a member of ZigBee Alliance." The annual fee conflicts with
the GNU General Public License. From the GPL v2, "b) You must cause
any work that you distribute or publish, that in whole or in part contains
or is derived from the Program or any part thereof, to be licensed as a
whole at no charge to all third parties under the terms of this License."
Since the GPL makes no distinction between commercial and noncommercial use it is impossible to implement a GPL licensed ZigBee
stack or combine a ZigBee implementation with GPL licensed code. The
requirement for the developer to join the ZigBee Alliance similarly
conflicts with most other Free software licenses.
Uses
ZigBee protocols are intended for use in embedded applications
requiring low data rates and low power consumption. ZigBee's current
focus is to define a general-purpose, inexpensive, self-organizing mesh
network that can be used for industrial control, embedded sensing,
medical data collection, smoke and intruder warning, building
automation, home automation, etc. The resulting network will use very

small amounts of power individual devices must have a battery life of


at least two years to pass ZigBee certification.
Typical application areas include
Home Entertainment and Control Smart
lighting, advanced temperature control, safety and
security, movies and music
Home Awareness Water sensors, power sensors,
smoke and fire detectors, smart appliances and
access sensors
Mobile Services m-payment, m-monitoring and
control, m-security and access control, m-healthcare
and tele-assist
Commercial Building Energy monitoring, HVAC,
lighting, access control
Industrial Plant Process control, asset
management, environmental management, energy
management, industrial device control
Device types
There are three different types of ZigBee devices:
ZigBee coordinator (ZC): The most capable device,
the coordinator forms the root of the network tree
and might bridge to other networks. There is exactly
one ZigBee coordinator in each network since it is
the device that started the network originally. It is
able to store information about the network,
including acting as the Trust Centre & repository for
security keys.

ZigBee Router (ZR): As well as running an application


function, a router can act as an intermediate router,
passing on data from other devices.
ZigBee End Device (ZED): Contains just enough
functionality to talk to the parent node (either the
coordinator or a router); it cannot relay data from
other devices. This relationship allows the node to be
asleep a significant amount of the time thereby
giving long battery life. A ZED requires the least
amount of memory, and therefore can be less
expensive to manufacture than a ZR or ZC.
Protocols
The protocols build on recent algorithmic research (Ad-hoc On-demand
Distance Vector, neuRFon) to automatically construct a low-speed adhoc network of nodes. In most large network instances, the network will
be a cluster of clusters. It can also form a mesh or a single cluster. The
current profiles derived from the ZigBee protocols support beacon and
non-beacon enabled networks.
In non-beacon-enabled networks (those whose beacon order is 15), an
unslotted CSMA/CA channel access mechanism is used. In this type of
network, ZigBee Routers typically have their receivers continuously
active, requiring a more robust power supply. However, this allows for
heterogeneous networks in which some devices receive continuously,
while others only transmit when an external stimulus is detected. The
typical example of a heterogeneous network is a wireless light switch:
The ZigBee node at the lamp may receive constantly, since it is
connected to the mains supply, while a battery-powered light switch
would remain asleep until the switch is thrown. The switch then wakes
up, sends a command to the lamp, receives an acknowledgment, and

returns to sleep. In such a network the lamp node will be at least a


ZigBee Router, if not the ZigBee Coordinator; the switch node is
typically a ZigBee End Device.
In beacon-enabled networks, the special network nodes called ZigBee
Routers transmit periodic beacons to confirm their presence to other
network nodes. Nodes may sleep between beacons, thus lowering their
duty cycle and extending their battery life. Beacon intervals may range
from 15.36 milliseconds to 15.36 ms * 214 = 251.65824 seconds at 250
kbit/s, from 24 milliseconds to 24 ms * 214 = 393.216 seconds at 40
kbit/s and from 48 milliseconds to 48 ms * 214 = 786.432 seconds at 20
kbit/s. However, low duty cycle operation with long beacon intervals
requires precise timing, which can conflict with the need for low product
cost.
In general, the ZigBee protocols minimize the time the radio is on so as
to reduce power use. In beaconing networks, nodes only need to be
active while a beacon is being transmitted. In non-beacon-enabled
networks, power consumption is decidedly asymmetrical: some devices
are always active, while others spend most of their time sleeping.
ZigBee devices are required to conform to the IEEE 802.15.4-2003
Low-Rate Wireless Personal Area Network (WPAN) standard. The
standard specifies the lower protocol layersthe physical layer (PHY),
and the media access control (MAC) portion of the data link layer
(DLL). This standard specifies operation in the unlicensed 2.4 GHz
(worldwide), 915 MHz (Americas) and 868 MHz (Europe) ISM bands.
In the 2.4 GHz band there are 16 ZigBee channels, with each channel
requiring 5 MHz of bandwidth. The center frequency for each channel
can be calculated as, FC = (2405 + 5 * (ch - 11)) MHz, where ch = 11,
12, ..., 26.

The radios use direct-sequence spread spectrum coding, which is


managed by the digital stream into the modulator. BPSK is used in the
868 and 915 MHz bands, and orthogonal QPSK that transmits two bits
per symbol is used in the 2.4 GHz band. The raw, over-the-air data rate
is 250 kbit/s per channel in the 2.4 GHz band, 40 kbit/s per channel in
the 915 MHz band, and 20 kbit/s in the 868 MHz band. Transmission
range is between 10 and 75 meters (33 and 246 feet) and up to 1500
meters for zigbee pro, although it is heavily dependent on the particular
environment. The maximum output power of the radios is generally 0
dBm (1 mW).
The basic channel access mode is "carrier sense, multiple
access/collision avoidance" (CSMA/CA). That is, the nodes talk in the
same way that people converse; they briefly check to see that no one is
talking before they start. There are three notable exceptions to the use of
CSMA. Beacons are sent on a fixed timing schedule, and do not use
CSMA. Message acknowledgments also do not use CSMA. Finally,
devices in Beacon Oriented networks that have low latency real-time
requirements may also use Guaranteed Time Slots (GTS), which by
definition do not use CSMA.
ZigBee RF4CE
On March 3, 2009 the RF4CE (Radio Frequency for Consumer
Electronics) Consortium agreed to work with the ZigBee Alliance to
jointly deliver a standardized specification for radio frequency-based
remote controls. ZigBee RF4CE is designed to be deployed in a wide
range of remotely-controlled audio/visual consumer electronics
products, such as TVs and set-top boxes. It promises many advantages
over existing remote control solutions, including richer communication

and increased reliability, enhanced features and flexibility,


interoperability, and no line-of-sight barrier.

MEMS Accelerometers
Micro electromechanical systems (MEMS) is a technology of miniaturization that
has been largely adopted from the integrated circuit (IC) industry and applied to the
miniaturization of all systems not only electrical systems but also mechanical, optical, fluid,
magnetic, etc.
Micro Electromechanical systems or MEMS, represent an extraordinary technology that
promises to transform whole industries and drive the next technological revolution. These
devices can replace bulky actuators and sensors with micron-scale equivalent that can be
produced in large quantities by fabrication processes used in integrated circuits photolithography.
This reduces cost, bulk, weight and power consumption while increasing performance,
production volume, and functionality by orders of magnitude. For example, one well known
MEMS device is the accelerometer (its now being manufactured using mems low cost, small
size, more reliability). Furthermore, it is clear that current MEMS products are simply precursors
to greater and more pervasive applications to come, including genetic and disease testing,
guidance and navigation systems, power generation, RF devices( especially for cell phone
technology), weapon systems, biological and chemical agent detection, and data storage. Micro
mirror based optical switches have already proven their value; several start-up companies
specializing in their development have already been sold to large network companies for
hundreds of millions of dollars. The promise of MEMS is increasingly capturing the attention of
new and old industries alike, as more and more of their challenges are solved with MEMS.

Inertial sensors:

Inertial sensors are mechanics sensors aiming at measuring accelerations, in the


mechanics science definition. There are two categories of inertial sensors. They are,
accelerometers which measures variation of rotational speed and gyroscopes which measures
variation of rotational speed.

Accelerometers:

Schematic of micro accelerometer, ADXL series, produced by Analog Device.

On these diagrams, we can see a micro accelerometer device and the chip
including associated electronics, made by Analog Device. This is a two axis micro accelerometer.
This means it is able to measure accelerations in two directions at a time (in the directions of the
plane).
Micro accelerometers were the first MEMS device to flood the market. Micro
accelerometers measure variation of translational speed. So acceleration, deceleration, even very
high deceleration, likeshock! The sensor that detects a shock and launches the airbag is a
micro accelerometer combined with a electronic circuit able to decide whether or not the shock
was an accident or just your car passing a pothole. There are lots of applications, like navigation,
micro accelerometers can help in increasing precision. There are more and more to say about
micro accelerometers, they are still the spearhead of MEMS industry.

Gyroscopes:
Micro gyroscopes are newer in the market compared to micro accelero meters.
Some devices have appeared on the market for navigation application. The key point in these
devices is sensitivity.

MAX 232:

Max 232

The MAX232 is a dual driver/receiver that includes a capacitive voltage


generator to supply RS 232 voltage levels from a single 5v supply. Each receiver
converts RS-232 to 5v TTL/CMOS levels. Each driver converts TLL/CMOS input levels
into EIA-232 levels. The P3_0 (RX) and P3_1 (TX) pin of controller is connected to the
max 232 driver and the TX and RX pin of max 232 is connected to the GSM modem
or PC.

In this circuit the microcontroller transmitter pin is connected in the MAX232


T2IN pin which converts input 5v TTL/CMOS level to RS232 level. Then T2OUT pin is
connected to reviver pin of 9 pin D type serial connector which is directly connected
to PC.

In PC the transmitting data is given to R2IN of MAX232 through transmitting pin


of 9 pin D type connector which converts the RS232 level to 5v TTL/CMOS level. The
R2OUT pin is connected to receiver pin of the microcontroller. Likewise the data is
transmitted and received between the microcontroller and PC or other device vice
versa.

CIRCUIT

Hardware Requirements:
PIC Microcontroller
Zigbee
MEMS Accelerometer
Max232
LCD

Software Requirements:
MPLab Compiler
Embedded C

.Net

Advantage
Using Zigbee technology, the control is easily transmitted with individual address.
Its response time is higher than other wireless communications.

Application
Used in Industries and Homes
Controlling all the industrial equipments and monitoring the status of all the
Equipments from a remote place is possible.

CONCLUSION
As the existing system has the above mentioned drawback we need a system to overcome
those drawbacks so we go for the proposed system. This system has modules like Zigbee which
can transmit data few meters where we can monitor from remote place.

FUTURE ENHANCEMENT
The presented wireless system for building monitoring takes advantage of the unique
features of custom-developed MEMS sensors and read-out ASIC combined with an optimized
network and module architecture, to realize a solution which offers long battery lifetime and
potentially low cost in manufacturing, installation and maintenance, while providing high-quality
sensor data at the right time.

REFERENCES
[1] M. Pozzi, D. Zonta, W.Wang, and G. Chen, A framework for evaluating the impact of
structural health monitoring on bridge management, in Proc. 5th Int. Conf. Bridge
Maintenance, Safety Manage., Philadelphia, PA, Jul. 2010, p. 161.
[2] J. P. Lynch and K. J. Loh, A summary review of wireless sensors and sensor networks for
structural health monitoring, Shock Vibrat. Dig.,vol. 38, no. 2, pp. 91128, 2006.

[3] D. Zonta, M. Pozzi, and P. Zanon, Managing the historical heritage using distributed
technologies, Int. J. Arch. Heritage, vol. 2, no. 3, pp. 200225, 2008.
[4] M. Kruger, C. U. Grosse, and P. J. Marron, Wireless structural health monitoring using
MEMS, Key Eng. Mater., vols. 293294, pp. 625634, Sep. 2005.
[5] A. Amditis, Y. Stratakos, D. Bairaktaris, M. Bimpas, S. Camarinopolos, and S. FrondistouYannas, Wireless sensor network for seismic evaluation of concrete buildings, in Proc. 5th
Eur. Workshop Struct. Health Monitor., Sorrento, Italy, Jun.Jul. 2010.
[6] J. Santana, R. van den Hoven, C. van Liempd, M. Colin, N. Saillen, and C. Van Hoof, A 3axis accelerometer and strain sensor system for building integrity monitoring, in Proc. 16th Int.
Conf. Solid-State Sensors, Actuat., Microsyst., Beijing, China, Jun. 2011, pp. 3639.
[7] A. Amditis, Y. Stratakos, D. Bairaktaris, M. Bimpas, S. Camarinopolos, and S. FrondistouYannas, An overview of MEMSCON project: An intelligent wireless sensor network for afterearthquake evaluation of concrete buildings, in Proc. 14th Eur. Conf. Earthquake Eng., Aug.
Sep. 2010.
[8] D. Trapani, D. Zonta, F. Larcher, A. Amditis, N. Bertsch, M. Bimpas, A. Garetsos, N. Saillen,
J. Santana, T. Sterken, Y. Stratakos, T. Torfs, and D. Ulieru, Laboratory validation of MEMSbased sensors for postearthquake damage assessment, in Proc. 8th Int. Workshop Struct. Health
Monitor., Stanford, CA, Sep. 2011, pp. 21652172.

Das könnte Ihnen auch gefallen