WIRELESS DATA ACQUISITIONSYSTEM USING Zigbee PROTOCOL

Share Embed


Descrição do Produto

TABLE OF CONTENT ACKNOWLEDGEMENT

I

ABSTRACT

II

CERTIFICATE

III

LIST OF FIGURES

VI

LIST OF TABLES

VII

TABLE OF CONTENT

V

CHAPTERS

1) INTRODUCTION ............................................................................................. 1 1.1 OVERVIEW .................................................................................................. 1 1.2 OBJECTIVE OF PROJECT ........................................................................... 1 2) FUNDAMENTALS OF ZIGBEE TECHNOLOGY ......................................... 4 2.1 ZigBee Alliance ............................................................................................. 4 2.2 ZigBee Specification ...................................................................................... 5 2.2.1 ZigBee devices ............................................................................... 7 2.2.2 ZigBee Network Topology ............................................................. 8 2.3 Why ZigBee? ............................................................................................... 11 2.4 IEEE 802.15.4.............................................................................................. 13 2.5 Comparison of ZigBee over the other protocol ............................................ 14 2.6 ZigBee Framing Format .............................................................................. 18 3) CONCLUSION AND FUTURE EXPANSION .............................................. 43 3.1 Asynchronous serial communication and data framing ................................. 43 3.1.1 Start and Stop bits ........................................................................... 7 3.1.2 Data Transfer Rate .......................................................................... 7

IV

3.2 RS232 Standards .......................................................................................... 43 3.2.1 RS232 Pins ................................................................................... 32 3.2.2 DB-9 Pin connector ...................................................................... 32 3.3 PIC16F887 connection with RS232 ............................................................. 32 3.3.1 MAX232 ...................................................................................... 32 4) PROJECT RESOURCES ................................................................................ 20 4.1 Over View ................................................................................................... 20 4.2 HARDWARE RESOURCES ....................................................................... 20 4.2.1 EasyBee3 Board ........................................................................... 32 4.2.2 MRFJ40MA Transceiver .............................................................. 23 4.2.3 PIC 16F887 ................................................................................... 24 4.3 SOFTWARE RESOURCES ........................................................................ 26 4.3.1 Mikro C Pro IDE for PIC from Mikro-elektronika ......................... 26 5) SCHEMATIC OF HARDWARE .................................................................... 30 5.1 SCHEMATIC DESIGN ............................................................................... 30 6) PROJECT DETAIL ........................................................................................ 34 6.1 PROJECT-1 ................................................................................................. 34 6.2 PROJECT-2 ................................................................................................. 35 6.3 ZIGBEE CODE(MAIN) .............................................................................. 38 6.3.1 Transmitter side ............................................................................. 38 6.3.2 Receiver side ................................................................................ 40 6.4 PROJECT-3 ................................................................................................. 38 6.4.1 PROJECT DESCRIPTION ............................................................ 38 6.4.2 C Code .......................................................................................... 38 7) CONCLUSION AND FUTURE EXPANSION .............................................. 43 7.1 Conclusion ................................................................................................... 43 7.2 Future Expansion ......................................................................................... 43 V

APPENDIX – A……. NOMENCLATURE .......................................................... 45 REFERENCES ..................................................................................................... 47

LIST OF FIGURES

Figure No.

Figure Description

Page No.

Fig.1(a)

Home Automation using Zigbee

03

Fig.2(a)

ZigBee Protocol Layers

06

Fig.2(b)

Star Topology

09

Fig.2(c)

Mesh Topology

10

Fig.2(d)

Tree Topology

11

Fig.2(e)

Comparison of Power Consumption between Various Protocols

15

Fig.2(f)

Types of Network Topology

16

Fig.2(g)

Comparison for SNR and Bit Error Rate Performance

17

Fig.2(h)

Comparison of ZigBee, Bluetooth & IEEE802.11b

17

Fig.2(i)

ZigBee Frame Format

19

VI

Fig.3(a)

Easy Bee 3 board front view

21

Fig.3(b)

Easy Bee 3 board back view

23

Fig.3(c)

Diagram of MRF24J40MA Trans-receiver

24

Fig.3(d)

PIC16F887 Pin Diagram

25

Fig.3(e)

Screen shot of mikro C Pro Compiler

27

Fig.3(f)

Screenshot for Creating New file in Mikro C

28

Fig.3(g)

Screenshot for Creating New file in Mikro C

29

Fig.4(a)

PIC16F887 Pin Diagram

30

Fig.4(b)

Simple Master Slave Implementation using SPI bus

31

Fig.4(c)

PCB Design Schematic

32

Fig.4(d)

Front view of PCB

33

Fig.4(e)

Back view of PCB

33

Fig.5(a)

Circuit connection for data communication

35

Fig.5(b)

Circuit connection for data communication using star topology

36

Fig.5(c)

Circuit connection for data communication at transmitter side

37

Fig.5(d)

Circuit connection for data communication at receiver side

37

VII

LIST OF TABLES

Table No.

Table Description

Page No

Table 2.1

Comparison between ZigBee & other Wireless Protocols

14

Table 3.1

Features of the PIC16F887

25

VIII

CHAPTER 1 INTRODUCTION

1.1 OVERVIEW

In 21st Century, with the advent of new technologies almost every day, the living standards and comfort level of people has reached a very high level. A large part of the modern lifestyle is usage of electronic and electrical devices. As increase in people’s lifestyle level, Industrial level is also increasing. It demands the reliable and robust system for data logging, so the saved data is processed further later. However, increased electronic and electrical appliances usage has exponentially increased the power consumption having wireless network control. Due to the demand-supply gap, the price that the end user or industry has to pay is increasing day by day. As a result, there is an unmet need of new technologies so that the wireless control with lower power usage can be optimized. This unmet need has resulted in fundamental and applied research in this field. Such research has led to some advanced monitoring and control features so industrial people are able to control the DAQ system with minimum power consumption as well as monitor the system so that they can optimize them to get better performance.

1.2 OBJECTIVE OF PROJECT

For some organization it is essential to distribute the data at that instant itself or store it to do further operations. The controlling unit collects the data made in form suitable to transfer. Micro-controller is used as control unit for collecting data and transferring using USART. The newly designed digital switchboard, which will be an embedded system, which consist of a microcontroller, push buttons (instead of normal switches), character LCD, and a keypad. All the rooms will be connected wirelessly with each other on a distributed wireless network running a Zigbee protocol. Thus in future other devices can also be added to the Zigbee network with ease and all the devices can communicate with

each other on a signal 2.4GHz band. The Zigbee protocol is such that it can run alongside with WiFi on the same frequency band. Through the Zigbee protocol the digital switchboard can communicate with other products also.

Data loggers are used to collect and centralize the data for processing. This project is a proto type for such system. Three boards are there in this project out of which two board contains sensors. These are interfaced to the microcontroller. The microcontroller collects the data from the sensors and the data is passed to the other board (Receiver). The microcontroller in this board collects the data from the both board and the whole data is passed to the PC for display and for centralization purpose through UART.

PIC is a family of modified Harvard architecture microcontrollers made by Microchip Technology, derived from the PIC1650 originally developed by General Instrument's Microelectronics Division. The name PIC initially referred to "Peripheral Interface Controller" which was developed by Intel in 1975 for use in embedded systems. Intel's original versions were popular in the 1980s and early 1990s, but has today largely been superseded by a vast range of faster and/or functionally enhanced PIC-compatible devices manufactured by more than 20 independent manufacturers including Atmel, Infineon Technologies (formerly SiemensAG), Maxim integrated product via its dallas semiconductor subsidiary), STMicroelectronics, SiliconLaboratories (formerly Cygnal), Texas Instruments and Cypress Semiconductor. Intel's official designation for the PIC family of µCs is PIC16.

Advantages: •

Reduced data redundancy



Reduced updating errors and increased consistency



Greater data integrity and independence from applications programs



Improved data access to users through use of host and query languages



Improved data security



Reduced data entry, storage, and retrieval costs



Facilitated development of new applications program

Disadvantages •

Database systems are complex, difficult, and time-consuming to design



Substantial hardware and software start-up costs



Damage to database affects virtually all applications programs



