Sei sulla pagina 1di 146

Wireless Transmission Line Fault Detection Using RF

Session 2011-2015

Project Supervisor

Engr. Musawar Hussain

Submitted By

Abdul Rehman Samad 211-19345


Nawaf Muhammad Tahir 211-19337
Muhammad Usman Nazir 311-20372

Department of Electrical Engineering


Hajvery University, Lahore
A report submitted to the
Department of Electrical Engineering
In partial fulfillment of the requirements for the

Degree

Bachelor of Science
In
Telecommunication/Electronics
By

Abdul Rehman Samad


Nawaf Muhammad Tahir
Muhammad Usman Nazir

_______________ ________________
Supervisor Dean

Hajvery University, Lahore


A cknowledgement
First of all, we would like to thank Almighty ALLAH for giving us strength to complete our
final year project. Then to thank our parents without their support this project was impossible to
finish. We truly acknowledge the cooperation and help make by Mr. MUSAWAR HUSSAIN
Project Advisor and Brig®. Prof. Dr. NAEEM AFRIDI, Dean of Hajvery University. The project
wouldn’t have been in the present form without his unflagging guidance and support. He took
out his precious time and helped us right from the beginning of the project. He has been a
constant source of guidance throughout the course of this project. We also take this opportunity
to thank all those persons/teachers we have consulted during the course of project making.

Lastly, we thank all our teachers who have sweated their guts during these four years to train us
as efficient engineers.

Abdul Rehman Samad 211-19345

Nawaf Muhammad Tahir 211-19337

Muhammad Osman Nazir 311-20372

12th August, 2015


A bstract

The concept of our project revolves around the sensor node which is essentially is a sensor,
microcomputer, power source and transceiver which form the input stage of any system. It
detects some physical parameter (temperature, pressure, proximity, vibration, sound,
electromagnetic, etc.), converts it into quantifiable data and sends the data to a host for
processing. The information is then collected by the system along with all the other sensors for a
specific control or monitoring task.

Wireless sensors gather information about the physical environment and connect it to systems
and networks to provide monitoring, automation and control for many varied applications. The
uses of wireless sensor networks are almost unlimited with many industries and applications
having specific technology requirements such as reliability, permanence, battery life, range,
frequencies and sensor use. These systems can take the form of security systems, monitoring
equipment and machinery in factories, monitoring forces.

Current and future design goals in the aerospace sensors and transducers field call for the
development of new sensing devices that require less electrical power, occupy less space, and
weigh less. Self-calibration, self-health assessment, processing of raw data at the sensor level,
and alternate data transmission methods are desired to provide the user with information in a
more efficient way. The Instrumentation Branch of the NASA Spaceport Engineering and
Technology Directorate at Kennedy Space Center, along with Dynacs Inc., was tasked to
investigate new ways to design and develop transducers with these characteristics. As part of the
initial efforts to acquire the skills and new technologies for such pursuits, the Transducers
Development Group began investigating the use of wireless communications at the sensor level.

Hajvery University Lahore ii


LIST OF FIGURES

[1] Figure 1.1: Wireless sensors implementation 3


[2] Figure 1.2: Node unit 5
[3] Figure 1.3: Base unit 6
[4] Figure 1.4: Power supply unit 6
[5] Figure 2.1: Sensor Node Network Block Diagram 9
[6] Figure 2.2: Block Diagram Sensor Node 11
[7] Figure 2.3: Block Diagram Base Node 12
[8] Figure3.1: Design of Temperature sensor 16
[9] Figure3.2: Implementation of Temperature sensor 16
[10] Figure3.3: Design of Voltage Measuring Circuit 17
[11] Figure3.4: Implementation of Voltage Sensor 18
[12] Figure3.5: Design of Current Sensor 19
[13] Figure3.6: Implementation of Current Sensor 20
[14] Figure3.7: Design of PSU 22
[15] Figure3.8: Full-wave rectifier 24
[16] Figure4.1: Pin Configuration 32
[17] Figure4.2: Block Diagram 36
[18] Figure4.3: Serial Data transmission 37
[19] Figure4.4: Schematic diagram 39
[20] Figure4.5: Lcd Interface with PIC 41
[21] Figure5.1: Serial Vs Parallel Data Transfer 44
[22] Figure5.2: Simplex, Half-, Full-Duplex Transfer 45
[23] Figure5.3: Framing ASCII "A" (41H)” 45
[24] Figure5.4: Null Modem Connection 47
[25] Figure5.5: MAX232 Pin Description 48
[26] Figure5.6: MAX232 Typical Connection Circuit 49
[27] Figure5.7: Interfacing b/w computer and PIC through RS232 50
[28] Figure5.8: Schematic of max232” 51
[29] Figure5.9: RS232 Connector DB-25 52
[30] Figure5.10:DB-9 Pin Connector 52
[31] Figure6.1: Pin configuration of PT2262 60
[32] Figure6.2: Pin configuration of PT2272 61
[33] Figure6.3: ASK 66
[34] Figure6.4: PSK 66
[35] Figure6.5: FSK 67
[36] Figure6.6: BFSK 69

Hajvery University Lahore iii


LIST OF TABLES

[1] Table4.1: Pin Description1 33

[2] Table4.2: Pin Description2 34

[3] Table4.3: Comparison 35

[4] Table4.4: Absolute maximum ratings 40

[5] Table4.5: Reliability characteristics 40

[6] Table4.6: Interfacing 41

[7] Table5.1: Pin description of RS232 52

[8] Table 6.1: RF Spectrum 57

Hajvery University Lahore iv


Table of Contents
Statement Of Submission..............................................................................................................i
Acknowledgements.......................................................................................................................ii
Abstract.........................................................................................................................................iii
Table of Figures............................................................................................................................iv
List of Tables.................................................................................................................................v
Table of Contents..........................................................................................................................vi
Chapter 1 ................................................................................................................................... 1
Introduction ................................................................................................................................ 1
1.1 Project Introduction ............................................................................................................ 2
1.2 Motivation .......................................................................................................................... 3
1.3 Aim of project ..................................................................................................................... 3
1.4 Historical Review ............................................................................................................... 4
1.5 Background of Wireless sensors ........................................................................................ 4
1.6 Basics of Monitoring System .............................................................................................. 4
1.7 Applications ....................................................................................................................... 4
1.8 Block diagrams .................................................................................................................. 5
Chapter 2 ................................................................................................................................ 7
System Description .................................................................................................................... 7
2.1 Wireless Sensor Network ................................................................................................... 8
2.2 Sensor Nodes Network ...................................................................................................... 9
2.3 Sensor Node .....................................................................................................................10
2.3.1 Operation of Nodes ...................................................................................................10
2.3.2 Block diagram ...........................................................................................................11
2.4 Base Node ........................................................................................................................11
2.4.1 Operation of Base Node ............................................................................................11
2.4.2 Block diagram ...........................................................................................................12
Chapter 3 ................................................................................................................................13
Sensors.....................................................................................................................................13
3.1 Introduction .......................................................................................................................14
3.2 Types of Sensors to be used ............................................................................................14
3.2.1Temperature Sensor ..................................................................................................14
(a)Types of Temperature Sensors ..................................................................................14

Hajvery University Lahore v


(b)Semiconductor temperature sensor (LM35) ...............................................................15
(c)The LM35 ...................................................................................................................15
i. Specification.............................................................................................................15
ii. Design of temperature sensor .................................................................................16
iii. Working of temperature Sensor ..............................................................................16
iv. Implementation .......................................................................................................16
3.2.2 Voltage sensor ..........................................................................................................17
(a)Specification...............................................................................................................17
(b)Design........................................................................................................................17
(c)Working ......................................................................................................................17
(d) Implementation .........................................................................................................18
3.2.3 Current Sensor ..........................................................................................................19
(a)Specification...............................................................................................................19
(b)Design........................................................................................................................19
(c)Working ......................................................................................................................20
(d)Implementation ..........................................................................................................20
(e)Lm324 ......................................................................................................................201
i.Specification............................................................................................................211
3.3 Power supply ..................................................................................................................211
3.3.1 Design.....................................................................................................................222
3.3.2 Working ...................................................................................................................222
(a) Conversion of AC to DC ..........................................................................................222
(b )Regulation of Output Voltage ..................................................................................233
3.3.3 Rectification ............................................................................................................233
(a) Full-wave rectification ..............................................................................................233
(b)Rectifier output smoothing........................................................................................244
Chapter 4 .............................................................................................................................255
PIC Microcontroller .................................................................................................................255
4.1 Introduction to Microcontroller .........................................................................................266
4.2 Criteria for Choosing a Microcontroller ............................................................................266
4.3 PIC microcontroller .........................................................................................................277
4.3.1 Features ....................................................................................................................28
4.4 Microcontroller PIC 16F877 ..............................................................................................28

Hajvery University Lahore vi


4.4.1 Features of PIC 16F877 ............................................................................................28
4.4.2 Ports description .......................................................................................................29
(a)PORT A and the TRIS(Tri-state) A Registers ............................................................29
(b)PORT B and the TRIS B Registers ............................................................................30
(c)PORT C and the TRIS C Registers ............................................................................30
(d)PORT D and TRIS D Registers ................................................................................311
(e)PORT E and TRIS E Registers ................................................................................311
4.4.3 Pin configuration .....................................................................................................322
4.4.4 Pin description of PIC 16F877 .................................................................................333
4.4.5 Comparison with other PIC controllers ....................................................................355
4.4.6 Block Diagram .........................................................................................................366
4.5 Interfacing PIC with MAX232 ..........................................................................................377
4.5.1 PIC USART .............................................................................................................377
4.6 PIC interfacing with LCD ...................................................................................................39
4.6.1 JHD164 Features ......................................................................................................39
4.6.2 Absolute maximum ratings ......................................................................................400
4.6.3 Reliability ................................................................................................................400
(a)Operating life time ....................................................................................................400
(b)Reliability characteristics ..........................................................................................400
4.6.4 Interface ..................................................................................................................411
4.6.6 LCD Pin connections with Microcontroller ...............................................................411
Chapter 5 ..............................................................................................................................422
Serial communication ..............................................................................................................422
5.1 Introduction to serial Communication ..............................................................................433
5.2 Basics of Serial Communication......................................................................................434
5.3 Half- and full-duplex transmissions .................................................................................444
5.3.1 Start and Stop Bits ..................................................................................................455
5.4 Data Communication Classification.................................................................................466
5.5 Data Transfer Rate .........................................................................................................477
5.6 MAX232 ..........................................................................................................................477
5.6.1 Features ..................................................................................................................477
5.6.2 Description ................................................................................................................49
5.6.3 MAX232 Interfacing with Serial port ........................................................................500

Hajvery University Lahore vii


5.6.4 Schematic ...............................................................................................................511
5.7 RS232 Standards ...........................................................................................................511
5.7.1 RS232 Pins .............................................................................................................522
5.8 Baud Rate.........................................................................................................................53
5.9 Maximum Transmission rate ...........................................................................................544
Chapter 6 ..............................................................................................................................555
Radio Frequency.....................................................................................................................555
6.1 Introduction .....................................................................................................................566
6.2 Specifications of RF Transceivers ...................................................................................577
6.3 Working of Transceiver .....................................................................................................59
6.4 RF transmitter Diagram .....................................................................................................59
6.5 RF receiver diagram .........................................................................................................59
6.6 PT2262 .............................................................................................................................59
6.6.1 Features ....................................................................................................................59
6.6.2 Pin Configuration.....................................................................................................600
6.7 PT 2272 ..........................................................................................................................600
6.7.1 Features ..................................................................................................................601
6.7.2 Pin Configuration.....................................................................................................611
6.8 CODEC chip principle PT2262/PT2272 Description ........................................................622
6.9 Modulation ......................................................................................................................623
6.10 Digital Communication ..................................................................................................644
6.11 Digital v/s Analog Transmission ....................................................................................644
6.12 Purpose of Digital transmission .....................................................................................644
6.13 Fundamental digital modulation methods ......................................................................655
6.13.1 Amplitude Shift Keying (ASK) ................................................................................666
6.13.2 Phase Shift Keying (PSK) .....................................................................................666
6.13.3 Frequency Shift Keying (FSK). ..............................................................................677
6.14 Criteria of choosing Modulation method ........................................................................677
6.15 Noise and Electrical distortion .........................................................................................69
6.16 Transmission characteristics .........................................................................................700
6.17 Directional transmission ................................................................................................700
6.18 Asynchronous VS Synchronous Transmission ..............................................................700
6.18.1 Asynchronous .......................................................................................................700