Extensive conversion costs in moving form a file-based system to a database system



Initial training required for all programmers and users

Fig.(a) Data Acquisition System using Zigbee[10]

CHAPTER 2 FUNDAMENTALS OF ZIGBEE TECHNOLOGY The past few years have witnessed a rapid growth of wireless networking. However, up to now wireless networking has been mainly focused on high – speed communications, and relatively long range applications such as IEEE 802.11 wireless local area network standards. The first well known standard focusing on low rate wireless personal area networks was Bluetooth. However it has limited capacity for networking of many nodes. There are many wireless monitoring and control applications in industrial and home environments which require longer battery life, lower data rates and less complexity than those from existing standards. For such wireless applications, a new standard called IEEE 802.15.4 has been developed by IEEE. The new standard is also called ZigBee.

2.1 THE ZIGBEE ALLIANCES

The ZigBee standard is organized under the auspices of the ZigBee Alliance. The ZigBee alliance is an organization of companies working together to define an open global standard for making low power wireless networks. The intended outcome of ZigBee alliance is to create a specification defining how to build different network topologies with data security features and interoperable application profiles. This organization has over 150 members, of which seven have taken on the status of what they term “promoter.” These seven companies are Ember, Honeywell, Invensys, Mitsubishi, Motorola, Philips and Samsung. A big challenge for the alliance is to make the interoperability to work among different products. To solve this problem, the ZigBee Alliance has defines profiles, depending on what type of category the product belongs to. For example there is a profile called home lightning that exactly defines how different brands of home lightning-products should communicate with each other. Under the umbrella of the ZigBee Alliance, the new standard will be pushed forward, taking on board the requirements of the users, manufacturers and the system developers.

Currently there are three different types of ZigBee profiles available given by ZigBee Alliances on which we can work:

1. Private profile: In this profile interoperability is not important. No ZigBee stamp on the product, but one can claim "based on a ZigBee platform" 2. Published profile: This is the profile in which, private profile is shared with others. No ZigBee stamp on the product, but one can claim "based on a ZigBee platform" 3. Public profile: This is the official ZigBee profile which has ZigBee stamp on the product.

2.2 ZIGBEE SPECIFICATION ZigBee is a relatively new, wireless personal area network technology based on IEEE 802.15.4.ZigBee is a standard that defines a set of communication protocols for low-datarate Short-range wireless networking. ZigBee-based wireless devices operate in 868 MHz, 915 MHz, and 2.4 GHz frequency bands. The maximum data rate is 250 Kbits per second. ZigBee is targeted mainly for battery-powered applications where low data rate, low cost, and long battery life are main requirements. In many ZigBee applications, the total time the wireless device is engaged in any type of activity is very limited; the device spends most of its time in a power-saving mode, also known as sleep mode. As a result, ZigBee enabled devices are capable of being operational for several years before their batteries need to be replaced. The ZigBee standard is developed by the ZigBee Alliance, which has hundreds of member companies, from the semiconductor industry and software developers to original equipment manufacturers (OEMs) and installers. The ZigBee standard has adopted IEEE 802.15.4 as its Physical Layer (PHY) and Medium Access Control (MAC) protocols. Therefore, a ZigBee-compliant device is compliant with the IEEE 802.15.4 standard as well.

One of the common ways to establish a communication network (wireless) is to use the concept of networking layers. Each layer is responsible for certain functions in the network.

The layers normally pass data and commands only to the layers directly above and below them. ZigBee wireless networking protocol layers are shown in Figure-4. [1]

Fig.2(a)ZigBee Protocol Layers [11]

ZigBee protocol layers are based on the Open System Interconnect (OSI) basic reference model dividing a network protocol into layers has a number of advantages. For example, if the protocol changes over time, it is easier to replace or modify the layer that is affected by the change rather than replacing the entire protocol. Also, in developing an application, the lower layers of the protocol are independent of the application and can be obtained from a third party, so all that needs to be done is to make changes in the application layer

of the protocol. The software implementation of a protocol is known as protocol stack software. As shown in Figure-4, the bottom two networking layers are defined by the IEEE 802.15.4 Standard. This standard is developed by the IEEE 802 standards committee and was initially released in 2003. IEEE 802.15.4 defines the specifications for PHY and MAC layers of wireless networking, but it does not specify any requirements for higher networking layers. The ZigBee standard defines only the networking, application, and security layers of the protocol and adopts IEEE 802.15.4 PHY and MAC layers as part of the ZigBee networking protocol. Therefore, any ZigBee-compliant device conforms to IEEE 802.15.4 as well.

2.2.1 ZigBee Devices

There are mainly two type of ZigBee devices are available. 1) Full-Function Devices (FFDs) 2) Reduced-Function Devices (RFDs).



The Full Function Device (FFD): It supports all IEEE 802.15.4 functions and features specified by the standard and can accept any role in the network. It can function as a network coordinator. Additional memory and computing power make it ideal for network router functions or it could be used in network-edge devices (where the network touches the real world).



The Reduced Function Device (RFD): It carries limited (as specified by the standard) functionality to lower cost and complexity. It is generally found in network-edge devices. The RFD can be used where extremely low power consumption is a necessity.

For example, an FFD can communicate with any other device in a network, but an RFD can talk only with an FFD device. RFD devices are intended for very simple applications such as turning on or off a switch. The processing power and memory size of RFD devices are normally less than those of FFD devices. Now, we can also classify the devices as per functioning of the devices:



ZigBee Coordinator

For each Network minimum one coordinator is required and depending on the application we can use number of coordinators in a network. The coordinator initiates the network formation. ZigBee coordinator is installed at control device side. So, it controls the devices according to the sensor data which is sent by end devices or a router.



ZigBee Router It participates in multi-hop routing of messages. When required range of transmission is very high, we can use ZigBee router to route the data and extend the range of the transmission. It can also work as an end device.



ZigBee End Device It does not allow association or routing. Generally this devices remains in sleep mode, whenever request for data is generated by coordinator, it awakes and gives whatever data it has regarding to the sensor and goes again to the sleep mode. So this device takes critical part in power saving. These devices are installed at sensor side.

2.2.2 ZigBee Network Topology The network formation is managed by the ZigBee networking layer. The network must be in one of two networking topologies specified in IEEE 802.15.4.

There are mainly 2 types of network topology supported by ZigBee. 1) Star Topology 2) Peer-To-Peer 

Mesh Topology



Tree Topology.

Star Topology: In the star topology, shown below, every device in the network can communicate only with the PAN (Personal Area Network) coordinator. A typical scenario in a star network formation is that an FFD, programmed to be a

PAN coordinator, is activated and starts establishing its network. The first thing this PAN coordinator does is select a unique PAN identifier that is not used by any other network in its radio sphere of influence —the region around the device in which its radio can successfully communicate with other radios. In other words, it ensures that the PAN identifier is not used by any other nearby network.

Fig.2(b) Star Topology [12]

Peer-To-Peer:

(a) Mesh Topology:In a peer-to-peer topology, each device can communicate directly with any other device if the devices are placed close enough together to establish a successful communication link. Any FFD in a peer-to-peer network can play the role of the PAN coordinator. One way to decide which device will be the PAN coordinator is to pick the first FFD device that starts communicating as the PAN coordinator. In a peer-to-peer network, all the devices that participate in relaying the messages are FFDs because RFDs are not capable of

relaying the messages. However, an RFD can be part of the network and communicate only with one particular device (a coordinator or a router) in the network.

Fig.2(c) Mesh Topology [12]

(b) Tree Topology:Another form of peer-to-peer network ZigBee supports is a tree topology. In this case, a ZigBee coordinator (PAN coordinator) establishes the initial network. ZigBee routers form the branches and relay the messages. ZigBee end devices act as leaves of the tree and do not participate in message routing. ZigBee routers can grow the network beyond the initial network established by the ZigBee coordinator.

Fig. 2(d) Tree Topology [12]

The name ZigBee is said to come from the domestic honeybee which uses a zigzag type of dance to communicate important information to other hive members. This communication dance (“The ZigBee Principle”) is what engineers are trying to emulate with this protocol – a bunch of separate and simple organisms that join together to tackle complex tasks.