Hajvery University Lahore viii


6.18.1Example .................................................................................................................711
6.18.2 Synchronous .........................................................................................................722
Chapter 7 ...............................................................................................................................733
Source Code ...........................................................................................................................733
7.1 Base Unit Code...............................................................................................................744
7.2 Node Unit Code ................................................................................................................82
Chapter 8 ..................................................................................................................................92
Conclusion and Future Work .....................................................................................................93
8.1 Introduction .....................................................................................................................933
8.2 Conclusion ......................................................................................................................933
8.3 Future work .....................................................................................................................944
8.4 Cost analysis .....................................................................Error! Bookmark not defined.5
8.5 Time Analysis .................................................................................................................956
Chapter 9 ..................................................................................................................................97
9.1 References .....................................................................................................................988
Appendix A .............................................................................................................................99
Appendix B ..........................................................................................................................1122
Appendix C .........................................................................................................................1199

Hajvery University Lahore ix


Chapter 1
Introduction

Hajvery University Lahore 1


1.1 Project Introduction
This Project is about working of wireless sensors, how they work, how specified data
transmit through them, what factors affect our accurate reading while data transmission and
how the data could help us in protecting the devices.

This section will give some brief details of the project. The goal of this project is to utilize
the after-market parts and build a Communication system. This section will also state the
basic characteristics of the project. The basic idea behind the project is to develop a smart
system that can be used for communication purpose between two nodes.

The main function of these circuits is to send information of sensors to the computer by
wireless communication. We chose this as our final project because we were inspired by the
recent technological trend in wireless communication systems.

Circuit has one node unit and one base unit. Node unit send the information of sensors to the
base unit or when the base unit ask for the information of sensors to the node.

Node unit consists of three sensors temperature sensor, current sensor and voltage sensor and
a microcontroller and R.F module. These sensors send the analogue data to microcontroller
and first this data is converted to digital form in the microcontroller and then save that data in
it and display on LCD and also send data to R.F module by which this send to base unit.

Base unit consists of R.F module, microcontroller, RS232 serial cable. R.F module receives
data from node unit, delivers it to microcontroller and that data moves to computer by serial
cable RS232. This base unit also sends the query to get the information of sensors to get the
decision against information of nodes.

Hajvery University Lahore 2


“Figure 1.1: Wireless sensors implementation”

1.2 Motivation
The motivation factor in attempting this project was our learning, understanding and helping
the system to be improved. Imagine that a employee of electricity department is sitting in
front of his computer in base unit, and he wants to observe the voltage or current or
temperature or humidity of a specific area transmission line, rather to get the values by going
physically he get these values through wireless sensors, which would be an easier way and
gives relief to the employee.

1.3 Aim of project


The objective of this project is to develop a device that allows a user maximum relax ability.
This system will be a powerful and flexible tool that will offer this service at any time, and
from anywhere with the constraints of the technologies being applied. According to our
search, the current working systems have only on sensor at one node, but we tried to combine
four sensors at one node to make system more efficient and less costly.

The proposed approach for designing this system is to implement a microcontroller based
sensor and control module that receives and transmit the data from node to computer.

Hajvery University Lahore 3


1.4 Historical Review
Automatic monitoring has been played a vital role in advance of Engineering and Science. In
addition to its extreme importance in space-vehicle systems, missile-guidance systems,
robotic systems, and the like, monitoring systems has become an important and integral part
of modern manufacturing and industrial processes. For example monitoring is now, essential
in the design of autopilot systems in the aerospace industries, and in the design of cars and
trucks in the automobile industries. It is also essential in such industrial operations as
monitoring Pressure, Temperature, Humidity, Viscosity, and Flow in the process industries.

1.5 Background of Wireless sensors


The technological drive for smaller devices using less power with greater functionality has
created new potential applications in the sensor and data acquisition sectors. Low-power
microcontrollers with RF transceivers and various digital and analog sensors allow wireless,
battery-operated sensor modules (“nodes”) to acquire a wide range of data. MIT even
recognized wireless sensor networks as one of the ten emerging technologies that will change
the future (Technology Review, 1 February 2003).

1.6 Basics of Monitoring System


The applications of this system are quite diverse. There are many real life situations that
require transfer of data between remotely located devices. There will be instances where a
wised connection between a remote device and the control room might be not being feasible
due to structural problems. In such cases a wireless connection is a better option, especially,
when the distances are such that an IR (Infrared) link might prove to be useless.

1.7 Applications
 Military sensor to detect and gain as much information as possible about enemy
movements, explosions, and other phenomena of interest
 Sensor to detect and characterize Chemical, Biological, Radiological, Nuclear, and
Explosive (CBRNE) attacks and material
 Sensor networks to detect and monitor environmental changes in plains, forests,
oceans, etc.

Hajvery University Lahore 4


 Wireless traffic sensor to monitor vehicle traffic on highways or in congested parts of
a city
 Wireless surveillance sensor for providing security in shopping malls, parking
garages, and other facilities
 Wireless parking lot sensor to determine which spots are occupied and which are free

1.8 Block diagrams


The logical structure of our design is shown in the block diagrams in fig and fig. The micro
controller will handle all the equipment and keypad input, output information. The two block
diagram are given below first is for Transmitter and second is for Receiver. Schematic and
working of both transmitter and receiver is discussed in

“Figure 1.2: Node unit”

Hajvery University Lahore 5


“Figure 1.3: Base unit”

“Figure 1.4: Power supply unit”

Hajvery University Lahore 6


Chapter 2
System Description

Hajvery University Lahore 7


Wireless communication is one of the wonderful successes of electronics. Wireless systems
operate by transmission of date through space rather than through wired connection. The
primary advantage of wireless communication over wired communication is that
communication can take place without laying a wire between transmitter and receiver. This
means that users can communicate while moving or while temporarily stationed in some
location not attached to the wired network.

Wireless LANs are designed for much higher data rates. These are designed to connect PC’s,
shared peripheral devices, large computers etc., within an office building or similar local
environment. The use of infrared, RF and ultrasonic technologies have been proposed for
wireless communication

Wireless can be divided into:

 Fixed wireless -- the operation of wireless devices or systems in homes and offices,
and in particular, equipment connected to the Internet via specialized modems
 Mobile wireless -- the use of wireless devices or systems aboard motorized, moving
vehicles; examples include the automotive cell phone and PCS (personal
communications services)
 Portable wireless -- the operation of autonomous, battery-powered wireless devices or
systems outside the office, home, or vehicle; examples include handheld cell phones
and PCS units
 IR wireless -- the use of devices that convey data via IR (infrared) radiation;
employed in certain limited-range communications and control systems

2.1 Wireless Sensor Network

A Wireless Sensor Network (WSN) consists of multiple sensors to monitor physical or


environmental conditions, such as temperature, sound, vibration, pressure, motion or
pollutants and to cooperatively pass their data through the network to a main location. The
more modern networks are bi-directional, enabling also to control the activity of the sensors.
The development of wireless sensor networks was motivated by military applications such as
battlefield surveillance; today such networks are used in many industrial and consumer

Hajvery University Lahore 8


application, such as industrial process monitoring and control, machine health monitoring,
environment and home automation, and traffic control.

The WSN is built of "nodes" - from a few to several hundreds or even thousands, where each node is
connected to one (or sometimes several) sensors. Each such sensor network node has typically several
parts: a radio transceiver with an internal antenna or connection to an external antenna, a
microcontroller, an electronic circuit for interfacing with the sensors and an energy source, usually a
battery. A sensor node might vary in size from that of a shoebox down to the size of a grain of dust,
although functioning "motes" of genuine microscopic dimensions have yet to be created.

2.2 Sensor Nodes Network


The primary focus of WSN was the development of the Sensor Nodes Network component.
It was the component responsible for collecting and transmitting raw environmental data to
Base Node. There was also the potential for the nodes to receive commands from the base,
although that functionality was not implemented in WSN. This component consisted of two
parts. The first was the sensor node. The primary purpose of the Sensor Node was to collect
and transmit raw environmental data wirelessly to Base Node. When not doing this, it went
into a low-power idle mode to conserve energy.

Base Node Unit Node

“Figure 2.1: Sensor Node Network Block Diagram”

The Base Node was the second part of the Sensor Nodes Network. Its purpose was to PC as
the liaison between the PC and the Sensor Nodes Network (through Serial Port) and delivers
all the data to PC.

Hajvery University Lahore 9


For WSN, however, we use slightly different hardware and software configurations for Base
versus Nodes.

2.3 Sensor Node


Sensor Node consists of:

 Temperature
 Voltage Sensor
 Current Sensor
 Analogue to Digital Converter
 PIC Microcontroller.(PIC 16F877)
 Encoder
 Decoder
 Transceiver

2.3.1 Operation of Nodes

 Taking analog data of Temperature, Voltage and Current through sensors.

 Converting analog data into digital through ADC.


 Programming using micro-controller.
 Encode data
 Transmission of digital data through RF to Base Node.
 Perform actions as told by the user

Hajvery University Lahore 10


2.3.2 Block diagram

“Figure 2.2: Block Diagram Sensor Node”

2.4 Base Node


Base consists of:

 Analogue to Digital Converter(built-in PIC microcontroller)


 PIC Microcontroller.(PIC 16F877)
 Encoder
 Decoder
 Transceiver
 Receiver
 RS 232 Port (Serial Port)

2.4.1 Operation of Base Node

 Receive data transmitted by Sensor Node.


 Decode Data
 Programming using micro-controller.
 Send data to PC through RS 232 ( Serial Port)
 Take actions told by user

Hajvery University Lahore 11


 Send action commands to node

2.4.2 Block diagram

“Figure 2.3: Block Diagram Base Node”

Hajvery University Lahore 12


Chapter 3
Sensors

Hajvery University Lahore 13


3.1 Introduction
Sensor is a device that measure physical quantity and converts it into a signal which can be
read by an observer or by an instrument. There are many types and applications of all the
different available sensors and transducers. Here we introduce three of them. And show how
they can be used to get data for microcontroller-based systems.

3.2 Types of Sensors to be used


There are four types of sensors, we are using in our project to get analogue data.

 Temperature Sensor.
 Voltage Sensor.
 Current Sensor.

3.2.1 Temperature Sensor

The temperature sensor is an integrated circuit that can be used to measure temperature with
an electrical output proportional to the temperature (in oC)

(a) Types of temperature sensors


There are four major types of the temperature sensors.

1. Semiconductor devices
2. Thermocouples
3. RTD’s
4. Thermistor

Hajvery University Lahore 14


(b)Semiconductor temperature sensor (LM35)

The two main types of the semiconductor temperature sensor are temperature sensitive
voltage source and the temperature sensitive current source. An example of the first type of
the temperature sensor is LM35.

(c)The LM35

The LM35 is an integrated circuit sensor that can be used to measure temperature with an
electrical output proportional to the temperature (in oC). LM35 is use measure temperature
more accurately than a using a thermistor. The sensor circuitry is sealed and not subject to
oxidation, etc. LM35 generates a higher output voltage than thermocouples and may not
require that the output voltage be amplified.

i. Specification

 Calibrated directly in ° Celsius (Centigrade)


 Linear + 10.0 mV/°C scale factor
 0.5°C accuracy guarantee able (at +25°C)
 Rated for full −55° to +150°C range
 Suitable for remote applications
 Low cost due to wafer-level trimming
 Operates from 4 to 30 volts
 Less than 60 μA current drain
 Low self-heating, 0.08°C in still air
 Nonlinearity only ±1⁄4°C typical
 Low impedance output, 0.1 ohm for 1 mA load

Hajvery University Lahore 15


ii. Design of temperature sensor

“Figure3.1: Design of Temperature sensor”

iii. Working of temperature Sensor

LM35 gives the output voltage that is proportional to the Celsius temperature. The scale
factor is .01V/oC .it does not require any external calibration or trimming and maintains an
accuracy of +/-0.4 oC at room temperature and +/- 0.8 oC over a range of 0 oC to +100 oC.
Another important characteristic of the LM35 is that it draws only 60 micro amps from its
supply and possesses a low self-heating capability. The sensor self-heating causes less than
0.1 oC temperature rise in still air. The output voltage is converted to temperature by a simple
conversion factor. The sensor has a sensitivity of 10mV / oC. Use a conversion factor that is
the reciprocal that is 100 oC/V. The general equation used to convert output voltage to
temperature is:

Temperature ( oC) = Vout * (100 oC/V) So if Vout is 1V , then, Temperature = 100 oC .The
output voltage varies linearly with temperature.

iv. Implementation

“Figure3.2: Implementation of Temperature sensor”

Hajvery University Lahore 16


3.2.2 Voltage sensor

A Voltage sensor is the one which detects the input voltage in the line and generates the
corresponding stepped down DC output voltage which can easily be measured.

(a)Specification

 Rated for 0 to 500 volts


 Linear calibration
 Suitable for remote applications
 Current rating 0-5 A
 Frequency 50 hertz

(b)Design

“Figure3.3: Design of Voltage Measuring Circuit”

(c)Working

The main function of voltage sensor is to convert 220v AC to desired DC volts. We are using
the same concept but we adjust our variable resister in such a way that power supply gives
the following outputs of DC.

Hajvery University Lahore 17


Input Output

220 AC 2.20 DC

215 AC 2.15 DC

210 AC 2.10 DC

“Table3.1: Output of voltage sensor with corresponding AC voltage“

Voltage sensor circuit has one step down transformer and a full wave rectifier and two
capacitors of 470µf and 10µf and also has two resistance of 1k ohm, 22kohm and one
variable resistance of 10kohm.

The A.C voltage of transmission line of 220V are step down by the transformer and that
step down voltage value is depend upon the input voltage given to the transformer further
the step down voltage is converted to D.C voltage by the process of full wave rectification.
That full wave rectified voltage comes towards the 470µf capacitor which gives the straight
line voltage and a resistance of 1kohm is connected to the capacitor in parallel to discharge
the capacitor rapidly and 22kohm resistance works for filtrations of the D.C volts. Then that
D.C voltage goes towards the 10kohm variable to get the output according to the input A.C
voltage and 10µf capacitor is connected parallel to get smooth and consistent (steady) D.C
voltage output.

(d) Implementation

Hajvery University Lahore 18


“Figure3.4: Implementation of Voltage Sensor”

3.2.3 Current sensor


A current sensor is a device that detects electrical current (AC or DC) in a wire, and
generates a signal proportional to it.
The sensed current and the output signal can be:
AC current input,
 analog output, which duplicates the wave shape of the sensed current
 bipolar output, which duplicates the wave shape of the sensed current
 unipolar output, which is proportional to the average or RMS value of the
sensed current
DC current input,
 unipolar, with a unipolar output, which duplicates the wave shape of the
sensed current
 digital output, which switches when the sensed current exceeds a certain
threshold

(a)Specification

 Rated at 0-500 volts


 Current rating 0-5 A
 Frequency 50-60 hertz

(b)Design

“Figure3.7: Design of Current Sensor”

Hajvery University Lahore 19


(c)Working

First the current signal is send to CT and then is step down here in (mA). Then there is a
resistor of 1k which is protecting the amplifier and then signal is amplified in LM 324 and
passed to diode where it gets a signal as a switch and the amount of energy is then stored in
capacitor and then there is a variable resistor which is connected to MC to give a proper
signal of 5 or less than 5 volts to MC according to our need.

(d)Implementation

“Figure3.8: Implementation of Current Sensor”

(e)LM324

The LM324 consist of four independent, high gain, internally frequency compensated
operational amplifiers which were designed specifically to operate from a single power
supply over a wide voltage range. Operation from split power supplies is also possible so
long as the difference between the two supplies is 3 volts to 32 volts. Application areas
include transducer amplifier, DC gain blocks and all the conventional OP Amp circuits which
now can be easily implemented in single power supply systems.

Hajvery University Lahore 20


i. Specification

 Large DC voltage gain 100 dB


 Wide bandwidth (unity gain) 1 MHz
 Temperature compensated
 Wide power supply range:
Single supply 3V to 32V
Or dual supplies ±1.5V to ±16V
 Very low supply current drain (700 μA)—essentially
Independent of supply voltage
 n Low input biasing current 45 nA
(Temperature compensated)
 Low input offset voltage 2 mV and offset current: 5 nA
 Input common-mode voltage range includes ground
 Differential input voltage range equal to the power
 Supply voltage
 Large output voltage swing 0V to V+ − 1.5V

3.3 Power supply


A power supply is a device that supplies electrical energy to one or more electric loads. The
term is most commonly applied to devices that convert one form of electrical energy to
another, though it may also refer to devices that convert another form of energy (e.g.,
mechanical, chemical, solar) to electrical energy. A regulated power supply is one that
controls the output voltage or current to a specific value; the controlled value is held nearly
constant despite variations in either load current or the voltage supplied by the power
supply's energy source.

Hajvery University Lahore 21


3.3.1 Design

“Figure3.9: Design of PSU”

3.3.2 Working

Telecommunications equipment is designed to operate on voltages lower than the domestic


Mains voltage. In order to reduce this voltage a PSU is used.

To provide a useable low voltage the PSU needs to do a number of things:-

 Reduce the Mains AC (Alternating current) voltage to a lower level.


 Convert this lower voltage from AC to DC (Direct current)
 Regulate the DC output to compensate for varying load (current demand)
 Provide protection against excessive input/output voltages.

(a) Conversion of AC to DC

To convert our now low AC voltage to DC we use a Rectifier Diode connected to


the Secondary Winding.

As our low AC voltage will be working at a frequency of 50Hz (Mains AC frequency) it is


desirable to reduce the inherent hum on this to a lower level. This is achieved by a technique
known as Smoothing (“Ironing” out the bumps in the AC). A simple way to reduce the hum
is to use Full Wave Rectification.

Hajvery University Lahore 22


Today this is usually done by four diodes in a bridge configuration known as a Bridge
Rectifier. (This can be four individual diodes or a dedicated self-contained package)

(b)Regulation of Output Voltage


The Electrolytic Capacitor is a device capable of storing energy the amount of energy and the
time it remains stored depending on the value.

In a simple PSU the easiest way to provide regulation to compensate for varying load
conditions is to use a pair of relatively high value Electrolytic Capacitors. Their values in this
case being in the region of 470uF to 2000uF depending on the application and the amount of
current required from the output of the unit. One of these capacitors is connected across the
DC output of the rectifier diode(s) or bridge, this capacitor also providing an extra degree of
smoothing the output waveform.

The second capacitor is connected via a low value, medium to high wattage resistor, which
assists in limiting the current demand.

3.3.3 Rectification

(a) Full-wave rectification

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

“Figure3.10: Full-wave rectifier”

Hajvery University Lahore 23


(b)Rectifier output smoothing

While half-wave and full-wave rectification suffice to deliver a form of DC output, neither
produces constant-voltage DC. In order to produce steady DC from a rectified AC supply, a
smoothing circuit or filter is required. In its simplest form this can be just a reservoir
capacitor or smoothing capacitor, placed at the DC output of the rectifier. There will still
remain an amount of AC ripple voltage where the voltage is not completely smoothed.

Hajvery University Lahore 24


Chapter 4
PIC Microcontroller

Hajvery University Lahore 25


4.1 Introduction to Microcontroller
A microcontroller is a whole computer system on a chip integrating CPU, memory, I/O ports,
and some peripheral devices (timers, converters) etc.
Microcontroller are hidden inside a surprising number of products these days, if your
microwave oven has an LED o LCD screen and a keypad, it contains a microcontroller. All
modern automobiles contain at least one microcontroller, and can have as many as six or
seven: the engine is controlled by a microcontroller, and are the anti-lock brakes, the cruise
control and so on. Any device that has a remote control almost certainly contains a
microcontroller: TVs, VCRs and high-end stereo systems all fall into this category.
A microcontroller is a computer. All computers – whether we are talking about a personal
desktop computer or a large mainframe computer or a microcontroller – have several things
in common:

4.2 Criteria for Choosing a Microcontroller


The first and foremost criterion in choosing a Microcontroller is that it must meet the task
efficiently and cost effectively.
In a analyzing the needs of a Microcontroller – based project, we must first see whether an 8-
bit, or 32-bit Microcontroller can best handle the computer needs of the task most effectively.
Among other considerations in this category are:
Speed: What is the highest speed that the Microcontroller Supports?
Packaging: Does it come in 40 pin DIP (dual inline package) or a QFP (quad flat package),
or some other packaging format
Power consumption: This is important in terms of the final Cost of the product in which a
Microcontroller is used.
The second criterion in choosing a Microcontroller is its ready availability in needed
quantities both now and in the future. The third Criterion in choosing a Microcontroller is its
ready availability in needed quantities both now and in the future.

Hajvery University Lahore 26


4.3 PIC microcontroller

PIC is a family of Harvard architecture microcontrollers made by Microchip Technology,


derived from the PIC1640 originally developed by General Instrument's Microelectronics
Division. The name PIC initially referred to "Programmable Interface Controller"

PICs are popular with both industrial developers and hobbyists alike due to their low cost,
wide availability, large user base, extensive collection of application notes, availability of
low cost or free development tools, and serial programming (and re-programming with flash
memory) capability.

The PIC architecture is distinctively minimalist. It is characterized by the following features:

 Separate code and data spaces (Harvard architecture)


 A small number of fixed length instructions
 Most instructions are single cycle execution (4 clock cycles), with single delay cycles
upon branches and skips
 A single accumulator (W), the use of which (as source operand) is implied (i.e. is not
encoded in the opcode)
 All RAM locations function as registers as both source and/or destination of math and
other functions.
 A hardware stack for storing return addresses
 A fairly small amount of addressable data space (typically 256 bytes), extended
through banking
 Data space mapped CPU, port, and peripheral registers
 The program counter is also mapped into the data space and writable (this is used to
implement indirect jumps).

Unlike most other CPUs, there is no distinction between memory space and register space
because the RAM serves the job of both memory and registers, and the RAM is usually just
referred to as the register file or simply as the registers.

Hajvery University Lahore 27


4.3.1 Features

Current PICs offer a wide range of inbuilt hardware, such as:

 synchronous/asynchronous serial transmission UARTs


 Analog to Digital converters
 Voltage Comparators
 Capture/Compare/PWM modules
 LCD Drivers
 I2C and SPI peripheral Bus Support
 Internal (software accessible) EEPROM memory
 Motor Control Kernels

4.4 Microcontroller PIC 16F877


Most of the engineering projects are done with the help of Micro controller. In this project,
we are going to use MICROCONTROLLER PIC 16F877. Here are some Features of PIC
16F877

4.4.1 Features of PIC 16F877

 High-performance RISC CPU.


 All single cycle instructions except for program branches which are 2 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 256 x 8 bytes of EEPROM data memory.
 Pin out compatible to the PIC16C73/74/76/77.
 Interrupt capability -up to 14 internal/external.
 Eight level deep hardware stack.
 Direct, indirect, and relative addressing modes
 Power-on Reset (POR)
 Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)
 Watchdog Timer (WDT) with its own on-chip RC Oscillator for reliable