2.3 WHY ZIGBEE?

There are a multitude of standards like Bluetooth and Wi-Fi that address mid to high data rates for voice, PC LANs, video etc. However, up till now there hasn’t been a wireless network standard that meets the unique needs of sensors and control devices. Sensors and controls don’t need high bandwidth but they do need low latency and very low energy consumption for long battery lives and for large device arrays.

There are a multitude of proprietary wireless systems manufactured today to solve a multitude of problems that don’t require high data rates but do require low cost and very low current drain. These proprietary systems were designed because there were no standards that met their application requirements. These legacy systems are creating significant interoperability problems with each other and with newer technologies. The ZigBee Alliance is not pushing a technology; rather it is providing a standardized base set of solutions for sensor and control systems. Here are the following points that justify the use of ZigBee over the existing standards. Low power consumption, simply implemented: Users expect batteries to last many months to years! Consider that a typical single-family house has about 6 smoke/CO detectors. If the batteries for each one only lasted six months, the home owner would be replacing batteries every month! In contrast Bluetooth, which has many different modes and states depending upon your latency and power requirements, ZigBee/IEEE 802.15.4 has two major states: 

Active(transmit/receive)



Sleep. The application software needs to focus on the application, not on which power mode is

optimum for each aspect of operation. Even mains powered equipment needs to be conscious of energy. ZigBee devices will be more ecological than their predecessors saving megawatts at it full deployment. Consider a future home that has 100 wireless control/sensor devices, Case 1:802.11 Rx power is 667 mW (always on) @ 100 devices/home & 50,000 homes/city = 150 3.33 megawatts.

Case 2:802.15.4 Rx power is 30 mW (always on) @ 100 devices/home & 50,000 homes/city = 150 kilowatts.

Case 3:802.15.4 power cycled at .1% (typical duty cycle) = 150 watts So, Low cost to the users means low device cost, low installation cost and low maintenance.

ZigBee devices allow batteries to last up to years using primary cells (low cost) without any chargers (low cost and easy installation). ZigBee’s simplicity allows for inherent configuration and redundancy of network devices provides low maintenance. High density of nodes per network: ZigBee’s use of the IEEE 802.15.4 PHY and MAC allows networks to handle any number of devices. This attribute is critical for massive sensor arrays and control networks. Simple protocol, global implementation: ZigBee’s protocol code stack is estimated to be about 1/10th of Bluetooth’s or 802.11’s.Simplicity is essential to cost, interoperability, and maintenance. The IEEE 802.15.4 PHY adopted by ZigBee has been designed for the 868MHz band in Europe, the 915 MHz band in N America, Australia, etc.; and the 2.4 GHz band is now recognized to be a global band accepted in almost all countries.

2.4 IEEE 802.15.4

IEEE 802.15 is the working group 15 of the IEEE 802 which specializes in Wireless PAN Standards. It includes four task groups (numbered from 1 to 4): 

Task group 1 (WPAM/Bluetooth) deals with Bluetooth, having produced the 802.15.1 standard, published on June 14, 2002. It includes a medium access control and physical layer specification adapted from Bluetooth 1.1.



Task group 2 (coexistence) deals with coexistence of Wireless LAN (802.11) and Wireless PAN.



Task group 3 is in fact two groups: 3 (WPAN High Rate) and 3a (WPAN Alternate Higher Rate), both dealing with high-rate WPAN standards (20 Mbps or higher).



Task group 4 (WPAN Low Rate) deals with low rate but very long battery life (months or even years).The first edition of the 802.15.4 standard was released in May 2003.

2.5 COMPARISON OF ZIGBEE PROTOCOL OVER OTHER WIRELESSPROTOCOLS

ZigBee differs from existing networking standards to address several key areas:

 

Supporting robust, fault tolerant mesh networks.

Low power requirements permitting a wide variety of truly wireless devices which are battery powered with a long battery life.



Simple network configuration and management allowing devices to be added to existing networks with little if any administrative work.



Also it requires less time to wakeup (approximately 30ms). Various Types of Protocols available & Their Comparison are listed in Table-

1: [5] Table 2.1: Comparison between ZigBee& other Wireless Protocols. [5]

Standard

Bluetooth

ZigBee

Wi-Fi

IEEE Spec.

802.15.1

802.15.4

802.11a/b/g

Frequency Band

2.4GHz

868/915 MHz; 2.4GHz

2.4GHz; 5GHz

Max Signal Rate

1 Mb/s

250 Kb/s

54 Mb/s

Nominal Range

10 m

10-100 m

100 m

Number of RF Channels

79

1/10; 16

14 (2.4GHz)

Channel Bandwidth

1 MHz

0.3/0.6 MHz; 2 MHz

22 MHz

Modulation Type

GFSK

BPSK(+ASK); O-QPSK

BPSK; QPSK;

Spreading

FHSS

DSSS

DSSS; CCK; OFDM

Protocol Stack Size

250KB+

4 KB-32 KB

1 MB+

Battery Life

1-7 days

3-5 years

0.5-5 days

Power Consumption in

40 Ma

25-35 mA

400 mA

0.2 mA

3 uA

20 mA

Tx mode Power Consumption in Sleep mode

Now the choice of the ZigBee standard can be conveyed by Table-1. The above specifications described are related with our application as below which gives detail that why we have selected ZigBee for our application. 

Data Rate: For our application we require the low data rate because we have to send the data of the Sensor/Switch only which is not more than the few bytes. From the table the other device has higher data rate but that consume more power than ZigBee.



Range: The ZigBee standard have the range of the 100m while the other device which have the range less than that of the ZigBee standard.



Power Consumption: The biggest advantage of using the ZigBee standard is the power consumption. The other standard which is used for my application requires more power than the other. The battery life time of the device is poor. So that we have to replace the battery in a few days. But using ZigBee we can use the battery for a few months because of the low power consumption. Too make the low power consumption is the main goal of my project.

Fig.2(e) Comparison of Power Consumption between Various Protocols. [13]

For example, if a device wakes up every minute and stays active for 60 ms, then the duty cycle of this device is 0.001, or 0.1%. In many ZigBee applications, the devices have duty cycles of less than 1% to ensure years of battery life. 

The security: In the wireless application the security is the main problem. The ZigBee provide application layer security .The Bluetooth is also provide the security

but there power consumption is very high. The other device which is

described above does not provide the security. 

Association Time: The connection time required for the one ZigBee module to the other module is very less (approximately 30ms.)While in the other like Bluetooth & IEEE 802.11 standard requires more time to form the network.



Network Topology: We can implement various types of network topology as described in below figure.

TOPOLOGY

MESH

STAR

RING

TREE

Fig.2(f) Types of Network Topology.[5]

But, All the network topology cannot be implemented with the use of all the modules. For example, with the use of the ZigBee module we can form the mesh network which cannot be possible with the other protocols available. ZigBee is not necessarily a replacement for the wireless standards you may already be familiar with but is specifically designed for a unique set of applications, situations, and scenarios where existing wireless standards fall short or won’t work at all.

Fig. 2(g) Comparison for SNR and Bit Error Rate Performance [13]

Here is the Basic radio characteristic of ZigBee and other wireless protocol. This characteristic shows that ZigBee has excellent performance even in low SNR environments.

Fig. 2(h) Comparison of ZigBee, Bluetooth & IEEE802.11b [13]

From this comparison it should be noted that the transmission rate of the ZigBee is very less like Bluetooth but we can use routing protocols and send the data at large distance which is not possible in case of Bluetooth. The Network size of the ZigBee is also far

more than other protocols. If we compare ZigBee with other wireless protocol in the sense of cost, power & Complexity wise then it says that ZigBee is appropriate for the application like wireless sensor network. So we can have robust wireless Sensor network with the use of ZigBee.

2.6 ZigBee Framing Format

We can have ZigBee frame at the various layers is shown below. Following figure shows only MAC Sub layer & Physical Sub layer frame format. It also shows the packet format called PPDU on air while communication occur.