Hajvery University Lahore 28


 Operation Programmable code-protection
 Power saving SLEEP mode
 Selectable oscillator options
 Low-power, high-speed CMOS EPROM/EEPROM technology
 Fully static design
 In-Circuit Serial Programming (ICSP) via two pins
 Only single 5V source needed for programming capability
 In-Circuit Debugging via two pins
 Processor read/write access to program memory
 Wide operating voltage range: 2.5V to 5.5V
 High Sink/Source Current: 25 mA
 Commercial and Industrial temperature ranges

4.4.2 Ports description

PIC 16F877 series normally has five input/output ports. They are used for the input/output
interfacing with other devices/circuits. Most of these port pins are multiplexed for handling
alternate function for peripheral features on the devices. All ports in a PIC chip are bi-
directional. When the peripheral action is enabled in a pin, it may not be used as its general
input/output functions. The PIC 16F877 chip basically has 5 input/output ports. The five
input/output ports and its functions are given below.

(a)PORT A and the TRIS (Tri-state) A Registers

PORT A is a 6-bit wide bi-directional port, the direction of this port is controlled by TRIS A
data direction register. Setting a TRIS A (=1) makes corresponding PORT A pin as an input,
clearing the TRIS A (=0) making the corresponding PORT A pin as an output Pin RA4 is
multiplexed with the “Timer0” module clock input to become the RA4 pin and functioning
either input/output operation or Timer 0 clock functioning module. The RA4 pin is a Schmitt
Trigger input and an open-drain output. All other PORT A pins has TTL input levels and full
CMOS output drivers.

Hajvery University Lahore 29


Other PORT A pins in this microcontroller multiplexed with analog inputs and the analog
VREF (Voltage reference) input for both the A/D converters and the comparators. The
operation of each pin is selected by clearing/setting the appropriate control bits in the
ADCON1 (Analogue to Digital Converter) and/or CMCON (Comparator analogue Control)
registers. The TRIS A register controls the direction of the PORT pins even when they are
being used as analog inputs. The user must ensure the bits in the TRISA register are
maintained set when using them as analog inputs. The functions and the registers associated
with PORT A register is given in the table below.

(b)PORT B and the TRIS B Registers

PORT B is also an 8 bit bi-directional PORT. Its direction controlled and maintained by
TRIS B data direction register. Setting the TRIS B into logic ‘1’ makes the corresponding
“PORT B” pin as an input. Clearing the TRIS B bit make PORT B as an output. Three pins
of PORT B are multiplexed with the In-Circuit Debugger and Low-Voltage Programming
function: RB3, RB6 and RB7 for performing its alternate functions.
The block diagram of PORT B register is given in the figure below.
PORT B functioning table and the registers associated with PORT B is given in the table
below.

(c)PORT C and the TRIS C Registers

PORT C is an 8-bit wide, bidirectional PORT which controlled and maintained by TRIS C
data direction register. Setting a TRIS C bit (= 1) will make the corresponding PORT C pin
an input (i.e., put the corresponding output driver in a High-Impedance mode). Clearing a
TRIS C bit (= 0) will make the corresponding PORT C pin an output PORT C is also
multiplexed with several peripheral functions. PORT C pins have Schmitt Trigger input
buffers.
When enabling peripheral functions, more care should be taken in defining TRIS bits for
each PORT C pin as compared to other. Some peripherals override the TRIS bit to make a
pin an output, while other peripherals override the TRIS bit to make a pin an input. Since the
TRIS bit override is in effect while the peripheral is enabled, read-modify write instructions

Hajvery University Lahore 30


with TRISC as the destination, should be avoided. The user should refer to the corresponding
peripheral section for the correct TRIS bit settings.
The block diagram of PORT C register is shown in the figures below.
The functions and registers associated with PORT C register is given in the table below.

(d)PORT D and TRIS D Registers

PORT D is an 8-bit PORT with bi-directional nature. This port also with Schmitt Trigger
input buffers, each pin in this PORT D individually configurable as either input or output.
PORT D can be configured as an 8-bit wide microprocessor PORT (functioning as Parallel
Slave PORT) by setting control bit. In this mode, the input buffers are TTL (transistor-
transistor logic).

(e)PORT E and TRIS E Registers

PORT E has only three pins (RE0, RE1 and RE2) which are individually configurable as
inputs or outputs. These pins controllable by using its corresponding data direction register
“TRIS E”. These pins also have Schmitt Trigger input buffers. The PORT E pins become the
I/O control inputs for the microprocessor PORT when bit PSPMODE is set. In this mode, the
user must make certain that the TRIS E bits are set and that the pins are configured as digital
inputs. Also, ensure that ADCON1 is configured for digital I/O. In this mode, the input
buffers are TTL.
TRISE register which also controls the Parallel Slave PORT operation. PORT E pins are
multiplexed with analog inputs. When selected for analog input, these pins will read as ‘0’s.
TRIS E controls the direction of the RE pins, even when they are being used as analog
inputs. The user must make sure to keep the pins configured as inputs when using them as
analog inputs.

Hajvery University Lahore 31


4.4.3 Pin configuration

“Figure4.1: Pin Configuration”

Hajvery University Lahore 32


4.4.4 Pin description of PIC 16F877

“Table4.1: Pin Description”

Hajvery University Lahore 33


“Table4.2: Pin Description2”

Hajvery University Lahore 34


4.4.5 Comparison with other PIC controllers

Key Features PIC16F873 PIC16F874 PIC16F876 PIC16F877


MAX Operating Frequency 20MHz 20MHz 20MHz 20MHz
FLASH Program Memory 4K 4K 8K 8K
(14-bit words)
Data Memory (bytes) 192 192 368 368
EEPROM Data Memory (bytes) 128 128 256 256
I/O Ports RA0-5 (6) RA0-5 (6) RA0-5 (6) RA0-5 (6)
RB0-7 (8) RB0-7 (8) RB0-7 (8) RB0-7 (8)
RC0-7 (8) RC0-7 (8) RC0-7 (8) RC0-7 (8)
RD0-7 (8) RD0-7 (8)
RE0-2 (3) RE0-2 (3)
Timers 3 3 3 3
CCP 2 2 2 2
Serial Communications MSSP, USART MSSP, USART MSSP, USART MSSP, USART
Parallel Communications - PSP - PSP
10-bit Analog-to-Digital Module 5 Channels 8 Channels 5 Channels 8 Channels
Instruction Set 35 Instructions 35 Instructions 35 Instructions 35 Instructions
Pins (DIP) 28 Pins 40 Pins 28 Pins 40 Pins

“Table4.3: Comparison”

Hajvery University Lahore 35


4.4.6 Block Diagram

“Figure4.2: Block Diagram”

Hajvery University Lahore 36


4.5 Interfacing PIC with MAX232

4.5.1 PIC USART

In the PIC 16F877, the USART is accessed through pins RB6 and RB7. It has two modes of
operation, synchronous (using a separate clock signal) and asynchronous (no clock
connection). The asynchronous mode is probably used more often, as other methods of
synchronous transmission are available in the PIC, as we will see. In asynchronous mode,
RB6 acts as a data transmit (TX) output, and RB7 as data receive input (RX) Data is usually
transmitted in 8-bit words (9 is an option), with the least significant bit sent first. The
receiver must sample the input at the same rate as the data is sent, so standard clock (baud)
rates are used. 9600 baud is used in our example here, meaning that the bits are transmitted at
about 10k bits/s. Separate transmit and receive lines are used, so it is possible for these
operations to be carried out simultaneously.
In the block diagram, the PIC is connected to a PC. The PIC USART output itself operates at
TTL voltages, and needs an external serial line driver to convert its output into a higher
symmetrical line voltage. This is necessary because a simple baseband data signal is
attenuated down a line, due to the distributed resistance and capacitance of the cabling. The
standard RS232 interface operates with a higher line voltage so that the signal can be

“Figure4.3: Serial Data transmission”

Hajvery University Lahore 37


Transmitted further before being overcome by noise and interference. A typical link distance
for RS232 is around 10 m with symmetrical voltages of up to _/_25V. _/_12 V is more
typical. The signal is also inverted with respect to the TTL version as shown in Figure (b).
We will assume initially that the MCU is transmitting. The sender and receiver have to be
initialised to use the same baud rate, number of data bits (default 8) and number of stop bits
(default 1). The transmit (TX) output is high when idle (external line negative). When the
serial buffer register (TXREG) is written, the data is automatically sent as follows. The start
of the byte transmission is signalled by the line going low for one clock period (start bit). The
following 8 bits are then output from the transmit register, at intervals determined by the
selected baud rate. In the diagram, the bits are shown as both high and low, to indicate that
either is possible, depending on the particular data word. After the last data bit, the line is
taken high by the transmitter for one clock period (stop bit), and that is the end of that
transmission. The line is left high if there is no more data; another word can be transmitted
after a delay, or immediately following. The protocol is thus about as simple as it is possible
to get. The data is often ASCII coded, as the USART is frequently used to transmit character-
based messages. The receiver must be initialised to read in the data at the same baud rate. At
9600 baud, the bit period is about 100 _s. When the falling edge of the start bit is detected,
the receiver must wait for 1.5 bit periods, and then sample the line for the first data bit (LSB),
read the next after a further clock cycle and so on until the set number of bits has been read
in. The stop bit confirms the end of the byte, and another transmission can start. An interrupt
flag is used to signal to the receiver MCU that there is data waiting. It must be read from
RCREG before the next byte arrives.

Hajvery University Lahore 38


“Figure4.4: Schematic diagram”

4.6 PIC interfacing with LCD


The LCD is now a very common choice for graphical and alphanumeric displays. This range
from small, 7-segment monochrome numerical types such as those used in digital millimetres
(typically 3 ½ digits, maximum reading 1.999) to large, full colour, high-resolution screens
which can display full video. Here we shall concentrate on the small monochrome,
alphanumeric type which displays alphabetical, numerical and symbolic characters from the
standard ASCII character set.

4.6.1 JHD164 Features


Display construction: 16 character * 4 lines
Display mode: TN/STN
Display type: Positive reflective
Back light: LED/4.2 VCD
Viewing direction: 6 o’ clock
Operating temperature: Indoor
Driving voltage: single power
Driving method: 1/16 duty
Type: COB (chip on board)
Number of data lines: 8-bit parallel
Connector: pin

Hajvery University Lahore 39


4.6.2 Absolute maximum ratings

“Table4.4: Absolute maximum ratings”

4.6.3 Reliability

(a)Operating life time


 Larger than 5000 hours

(b)Reliability characteristics

“Table4.5: Reliability characteristics”

Hajvery University Lahore 40


4.6.4 Interface

“Table4.6: Interfacing”

4.6.6 LCD Pin connections with Microcontroller

“Figure4.5: LCD Interface with PIC”

Hajvery University Lahore 41


Chapter 5
Serial communication

Hajvery University Lahore 42


5.1 Introduction to serial Communication

In telecommunication and computer science, serial communication is the process of sending


data one bit at a time, sequentially, over a communication channel or computer bus. This is in
contrast to parallel communication, where several bits are sent together, on a link with
several parallel channels. Serial communication is used for all long-haul communication and
most computer networks, where the cost of cable and synchronization difficulties make
parallel communication impractical. Serial computer buses are becoming more common even
at shorter distances; as improved signal integrity and transmission speeds in newer serial
technologies have begun outweigh the parallel bus's advantage of simplicity. Serial
communication is often used either to control or to receive data from an embedded
microprocessor. Serial communication is forms of I/O in which the bits of a byte begin
transferred appear one after the other in a timed sequence on a single wire. Serial
communication has become the standard for inter computer communication. In this part,
we'll try to build a serial link between PIC16F877 and PC using RS232.

Serial communication requires that you specify the following four parameters:

 The baud rate of the transmission


 The number of data bits encoding a character
 The sense of the optional parity bit
 The number of stop bits

Each transmitted character is packaged in a character frame that consists of a single start bit
followed by the data bits, the optional parity bit, and the stop bit or bits.

5.2 Basics of Serial Communication

.
“Figure5.1: Serial Vs Parallel Data Transfer”

Hajvery University Lahore 43


The fact that in serial communication a single data line is used instead of the 8-bit data line of
parallel communication makes it not only much cheaper but also makes it possible for two
computers located in two different cities to communicate over the telephone.

For serial data communication to work the byte of data must be converted to serial bits using
a parallel-in-serial –out register; then it can be transmitted over a single data line. This also
means that at the receiving end there must be a serial-in-parallel-out shift register to receive
the signal data and pack them into byte. Of course, 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. This conversion is performed by a peripheral device called a modem, which
stands for "modulator/demodulator".
Serial data communication uses two methods, asynchronous and synchronous. The
synchronous method transfers a block of data (characters) at a time while the asynchronous
transfers a single byte at a time. It is possible to write soft ware to use either of these
methods, but the programs can be tedious and long. For this reason, there are special IC chips
made by many manufacturers for serial data communications.

5.3 Half- and full-duplex transmissions


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, iris 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 (in addition to the signal ground), one
for transmission and one for reception, in order to transfer and receive data simultaneously.
See Figure.

Hajvery University Lahore 44


“Figure5.2: Simplex, Half-, Full-Duplex Transfer”

5.3.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 in between start and stop bits. This is called framing. In data
framing for asynchronous communications, the data, such as ASCII characters, are packed in
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). For example, look at
Figure below in which the ASCII character "A" (8-bit binary 0100 0001) is framed in
between the start bit and a single stop bit. Notice that the LSB is sent out first.

Notice in Figure below that when there is no transfer, the signal is 1 (high), which is referred
to as mark. The 0 (low) is referred to as space. Notice that the transmission begins with a
start bit followed by D0, the LSB, then the rest of the 'bits until the MSB (07), and finally,
the one stop bit indicating the end of the character "A".

“Figure5.3: Framing ASCII “A" (41H)”

In asynchronous serial communications, peripheral chips and modems can be programmed


for data that is 7 or 8 bits wide. This is in addition to the number of stop bits, 1 or 2. While in
older systems ASCII characters were 7 -bit, in recent years due to the extended ASCII

Hajvery University Lahore 45


characters, 8-bit data has become common. In some older systems, due to the slowness of the
receiving mechanical device, two stop bits were used to give the device .sufficient time to
organize itself before transmission of the next byte. However, in modem PCs the use of one
stop bit is standard. Assuming that we are transferring a text file of ASCII characters using 1
stop bit, we have a total of 10 bits for each character: 8 bits for the ASCII code, and 1 bit
each for the start and stop bits. Therefore, for each 8-bit character there are an extra 2 bits,
which gives 25% overhead.

In some systems in order to maintain data integrity, the parity bit of the character byte is
included in the data frame. This means that for each character (7or 8-bit, depending on the
system) we have a single parity bit in addition to start and stop bits. The parity bit is odd or
even. In the case of an odd-parity bit the number of data bits, including the parity bit, has an
odd number of Is. Similarly, in an even-parity bit system the total number of bits, including
the parity bit, is even. For' example, the ASCII character "A", binary 0100 0001, has 0 for the
even-parity bit. UART chips allow programming of the parity bit for odd-, even-, and no-
parity options.

5.4 Data Communication Classification


Current terminology classifies data communication equipment as DTE (data terminal
equipment) or DCE (data communication equipment). DTE refers to terminals and computers
that send and receive data, while DCE refers to communication equipment, such as modems,
that are responsible for transferring the data. Notice that all the RS232 pin function defined in
table above are from DTE point of view.

The simplest connection between a PC and microcontroller requires a minimum of three pins,
TxD, RxD, and ground, as shown in Figure below. Notice in figure that the RxD and TxD
pins are interchanged and TxD pins are interchanged.

Hajvery University Lahore 46


“Figure5.4: Null Modem Connection”

5.5 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, there are occasions when a single change of signal 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 in this book we use the terms bps and baud interchangeably.

The data transfer rate of a given computer system. Depends on communication ports
incorporated into that system. For example, the early IBM PC/XT could transfer data at the
rate of 100 to 9600 bps. However in recent years, 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,000 bps.

5.6 MAX232

5.6.1 Features
 Operates From a Single 5-V Power Supply
 With 1.0 µF Charge-Pump Capacitors
 Operates Up To 120 kbit/s

Hajvery University Lahore 47


 Two Drivers and Two Receivers
 ±30 V Input Levels
 Low Supply Current . . . 8 mA Typical
 ESD Protection Exceeds JESD 22
2000-V Human-Body Model (A114-A)
 Upgrade With Improved ESD (15-kV HBM)
And 0.1-_F Charge-Pump Capacitors is
Available With the MAX202
 Applications
TIA/EIA-232-F, Battery-Powered Systems,
Terminals, Modems, and Computers

5.6.2 Description

Usually all the digital ICs work on TTL or CMOS voltage levels which cannot be used to
communicate over RS-232 protocol. So a voltage or level converter is needed which can
convert TTL to RS232 and RS232 to TTL voltage levels. The most commonly used RS-232
level converter is MAX232. This IC includes charge pump which can generate RS232
voltage levels from 5V power supply. It also includes two receiver and two transmitters and
is capable of full-duplex UART/USART communication.

“Figure5.5: MAX232 Pin Description”

Hajvery University Lahore 48


“Figure5.6: MAX232 Typical Connection Circuit”

The voltage level of the RS232 is used to assure error-free transmission over greater
distances than would be possible with TTL levels. For error checking it is possible to include
a parity bit as well, just prior to the stop bit. The bits are transmitted at specific time intervals
determined by the baud rate of the serial signal. The baud rate is the reciprocal of the time to
send 1 bit. Error-free serial communication requires that the baud rate, number of data bits,
number of stop bits, and presence or absence of a parity bit be the same at the transmitter and
at the receiver.