Calculation: During wireless transmission in the air, the Frame is called PHY Protocol Data Unit (PPDU). PPDU contains Preamble of 4 bytes, SFD of 1 byte, Frame length of 1 byte and PSDU (Physical Service Data Unit) of 5-127 bytes. PSDU conations Frame Control of 2 bytes, Sequence number of 1 byte, addressing field of 4 bytes (maximum up to 20 bytes), Data payload of 118 bytes (or 102 bytes). Maximum length of PPDU goes up to 133 bytes. If we transmit word “Enable” from ZigBee transmitter to the ZigBee Receiver then we can calculate PPDU or frame length as below. 1) Preamble of 4 byte 2) SFD of 1 byte 3) Frame length of 1 byte 4) Frame Control of 2 bytes 5) Sequence number of 1 byte 6) addressing field of 4 bytes 7) Data payload of 6 bytes (as Enable has 6 character) 8) Frame Check Sequence for error control is 2 bytes.

Fig. 2(i) ZigBee Frame Format [14] So, Total Length is = 4+1+1+2+1+4+6+2=21 bytes. i.e. 21*8= 168 bits. For word “Disable” we have total frame Length is = 4+1+1+2+1+4+7+2=22 bytes. i.e. 22*8=176 bits

CHAPTER 3 SERIAL COMMUNICATION

Computers can transfer data in two ways: parallel and serial. In parallel data transfers, often 8 or more lines (wire conductors) are used to transfer data to a device that is only a few feet away. Examples of parallel data transfer are printers and hard disks; each uses cables with many wire strips. Although in such cases a lot of data can be transferred in a short amount of time by using many wires in parallel, the distance cannot be great. To transfer to a device located many meters away, the serial method is used. In serial communication, the data is sent one bit at a time, in contrast to parallel communication, in which the data is sent a byte or more at a time. Serial communication of the 8051 is the topic of this chapter. The 8051 has serial communication capability built into it, there by making possible fast data transfer using only a few wires.

If data is to be transferred on the telephone line, it must be converted from 0s and 1s to audio tones, which are sinusoidal-shaped signals. A peripheral device called a modem, which stands for “modulator/demodulator”, performs this conversion. Serial data communication uses two methods, asynchronous and synchronous. The synchronous method transfers a block of data at a time, while the asynchronous method transfers a single byte at a time.

In data transmission if the data can be transmitted and received, it is a duplex transmission. This is in contrast to simplex transmissions such as with printers, in which the computer only sends data.

Duplex transmissions can be half or full duplex,

depending on whether or not the data transfer can be simultaneous. If data is transmitted one way at a time, it is referred to as half duplex. If the data can go both ways at the same time, it is full duplex. Of course, full duplex requires two wire conductors for the data lines, one for transmission and one for reception, in order to transfer and receive data simultaneously.

3.1 ASYNCHRONOUS SERIAL COMMUNICATION AND DATA FRAMING

The data coming in at the receiving end of the data line in a serial data transfer is all 0s and 1s; it is difficult to make sense of the data unless the sender and receiver agree on a set of rules, a protocol, on how the data is packed, how many bits constitute a character, and when the data begins and ends.

3.1.1 START AND STOP BITS Asynchronous serial data communication is widely used for character-oriented transmissions, while block-oriented data transfers use the synchronous method. In the asynchronous method, each character is placed between start and stop bits. This is called framing. In the data framing for asynchronous communications, the data, such as ASCII characters, are packed between a start bit and a stop bit. The start bit is always one bit, but the stop bit can be one or two bits. The start bit is always a 0 (low) and the stop bit (s) is 1 (high).

3.1.2 DATA TRANSFER RATE The rate of data transfer in serial data communication is stated in bps (bits per second). Another widely used terminology for bps is baud rate.

However, the baud and bps rates are not

necessarily equal. This is due to the fact that baud rate is the modem terminology and is defined as the number of signal changes per second. In modems a single change of signal, sometimes transfers several bits of data. As far as the conductor wire is concerned, the baud rate and bps are the same, and for this reason we use the bps and baud interchangeably. The data transfer rate of given computer system depends on communication ports incorporated into that system. For example, the early IBMPC/XT could transfer data at the rate of 100 to 9600 bps. In recent years, however, Pentium based PCS transfer data at rates as high as 56K bps. It must be noted that in asynchronous serial data communication, the baud rate is generally limited to 100,000bps.

Computers can transfer data in two ways: parallel and serial. In parallel data transfers, often 8 or more lines (wire conductors) are used to transfer data to a device that is only a few feet away. Examples of parallel transfers are printers and hard disks; each uses cables with many wire strips. Although in such cases a lot of data can be transferred in a short amount of time by using many wires in parallel, the distance cannot be great. To transfer to a device located many meters away, the serial method is used. In serial communication, the data is sent one bit at a time, in contrast to parallel communication, in which the data is sent a byte or more at a time. The 8051 has serial communication capability built into it, thereby making possible fast data transfer using only a few wires. The PC uses RS 232 as a Serial Communication Standard.

3.2 RS232 STANDARDS

To allow compatibility among data communication equipment made by various manufacturers, an interfacing standard called RS232 was set by the Electronics Industries Association (EIA) in 1960. In 1963 it was modified and called RS232A. RS232B AND RS232C were issued in 1965 and 1969, respectively. Today, RS232 is the most widely used serial I/O interfacing standard. This standard is used in PCs and numerous types of equipment. However, since the standard was set long before the advert of the TTL logic family, its input and output voltage levels are not TTL compatible. In RS232, a 1 is represented by -3 to -25V, while a 0 bit is +3 to +25V, making -3 to +3 undefined. For this reason, to connect any RS232 to a microcontroller system we must use voltage converters such as MAX232 to convert the TTL logic levels to the RS232 voltage levels, and vice versa. MAX232 IC chips are commonly referred to as line drivers.

3.2.1 RS232 PINS RS232 cable connector commonly referred to as the DB-25 connector.

In

labeling, DB-25P refers to the plug connector (male) and DB-25S is for the socket connector (female). Since not all the pins are used in PC cables, IBM introduced the DB-9 Version of the serial I/O standard, which uses 9 pins only, as shown in table.

3.2.2 DB-9 PIN CONNECTOR

12345 6789

(Out of computer and exposed end of cable)

Pin Functions:

Pin

Description

1

Data carrier detect (DCD)

2

Received data (RXD)

3

Transmitted data (TXD)

4

Data terminal ready(DTR)

5

Signal ground (GND)

6

Data set ready (DSR)

7

Request to send (RTS)

8

Clear to send (CTS)

9

Ring indicator (RI)

Table 3.1 Pin description of the RS232[22]

Note: DCD, DSR, RTS and CTS are active low pins.

The method used by RS-232 for communication allows for a simple connection of three lines namely TX, Rx, and Ground.

TXD: carries data from DTE to the DCE. RXD: carries data from DCE to the DTE SG:

signal ground

3.3 PIC16F887 CONNECTION TO RS232

Embedded Controller

TXD

RXD

RXD

TXD

2 3

GND 5

MAX 232

Fig. 3(a) Schematic Diagram of RS232 connection to µC[22] The RS232 standard is not TTL compatible; therefore, it requires a Line Driver such as the MAX232 chip to convert RS232 voltage levels to TTL levels, and vice versa. The 8051 has two pins that are used specifically for transferring and receiving data serially. These two pins are TXD and RXD and are a part of the port 3 (P3.0 and P3.1). Pin 11 of the 8051 is designated as TXD and pin 10 as RXD. These pins are TTL compatible; therefore, they require a line drive to make them RS232 compatible. One such line driver is the MAX232 chip. MAX232 converts from RS232 voltage levels to TTL voltage levels, and vice versa. One advantage of the MAX232 chip is that it uses a +5V power source which, is the same as the source voltage for the 8051. In the other words, with a single +5V power supply we can power both the 8051 and MAX232, with no need for the power supplies. The MAX232 has two sets of line drivers for transferring and receiving data. The line drivers used for TXD are called T1 and T2, while the line drivers for RXD are designated as R1 and R2. In many applications only one of each is used.

3.3.1 MAX-232

LOGIC SIGNAL VOLTAGE Serial RS-232 (V.24) communication works with voltages (between -15V ... -3V and used to transmit a binary '1' and +3V ... +15V to transmit a binary '0') which are not compatible with today's computer logic voltages. On the other hand, classic TTL computer logic operates between 0V ... +5V (roughly 0V ... +0.8V referred to as low for binary '0', +2V ... +5V for high binary '1' ). Modern low-power logic operates in the range of 0V ... +3.3V or even lower. So, the maximum RS-232 signal levels are far too high for today's computer logic electronics, and the negative RS-232 voltage can't be grokked at all by the computer logic. Therefore, to receive serial data from an RS-232 interface the voltage has to be reduced, and the 0 and 1 voltage levels inverted. In the other direction (sending data from some logic over RS232) the low logic voltage has to be "bumped up", and a negative voltage has to be generated, too.

RS-232

TTL

Logic

--------------------------------------------------------15V ... -3V +2V ... +5V

1

+3V ... +15V 0V ... +0.8V 0

All this can be done with conventional analog electronics, e.g. a particular power supply and a couple of transistors or the once popular 1488 (transmitter) and 1489 (receiver) ICs. However, since more than a decade it has become standard in amateur electronics to do the necessary signal level conversion with an integrated circuit (IC) from the MAX232 family (typically a MAX232A or some clone). In fact, it is hard to find some RS-232 circuitry in amateur electronics without a MAX232A or some clone.

CHAPTER 4 PROJECT RESOURCES

4.1 OVERVIEW

To start with, the Graphical User Interface enable the wireless network with Reduced Function Device as described in chapter 2. The Reduced Function Device is connected to PIC controller which in-turn is connected to the EASY Bee 3 module. The Data is transmitted through the Transmitter module programmed by mikroProg Suite for PIC in computer or with the help of the SUPER PRO IC Burner/PICkit-3 In-Circuit Debugger. Data received by the Receiver module is processed and display on the Graphical User Interface like LCD and send to the PC for data logging purpose for further processing of it. To conclude, this project primarily includes two types of resources: •

Hardware resources which include RF module, also called as Zigbee module, PIC controller kit, USB cable that is used for the wired communication between Zigbee device, RS232 cable that is used for the wired communication between PIC controller and PC, PIC kit, PICkit-3, Temperature sensor (DS18B20), Proximity sensor and the computer serial port.



Software Resources includes mikroProg Suite for PIC in which C languagebasic coding is done and SUPER PRO that is used for burning the generated hex file in the mikroProg Suite, MPLAB used for burning of the Hex file through help of PICkit-3.

4.2 HARDWARE RESOURCES 4.2.1 EASYBEE 3 Board The EasyBee3 board includes the MRF24J40MA module used to connect your

development board to wireless 2.4GHz IEEE 802.15.4 network easily. The module connects with microcontrollers via a serial interface (SPI).

Fig. 4(a) EASYBEE 3 board[4]

Key Features 

IEEE 802.15.4 Standard Compliant RF Transceiver



Support ZigBee, MiWi,MiWi P2P and Proprietary wireless Networking Protocols



Integrated 20MHz and 32.768KHz crystal oscillator circuitry



Data rate:250Kbps(IEEE 802.15.4);625(IEEE 802.15.4)



Simple,4-wire serial interface (SPI)



Low Power Consumption

Operating Voltage •

Board is design to use with both 3.3V and 5 V Power Supply. Voltage is selected using on board Supply select jumper.

Key Benefits 

On Board Voltage translators enable compatibility with most development board.



Extended battery life due to low power consumption.



Supported in all MikroE compilers.



IDC10 cables with connectors enable easy connection with peripheral modules.



Ready to use examples save development time.

Application •

EasyBee3 is a great choice for building automation & monitoring, industrial monitoring, automated meter reading, security, inventory management and more.

Description of EasyBee3 board •

EasyBee3 board is used for wireless communication for short distance & with low power consumption. Wireless communication is enabled due to ZigBee module MRF24J40MA provided on EasyBee3 board. Connection between the additional board & a microcontroller is established via a 2x5 female connector supplied on the additional board & a 2x5 male connector on the development system. Communication between them is performed via serial peripheral interface (SPI).Since the additional system may be connected to different development system, it is necessary to select appropriate microcontroller pins used for SPI communication. DIP switch SW1 & SW2 on the additional board used depending on the development system.

The ZigBee module requires 3.3v power supply voltage for its operation. Since different development system require different voltage level, it is necessary to adjust the additional board’s voltage level to the development system voltage level. It is performed by a voltage regulator supplied on additional board. Jumper J1 is used to select power supply voltage for the additional board. If board is

connected to 5v development system, it is necessary to place jumper J1 in 5v position. For 3.3v development system, jumper J1 should be placed in 3.3v position. In addition to the voltage level adjustment, it should necessary to adjust Voltage signal provide by ZigBee module. The additional board features transceivers 74lLVCC3245 & 74LVC1T45 that serve as voltage level translators.

Fig. 4(b) Easy Bee 3 board [4]

4.2.2 MRF24J40MA TRANSCEIVER 

MRF240J40MA Transceiver has integrated PCB antenna and has the range of 40 meters for indoor communication and 100 meters for line sight of communication.



Low Current Consumption Rx mode:19 mA Tx mode:23 mA Sleep: 2 uA



Operating Voltage:2.4-3.6v



Temperature range:-40oC to 50oC



ISM Band:2.405 to 2.48GHz



Data rate :250Kbps



Range : up to 400ft

Fig. 4(c) Diagram of MRF24J40MA Trans-receiver [15]

4.2.3 PIC16F887

In today’s embedded market there are lot of microcontroller is available from the different companies like Atmel, Microchip, Texas, Phillips and all other vendors. Our project requirement is the memory which is supported the ZigBee full stack for both RFD (Reduced Function Device) and FFD (Full Function Device). Also it should have the both SPI (Serial Peripheral interface) and USART (Universal Serial Synchronous & Asynchronous terminal).This all requirements are full filled by the PIC16F887 from microchip. So, we are using the PIC16F887 for our project. Also the ZigBee stack is also available as open source for this device. The pin diagram and features for this PIC16F887 is listed below.

PIC16F887 The PIC16F887 is one of the latest products from Microchip. It features all the components which modern microcontrollers normally have. Fortis low price, wide range of application, high quality and easy availability, it is an ideal solution in applications such as: the control of different Processes in industry, machine control devices, measurement of different values etc. Some of its main features are listed in the table.

Table 4.1 Features of the PIC16F887

Fig. 4(d) PIC16F887 Pin Diagram[15]

4.2.4 PICkit-3 Microchip’s PICkit 3 In-Circuit Debugger/Programmer uses in-circuit debugging logic incorporated into each chip with Flash memory to provide a low-cost hardware debugger and programmer. In-circuit debugging offers these benefits:



Low cost



Minimum of additional hardware needed for debug



Expensive sockets or adapters are not required

Fig. 4(e) PICkit-3[15] The MPLAB PICkit 3 allows debugging and programming of PIC and dsPIC Flash microcontrollers at a most affordable price point using the powerful graphical user interface of the MPLAB Integrated Development Environment (IDE). The MPLAB PICkit 3 is connected to the design engineer's PC using a full speed USB interface and can be connected to the target via an Microchip debug (RJ-11) connector (compatible with MPLAB ICD 2, MPLAB ICD 3 and MPLAB REAL ICE). The connector uses two device I/O pins and the reset line to implement in-circuit debugging and In-Circuit Serial Programming™.

Key Features 

USB (Full speed 12 Mbits/s interface to host PC)



Real-time execution



MPLAB IDE compatible (free copy included)



Built-in over-voltage/short circuit monitor



Firmware upgradeable from PC/web download



Totally enclosed



Supports low voltage to 2.0 volts (2.0v to 6.0v range)



Diagnostic LEDs (power, busy, error)



Read/write program and data memory of microcontroller



Erase of program memory space with verification



Freeze-peripherals at breakpoint



Program up to 512K byte flash with the Programmer-to-Go

4.2.5 SENSORS

4.2.5.1 TEMPERATURE SENSOR (DS18B20)

DESCRIPTION The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of -55°C to +125°C and is accurate to ±0.5°C over the range of -10°C to +85°C. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply. Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems.

FEATURES 