The serial port is full duplex, meaning it can transmit and receive simultaneously.
PIC16F877 provides a transmit channel and a receive channel of serial communication. The
transmit data pin (TXD) and the receive data pin (RXD. The serial signals provided on these
pins are TTL signal levels and must be boosted and inverted through a suitable converter
MAX232 to comply with RS232 standards. All modes are controlled through SCON, the
Serial Control register. The SCON bits are defined as SM0, SM1, SM2, REN, TB8, RB8, TI,
and RI from MSB to LSB. The timers are controlled using TMOD, the Timer Mode register,
and TCON, the Timer Control register.

It is also receive-buffered, meaning it can commence reception of a second byte before a


previously received byte has been read from the register. The serial port receive and transmit

Hajvery University Lahore 49


registers are both accessed at Special Function Register SBUF. Writing to SBUF loads the
transmit register, and reading SBUF accesses a physically separate receive register. PCs have
9pin/25pin male SUB-D connectors.

5.6.3 MAX232 Interfacing with Serial port

“Figure5.7: Interfacing between computer and Microcontrollers through RS232 serial port”

The circuit of Figure above is a converter RS232/TTL signals used to make the connection
between the microcontroller and the computer through the serial port. Note that the pins 11
and 12 the Max232 are connected to the pins respectively 11 (TX) and 10 (RX) of
microcontroller AT89C51. The serial cable connected to your computer is composed of 3
wires (RX, TX and GND). Pins 2 and 3 of the DB9 connector are connected via serial cable
respectively to the pins 14 and 13 the Max232. 5 pin (GND) of the connector is connected to
power supply controller circuit. The electrolytic capacitors are used to configure the correct
operation of the Max232; some of them work with their inverted polarity.

Hajvery University Lahore 50


5.6.4 Schematic

“Figure5.8: Schematic of max232”

5.7 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. Here we refer to it simply as RS232.
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 advent of the TTL logic family, its input and output voltage levels are not TTL
compatible. In RS232, a 1 is represented by -3 to -25 V, while a 0 bit is +3 to +25 V, 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 level, and vice versa.

Hajvery University Lahore 51


5.7.1 RS232 Pins

Table below (for DB-9) provides the pins and their labels for the RS232 cable, commonly
referred to as DB-25 connector. In labeling, DB-25P refers to the plug connector (male) and
DB-25S is for the socket connector (female). See Figure.

“Figure5.9: RS232 Connector DB-25”

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. The DB-9 pins are shown in Figure
below.

Figure5.10: DB-9 Pin Connector”

“Table 5.1: Pin description of RS232”

Hajvery University Lahore 52


5.8 Baud Rate

Baud rate is a measure of how fast data are moving between instruments that use serial
communication. . The term roughly means the speed that data is transmitted. It is a derived
value based on the number of symbols transmitted per second.

The baud rate is associated with many mathematical formulas. Its units are either symbols
per second or pulses per second. Baud can be determined by using the following formula:
Baud = (Gross Bit Rate / Number of Bits per Symbol). This can be used to translate baud into
a bit rate using the following formula: Bit Rate = (Bits per Symbol * Symbol Rate). Baud can
be abbreviated using the shortened form “Bd” when being used for technical purposes.

RS-232 uses only two voltage states, called MARK and SPACE. In such a two-state coding
scheme, the baud rate is identical to the maximum number of bits of information, including
control bits, which are transmitted per second. MARK is a negative voltage, and SPACE is
positive. Figure 2 shows how the idealized signal looks on an oscilloscope. The following is
the truth table for RS-232:

Signal > 3V = 0

Signal > -3V = 1

The output signal level usually swings between +12 V and -12 V. The dead area between +3
V and -3 V is designed to absorb line noise.

A start bit signals the beginning of each character frame. It is a transition from negative
(MARK) to positive (SPACE) voltage. Its duration in seconds is the reciprocal of the baud
rate. If the instrument is transmitting at 9,600 baud, the duration of the start bit and each
subsequent bit is about 0.104 ms. The entire character frame of eleven bits would be
transmitted in about 1.146 ms. Data bits are transmitted upside down and backwards. That is,
inverted logic is used, and the order of transmission is from least significant bit (LSB) to
most significant bit (MSB). To interpret the data bits in a character frame, you must read
from right to left and read 1 for negative voltage and 0 for positive voltage. This yields

Hajvery University Lahore 53


1101101 (binary) or 6D (hex). An ASCII conversion table shows that this is the letter m. An
optional parity bit follows the data bits in the character frame. The parity bit, if present, also
follows inverted logic, 1 for negative voltage and 0 for positive voltage. This bit is included
as a simple means of error handling. You specify ahead of time whether the parity of the
transmission is to be even or odd. If the parity is chosen to be odd, the transmitter then sets
the parity bit in such a way as to make an odd number of ones among the data bits and the
parity bit. This transmission uses odd parity.

There are -ve ones among the data bits, already an odd number, so the parity bit is set to 0.
The last part of a character frame consists of 1, 1.5, or 2 stop bits. These bits are always
represented by a negative voltage. If no further characters are transmitted, the line stays in
the negative (MARK) condition. The transmission of the next character frame, if any, is
heralded by a start bit of positive (SPACE) voltage.

5.9 Maximum Transmission rate


Knowing the structure of a character frame and the meaning of baud rate as it apply to serial
communication, you can calculate the maximum transmission rate, in characters per second,
for a given communication setting. This rate is just the baud rate divided by the bits per
frame. For example, there are a total of eleven bits per character frame. If the transmission
rate is set at 9,600 baud, you get 9600 /11 = 872 characters per second.

Notice that this is the maximum character transmission rate. The hardware on one end or the
other of the serial link might not be able to reach these rates, for various reasons.

Hajvery University Lahore 54


Chapter 6
Radio Frequency

Hajvery University Lahore 55


6.1 Introduction
Radio frequency RF is a term that refers to alternating current (AC) having characteristics
such that, if the current is input to an antenna, an electromagnetic (EM) field is generated
suitable for wireless broadcasting and / or communications. These frequencies from nine
kilohertz (3 kHz), the lowest allocated wireless communications frequency (it’s within the
range of human hearing), to thousands of gigahertz (GHz).

When an RF current is supplied to an antenna, it gives rise to an electromagnetic field that


propagates through space. This field is sometime called an RF field; in less technical jargon it
is a “radio wave”. Any RF field has a wavelength that is inversely proportional to the
frequency. In the atmosphere or in outer space, if f is the frequency in megahertz and s is the
wavelength in meters, then

S = 300 / f

The frequency of an RF signal is inversely proportional to the wavelength of the EM field to


which it corresponds. At 9 kHz, the free-space wavelength is approximately 33 kilometers
(km) or 21 miles (mi). At the highest radio frequencies, the EM wavelengths measure
approximately one millimeter (1mm). As the frequency is increased beyond that of the RF
spectrum, EM energy takes the form of infrared (IR), visible, ultraviolet 90UV x rays and
gamma rays. Much type of wireless devices makes use of RF fields. Cordless and cellular
telephone, radio and television broad cast stations, satellite communications system, and two-
way radio services all operate in the RF spectrum. Some wireless devices operate at IR or
visible – light frequencies, whose electromagnetic wavelengths are shorter than those RF
fields. Example includes most television – set remote – control boxes, some cordless
computer keyboards and mice, and a few wireless hi-fi stereo headsets.

The RF spectrum is divided into several ranges, or bands. With the exception of the lowest-
frequency segment, each band represents an increase of frequency corresponding to an order
of magnitude (power of 10). The table depicts the eight bands in the RF spectrum, showing
frequency and band width ranges. The SHF and EHF bands are often referred to as the
microwave spectrum.

Hajvery University Lahore 56


Designation Ƒ Band ƒ λ

Extremely High Frequency ELF 30-300 Hz 104-103 km

Voice Frequency VF 300-3000 Hz 103-102 km

Very Low Frequency VLF 3-30 kHz 100-10 km

Low Frequency LF 30-300 kHz 10-1 km

Medium Frequency MF 0.3-3 MHz 1-0.1 km

High Frequency HF 3-30 MHz 100-10 m

Very High Frequency VHF 30-300 MHz 10-1 m

Ultra High Frequency UHF 300-3000 MHz 100-10 cm

Super High Frequency SHF 3-30 GHz 10-1 cm

Extremely High Frequency EHF 30-300 GHz 10-1 mm

Tremendously High Frequency THF 300-3000 GHz 1-0.1 mm

“Table 6.1: RF Spectrum”

6.2 Specifications of RF Transceivers


Some specification of RF transmitter which we are using is given below:

 Nominal Voltage: DC 3-12V


 Operating Current: 15mA, 9V
 Operating Frequency: 315MHz/433MHz
 Modulation: ASK/FSK
 Operating Temperature: -10 ℃ ~ +60 ℃
 Input Signal: TTL level

Hajvery University Lahore 57


 Radiated Power: 20mW, 5V
 Characteristics: Small size, low power, medial distance

6.3 Working of Transceiver


Communication unit basically transmits data from control unit part I to control unit part II.
Since hard wired communication is not allowed, wireless communication module is needed.
RF module which transmits data at 315/433 MHz is used. So there are two basic parts in
communication unit called as transmitter and receiver. Transmitter communicates with
control unit part I with hard wiring and sends signal to receiver using RF module. Receiver
side transmits the incoming data to control unit part II. Hardware coding is done while
sending data.

RF transmitters use oscillators to create sine waves, the simplest and smoothest form of
continuously varying waves, which contain information such as audio and video. Modulators
encode these sign wives and antennas broadcast them as radio signals. There are several
ways to encode or modulate this information, including amplitude modulation (AM) and
frequency modulation (FM).

The process of separating the original information or signal from the modulated carrier is
called demodulation. In the case of amplitude or frequency modulation it involves a device,
called a demodulator or detector, which produces a signal corresponding to the instantaneous
changes in amplitude or frequency, respectively. This signal corresponds to the original
modulating signal. In radio transmission this process is a major function of a receiver, in
order to retrieve the desired signal. In a wireless network, the device, named transceiver, is
connected to the wired network. The transceiver transmits and receives data between wireless
network and the wired network infrastructure. The RF-based low power transceivers
consume hundreds of mill watts of power with many of chip components.

6.6 PT2262
In our project we have use a RF EncoderPT2262 and PT2272 RF Decoder. RF Transmitter is
connected to the different components through RF Encoder. This encoder converts the 8-bit

Hajvery University Lahore 58


data into a single bit and sends it to the transmitter which will be transmitting. The data
which is in the air is an analog value.

PT 2262 is a remote control encoder paired with PT2272 utilizing CMOS technology. It
encodes data and address pins into a serial coded waveform suitable for RF or IR modulation.
PT 2262 has a maximum of 12 bits of tri-state address pins providing up to 531,441 (or 3^12)
address codes: thereby, drastically reducing any code collision and unauthorized code
scanning possibilities.

6.6.1 Features

 CMOS Technology
 Low Power Consumption
 Very High Noise Immunity
 Up to 12 Tri-state Code Address Pins
 Up to 6 Data Pins
 Wide range of Operating Voltage: Vcc = 4 ~ 15 Volts
 Single Resistor Oscillator
 Latch or Momentary Output Type
 Available in DIP and SO Package
 Applications
 Car Security System
 Garage Door Controller
 Remote Control Fan
 Home Security System/ Automation System
 Remote Control Toys
 Remote Control for Industrial Use

Hajvery University Lahore 59


6.6.2 Pin Configuration

“Figure6.1: Pin configuration of PT2262”

6.7 PT 2272
PT 2272 is a remote control decoder paired with 2262 utilizing CMOS Technology. It has 12
bits of Tri-state address pins providing a maximum of 531,441 (or 3^12) address codes;
thereby, drastically reducing and unauthorized code scanning possibilities. PT 2272 is
available in several options to suit every application need: variable number of data output
pins, latch or momentary output type.

At the receiving end, the receiver receives this analog value on a single data line and passes
this data to the decoder. The decoder does the opposite functioning of the encoder i.e., it
converts the single bit data into eight bit data and gives it to the microcontroller which does
the further processing.

6.7.1 Features

 CMOS Technology
 Low Power Consumption
 Very High Noise Immunity

Hajvery University Lahore 60


 Up to 12 Tri-state Code Address Pins
 Up to 6 Data Pins
 Wide range of Operating Voltage: Vcc = 4 ~ 15 Volts
 Single Resistor Oscillator
 Latch or Momentary Output Type
 Available in DIP and SO Package
 Applications
 Car Security System
 Garage Door Controller
 Remote Control Fan
 Home Security System/ Automation System
 Remote Control Toys
 Remote Control for Industrial Use

6.7.2 Pin Configuration

“Figure6.2: Pin configuration of PT2272”

Hajvery University Lahore 61


6.8 CODEC chip principle PT2262/PT2272 Description
In our project we have use a RF EncoderPT2262 and PT2272 RF Decoder. RF Transmitter is
connected to the different components through RF Encoder. This encoder converts the 8-bit
data into a single bit and sends it to the transmitter which will be transmitting. The data
which is in the air is an analog value. At the receiving end, the receiver receives this analog
value on a single data line and passes this data to the decoder. The decoder does the opposite
functioning of the encoder i.e., it converts the single bit data into eight bit data and gives it to
the microcontroller which does the further processing.

Transmitter communicates with control unit part I using RS232 protocol (baud rate is 9600).
RS232 protocol uses -12V for logic 1 and +12 for logic 0. However microcontroller and RF
module uses 5V for logic 1 and 0V for logic 0. So max232 circuit, which converts +12 & -12
to 0 & 5, is used for interfacing. Max232 sends converted data to microcontroller.
Microcontroller adds appropriate header to incoming data and sends to receiver side. At this
point hardware coding must be analyzed to understand communication protocol. PT2262 and
PT2272 encoder & decoder chips are used for hardware coding. Microcontroller controls
PT2262 encoder chip with 5 pins. At each transmission 4 bits can be sent from transmitter to
receiver.

The decoder (PT2272) pairs with the encoder PT2262 for RF wireless transmission. It
decodes data obtained from the receiver to binary series (data) identical to what is encoded in
the PT2262 encoder. In this design, 4 data pins (D0 to D3) are used for data registration. The
VT pin of the decoder is a decoding indicator. Data decoding is completed when the VT pin
is pulled up at high state level, the PIC16F877 retrieves the data by reading the states of D0
to D3 of the decoder. On the contrary, the PIC16F877 will not read the states of the pins
when the VT pin is pulled down to GND, which means that there is no data received by the
receiver.

6.9 Modulation

In electronics, modulation is the process of varying one or more properties of a high


frequency periodic waveform, called the carrier signal, with respect to a modulating signal.

Hajvery University Lahore 62


This is done in a similar fashion as a musician may modulate a tone (a periodic waveform)
from a musical instrument by varying its volume, timing and pitch. The three key parameters
of a periodic waveform are its amplitude ("volume"), its phase ("timing") and its frequency
("pitch"), all of which can be modified in accordance with a low frequency signal to obtain
the modulated signal. Typically a high-frequency sinusoid waveform is used as carrier signal,
but a square wave pulse train may also occur.

In telecommunications, modulation is the process of conveying a message signal, for


example a digital bit stream or an analog audio signal, inside another signal that can be
physically transmitted. Modulation of a sine waveform is used to transform a baseband
message signal to a pass band signal, for example a radio-frequency signal (RF signal). In
radio communications, cable TV systems or the public switched telephone network for
instance, electrical signals can only be transferred over a limited pass band frequency
spectrum, with specific (non-zero) lower and upper cutoff frequencies. Modulating a sine
wave carrier makes it possible to keep the frequency content of the transferred signal as close
as possible to the center frequency (typically the carrier frequency) of the pass band. When
coupled with demodulation, this technique can be used to, among other things, transmit a
signal through a channel which may be opaque to the baseband frequency range (for
instance, when sending a telephone signal through a fiber-optic strand).

A device that performs modulation is known as a modulator and a device that performs the
inverse operation of modulation is known as a demodulator (sometimes detector or demod).
A device that can do both operations is a modem (short for "Modulator-Demodulator").

 Communication systems convert information into a form suitable for transmission


 Analog systemsAnalog signals are modulated (AM, FM radio)
 Digital system generate bits and transmit digital signals (Computers)
 Analog signals can be converted to digital signals.

Hajvery University Lahore 63


6.10 Digital Communication
The move to digital modulation provides more information capacity, compatibility with
digital data services, higher data security, better quality communications, and quicker system
availability. Developers of communications systems face these constraints:

 available bandwidth
 permissible power
 inherent noise level of the system

The RF spectrum must be shared, yet every day there are more users for that spectrum as
demand for communications services increases. Digital modulation schemes have greater
capacity to convey large amounts of information than analog modulation schemes.

6.11 Digital v/s Analog Transmission


Two forms of transmission:

 digital transmission: data transmission using square waves


 analog transmission: data transmission using all other waves

Four possibilities to consider:

 analog data via analog transmission “as is” (e.g., radio)


 analog data via digital transmission sampling (e.g., voice, audio, video)
 digital data via analog transmission broadband & wireless
 digital data via digital transmission baseband (e.g., Ethernet)

6.12 Purpose of Digital transmission

 decrease in signal strength as a function of distance


 increase in attenuation as a function of frequency

Regeneration of signal via amplifiers (analog) and repeaters (digital)

Hajvery University Lahore 64


Delay distortion: different frequency components travel at different speeds.

Most problematic: effect of noise thermal, interference,

 Analog: Amplification also amplifies noise—filtering out just noise, in general, is a


complex problem.
 Digital: Repeater just generates a new square wave; more resilient against ambiguity.

Analog transmission of digital data

Three pieces of information to manipulate: amplitude, Frequency, phase

 Amplitude modulation (AM): encode bits using amplitude levels.


 Frequency modulation (FM): encode bits using frequency differences.
 Phase modulation (PM): encode bits using phase shifts.

6.13 Fundamental digital modulation methods

The most fundamental digital modulation techniques are based on keying:

 In the case of PSK (phase-shift keying), a finite number of phases are used.
 In the case of FSK (frequency-shift keying), a finite number of frequencies are used.
 In the case of ASK (amplitude-shift keying), a finite number of amplitudes are used.
 In the case of QAM (quadrature amplitude modulation), a finite number of at least
two phases, and at least two amplitudes are used.

Hajvery University Lahore 65


6.13.1 Amplitude Shift Keying (ASK)

“Figure6.3: ASK”

 Pulse shaping can be employed to remove spectral spreading.


 ASK demonstrates poor performance, as it is heavily affected by noise and interference.

6.13.2 Phase Shift Keying (PSK)

“Figure6.4: PSK”

Phase Shift Keying (BPSK) demonstrates better performance than ASK and FSK. PSK can be
expanded to a M-ary scheme, employing multiple phases and amplitudes as different states. Filtering
can be employed to avoid spectral spreading

Hajvery University Lahore 66


6.13.3 Frequency Shift Keying (FSK).

“Figure6.5: FSK”

Bandwidth occupancy of FSK is dependent on the spacing of the two symbols. A frequency
spacing of 0.5 times the symbol period is typically used. FSK can be expanded to a M-ary scheme,
employing multiple frequencies as different states.

6.14 Criteria of choosing Modulation method


Criteria to take into account when choosing the digital modulation method:

We can use both ASK and FSK modulation scheme because both of the transceivers can
operate on 315/433MHz. By doing so we can effectively reduce

 Power efficiency, i.e., the E b/N /ratio for a specific error probability
 Bandwidth efficiency, i.e., the data rate per unit bandwidth
 Performance on multipath fading channels and under non-linear distortion
 Implementation cost and complexity

Conflicting requirements that cannot be satisfied simultaneously

Due to the less complexity and cost of circuit we have selected a FSK. Frequency shifting a
carrier between known fixed frequencies to convey digital data. FSK signals can be heard in

Hajvery University Lahore 67


the HF amateur bands around 14100 kHz, 21150 kHz and in numerous other places in the
band.

There are numerous forms of FSK in use on the HF bands where the majority of this activity
takes place. Applications include amateur radio, press agencies and meteorological
broadcasts. Normally, FSK modulation is achieved using just two frequencies to represent
binary data. For example, a frequency of 2000 Hz may represent a binary 1 (mark) and 1000
Hz a binary 0 (space). The nominal carrier frequency of the RF signal is the center frequency
equidistant between the two FSK arms. The energy of the signal alternates between the mark
and space frequencies to convey the digital message.

The spectrogram of an off-air FSK signal is shown below. This clearly illustrates how two
frequencies can be used to convey binary information. It is even possible to read off the data
bits by eye (if you assume a bit value for each tone).

More than two levels are also used by some advanced systems since more bits per tone can
be sent. FSK signals may either be generated as an audio signal (baseband) then transmitted
using a conventional SSB or FM transmitter, or a transmitter's carrier may be frequency
keyed directly.

If the tones of the FSK transmissions are regarded as symbols, a 2-level FSK signal has 1 bit
per symbol. By contrast a 4-level system has 2 bits per transmitted symbol. A multi-level
signal is capable of much higher data rates but has the disadvantage that more bandwidth is
required. If a fixed bandwidth is available, a multi-level FSK system will experience greater
difficulty in resolving the symbols.

The rate at which symbols are sent is the baud rate; this need not be the same as the bit rate
supported by the modem. Typical baud rates range from 45 baud up to 300 baud on HF with
SSB modulation being used. Data rates of 1200 baud or more are commonly used on VHF
narrowband FM as the modulation method.

Hajvery University Lahore 68


“Figure6.6: BFSK”

6.15 Noise and Electrical distortion

Distortion and electrical distortion are the basic source of interruption in any kind of waves.
A distortion is the alteration of the original shape (or other characteristic) of an object, image,
sound, waveform or other form of information or representation. Distortion is usually
unwanted. In some fields, distortion is desirable, such as electric guitar (where distortion is
often induced purposely with the amplifier or an electronic effect to achieve an aggressive
sound where desired). The slight distortion of analog tapes and vacuum tubes is considered
pleasing in certain situations. The addition of noise or other extraneous signals (hum,
interference) is not considered to be distortion, though the effects of distortion are sometimes
considered noise.

Hajvery University Lahore 69


6.16 Transmission characteristics

 Used to transmit both analog and digital signals


 Superior frequency characteristics compared to twisted pair
 Can support higher frequencies and data rates
 Shielded concentric construction makes it less susceptible to interference and
crosstalk than twisted pair
 Constraints on performance are attenuation, thermal noise, and intermediation noise
 Requires appliers every few kilometers for long distance transmission
 Usable spectrum for analog signaling up to 500 MHz
 Requires repeaters every few kilometers for digital transmission
 For both analog and digital transmission, closer spacing is necessary for higher
frequencies/data rates
 Transmission and reception are achieved using an antenna
 Transmitter sends out the signal into the medium
 Receiver picks up the signal from the surrounding medium

6.17 Directional transmission


 Transmitter sends out a focused em beam
 Transmitter and receiver antennae must be carefully aligned
 More suitable for higher frequency signals

6.18 Asynchronous VS Synchronous Transmission

6.18.1 Asynchronous

Asynchronous communication utilizes a transmitter, a receiver and a wire without


coordination about the timing of individual bits. There is no coordination between the two
end points on just how long the transmitter leaves the signal at a certain level to represent a
single digital bit. Each device uses a clock to measure out the 'length' of a bit. The
transmitting device simply transmits. The receiving device has to look at the incoming signal

Hajvery University Lahore 70


and figure out what it is receiving and coordinate and retime its clock to match the incoming
signal.

Sending data encoded into your signal requires that the sender and receiver are both using the
same encoding/decoding method, and know where to look in the signal to find data.
Asynchronous systems do not send separate information to indicate the encoding or clocking
information. The receiver must decide the clocking of the signal on its own. This means that
the receiver must decide where to look in the signal stream to find ones and zeroes, and
decide for itself where each individual bit stops and starts. This information is not in the data
in the signal sent from transmitting unit.

When the receiver of signal carrying information has to derive how that signal is organized
without consulting the transmitting device, it is called asynchronous communication. In
short, the two ends do not synchronize the connection parameters before communicating.
Asynchronous communication is more efficient when there is low loss and low error rates
over the transmission medium because data is not retransmitted and no time is spent setting
negotiating the connection parameters at the beginning of transmission. Asynchronous
systems just transmit and let the far end station figure it out. Asynchronous is sometimes
called "best effort" transmission because one side simply transmits, and the other does it's
best to receive.

6.18.1 Example

Asynchronous communication is used in our project on RS-232 based serial devices such as
on an IBM-compatible computer's COM 1 ports. Asynchronous Transfer Mode (ATM) also
uses this means of communication. Your PS2 ports on your computer also use serial
communication. This is the method is also used to communicate with an external modem.
Asynchronous communication is also used for things like your computer's keyboard and
mouse. Think of asynchronous as a faster means of connecting, but less reliable.

Hajvery University Lahore 71


6.18.2 Synchronous

Synchronous systems negotiate the communication parameters at the data link layer before
communication begins. Basic synchronous systems will synchronize both clocks before
transmission begins, and reset their numeric counters for errors etc. More advanced systems
may negotiate things like error correction and compression.

It is possible to have both sides try to synchronize the connection at the same time. Usually,
there is a process to decide which end should be in control. Both sides can go through a
lengthy negotiation cycle where they exchange communications parameters and status
information. Once a connection is established, the transmitter sends out a signal, and the
receiver sends back data regarding that transmission, and what it received. This connection
negotiation process takes longer on low error-rate lines, but is highly efficient in systems
where the transmission medium itself (an electric wire, radio signal or laser beam) is not
particularly reliable.

Hajvery University Lahore 72


Chapter 7
Source Code

Hajvery University Lahore 73


7.1 Base Unit Code
#include <16F877.h>

#include <stdio.h>

//#device adc=10

#use delay (clock = 4000000)

#use rs232(baud=9600,parity=N, xmit=PIN_C6, rcv=PIN_C7, stream=RS=232, bits=8)

#fuses NOBROWNOUT, HS, NOWDT, NOLVP, PUT

#define vt pin_b7

/////////////////////////////////////////////////

///////// variables /////////////////////////////

unsigned int trans[10] ;

unsigned char rec;

/////////////////////////////////////////////////

///////// functions /////////////////////////////

void enter (void)

{ putc(10); putc(13); }

Hajvery University Lahore 74


/////////////////////////////////////////////////

///////// main //////////////////////////////////

void main()

enter();

printf("PROJECT: Wireless Transmission Line Fault Detection Using RF");

enter();

printf("PROJECT SUPERVISOR: Engr. Musawar Hussain");

enter();

printf("GROUP MEMBERS: 1-Abdul Rehman Samad 211-19345");

enter();

printf("GROUP MEMBERS: 2-Nawaf Muhammad Tahir 211-19337");

enter();

printf("GROUP MEMBERS: 3-Muhammad Osman Nazir 311-20372");

//trans[0]= 2;

//trans[1]= 2;

//trans[2]= 0;

//trans[3]= 1;

//trans[4]= 2;

//trans[5]= 2;

//trans[6]= 5;

//trans[7]= 4;

//trans[8]= 0;

Hajvery University Lahore 75


//trans[9]= 2;

{ while(1)

rec=getch();

if(rec=='R' || rec=='r')

enter();

printf("SENDING REQUEST ");

output_d(0b00001101);

delay_ms(500);

output_d(0b00000000);

delay_ms(500);

/////////////////////////////

enter();

printf("RECEIVING DATA ");

while(!input(vt)); // voltage digit1

delay_ms(10);

while(input(vt));

delay_ms(10);

Hajvery University Lahore 76


trans[0]=input_b();

putc('.');

/////////////////////////////

while(!input(vt)); // voltage digit1

delay_ms(10);

while(input(vt));

delay_ms(10);

trans[1]=input_b();

putc('.');

/////////////////////////////

while(!input(vt)); // voltage digit1

delay_ms(10);

while(input(vt));

delay_ms(10);

trans[2]=input_b();

putc('.');

/////////////////////////////

while(!input(vt)); // voltage digit1

delay_ms(10);

Hajvery University Lahore 77


while(input(vt));

delay_ms(10);

trans[3]=input_b();

putc('.');

/////////////////////////////

while(!input(vt)); // voltage digit1

delay_ms(10);

while(input(vt));

delay_ms(10);

trans[4]=input_b();

putc('.');

/////////////////////////////

while(!input(vt)); // voltage digit1

delay_ms(10);

while(input(vt));

delay_ms(10);

trans[5]=input_b();

putc('.');

/////////////////////////////

Hajvery University Lahore 78


while(!input(vt)); // voltage digit1

delay_ms(10);

while(input(vt));

delay_ms(10);

trans[6]=input_b();

putc('.');

/////////////////////////////

while(!input(vt)); // voltage digit1

delay_ms(10);

while(input(vt));

delay_ms(10);

trans[7]=input_b();

putc('.');

/////////////////////////////

while(!input(vt)); // voltage digit1

delay_ms(10);

while(input(vt));

delay_ms(10);

trans[8]=input_b();

putc('.');

Hajvery University Lahore 79


/////////////////////////////////////////////////

//enter();

printf(" COMPLETE.");

enter ();

putc(trans[0]+0x2f);

putc(trans[1]+0x2f);

putc(trans[2]+0x2f);

putc('V');

/////////////////////////////////////////////////

putc(' ');

putc(' ');

putc(trans[3]+0x2f);

putc('.');

putc(trans[4]+0x2f);

putc('A');

/////////////////////////////////////////////////

putc(' ');

putc(' ');

Hajvery University Lahore 80


putc(trans[5]+0x2f);

putc(trans[6]+0x2f);

putc('C');

/////////////////////////////////////////////////

putc(' ');

putc(' ');

putc(trans[7]+0x2f);

putc(trans[8]+0x2f);

putc('%');

/////////////////////////////////////////////////

else if(rec=='N' || rec=='n')

enter();

printf("SENDING ON REQUEST ");

output_d(0b00001011);

delay_ms(500);

output_d(0b00000000);

delay_ms(500);

Hajvery University Lahore 81


}

/////////////////////////////

else if(rec=='F' || rec=='f')

enter();

printf("SENDING OFF REQUEST ");

output_d(0b00001100);

delay_ms(500);

output_d(0b00000000);

delay_ms(500);

delay_ms(1000);

7.2 Node Unit Code

#include <16F877.h>

#device adc=10

Hajvery University Lahore 82


#use delay (clock = 4000000)

#fuses NOBROWNOUT, HS, NOWDT, NOLVP, PUT

#byte ADCON0 = 0X1F

#byte ADCON1 = 0X9F

#byte PORTB = 0x06

#byte PORTD = 0x08

#define RS pin_d6 //= PORTD.6

#define EN pin_d7 //= PORTD.7

#define relay pin_e2

/////////////////////////////////////////////////

///////// variables /////////////////////////////

unsigned int trans[16] ;

unsigned int count, count1, digit1;

unsigned int32 adc_value ;

/////////////////////////////////////////////////

///////// functions /////////////////////////////

Hajvery University Lahore 83


void lcd_ini (void);

void lcd_data (char);

void lcd_com (char);

void adc_read (void);

void process_temperature (void);

void process_voltage (void);

void process_current (void);

void transmitt (void);

/////////////////////////////////////////////////

///////// main //////////////////////////////////

void main()

{ set_tris_a(0xFF);

set_tris_b(0x00);

//set_tris_c(0b00000100);

//set_tris_d(0x00);

output_b(0x00);

//output_c(0x00);

//output_d(0x00);

ADCON0 = 0B01000001 ;

ADCON1 = 0B10000010 ;

Hajvery University Lahore 84


lcd_ini();

while(1)

process_voltage();

process_current();

process_temperature();

//delay_ms(500);

transmitt();

delay_ms(500);

/////////////////////////////////////////////////

void transmitt (void)

{ unsigned int8 dat;

dat=input_d() & 0b00001111;

if(dat==0b00001011) output_high(relay);

if(dat==0b00001100) output_low (relay);

if(dat==0b00001101)

Hajvery University Lahore 85


for (count = 0; count < 10 ; count++)

output_c(trans[count] + 1);

delay_ms(400);

output_c(0b00000000);

delay_ms(400);

/////////////////////////////////////////////////

void process_current (void)

{ set_adc_channel(2);

delay_ms(5);

adc_read();

adc_value = adc_value*50000/1023;

lcd_com(0xc0); // line 2 of lcd

lcd_data('C');

lcd_data('U');

lcd_data('R');

lcd_data('R');

lcd_data('E');

lcd_data('N');

lcd_data('T');

Hajvery University Lahore 86


lcd_data('=');

digit1 = adc_value/10000;

trans[3] = digit1 ;

lcd_data (digit1+0x30);

lcd_data ('.');

digit1 = (adc_value/1000)%10;

trans[4] = digit1 ;

lcd_data (digit1+0x30);

lcd_data('A');

/////////////////////////////////////////////////

void process_voltage(void)

{ set_adc_channel(3);

delay_ms(5);

adc_read();

adc_value = adc_value*5000/1023;

lcd_com(0x80);

lcd_data('V');

lcd_data('O');

lcd_data('L');

lcd_data('T');

lcd_data('A');

lcd_data('G');

Hajvery University Lahore 87


lcd_data('E');

lcd_data('=');

digit1 = adc_value/1000;

trans[0] = digit1 ;

lcd_data (digit1+0x30);

digit1 = (adc_value/100)%10;

trans[1] = digit1 ;

lcd_data (digit1+0x30);

digit1 = (adc_value/10)%10;

trans[2] = digit1 ;

lcd_data (digit1+0x30);

lcd_data('V');

/////////////////////////////////////////////////

void process_temperature(void)

{ set_adc_channel(0);

delay_ms(5);

adc_read();

adc_value = adc_value*5000/1023;

lcd_com(0x90);

Hajvery University Lahore 88


lcd_data('T');

lcd_data('E');

lcd_data('M');

lcd_data('P');

lcd_data('E');

lcd_data('R');

lcd_data('A');

lcd_data('T');

lcd_data('U');

lcd_data('R');

lcd_data('E');

lcd_data('=');

digit1 = (adc_value/100)%10;

trans[5] = digit1 ;

lcd_data (digit1+0x30);

digit1 = (adc_value/10)%10;

trans[6] = digit1 ;

lcd_data (digit1+0x30);

lcd_data('C');

/////////////////////////////////////////////////

Hajvery University Lahore 89


void adc_read(void)

{ adc_value = 0;

for (count=0; count < 30; count++)

{ adc_value = adc_value+read_adc(); delay_ms(10); }

adc_value = adc_value/30;

/////////////////////////////////////////////////

void lcd_ini(void)

{ delay_ms(300);

lcd_com(0x38);

lcd_com(0x0C);

lcd_com(0x01);

delay_ms(50);

/////////////////////////////////////////////////

void lcd_com(char i)

{ output_low (RS); // = 0;

PORTB = i;

output_high(EN);

delay_us(100);

output_low (EN);

Hajvery University Lahore 90


}

/////////////////////////////////////////////////

void lcd_data(char i)

{ output_high (RS); // = 0;

PORTB = i;

output_high(EN);

delay_us(100);

output_low (EN);

Hajvery University Lahore 91


Chapter 8
Conclusion and Future Work

Hajvery University Lahore 92


8.1 Introduction
We have tried to build an innovative and effective Communication system between node unit
and base unit by through RF. In this section we discuss the conclusion that we have collect
from our project.

8.2 Conclusion

A fully functional wireless communication system between two units can be made cost
effectively. The architecture designed is implementable in real applications with very few or
no modifications required. This project if researched on a little more will become a
successful product whose market can be all domestic. Now after completing this project, we
are quite satisfied that we have achieved our goal to extend. During the period of our final
project, we came to know about particle aspects of implementation and maintenance of
wireless sensors in transmission lines that sound our knowledge in electrical, telecom and
electronics. As these are the most disciplined fields with challenges and prospect. Indeed,
having entered this splendid world, we greedier for the new.

Reliable communication is crucial for successful deployment of wireless networks. After


much tweaking and debugging, we finally got the communication system between two units
to work as we specified. It is able to exchange data and handle all handshaking and error
cases as planned. Transceivers should be able to communicate up to 100 feet. We connect a
LED’s wit transmitter and receivers they blink at the time when the data is transmitting by
the transmitter and on the other hand data is received by the receiver.

RF communication system works better in free space.

 The transmitted power of the system varies with the variation in temperature.
 RF system works well in conditions with a high humidity (i.e., at night and during
rain)

Hajvery University Lahore 93


8.3 Future work

A lot of future enhancements can be worked on this project. If we were to do this project
again, we would probably consider finding a pair of transceivers that operates on different
frequencies. This would simplify the logic and state transition of the project by a lot since we
would need much less handshaking and error control

We would also change it so that one node can communicate with more node at the same time
in wireless domain and partially accessible by the base node, by doing that we can reduce
human efforts, time saving and less security issue. This should not be too difficult, since all
we have to do is to include the target device's identification number when we are about to
send data. That way, only the target device will pick up the transmission. We would also
change it so that the distance between transmitter and receiver will be more than 100 feet.

Hajvery University Lahore 94


8.4 Cost analysis

S.no Description Unit Price in Rs. Total Price in Rs.

1 2 Power Supplies (5V) 400 800

2 Temperature Sensor 200 200

3 Voltage Sensor 430 430

4 Current sensor (A) 390 390

5 2 µ Controllers PIC (PIC16F877) 600 1200

6 2 RF Transceivers 3000 6000

7 LCD 1600 1600

8 2 PCB Design and its fabrication 2500 5000

9 Max232 180 180

10 8 Optocoupler 60 480

11 4 Encoder and Decoder 320 1280

12 Misc. 3500 3500

Total 21060

Hajvery University Lahore 95


8.5 Time Analysis

Hajvery University Lahore 96


Chapter 9
References

Hajvery University Lahore 97


9.1 References
[1] http://www.lvr.com/serport.htm#pccode
[2] http://www.kpsec.freeuk.com/powersup.htm
[3] http://www.nabilkarami.com/projects.php?show=project&id=44
[4] http://esd.cs.ucr.edu/labs/serial/serial.html
[5] http://www.educypedia.be/electronics/rfdigmod.htm
[6] http://www.rentron.com/PicBasic/PBP.htm
[7] http://www.circuitstoday.com/inputoutput-ports-and-tris-registers-in-pic-
16f877
[8] http://www.rentron.com/Products/PIC-Micro.htm
[9] http://ww1.microchip.com/downloads/en/devicedoc/30292c.pdf
[10] http://www.rentron.com/
[11] http://www.rentron.com/PicBasic/RemoteControl.htm
[12] http://www.anotherurl.com/library/rs232.htm
[13] http://www.alldatasheet.com/
[14] http://www.fouriersystems.com/files/download_center/fourier_sensor_voltage
.pdf
[15] http://www.datasheetarchive.com/pdf-datasheets/Datasheets-10/DSA-
195117.html
[16] http://www.datasheetcatalog.com/datasheets_pdf/C/1/8/1/C1815.shtml
[17] http://www.alibaba.com/product-tp/107151050/RF_Transceiver_Module.html
[18] http://www.spelektroniikka.fi/kuvat/PT2262.pdf
[19] http://www.escol.com.my/Datasheets_specs/pt2262_1.pdf
[20] http://www.spelektroniikka.fi/kuvat/PT2272.pdf
[21] http://www.cymbet.com/content/applications-wsensors.asp
[22] http://www.facstaff.bucknell.edu/mastascu/elessonshtml/Sensors/LM35.pdf
[23] http://www.facstaff.bucknell.edu/mastascu/elessonshtml/Sensors/TempLM35.
html
[24] http://www.suite101.com/content/functions-of-a-current-transformer-a120516.
[25] http://www.datasheets.org.uk/pdf/getfile.php?dir=Datasheet-
017&file=DSA00289255.pdf&scan=n
[26] http://en.wikipedia.org/wiki/Current_sensor
[27] http://aitendo2.sakura.ne.jp/aitendo_data/product_img2/display/STN/JHD164
A /JHD164.pdf
[28] http://www.tme.eu/dok/a29/SENS-818.pdf
[29] www.st.com/stonline/books/pdf/docs/1707.pdf
[30] http://www.elechouse.com/elechouse/index.php?main_page=product_info&cP
ath=90_179&products_id=347&zenid=2aeff2be7fba766beac8891254d0545a

Hajvery University Lahore 98


Appendix A

Hajvery University Lahore 99


Hajvery University Lahore 100
Hajvery University Lahore 101
Hajvery University Lahore 102
Hajvery University Lahore 103
Hajvery University Lahore 104
Hajvery University Lahore 105
Hajvery University Lahore 106
Hajvery University Lahore 107
Hajvery University Lahore 108
Hajvery University Lahore 109
Hajvery University Lahore 110
Hajvery University Lahore 111
Appendix B

Hajvery University Lahore 112


Hajvery University Lahore 113
Hajvery University Lahore 114
Hajvery University Lahore 115
Hajvery University Lahore 116
Hajvery University Lahore 117
Hajvery University Lahore 118
Appendix C

Hajvery University Lahore 119


Hajvery University Lahore 120
Hajvery University Lahore 121
Hajvery University Lahore 122
Hajvery University Lahore 123
Hajvery University Lahore 124
Hajvery University Lahore 125
Hajvery University Lahore 126
Hajvery University Lahore 127
Hajvery University Lahore 128
Hajvery University Lahore 129
Hajvery University Lahore 130
Hajvery University Lahore 131
Hajvery University Lahore 132
Hajvery University Lahore 133
PT2272

Hajvery University Lahore 134


PT2262

Hajvery University Lahore 135

Potrebbero piacerti anche