Unique 1-Wire® Interface Requires Only One Port Pin for Communication



Each Device has a Unique 64-Bit Serial Code Stored in an On-Board ROM



Multidrop Capability Simplifies Distributed Temperature-Sensing Applications



Requires No External Components



Can Be Powered from Data Line; Power Supply Range is 3.0V to 5.5V



Measures Temperatures from -55°C to +125°C (-67°F to +257°F)



±0.5°C Accuracy from -10°C to +85°C



Thermometer Resolution is User Selectable from 9 to 12 Bits



Converts Temperature to 12-Bit Digital Word in 750ms (Max)

PIN CONFIGURATION

Fig. 4(f) DS18B20 with Pin Diagram[21]

PIN DESCRIPTION P SO 1, 2, 6, 3

µSOP TO-92 2, 3, — 5, 8

3

NAME N.C. VD D

4

1

2

5

4

1

D Q GND

FU NC No Connection Optional VDD. VDD must be grounded for operation in parasite power mode. Data Input/Output. Open-drain 1-Wire interface pin. Also provides power to the device when used in parasite power mode (see the Powering Ground

Table 4.2 PIN out of the DS18B20[21]

3.2.5.2 PROXIMITY SENSOR

Gnd DQ

Vcc

Fig. 4(g) Proximity Sensor A proximity sensor is a sensor able to detect the presence of nearby objects without any physical contact.

A proximity sensor often emits an electromagnetic field or a beam of electromagnetic radiation (infrared, for instance), and looks for changes in the fieldor return signal. The object being sensed is often referred to as the proximity sensor's target. Different proximity

sensor

targets

a capacitive photoelectric

demand

sensor might

different be

suitable

sensors. for

For a

plastic

example, target;

an inductive proximity sensor always requires a metal target. The maximum distance that this sensor can detect is defined "nominal range". Some sensors have adjustments of the nominal range or means to report a graduated detection distance. Proximity sensors can have a high reliability and long functional life because of the absence of mechanical parts and lack of physical contact between sensor and the sensed object. Proximity sensors are also used in machine vibration monitoring to measure the variation in distance between a shaft and its support bearing. This is common in large steam turbines, compressors, and motors that use sleeve-type bearings. The basic output from the Proximity sensor which we used is as below;

Target Detection

Logic Level

Output Voltage

Detected

1

3.67v

Not-detected

0

0.66v

Table 4.3 Output Logic of the Proximity Sensor

4.3 SOFTWARE RESOURCES

The system consists of a transmitter that grabs the switch data directly from the port of the microcontroller meant for transmitting the switch status. On the transmitter side it required to write software for PIC microcontroller that can read the microcontroller port

of existing system. The PIC microcontroller is interfaced with ZigBee module for wireless connectivity. The software for PIC microcontroller also requires handling the ZigBee protocol stack. It is required to write software to utilizing important function available in the form of this protocol stack. On the receiver side as well similar functionalities for the implementation of software is required. On the receiver side the data will be useful for the call and SMS purpose. The software for this task is written in the Embedded C language using Micro C Pro for PIC compiler available from Mikroelektronika. Flow in algorithm tic manner and the detail of the compiler is listed below.

4.3.1Mikro C Pro IDE for PIC from Mikroelektronika The mikro C PRO for PIC is a powerful, feature-rich development tool for PIC microcontrollers. It is designed to provide the programmer with the easiest possible solution to developing applications for embedded systems, without compromising performance or control. Mikro C PRO for PIC provides a successful match featuring highly advanced IDE, ANSI compliant compiler, broad set of hardware libraries, comprehensive documentation, and plenty of ready-to-run examples. Features: 1) Mikro C PRO for PIC allows you to quickly develop and deploy complex applications: 2) Write your C source code using the built-in Code Editor (Code and Parameter Assistants, Code Folding, Syntax Highlighting, Auto Correct, Code Templates, and more.) 3) Use included mikro C PRO for PIC libraries to dramatically speed up the development: data acquisition, memory, displays, conversions, communication etc. 4) Monitor your Program structures, variables and function in the code Explorer.

5) Generate commented, human-readable assembly, and standard HEX compatible with all programmers.

Fig. 4(h) Screen shot of mikro C Pro Compiler[15] 6) Inspect program flow and debug executable logic with the integrated Software Simulator. 7) Generate COFF (Common Object File Format) file for software and hardware debugging under Microchip's MPLAB software. 8) Mikro C PRO for PIC provides plenty of examples to expand, develop, and use as building bricks in your projects. Copy them entirely if you deem fit – that’s why we included them with the compiler.

Creating New Project in MikroC Pro Compiler The Process of creating new project is very simple. Select the New Project option from the Project Menu, as shown in Figure.

A window called New Project Wizard Fig., which will guide through the process of creating a new project, appears. The introductory window of this application contains a list of actions to be performed when creating a new project. Click Next. The process of creating new project can be broken up in to five basic steps: 1) Selecting the microcontroller to write a program for, in the case it is PIC 16F887. 2) Selecting the device clock, In this case, it is 8 MHz.

Fig. 4(i) Screenshot for Creating New file in Mikro C[15]

3) In the event that the project consists of several source files, it is necessary to specify them all and include into the project by clicking the add button. 4) After all, it is necessary to confirm all selected options by clicking Finish.

Fig.4(j) Screenshot for Creating New file in Mikro C[15] When the program is written, it is necessary to compile it into a program (.hex) code, by selecting one of the build options from the Project menu shown in Figure above. To create a Hex file, select Build (Ctrl+F9) from the Project menu. Or click the Build icon from the Project tool bar. The Build all Projects (Shift+F9) option builds all the files within the project. The Build+Program (Ctrl+F11) option is available which is special as it enables the mikroC PRO for PIC compiler to automatically load the program into microcontroller after compilation. The process of programming is performed by using PICflash programmer. All the errors detected during compilation will be shown in the Message Window. If no errors are encountered, the mikroC PRO for PIC compiler will generate output hex files.

4.3.2 MPLAB IDE MPLAB Integrated Development Environment (IDE) is a free, integrated toolset for the development of embedded applications on Microchip’s PIC and dsPIC microcontrollers.

The below steps guide through the loading of HEX file into the ICs.

1. Open the MPLAB IDE v8.60 and select the Programmer tab and in that PICkit-3.

Fig. 4(k) Screenshot for selecting PICkit-3 in MPLAB[15] 2. Then select the configure tab and go-to select device option and select the particular device which is used.

Fig. 4(l) Screenshot for selecting IC in MPLAB[15] 3. Then click on the File tab and go-to the Import option and select the HEX file which needs to be load.

Fig. 4(m) Screenshot for loading HEX file in MPLAB[15]

3.3.3 Serial Port Monitor / Real term

The above software provides the below features to monitor the serial port of the PC. •

The unique serial port communication data monitoring solution



Driver-based tool that helps developers to analyze functionality of any com port application



It's an invaluable utility for both software and hardware developers since it helps them to discover communication errors of serial port devices and applications



Powerful rs232 data sniffer with outstanding performance

Serial Port Monitor monitors serial ports used by any applications running on Windows NT 4.0, Windows 2000, Windows XP and Windows 2003 Server. The program intercepts, displays and analyzes all data, transferred between any Windows application and the device connected to the serial port. This software can be successfully used to track the behavior of programs, serial protocols, and also for effective software debugging, device drivers or serial hardware development.

Its efficient mechanisms help to quickly find and eliminate any software or hardware errors. This is a completely software solution, no additional hardware is required. The output can be stored into the .text or .log file which is shown below as the sample of our project.

Fig. 4(n) Screenshot of DATA logging in Serial port monitor[19]

Fig. 4(o) Screenshot of DATA logging in Realterm[20]

CHAPTER 5 SCHEMATIC OF HARDWARE 5.1 SCHEMATIC DESIGN

For designing the schematic the first and for most step is to work out on interfacing between PIC16f887 and EasyBee3 Board. The Pin diagram of PIC 16F887 is shown in the fig.

Fig. 5(a) PIC16F887 Pin Diagram [15] PIC16F887 is a 40 pin DIP having bidirectional I/0 ports namely Port A,B,C,D and port E. Out of which Port A,B,C,D are of 8 pins whereas Port E has 4 pins. To connect the sensing element in the wireless security system using ZigBee we are using Port D at the transmitter side. At the receiver side we are using Port C for the communication with the GSM module via male to male serial cable.

To connect the sensing element in the wireless security system using ZigBee we are using Port D at the transmitter side. At the receiver side we are using Port D (pin no 1, 3, 5, 7) for the interfacing of DC motor along with motor driver IC LM293. Serial Peripheral Interface (SPI) Bus: The SPI is used for a synchronous serial communication of host micro controller and peripherals. SPI requires two control lines (CS and SCK) and two data lines (SDI and SDO) as shown in Fig. 7 (e). The SPI bus specifies four logic signals: 

SCK – Serial Clock, provided by master



CS – Chip Select, allow master to select peripheral (slave) device



MOSI/SDI – Master Output Slave Input/Serial Data In



MISO/SDO – Master Input Slave Output/Serial Data Out

Fig. 5(b) Simple Master Slave Implementation using SPI bus [15]

With CS active low, the corresponding peripheral device is selected. A master, usually the host micro controller, always provides clock signal to all devices on a bus whether it is selected or not. Only one master must be active on a bus at a time. The SPI protocol operates in full duplex mode, when input and output data transfers on both lines simultaneously. The unselected devices keep the SDO lines in hi-Z state and therefore inactive.

PCB DESIGN SCHEMATIC:

Fig. 5(c) PCB Design Schamatic[15]

Fig. 5(d) Front View of PCB

Fig. 5(e) Back View of PCB

BASIC CONNECTION SCHEMETICS OF PROJECT :

Power supply MCU

MCU

Sensors

USART BUS

Power supply

MCU

Sensors

Fig. 5(f) BASIC PROJECT CONNECTION

PC

RS232 CONNECTION SCHEMETICS :

Fig. 5(g) RS232’s Connection To PC[15]

CHAPTER 6 PROJECT DETAILS

6.1 PROJECT 1

AIM: To develop a wireless communication between two ZigBee nodes (TX and Rx). ABOUT PROJECT: Our project is related to establishment wireless sensor network. We are using following components: •

EasyBee3 board,



PIC16F887 MCU,



MRF24J40MA Transceiver Module,



Easy PIC 5 development kit,



16x2 LCD and Boards specially designed for PIC16F887.



MicroC Pro IDE(Integrated development Environment).

We studied the sample code given by Microelectronika for EasyBee3 Board. We designed Two Board for PIC16F887.The program is about Transmitting 8 bit data at a time and receiving that data Serially at Receiver. At Receiver, we have connected 16x2 LCD on which the received data is to be displayed. When you powered up both the nodes, there will be communication between two nodes. And our message will be transferredfrom Transmitter to Receiver. So by using end to end communication we can make-out the wireless sensor network to implement security or any temperature control device. Here we only establish the end to end wireless network, but we thought to expand it to handle the real time data to make it out like most of the real-time operating application.

CIRCUIT:

Receiver

Transmitter

Fig. 5(a) Circuit connection for data communication

6.2 PROJECT 2 AIM: To establish Star topology Using Zigbee wireless Protocol. HARDWARE DETAILS: •

EasyBee3 board,



PIC16F887 MCU,



XELTEK Superpro IC burner



MRF24J40MA Transceiver Module,



16x2 LCD and Boards specially designed for PIC16F887.



MicroC Pro IDE (Integrated development Environment).

DESCRIPTION: After Performing End to End communication, we have decided to implement the different topology like Star topology, Tree topology, Ring Topology. So we made another PCB module for PIC16F887. We made Star topology using three node. We burnt the code for receiver in two different modules and code for Transmitter in one module. One thing should be noticed that to implement different topologies we need to change the PAN Ids of different nodes. So to establish STAR topology we should set PAN Id of all nodes to the same value. Here we set the transmitted data length of three. So we can Transmit 3 letters in each data packet. We Transmit ‘Z’, ’b’ and Third integer number which is incremented every time.

When we powered up all three nodes, there will be

communication between them. And our message will be Transferred from Transmitter to both Receiver.

CIRCUIT: TRANSMITTER:

Fig. 5(b) Circuit connection for data communication at transmitter side

RECEIVER:

Receiver-2

Receiver-1

Fig. 5(c) Circuit connection for data communication at receiver side

6.3 ZIGBEE CODE (MAIN) i)

TRANSMITTER

II)

RECEIVER

6.3.1 AT TRANSMITTER SIDE

void main(){ short int temp1 = 0; ANSEL = 0;

// Configure AN pins as digital

ANSELH = 0; C1ON_bit = 0;

// Disable comparators

C2ON_bit = 0; GIE_bit = 0;

// Disable interrupts

TRISA = 0x00;

// Set direction to be output

TRISB = 0x00;

// Set direction to be output

TRISC = 0x00;

// Set direction to be output

TRISD = 0x00;

// Set direction to be output

CS_Direction = 0;

// Set direction to be output

RST_Direction = 0;

// Set direction to be output

INT_Direction = 1;

// Set direction to be input

WAKE_Direction = 0;

// Set direction to be output

Delay_ms(5); // Initialize SPI module SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH); pin_reset();

// Activate reset from pin

software_reset();

// Activate software reset

RF_reset();

// RF reset

set_WAKE_from_pin();

// Set wake from pin

set_long_address(ADDRESS_long_1);

// Set long address

set_short_address(ADDRESS_short_1);

// Set short address

set_PAN_ID(PAN_ID_1);

// Set PAN_ID

init_ZIGBEE_nonbeacon();

// Initialize ZigBee module

nonbeacon_PAN_coordinator_device(); set_TX_power(31);

// Set max TX power

set_frame_format_filter(1);

// 1 all frames, 3 data frame only

set_reception_mode(1);

// 1 normal mode

pin_wake();

// Wake from pin

DATA_TX[0] = 'Z';

// First byte of data for sending

DATA_TX[1] = 'b';

// Second byte of data for sending

DATA_TX[2] = 0;

// Third byte of data for sending

PORTD = 0;

while(1){ write_TX_normal_FIFO();

// Infinite loop // Transmiting

Delay_ms(1000); DATA_TX[2]++;

// Incremeting value

PORTD++;

// Showing value that is sent on

PORTD } }

6.3.2 AT RECEIVER SIDE

void main(){ short int temp1 = 0; ANSEL = 0;

// Configure AN pins as digital

ANSELH = 0; C1ON_bit = 0;

// Disable comparators

C2ON_bit = 0; GIE_bit = 0;

// Disable interrupts

TRISA = 0x00;

// Set direction to be output

TRISB = 0x00;

// Set direction to be output

TRISC = 0x00;

// Set direction to be output

TRISD = 0x00;

// Set direction to be output

CS_Direction = 0;

// Set direction to be output

RST_Direction = 0;

// Set direction to be output

INT_Direction = 1;

// Set direction to be input

WAKE_Direction = 0;

// Set direction to be output

Delay_ms(5); // Initialize SPI module SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH); pin_reset();

// Activate reset from pin

software_reset();

// Activate software reset

RF_reset();

// RF reset

set_WAKE_from_pin();

// Set wake from pin

set_long_address(ADDRESS_long_2);

// Set long address

set_short_address(ADDRESS_short_2);

// Set short address

set_PAN_ID(PAN_ID_2);

// Set PAN_ID

init_ZIGBEE_nonbeacon();

// Initialize ZigBee module

nonbeacon_PAN_coordinator_device(); set_TX_power(31);

// Set max TX power

set_frame_format_filter(1);

// 1 all frames, 3 data frame only

set_reception_mode(1);

// 1 normal mode

pin_wake();

// Wake from pin

Lcd_Init();

// Initialize LCD

Lcd_Cmd(_LCD_CLEAR);

// Clear display

Lcd_Cmd(_LCD_CURSOR_OFF);

// Cursor off

Lcd_Out(1,1,"RX: 1[ADITEC09] :");

// Write on LCD

// Lcd_Out(1,1,"RX: 1[ADITEC09] :");

// For RX: 2(module 2)

ByteToStr(0,&txt); while(1){

// Infinite loop

if( debauns_INTn() == 0 ){

// Polling line INT

temp1 = read_ZIGBEE_short(INTSTAT);

// Read and flush register INTSTAT

read_RX_FIFO();

// Read receive data

ByteToStr(DATA_RX[2],&txt);

// Convert third byte to string

Lcd_Chr(2,1,DATA_RX[0]);

// Display first received byte

Lcd_Chr(2,2,DATA_RX[1]);

// Display second received byte

Lcd_Out(2,5,txt);

// Display third received byte

} } }

6.4 PROJECT 3

AIM: Real time data acquisition in PC using ZigBee wireless Network for Temperature and proximity sensor. ABOUT PROJECT: Component used: •

EasyBee3 board,



PIC16F887 MCU,



MRF24J40MA Transceiver Module,



Easy PIC 5 development kit,



16x2 LCD



Boards specially designed for PIC16F887



MicroC Pro IDE(Integrated development Environment)



MPLab IDE



PICkit 3 by Mikroelectronica



MAX 232(to interface PIC with PC)



RS232 to USB converter



Real Term serial data capture software



DS18B20 Temperature Sensor

6.4.1 PROJECT DESCRIPTION: We established a tree network of three ZigBeenodes(having two Transmitter and one receiver). Further we have interfaced temperature sensor to one transmitter to sense the temperature from remote location. We have also interfaced Proximity sensor which gives TTL output according to the proximity condition. These both sensors are interfaced with two different ZigBee nodes and they are configured as transmitter. Now in our network we have one node which is configured as receiver and is connected with PC through RS232 Serial port. This Receiver gets the data from both the nodes simultaneously and decides according to CSMA protocol which data is to be received. As the frequency of door’s open and close condition is less, we have put more

delay at the node having proximity sensor. While the instantaneous temperature is being displayed continuously.

Transmitter 1(proximity sensor): •

Range can be calibrated. We used around 0.5 - 1 cm to sense the proximity as we are using this sensor to sense door condition (open or close).



Uses One-wire protocol Door condition

Output voltage at

Transmitted

sensor data pin

message

open

3.64 V

-open-

close

0.6 V

-close

Transmitter 2(temperature sensor): • • •

Range: -55°C to +125°C Uses one-wire protocol Accuracy: +/-0.5 V



Transmit Data : 7 Bytes



Two temperature resolution 9 bit and 12 bit. We are using 9 bit resolution. DS18B20

Transmitter-2

Proximity Sensor

Transmitter-1

Receiver (connected with PC through RS232):



At Receiver side one 16X2 LCD is connected and it displays received data(It could be temperature or door condition) .



At the same time this received bytes go to PC (through RS232 port and RS232 to USB converter).



RealTerm serial data capture software catches the data from PIC controller through serial port.



We set the same bode rate at receiver and in Realterm software to make communication between them.

6.4.2 C code: 1) At Transmitter1(proximity sensor):

void main(){ shortint temp1 = 0; bitoldstate ; charuart_rd; oldstate =0; ANSEL = 0;

// Configure AN pins as digital

ANSELH = 0; C1ON_bit = 0;

// Disable comparators

C2ON_bit = 0; GIE_bit = 0;

// Disable interrupts

TRISA = 0x00;

// Set direction to be output

TRISB = 0x00;

// Set direction to be output

TRISC = 0x00;

// Set direction to be output

//TRISD = 0x00; CS_Direction = 0;

// Set direction to be output // Set direction to be output

RST_Direction = 0;

// Set direction to be output

INT_Direction = 1;

// Set direction to be input

WAKE_Direction = 0; Delay_ms(5); // Initialize SPI module

// Set direction to be output

SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH); pin_reset();

// Activate reset from pin

software_reset();

// Activate software reset

RF_reset();

// RF reset

set_WAKE_from_pin();

// Set wake from pin

set_long_address(ADDRESS_long_1);

// Set long address

set_short_address(ADDRESS_short_1);

// Set short address

set_PAN_ID(PAN_ID_1);

// Set PAN_ID

init_ZIGBEE_nonbeacon();

// Initialize ZigBee module

nonbeacon_PAN_coordinator_device(); set_TX_power(31);

// Set max TX power

set_frame_format_filter(1);

// 1 all frames, 3 data frame only

set_reception_mode(1);

// 1 normal mode

pin_wake();

// Wake from pin

TRISD0_bit = 1; UART1_Init(9600); Delay_ms(100);

// Initialize UART module at 9600 bps // Wait for UART module to stabilize

UART1_Write_Text("Start"); UART1_Write(10); UART1_Write(13);

while(1){ if (Button(&PORTD, 0, 1, 1)) {

// Detect logical one

oldstate = 1;

// Update flag

DATA_TX[0] = '-';

// First byte of data for sending

DATA_TX[1] = 'c';

// Second byte of data for sending

DATA_TX[2] = 'l';

// First byte of data for sending

DATA_TX[3] = 'o';

// Second byte of data for sending

DATA_TX[4] = 's';

// First byte of data for sending

DATA_TX[5]= 'e';

// Incremeting value

}

if (oldstate&& Button(&PORTD, 0, 1, 0)) { // Detect one-to-zero transition oldstate = 0;

// Update flag

DATA_TX[0] = '-';

// First byte of data for sending

DATA_TX[1] = 'o';

// Second byte of data for sending

DATA_TX[2] = 'p';

// First byte of data for sending

DATA_TX[3] = 'e';

// Second byte of data for sending

DATA_TX[4] = 'n';

// First byte of data for sending

DATA_TX[5]= '-';

// Incremeting value

} write_TX_normal_FIFO();

// Infinite loopTransmiting

Delay_ms(3000); //PORTD++;

// Showing value that is sent on PORTD

} }

2) Transmitter 2(temperature sensor): void main(){ shortint temp1 = 0; ANSEL = 0; ANSELH = 0; C1ON_bit = 0; C2ON_bit = 0; GIE_bit = 0; TRISA = 0x00; TRISB = 0x00;

// Configure AN pins as digital // Disable comparators // Disable interrupts // Set direction to be output // Set direction to be output

TRISC = 0x00; TRISD = 0x00;

// Set direction to be output // Set direction to be output

CS_Direction = 0; // Set direction to be output RST_Direction = 0; // Set direction to be output INT_Direction = 1; // Set direction to be input WAKE_Direction = 0; // Set direction to be output ANSELE = 0; TRISE.B2 = 1;

// Configure PORTE pins as digital // Configure RE2 pin as input

Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off Lcd_Out(1, 1, " Tx.Temperature: "); // Print degree character, 'C' for Centigrades Lcd_Chr(2,13,223); // Different LCD displays have different char code for degree // If you see greek alpha letter try typing 178 instead of 223 Lcd_Chr(2,14,'C'); Delay_ms(5); // Initialize SPI module SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH); pin_reset(); // Activate reset from pin software_reset(); // Activate software reset RF_reset(); // RF reset set_WAKE_from_pin(); // Set wake from pin set_long_address(ADDRESS_long_1); // Set long address set_short_address(ADDRESS_short_1); // Set short address set_PAN_ID(PAN_ID_1); // Set PAN_ID init_ZIGBEE_nonbeacon(); // Initialize ZigBee module nonbeacon_PAN_coordinator_device(); set_TX_power(31); // Set max TX power set_frame_format_filter(1); // 1 all frames, 3 data frame only set_reception_mode(1); // 1 normal mode pin_wake();

// Wake from pin

PORTD = 0; while(1){ Ow_Reset(&PORTE, 2);

// Onewire reset signal

Ow_Write(&PORTE, 2, 0xCC); Ow_Write(&PORTE, 2, 0x44); Delay_us(120);

// Issue command SKIP_ROM // Issue command CONVERT_T

Ow_Reset(&PORTE, 2); Ow_Write(&PORTE, 2, 0xCC); Ow_Write(&PORTE, 2, 0xBE); READ_SCRATCHPAD

// Issue command SKIP_ROM // Issue command

temperature = Ow_Read(&PORTE, 2); temperature = (Ow_Read(&PORTE, 2)
Lihat lebih banyak...

Comentários

Copyright © 2017 DADOSPDF Inc.