Project Report

117
SMART GRID SYSTEM By Aftab Hussain (2008-NUST-BEE-467) Shah Fahad (2008-NUST-BEE-500) Muhammad Sumran Saleem (2008-NUST-BEE-378) A Thesis report submitted in partial fulfillment Of the requirement for the degree of Bachelors in Electrical (Electronics) Engineering Department of Electrical Engineering School of Electrical Engineering & Computer Science National University of Sciences & Technology Islamabad, Pakistan 2011-2012

Transcript of Project Report

Page 1: Project Report

SMART GRID SYSTEM

By

Aftab Hussain (2008-NUST-BEE-467)

Shah Fahad (2008-NUST-BEE-500)

Muhammad Sumran Saleem (2008-NUST-BEE-378)

A Thesis report submitted in partial fulfillment

Of the requirement for the degree of

Bachelors in Electrical (Electronics) Engineering

Department of Electrical Engineering

School of Electrical Engineering & Computer Science

National University of Sciences & Technology

Islamabad, Pakistan

2011-2012

Page 2: Project Report

Page 2

CERTIFICATE

It is certified that the contents and form of thesis entitled “SMART GRID SYSTEM ”

submitted by Aftab Hussain-(2008-NUST-BEE-467), Shah Fahad –(2008-NUST-

BEE-500) and Muhammad Sumran Saleem-(2008-NUST-BEE-378 have been found

satisfactory for the requirement of the degree.

Advisor: ______________________________

( )

Co-Advisor: ______________________________

( )

Page 3: Project Report

Page 3

DEDICATION

To Allah the Almighty

&

To our Parents and Faculty

Page 4: Project Report

Page 4

ACKNOWLEDGEMENTS

We are deeply thankful to our advisor and Co-Advisor, Dr. Tauseef

Tauqeer, and Mr. Habeel Ahmad for helping us throughout the course in

accomplishing our final project. Their guidance, support and motivation enabled us in

achieving the objectives of the project.

We are also thankful to our friends for their valuable feedback for guiding us

through emails and sparing their valuable time for us.

Page 5: Project Report

Page 5

LIST OF FIGURES

Figure 2.2 Smart meter……………………………………………………………………………………….18

Figure 2.1 Machanical meter……………………………………………………………………………….18

Figure 2.3 Pin Diagram of ADE7878………………………………………………………………………20

Figure 2.4 Architecture of ADE7878………………………………………………………………………21

Figure 2.5 Test circuit of ADE7878………………………………………………………………………..20

Figure 2.6 pin diagram of CS5463…………………………………………………………………………22

Figure 2.7 Architecture CS5463…………………………………………………………………………….23

Figure 2.8 Test circuit of CS5463……………………………………………………………….............23

Figure 2.9 Pin diagram of MAXQ3180………………………………………………………………….25

Figure 2.10 Diagram of Architecture of MAXQ3180……………………………………………..26

Figure 2.11 Test diagram of circuit MAXQ3180…………………………………………………….26

Figure 2.12 Pin diagram of ADE7769……………………………………………………………………28

Figure 2.13 Block diagram ADE7769……………………………………………………………………..28

Figure 2.14 Pin Diagram with commercial view…………………………………………………..29

Figure 2.15 Block diagram of 78M6612………………………………………………………………...30

Figure 2.16 Test circuit of 78M6612……………………………………………………………………30

Figure 2.17 Plot of rms value of current and voltages…………………………………....32

Figure 2.18 Plot of voltage current and power……………………………………………………..32

Figure 2.19 Plot of instantaneous power across inductor…………………………………...33

Figure 2.20 Graph of power factor………………………………………………………………………34

Figure 2.21 Diagram explaining the various configurations for distributed power

factor correction……………………………………………………………………………………………………35

Figure 3.1 Block Diagram………………………………………………………………………………………41

Page 6: Project Report

Page 6

Figure 3.2 Automatic meter reading system…………………………………………………………42

Figure 3.3 CS5463…………………………………………………………………………………………………43

Figure 3.4 18F4520……………………………………………………………………………………………….43

Figure 3.5 Sim900 dz…………………………………………………………………………………………….44

Figure 3.6 LCD…………………………………………………………………………………………………….45

Figure 3.7 System Block Diagram………………………………………………………………………….46

Figure 3.8 Line voltage circuit……………………………………………………………………………….47

Figure 3.9 Voltage attenuation Circuit………………………………………………………………….47

Figure3.10 Line current circuit……………………………………………………...48

Figure 3.11 Input current Attenuation circuit……………………………………………………….48

Figure 3.12 Voltage power supply circuit with regulator…………………………………….49

Figure 3.13: Complete Schematic………………………………………………………..49

Figure 3.14 connection of CS5463………………………………………………………………………..50

Figure 3.15 Final meter circuit………………………………………………………………………………53

Figure 3.16 Power factor correction schematic…………………………………………………….54

Fig 4.1 Measurement of the power factor, current, voltage, frequency and phase.55

Figure 4.1 interface between EEPROM and 18F877A…………………………………………….56

Figure 4.2 interfacing between 18F877A and LCD………………………………………………….57

Figure 4.3 Interfacing between CS5463 and PIC 18F877A………………………………………58

Figure 4.4 MCU Flow diagram………………………………………………………………………………..59

Figure 4.5 LM35 Temperature sensor IC…………………………………………………………………60

Figure 4.6 Temperature measurement with pic microcontroller using the LM35 sensor..59

Figure 4.7 Block diagram of the meter implemented with pic microcontroller……..62

Figure 4.8- Simulations of the meter implemented with the pic microcontroller….…63

Page 7: Project Report

Page 7

Figure 4.9 Load management………………………………………………………………………………64

Fig 4.10 Complete System diagram……………………………………………………………………..65

Fig A.1 CS5463 Pin diagram………………………………………………………..69

Fig: A.2 Pin diagram of Pic16f877A………………………………………………………………………72

Fig A.3 LCD Pin diagram……………………………………………………………………………………….73

Fig A.4 LCD pins description…………………………………………………………………………………73

Fig B.1 Clock diagram of CS5463………………………………………………………………………….74

Page 8: Project Report

Page 8

Contents

Abstract ......................................................................................................................... 13

Chapter 1 ...................................................................................................................... 14

Introduction................................................................................................................... 14

Importance .................................................................................................................... 14

1.2 Project Goal ............................................................................................................ 15

1.3 Required Analysis: .................................................................................................. 15

1.3.1 Power Factor Measurement: ............................................................................... 16

1.3.2 Power Factor Correction: ................................................................................... 16

1.3.3 Smart Grid Application: ...................................................................................... 16

Chapter 2 ...................................................................................................................... 17

Literature Survey .......................................................................................................... 17

2.1 Comparison between Smart meters with Mechanical meters ............................... 17

2.1.1 Mechanical Meter ............................................................................................. 17

2.1.2 Smart Meter ....................................................................................................... 18

2.2 Organization of Literature Survey ........................................................................ 19

2.3 Energy measurement IC ........................................................................................ 19

2.3.1 ADE7878 ............................................................................................................ 19

2.3.1.1 Pin Configuration ........................................................................................... 19

2.3.1.2 Architecture.................................................................................................... 20

2.3.1.3 Test Circuit...................................................................................................... 21

2.3.1.4 Company Name ............................................................................................... 21

2.3.2 CS5463 ............................................................................................................... 22

2.3.2.1 Pin Configurations .......................................................................................... 22

2.3.2.2 Architecture.................................................................................................... 22

2.3.2.3 Test Circuit...................................................................................................... 23

Page 9: Project Report

Page 9

2.3.2.4 Company Name ............................................................................................... 24

2.3.3 MAXQ3180 ........................................................................................................ 24

2.3.3.1 Pin Configurations .......................................................................................... 25

2.3.3.2 Architecture.................................................................................................... 25

2.3.3.3 Test Circuit...................................................................................................... 26

2.3.3.4 Company Name ............................................................................................... 27

2.3.4 ADE7769 ............................................................................................................ 27

2.3.4.1 Pin Configurations .......................................................................................... 28

2.3.4.2 Architecture.................................................................................................... 28

2.3.4.3 Company ......................................................................................................... 28

2.3.5 78M6612 ........................................................................................................... 29

2.3.5.1 Pin Configurations .......................................................................................... 29

2.3.5.2 Architecture.................................................................................................... 29

2.3.5.3 Test Circuit...................................................................................................... 30

2.3.5.4 Company ......................................................................................................... 31

2.4 Power Factor: ....................................................................................................... 31

2.4.1 Need of improving of power factor: .................................................................. 34

2.4.4 Distributed power factor correction: ................................................................ 35

2.4.5 Group power factor correction:......................................................................... 35

2.4.6 Centralized power factor correction: ............................................................... 35

2.4.7 Combined power factor correction:................................................................... 36

2.4.8 Automatic Power factor correction: .................................................................. 36

2.5 Load Management: ............................................................................................... 36

2.5.1 Our work ........................................................................................................... 37

2.5.2 Brief History: .................................................................................................... 37

2.5.3 Advantages of load management: ..................................................................... 38

2.6 GSM module: ........................................................................................................ 38

2.6.1 Advantages of GSM Module ................................................................................ 39

Page 10: Project Report

Page 10

2.6.2 Functions of GSM ................................................................................................ 39

2.7 MARKET COMPARISON:.................................................................................... 39

Chapter 3 ...................................................................................................................... 41

Functionality and Design .............................................................................................. 41

3.1 Overview: ............................................................................................................... 41

3.2 Block Diagram: ....................................................................................................... 41

3.3 Metering IC Cirrus CS5463: .................................................................................. 43

3.4 Microcontroller PIC18f4520: ................................................................................. 43

3.5 GSM Modem Sim Com Sim900DZ: ........................................................................ 44

3.6 LCD: ....................................................................................................................... 45

3.7 Database: ................................................................................................................ 45

3.8 Functioning ............................................................................................................. 45

3.9 Voltage Sensing Circuit .......................................................................................... 46

3.10 Current Sensing Circuit ........................................................................................ 47

3.11 Power Supply to the IC: ........................................................................................ 48

3.12 CS5463 IC Connection diagra: ............................................................................ 50

3.9 System Flow Chart .................................................................................................. 51

3.10 Final metering circuit: ......................................................................................... 52

3.10.1 Working: ............................................................................................................ 52

3.10.2 Functionality: ..................................................................................................... 52

3.10.3 Timer Programming algorithm for power factor measurement: ....................... 52

3.11 Automatic Power factor Correction: .................................................................... 53

3.11.1 Functionality: ..................................................................................................... 54

3.11.2 Switching of capacitors for power factor correction ....................................... 54

Chapter 4 ...................................................................................................................... 55

Implementation and Results .......................................................................................... 55

4.1 Interfaces................................................................................................................. 55

4.1.1 18F877A and LCD ............................................................................................... 56

Page 11: Project Report

Page 11

4.1.2 16F877A and LCD ............................................................................................... 57

4.1.3 18F877A and CS5463 .......................................................................................... 57

4.2 SPI Meter Flow Diagram........................................................................................ 59

4.3 Programming .......................................................................................................... 59

4.4 LM35 Based Temperature Monitor ..................................................................... 60

4.4.1 LM35 Temperature Sensor: ................................................................................. 60

4.4.2 Converting ADC Reading to Celsius degrees:..................................................... 61

4.5 Detailed view of the meter implemented with pic microcontroller ......................... 62

4.6 Load Management .................................................................................................. 63

4.7 Complete System Diagram ...................................................................................... 65

Chapter 5 ...................................................................................................................... 66

Conclusions and Future Recommendations.................................................................. 66

5.1 Conclusions ............................................................................................................. 66

5.2 Recommendations ................................................................................................... 66

Chapter 6 ...................................................................................................................... 67

Appendices .................................................................................................................... 68

Appendix A .................................................................................................................... 69

Pin layouts .................................................................................................................... 69

A.1 CS5463 ................................................................................................................... 69

A.1.1 Clock .................................................................................................................. 69

A.1.2 Control Pins and Serial Data I/O: .................................................................... 70

A.2 16F877A ................................................................................................................. 72

Appendix B .................................................................................................................... 74

Timing Diagrams .......................................................................................................... 74

B.1 CS5463 Timing Diagram ........................................................................................ 74

Appendix C .................................................................................................................... 75

Coding ........................................................................................................................... 75

Meter Coding for power factor, voltage, current, phase and frequency measurement 75

Page 12: Project Report

Page 12

Meter Coding with GSM ............................................................................................... 86

Grid Side Coding .......................................................................................................... 98

Temperature Sensor Code........................................................................................... 114

References ................................................................................................................... 117

Page 13: Project Report

Page 13

Abstract

Smart Grid System plays an important role and is an effective means of data collection

and grid automation that allows substantial saving through the reduction of meter

reread, greater accuracy, allows frequent reading, improved billing and customer

service, more timely energy profiles and consumption trends updates, and better

deployment of human resource.

In this project, GSM technology is used to implement an AMR system by

means of PIC microcontroller that will read the power consumed by the customers and

send it to the power grid. Moreover a small Power grid is also implemented that will

be automatically supply the power according to the need of the customer by switching

the relays in order to avoid the loss of the extra power.

The GSM Energy Profiling System (GEPS) takes advantage of the available

GSM infrastructure’s nationwide coverage and the Short Messaging Service (SMS) to

transmit energy reading from the digital electric meters to the supplier (server) and

receive alerts at the consumer (User) end during the peak hours.

Dedicated Single phase meters are installed at the user end. Two meters were

implemented in this project. One that measures the power purely by the PIC

microcontroller and the second was implemented through the PIC and CS5463 SPI

interfacing. The microcontroller after measuring the energy generates a message that

contains the energy spent by the customer and this message is then transmitted to the

server over the GSM network via the transmission module (Serial GSM Modem). The

reception module is also a GSM modem connected to the server system which

receives the energy readings transmitted by the consumers and relays them to the

server system

If commercially employed, this is a comprehensive system which accurately

maintains and illustrates energy usage data via an efficient monitoring and profiling

system and extensive control by the supplier company.

Page 14: Project Report

Page 14

Chapter 1

Introduction

Smart grid fulfills the great vision for electrical networks because it improves the

reliability, security and efficiency of the electrical networks. Today’s electrical

network becomes smart when the conventional electric system becomes accompanied

with communications infrastructure, data management, automation, and control

technologies because when we apply modern communication system in electric

networks then it can give us a better result in terms of management of power

production, distribution, improvement of power losses and consumption which is done

by producers of electricity, consumers, domestic and industry users.

This concept is not new for the entire industry users but as far as the

domestic consumer concern it is new especially for sub continent region which include

Pakistan, India, Bangladesh. Industry has already recognized and enjoyed the benefits

of closely monitoring and intensively managed electric system delivered electricity to

its consumer. Control and monitoring equipment install on major part of the electric

system to improve the reliability and operational efficiency. The main disadvantage of

using highly monitoring and intensively managed electric system is of high cost

because high cost placed a limitation on practical usage on technology .High cost is

the most critical element for its largest consumers.

Smart grid is very vast field .It replaces the mechanical meter with a digital

meter or smart meter that records the usage of consumer in real time and the data at

headquarter without any lose of data and there is no need of meter reader . Smart

meter technology is very similar to advanced metering infrastructure and it provides a

communication path between generation plants to electrical outlets and other smart

grid enabled devices. [1] Smart meter with a power factor improver is the main part of

our project which we have to be done.

Importance

Smart grid with smart metering has initiated in a lot of countries all around the globe

and it has proven its concept because they are cost effective and has maximum energy

efficiency leading many governments to mandate advanced metering. Today in US

Page 15: Project Report

Page 15

this technology is grooming very rapidly and the expected growth is between 15 to 20

percent annually.

We mould our project of smart grid towards smart metering with load management.

Because smart grid is a vast field and smart metering with load management is a

subfield in smart grid .The importance of our project is that we try developing our

project in product form .The product has a smart meter with a power factor improver

and with a load management. The importance of smart metering cannot be neglected

during this era of technology. Smart meters are fully electronic and smart, with

integrated bi-directional communications, advanced power measurement and

management capabilities.

Smart with smart metering gives many advantages to customer .It Allows customers to

make informed decisions by providing highly detailed information about electricity

usage and costs. Armed with a better understanding of their energy use, consumers

can make informed decisions on how to optimize their electricity consumption and

reduce their bills. It helps the environment by reducing the need to build power plants,

or avoiding the use of older, less efficient power plants as customers lower their

electric demand.

1.2 Project Goal The goal of the project is to develop the product which gives meter readings of

current, voltage; power .It also improves the power factor and manage the load of

appliances. Following are the points.

First step is to read the data from load with the help of energy metering

IC. This data includes reading of voltage, current, energy, real power

apparent power, reactive power .

Second step to design the circuit for power factor improvement circuit

with the help of relays and capacitor for inductive load.

Third step is to manage the load by using GSM modules.

1.3 Required Analysis: There are basically three main modules of our project.

Power measurement

Power factor measurement and correction

Smart grid application through the GSM module and inverters

Page 16: Project Report

Page 16

1.3.1 Power Factor Measurement: In this module of the project the voltage,

current, power and power factor of the load will be measurement.

1.3.2 Power Factor Correction: Generally the power factor of our loads is

smaller than unity. So in this module we will compare the measured power factor with

unity and through automated power factor correction we will bring it approximately to

unity. This process is called the power factor correction.

1.3.3 Smart Grid Application: Based on the measured power of our load we will

divide our input power into the various loads in the ratio needed for it. This is called a

smart grid process. Based on the power received from the users we will run the

required generators in order to provide power to the users according to their need and

to avoid the production of extra power by the generators.

Page 17: Project Report

Page 17

Chapter 2

Literature Survey

Smart meter is actually an electrical meter that records and measure the

consumption of electric energy and sends this information or data to the server or

utility back once in a day or in a week or in a month for monitoring a billing purposes

. It allows two ways communication between meter and the server .It can also gather

data for remote operating. Such type of advanced metering system is different from

traditional metering system because it has a two way communication system which is

lacked in traditional metering system. [2]

The Term smart meter refers to electricity meter. Smart has features of real

or near real time sensors, notification of usage and power quality monitoring by

improving the power factor these additional features make smart metering technology

different from rational metering technology. Generally smart meter technology is less

costly than traditional metering technology and this technology can be used on wide

scale with all customer classes including industrial and domestic consumers.

2.1 Comparison between Smart meters with Mechanical meters

2.1.1 Mechanical Meter These are the meters that have been in use for a century. They

work like a sort of electrical motor, with the current passing through the meter turning

a wheel which runs a mechanical counter. They are simple and reliable, but they can

only measure the total amount of electricity used over time. Anything more

sophisticated will require an upgrade. This includes the time-of-use metering, where

the rate is lowered at off hours. [3]

Mechanical is on electricity meter. It is a devise that measures an electric

energy consumed by the residence with the help of a coil which is rotating inside the

meter .Electricity meters are calibrated in billing units and commonly used unit is

kilowatt hour . Periodic readings of electric meters establish billing cycles and energy

used during a cycle. In settings when energy savings during certain periods are

Page 18: Project Report

Page 18

desired, meters may measure demand, the maximum use of power in some interval. In

some areas the electric rates are higher during certain times of day, reflecting the

higher cost of power resources during peak demand time periods. Also, in some areas

meters have relays to turn off nonessential equipment.[4]

Figure 2.1 Machanical meter

2.1.2 Smart Meter

Smart meter using load monitoring to automatically determine the number

and type of appliances in a residence and how much energy are uses by a consumer

and when this energy is consumed .This meter is used by the electric utilities. It

eliminates the use of timer on all the appliances in a house to determine that how

much energy is used by the

device. There is also a price

difference between a smart meter

and mechanical meter because

of load shifting.

Figure 2.2 Smart meter

Page 19: Project Report

Page 19

2.2 Organization of Literature Survey We have divided our literature survey into three section.

Literature survey of energy measurement IC.

Literature survey of power factor improvement.

Literature of load management.

2.3 Energy measurement IC

Our first part is to measure the energy data with the help of energy

measurement IC and show this data on LCD. For this purpose we search upon various

IC’s .We will give you the detail research on IC’s later in this survey report. We read a

data sheet of various energy measurement IC’s .This search include how to measure

the current and voltage readings, how to use the IC in order to measure the power

factor and how to measure the real, apparent and reactive power .How to interface

with the IC? How to build its circuit board? In the next section the description of

various energy metering ICs is described.

2.3.1 ADE7878 Following are the features of this IC.

3 Phase electrical measurement IC

It can measure active, reactive, and apparent energy measurement and RMS

calculation

4 logical output pins

It also provide power quality measurement ,short duration lower voltage

detection ,short duration high current variation, line voltage period

measurement and angle phase voltage

2.3.1.1 Pin Configuration

The pin description of the IC is on next page. [6]

Page 20: Project Report

Page 20

Figure 2.3 Pin Diagram of ADE7878

The IC contains waveform sample register which allow access to all ADC outputs.

There are two serial interfaces that can be used to communicate with ADE7878 .It also

has two interrupted request pins IRQO and IRQ1 which are used to indicate that a

valid interrupt has been occurred. There are two special modes for low power which

ensures the continuity of energy accumulation when ADE7878 is in a tampering

mode. It has three logic outputs which give us a wide range of power information like

total active and reactive power, total rms current values .It’s used in energy metering

system

2.3.1.2 Architecture

Figure 2.4 Architecture of ADE7878

Page 21: Project Report

Page 21

2.3.1.3 Test Circuit

There is a test circuit of this IC. Which is use to test the IC. [6].

Figure 2.5 Test circuit of ADE7878

2.3.1.4 Company Name Its company name is analog devices. Following are the distributors of IC. [7]

Digikey

Newark

Farnell

Verical

Price (100-499) $8.76 1000PCS $7.47

Page 22: Project Report

Page 22

2.3.2 CS5463 Following are the features of this IC that we have used in

our project.

Single-Phase Bi-Directional Power/Energy IC

High speed power calculation serial interface on a single chip

It accurately measures instantaneous power RMS current and voltages real,

apparent, reactive, fundamental power, power factor ,line frequency

For communication with a microcontroller, the IC features a bi-directional

serial interface, which is initialized and fully functional upon reset

The CS5463 can interface to a low-cost shunt resistor or transformer for

current measurement and to a resistive divider or potential transformer for

voltage measurement

The CS5463 delivers accurate power usage measurements and is ideal for

electronic power meter applications

2.3.2.1 Pin Configurations The pin diagram is [8]

Figure 2.6 pin diagram of CS5463

2.3.2.2 Architecture

The block diagram of CS5463 is given below. [8]

Page 23: Project Report

Page 23

Figure 2.7 Architecture CS5463

2.3.2.3 Test Circuit

[8]

Figure 2.8 Test circuit of CS5463

Page 24: Project Report

Page 24

2.3.2.4 Company Name

Name of the company is cirrus logic Following are the distributors of . [7]

Digikey

Newark

Farnell

Verical

Avnett express

Tti

Mouser electronics

Price

1 $3.75 25 $75.38

2.3.3 MAXQ3180

Following are the features of the IC

Low-Power, Multifunction, Polyphase

The MAXQ3180 is a dedicated electricity measurement front-end that collects

and calculates polyphase voltage, current, power, energy, and many other

metering and power-quality parameters of a polyphase load.

Active Power and Energy of Each Phase and Combined 3-Phase (kWh),

Positive and Negative

Reactive Power and Energy of Each Phase and Combined, Positive and

Negative.

Apparent Power and Energy of Each Phase and Combined 3-Phase.

Neutral Line Current Measurement.

Page 25: Project Report

Page 25

Line Frequency (Hz)

Power Factors

Voltage Phasor Angles

Phase Sequence Indication

Phase Voltage Absence Detection

Voltage and Current Harmonic Measurement

Fundamental and Total Power and Energy

2.3.3.1 Pin Configurations

The diagram is as below. [9]

Figure 2.9 Pin diagram of MAXQ3180

2.3.3.2 Architecture

The MAXQ3180 contains four major subsections:

The analog front-end,

The digital signal processor,

Page 26: Project Report

Page 26

The precision pulse generators

An SPI peripheral for communication to the host processor.[9]

Figure 2.10 Diagram of Architecture MAXQ3180

2.3.3.3 Test Circuit The block diagram is given below. [9]

Figure 2.11 Test diagram of circuit MAXQ3180

Page 27: Project Report

Page 27

2.3.3.4 Company Name

Name of the company is maxim .following are the distributers of this IC. [7]

Digikey

Avnett express

Mouser electronics

Price 1 $21.97

25 $14.65

100 $10.62

500 $9.4245

2.3.4 ADE7769 Following are the features of the IC.

Single Phase Energy Metering IC with Integrated Oscillator and no-load

indication

The ADE7769 is a high accuracy electrical energy metering IC.

It is a pin reduction version of the ADE7755 with an enhanced, precise

oscillator circuit that serves as a clock source to the chip.

Internal phase matching circuitry ensures that the voltage and current channels

are phase matched, while the HPF in the current channel eliminates dc offsets.

An internal no-load threshold ensures that the ADE7769 does not exhibit creep

when no load is present. During a no-load condition, the CF pin stays logic

high.

Page 28: Project Report

Page 28

2.3.4.1 Pin Configurations

[10]

Figure 2.12 Pin diagram of ADE7769

2.3.4.2 Architecture

The block diagram is given below [10]

Figure 2.13 Block diagram ADE7769

2.3.4.3 Company The name of the company is Analog Devices. Following are the distributers [7]

Digikey

Avnett express

Arrow electronics

Page 29: Project Report

Page 29

PRICE

192 $2.2894

2.3.5 78M6612

Following are the features of the IC.

The 78M6612 is a highly integrated, single-phase AC power measurement and

monitoring (AC-PMON) IC for consumer and enterprise applications capable of

0.5% Wh or better accuracy over 2000:1 current range and over temperature.

Complete firmware is available for supporting the serial UART interface for

simplified calibration, configuration, and data extraction

LCD driver (up to 152 pixels).

Single-Phase, Dual-Outlet

Power and Energy Measurement IC

Energy display on main power failure

Wake-up timer

22-bit delta-sigma ADC

8-bit MPU (80515), 1 clock cycle per instruction/ integrated ICE for MPU debug

RTC with temperature compensation.

2.3.5.1 Pin Configurations

[11]

Figure 2.14 Pin Diagram with commercial view

2.3.5.2 Architecture

Block diagram is given on next page [11]

Page 30: Project Report

Page 30

Figure 2.15 Block diagram of 78M6612

2.3.5.3 Test Circuit Test circuit is given below. [11]

Figure 2.16 Test circuit of 78M6612

Page 31: Project Report

Page 31

2.3.5.4 Company Its company name is tridian semiconductor Corporation. Folowing are the distributors

of this IC. [7]

Digikey

Avnett express

Mouser electronics

Price

1 $3.61

25 $3.14

100 $2.89

500 $2.75

2.4 Power Factor:

In any electrical component the instantaneous power is the

product of the instantaneous voltage and instantaneous current. In a resistive circuit

the voltage and current are in phase and the power calculation is a straightforward

process, (P=VI). But in reactive circuits (capacitive or inductive) the voltage and

current are not in phase and the power calculation becomes very complicated.

Suppose that a sinusoidal voltage v = tVP sin is applied across

a resistor R then the current across the resistor is i = tI P sin where PI =

PV /R. and

so the power across the resistor will be:

p vi = tVP sin tI P sin = )(sin 2 tIV PP = )2

2cos1(

tIV PP

Now the average value of the terms (1-cos2wt) is 1 and so the average power becomes:

Where, V and I are the RMS values of the voltage and current respectively.

Relationship between current voltage and the power is as follows.

VIIV

IVP PPPP

222

1 Power Average

Page 32: Project Report

Page 32

Figure 2.17 Plot of rms value of current and voltages

Now let’s apply the same voltage to a capacitive load of capacitance C, then we know

that in capacitor the current leads the voltage by 900, so if the voltage applied to the

capacitor is VpSin(wt) then the current across the capacitor will be IpSin(wt) where

Ip=Vp/R. So the instantaneous power across the capacitor will be

vip = tItV PP cossin = )cos(sin ttIV PP = )2

2sin(

tIV PP

From the above equation it is obvious that the average power is zero. Following is the

relationship between current, voltage and the power.

Figure 2.18 Plot of voltage current and power

Now if the same sinusoidal voltage is applied across an inductor of inductance L, then

we know that in an inductor the current lags the voltage by 900, so if the voltage

applied across an inductor is v=VpSin(wt) then the current across the inductor will be I

= -IpCos(wt), and the instantaneous power across the inductor will be

Page 33: Project Report

Page 33

p vi = tItV PP cossin = )cos(sin ttIV PP = )2

2sin(

tIV PP

Again the average power is zero, and the relationship between current, voltage and the

power is shown below.

Figure 2.19 Plot of instantaneous power across inductor

Now suppose that we have an RC circuit (circuit with a resistor and a capacitor) to

which we want to apply our sinusoidal input voltage. If the voltage applied to RC

circuit is v = Vpsin(t) then the general form of the current is RC circuit will be i =

Ipsin(t - ), and the instantaneous power provided at any instant of time is:

vip )sin(sin tItV PP )}2cos({cos2

1 tIV PP

)2cos(

2

1cos

2

1 tIVIVp PPPP

The above expression has two terms. The second term is a periodic waveform that

oscillates with a frequency of 2w and so it has an average value of zero. This is

actually the reactive power that is stored by the load and the source. While the

average value provided back to of the first term is not equal to zero. This is the actual

power that is dissipated in the resistor and its average value is P cosPP IV =

)(cos22

PP IV= cosVI . This quantity is termed as the active power in the

circuit and is measured in watts.

The product of the RMS voltage and the RMS current in the circuit is called as the

apparent power denoted by S and is measured in (VA) to avoid confusion. From the

above equation it is clear that the active power P cosS . In these equations the term

Page 34: Project Report

Page 34

cos is known as the power factor. In other words active power is the apparent power

time the power factor. OR

factorPower amperes)(in volt power Apparent

(in watts)power Active

Generally power is represented as a sum of apparent power and reactive

power known as complex power. Complex Power = P+jS. And the magnitude of

complex power is known as the apparent power. The relationship between these

quantities is shown by means of a triangle known as the power triangle as shown in

the following figure.

Active Power

Reactive Power

Apparent Power

Figure 2.20 Graph of power factor

Now consider an RL circuit to which we want to apply our sinusoidal input. The

relationship between the various types of power can be determined using the power

triangle as, Active Power:

P = VI cos (Watts), Reactive Power Q = VI sin (VAR) and the apparent power S =

VI (VA) with S2 = P2 + Q

2.

2.4.1 Need of improving of power factor: Power factor is much more important in high power applications.

The reactive power is not dissipated in the circuit but it increases the current in the

lines and as a result our losses in the circuit increase. Aside from this we will also

require to install switches and other electric equipments of a high current rating and so

the charges to buy these components will be increased. Inductive loads have a lagging

power factor while capacitive loads have a leading power factor. Due to these reasons

Power Factor = Active (Real) Power

Apparent Power

= kW

kVA

= Cosine (θ)

Page 35: Project Report

Page 35

the power supplying industries put a limit on the equipments providers for a power

factor limit not to be less than that.

2.4.4 Distributed power factor correction: Distributed power factor correction is achieved by connecting a bank of capacitors

proper size directly to the terminals of the load. The load and the capacitors use the

same protective devices for over currents and they are switched on and off

simultaneously. This type of power factor correction is not advisable for high power

applications such as industries but it can be used for low power applications such as

for motors in our homes.

The following figure shows its installment.

Figure 2.21 Diagram explaining the various configurations for distributed power factor

correction [16]

2.4.5 Group power factor correction: This method involves the correction of power factor for a group of

equipments that have similar characteristics through a dedicated capacitor. This

method is a compromise between the inexpensive power factor correction and the

proper management for power factor correction because the benefit taken can be felt

along upstream the line where the capacitor bank is located.

2.4.6 Centralized power factor correction: As the time passes, people are searching for efficient ways of power

factor correction. This method fulfills the fact that since each load is our homes or

industries are not working all the time. Some may be idle and some may be working.

It is obvious that many of the capacitors in this method will remain idle and it will

Page 36: Project Report

Page 36

become too enormous. Therefore the use of compensation system at the installment

center will remarkably reduce the amount of power in the capacitor.

2.4.7 Combined power factor correction: This method is a compromise between the distributed power factor

correction and the centralized power factor correction. In a situation where equipments

of high power are frequently used use the distributed power factor correction for the

high power equipments centralized power factor correction for the smaller

equipments.

2.4.8 Automatic Power factor correction: Since in most situations the reactive power is not constant and so a

method should be used such that we take a variable capacitance each time the reactive

power changes. In such systems there must be a monitoring system that monitors the

reactive power each time and a control system that controls the switching of the

capacitors. It will be composed of

Sensors that will sense the current and voltage signals

Some sort of intelligent system that will control the switching of the

capacitors based on the comparison of the present power factor with

our desired one.

Capacitor banks

An electric power board that will contains switches and protection

devices.

2.5 Load Management: Load management is defined as those actions that are taken by the

customers or the power suppliers in order to change the load profile to gain from

reduced total system peak load and increased load factor or improved utilization of

resources.[29]

OR

It is the process of balancing the supply of electricity on the network with

the electrical load by adjusting or controlling the load rather than the power station

output. Load management is used to allowed utilities to reduce the demand for

electricity at the time of use which in turn reduce costs Similarly peaking power

Page 37: Project Report

Page 37

plants often require hours to bring on-line, presenting challenges should a plant go off-

line unexpectedly. Load management is used to overcome harmful emission. Both

private industry and public entities are developing new load management

technologies.

Load management is the fundamental requirement worldwide because

industries and houses have to keep a proper management of the loads according to the

appliances they use. Different appliances and utilities require different amount of

electricity and for this there would be a proper management to keep them in order. A

better load management system will prevent the great loss of power as well as the

harmful effect to the appliances or utilities. [30]

Different utilities have different load management techniques for the

improvement of the load profile of their power system. . These techniques are mostly

implemented by utilities with the co-operation of the customers. As we know that in

today’s word energy management is an important issue. The successful management

of load yields various benefits. The management of load in electric power system

benefits both power utilities and their customers and also saves environment from

unnecessary pollution. Smart grids provide an excellent opportunity to better manage

power quality and reduce harmonic distortions present in power.

2.5.1 Our work In load management we are having three inverters. We will set three

marks that when the power consumption of our load reaches the first mark one of our

inverter will start serving. If the power consumption reaches the 2nd

mark another

inverter will become start serving and so the 3rd

inverter will do so after reaching the

3rd

mark. The communication between the meter and the load management side will

be taking place by GSM.

2.5.2 Brief History: In 1972, George a sensor monitory system uses digital transmissions for

security and medical alarm systems as well as meter reading capabilities for all

utilities while working for Boeing in Huntsville, Alabama. The technology he

developed was an automatic telephone line identification system, now known as caller

ID. In, 1974, he was awarded a U.S. Patent for this technology. The Alabama Power

Company requested him to develop a load management system. He developed a load

management system along with automatic meter reading technology. He utilized the

Page 38: Project Report

Page 38

ability of the system to monitor the speed of the watt power meter disc and power

consumption. This information, along with the time of day, gave the power company

the ability to instruct individual meters to manage water heater and air conditioning

consumption in order to prevent peaks in usage during the high consumption portions

of the day. Due to this approach Mr. Paraskevakos was awarded multiple patents.[31]

2.5.3 Advantages of load management: As we know that electrical energy is a form of energy which cannot

be stored in something like bulks but it must be generated, distributed and consumed

immediately. I mean it cannot be stored for so much time. So whenever the load of the

system approaches maximum generating capacity network operators has to find

additional supplies of energy or find some other ways to curtail the load which may be

called load management. If in case they are unsuccessful to control the load the system

should become unstable and many dangerous or unhealthy things can happen.

Following are the application of load management.

The application of load management can help a power plant to have higher

plant load factor

Plant load factor is a measure of the output of a power plant compared to the

maximum output it could produce. Plant load factor is defined as “the ratio of

average load to capacity or the ratio of average load to peak load in a period

of time.”

A higher load factor is useful because at low load factors power plant may be

not so efficient.

Smaller utilities that buy power instead of generating their own find that they

can also benefit by installing a load control system. The penalties they must

pay to the energy provider for peak usage can be significantly reduced. Many

report that a load control system can pay for itself in a single season

2.6 GSM module: Similar to modems GSM modules work but have on difference. A GSM

modem is external device while GSM module is integrated within equipment. It is

embedded piece of hardware. The GSM module we will use in our project. It will

control the load management by sending message. The GSM module is used in daily

use like in mobile phones.

Page 39: Project Report

Page 39

2.6.1 Advantages of GSM Module Following are the advantages of GSM module hardware.

It is small in size

It is light in weight

It is easy to integrate

It has low power consumption

It has high performance on low price

2.6.2 Functions of GSM Through GSM technology the following functions are done.

Read, write and delete SMS messages.

Send SMS messages.

Monitor the signal strength.

Monitor the charging status and charge level of the battery.

The number of SMS messages processed by a GSM modem is very low, almost six

messages per minute can be transferred. In our case the GSM will transmit

information of data that coming from one point to another. This will be done

according to the programming done in the micro controller. [35]

We use AT commands in GSM to interface with microcontroller. AT is the

abbreviation for attention. A line convertor MAX232 is employed to convert RS232

logic data of GSM module to TTL logic so that it can processed by a microcontroller

TTL logic output has been taken and thus PIC18F4550 has been directly connected

with GSM Modem without any line converter in between.

2.7 MARKET COMPARISON: In Pakistan there is no trend of smart metering because we use a mechanical meters in

Pakistan .but three is trend arises by government of Pakistan is to introduce a digital

meter for domestic use .In market there is a lot of demand of smart meter in Pakistan

and other underdeveloped countries .In developing countries they use smart

technology .The product which we made in our final year project is reliable and

cheaper because we design this meter with locally equipment and we try to utilize the

available resources .We design our board for power meter IC .In market the cost of

this board is 30 to 40 thousand .which cannot afford by layman so we target this unmet

need of our country. By designing we save our 10 to 15 thousands. In developed

Page 40: Project Report

Page 40

countries they use smart meters for metering purposes .and there is also a edge in this

that we also design a power factor improvement circuit for inductive load with this

product .Which help the consumer to manage the power losses of the appliances and

mange the billing utility

Page 41: Project Report

Page 41

Chapter 3

Functionality and Design

3.1 Overview: In this project we use a 18F4520 microcontroller to control operation of the Cirrus

CS5463 power measuring integrated circuit, it stores and retrieve the data using the

EEPROM of 18f4520 because 18f4520 has built in EEPROM and displays the data on

a LCD moreover it also send the information to the GSM modem to be transmitted to

the central data base. Energy transferred between the line and load is measured by the

CS5463. The 18F4520 initializes the CS5463 with calibration data stored in the

EEPROM, records the total energy measured in the memory , display results on

the LCD panel then we have the power factor improve circuit and after improving the

power circuit data is transmitted to central data base periodically. A GSM Modem is

connected to the database for the purpose for receiving the readings.

3.2 Block Diagram:

Energy calculation Communication

Figure 3.1 Block Diagram

MAIN

LOAD

METERING IC

MICRO CONTROLER

GSM MODEM

USER DATA

POWER FACTOR

IMPROVEMENT

IMPRO

Page 42: Project Report

Page 42

Figure 3.2 Automatic meter reading system

Page 43: Project Report

Page 43

3.3 Metering IC Cirrus CS5463:

Figure 3.3 CS5463

Following are the features of this IC.

Single-Phase Bi-Directional Power/Energy IC

High speed power calculation serial interface on a single chip

It accurately measures instantaneous power RMS current and voltages

real, apparent, reactive, fundamental power, power factor, line

frequency

For communication with a microcontroller, the IC features a bi-

directional serial interface, which is initialized and fully functional

upon reset

The CS5463 can interface to a low-cost shunt resistor or transformer

for current measurement and to a resistive divider or potential

transformer for voltage measurement

The CS5463 delivers accurate power usage measurements and is ideal

for electronic power meter applications

3.4 Microcontroller PIC18f4520:

Figure 3.4 18F4520

Page 44: Project Report

Page 44

PIC 18F4520 is a powerful microcomputer which provides a highly-flexible and

cost-effective solution to many embedded control applications. It is one of the most

widely used microcontrollers.

It provides the following standard features. It has power management features like run,

speed, idle, watchdog timers, two-speed oscillator start up, and timer one oscillator.

PIC18f4520 has flexible oscillator structure like four crystal mode up to 40MHz, two

external RC modes, two external clock modes, internal oscillator block, secondary

oscillator timer using timer 1 @ 32 kHz.

It has also special microcontroller features like C compiler optimized architecture

optional extended instruction set designed to optimize re-entrant code, 100000

erase/write cycle enhanced flash program memory typical,1000000 erase/write cycle

data EEPROM memory typical, flash/data EEPROM retention: 100 years typical, self-

programmable under software control, priority levels for Interrupts,8 x 8 single-cycle

hardware multiplier, extended watchdog timer (WDT) programmable period from 4

ms to 131s,single-supply 5V in-circuit serial programming™ (ICSP™) via two pins,

In-circuit debug (ICD) via two pins, wide operating voltage range: 2.0V to 5.5V and

programmable brown-out reset (BOR) with software enable option.

3.5 GSM Modem Sim Com Sim900DZ:

SIM900 is a quad-band GSM engine that works on frequencies GSM 850MHz, with a

tiny configuration of 24mm x 24mm x 3mm; SIM900 can meet almost all the space

requirements in your applications. The SIM900 is designed with power saving

technique so that the current consumption is as low as 1.5mA in SLEEP mode. The

modem package the main board with SIM holder and a magnet based antenna.

The package is the SMD one and is soldered as desired.

Figure 3.5 Sim900 dz

Page 45: Project Report

Page 45

3.6 LCD:

Figure 3.6 LCD

The LCD being used is the JHD 162A. It has a display of 16x2. It has a built in

controller of Samsung KS0066U or equivalent. It is the most commonly used LCD

capable of a 4-bit or 8-bit data interface.

3.7 Database: The date base unit is responsible for maintaining and updating the records. The

database will store info like User ID, Units consumed and the billing. The data base is

a program written in C++. The data base is connected to the modem via RS-232 cable

and receives the data coming from the modem.

3.8 Functioning On power-up, the 18f4520 microcontroller reads the calibration data,

device serial number, and total energy from the EEPROM which is built

in, writes the calibration data to the CS5463, initializes the CS5463, and

reads the state of the control buttons

During normal operation, the 18f4520 counts pulses from the CS5463, reads

CS5463 data registers, drives the LCD panel to display the requested data. The

pulses are used to update the total energy count and are periodically

written to the EEPROM .The total energy count is also forwarded to the

modem for transmission to the central data base after certain time period

The CS5463 measures line voltage and line current to compute power and

energy transferred on the line. When a unit of energy has transferred between

the line and the load, a pulse with direction indication is generated

Page 46: Project Report

Page 46

The units consumed of electricity are computed by the Microcontroller

Unit and passed to the GSM Modem

GSM communication

Figure 3.7 System Block Diagram

3.9 Voltage Sensing Circuit

The line voltage is sampled using a transformer. The differential input is limited to

150mVRMS. In this application, line voltage is detected from the secondary winding

of the power supply transformer.

L

N

G

n

G

L

N

G

G

Current sensor

Voltage

sensor CS5463

18F4520 GSM

Mode

m

Database

GSM

Modem

Power

factor

controller

LCD

Page 47: Project Report

Page 47

Figure 3.8 Line voltage circuit

When operating from 220V, there is about a 6V peak. This voltage is further reduced

by a resistor network before being applied to the CS5463

Figure 3.9 Voltage attenuation Circuit

3.10 Current Sensing Circuit:

The line current will be sampled using a current transformer. In our meter, the current

channel gain is 10, for a maximum input voltage of 150mV RMS. This voltage is

Vin+

CS5463

Vin-

Page 48: Project Report

Page 48

provided by the current sense transformer T1 and resistor R21, and is reduced by a

resistor network.

Figure3.10 Line current circuit

Figure 3.11 Input current Attenuation circuit

3.11 Power Supply to the IC: A transformer isolated power supply provides power for the Watt-Hour Meter.

The transformer primary is connected to the line between the power

source and the current sense transformer. The AC voltage from the

transformer secondary is used to detect the line voltage and is coupled to the

CS5463 through a resistor network.

The AC from the center tapped secondary is full wave rectified,

filtered, and provided to the 5V regulator. The 5V loads are the “power-on”

LED, the CS5463, and the 18f4520. The majority of the current is drawn by

the LED, about 7.5mA. The rest of the circuit draws less than 5mA.

Iin+

CS5463

Iin-

Page 49: Project Report

Page 49

Lm7805 voltage regulator is used in this circuit to provide 5V constant voltage

to the IC for its smooth functioning.

Figure 3.12 Voltage power supply circuit with regulator:

Figure 3.13: Complete Schematic

Page 50: Project Report

Page 50

3.12- CS5463 IC Connection diagram:

Figure 3.14 connection of CS5463

Page 51: Project Report

Page 51

3.9- System Flow Chart:

MAIN

LOAD

Circuit for current

and voltage sense

CS5463

MCU 18F4520 LCD

GSM Modem User cell

GSM Modem Database

Power Factor

correction circuit

Load

management

Page 52: Project Report

Page 52

3.10 Final metering circuit: Following is the finally metering circuit that measures the current, voltage, phase

angle, power factor, frequency and shows them corresponding on the LCD. The IC

used here is the PIC 18f452.

3.10.1 Working: The input to the circuit is taken from the main line which we gave to the current

sensing IC which produces the voltage which is proportional to the current in the

circuit. A step down transformer is used which steps down 220 v to 12 v which is

according to our requirement. After the step down transformer is the resistor divider

which is used to divide the 12 volts to respective required voltages. Now the required

voltages according to specifications are given to the analog input pins of the IC. LCD

is connected to the port D of the ice and the serial communication is done by the Rx

pin of IC.

3.10.2 Functionality: We apply 220 volt to the circuit which passes through the current transformer.

The current transformer senses the current. We connected a step down transformer

which is used to step down 220 V to 12 V in order to bring it to the safety level. After

stepping down the voltage we connected a comparator that is used to detect the zero

crossings of the incoming voltage. When a zero occurs the comparator output becomes

high and an interrupt of the controller is enabled. Similarly from the step down

transformer 12V is sent to the resistor divider circuit that contains two resistors. The

resistor divider divides the voltage and according to the requirement of the controller 5

V is sent to the controller. The controller IC contains the code for measuring voltage,

current, phase, power factor, and frequency. The values of these parameters are shown

on the LCD.

3.10.3 Timer Programming algorithm for power factor measurement: Following are the steps through which we have calculated our factor.

Step 1- Check for voltage cross zero.

Step 2- Timer T starts (T0).

Step 3- Timer T2 starts (T1).

Step 4- Check for current cross zero.

Step 5- Timer T2 stops.

Step 6- Check again for voltage cross zero.

Page 53: Project Report

Page 53

Step 7- Timer T stops.

Step 8- Phase φ = (T2 / T) * 360.

Step 9- Get Cos φ.

Figure 3.15 Final meter circuit

3.11 Automatic Power factor Correction: Automatic power factor correction is used to improve the power factor according to

the load used. As most of the loads in our daily appliances are inductive loads which

causes decrease in power factor so in order to improve the power factor we

added capacitors to our circuit that will stabilize the apparent power of the circuit and

thus improve the power factor. In the circuit that we have designed first we detect the

power factor and then improve it by connecting the capacitors to it.

IP+

4

IP-

5

VIO

UT

3

VC

C1

GN

D2

U2ACS755XCB-050

MCLR/VPP1

RA0/AN02

RA1/AN13

RA2/AN2/VREF-4

RA3/AN3/VREF+5

RA4/T0CKI6

RA5/AN4/SS/LVDIN7

RE0/RD/AN58

RE1/WR/AN69

RE2/CS/AN710

OSC1/CLKI13

RA6/OSC2/CLKO14

RC0/T1OSO/T1CKI15

RC2/CCP117

RC3/SCK/SCL18

RD0/PSP019

RD1/PSP120

RD2/PSP221

RD3/PSP322

RD4/PSP427

RD5/PSP528

RD6/PSP629

RD7/PSP730

RC4/SDI/SDA23

RC5/SDO24

RC6/TX/CK25

RC7/RX/DT26

RB0/INT033

RB1/INT134

RB2/INT235

RB3/CCP2B36

RB437

RB5/PGM38

RB6/PGC39

RB7/PGD40

RC1/T1OSI/CCP2A16

U1

PIC18F452

VCC

AC1

TR1

TRANSFORMER

BAT116V

U4

OP1P

R110k

+8

8.8

AC

Am

ps

R69k

R41k

+88.8

+88.8

AC Volts

+88.8

AC Volts

R2050

Zero Cross Detector

C1

30uF

D7

14

D6

13

D5

12

D4

11

D3

10

D2

9D

18

D0

7

E6

RW

5R

S4

VS

S1

VD

D2

VE

E3

LCD1LM016L

A

B

C

D

RXD

RTS

TXD

CTS

Page 54: Project Report

Page 54

Figure 3.16 Power factor correction schematic

3.11.1 Functionality: The incoming main lines after passing through a step down transformer is passed

through the bridge rectifier, after which it is passed through the voltage regulator to

give a fixed 5 volts to the LED. This pulsating DC is also passed through the 7812

voltage regulator that gives a 12 volt to the LM339 and the relays. We have a zero

voltage cross detector that detects the zero crossings of the voltage and give it to the

microcontroller. The current that is sensed by the current transformer and passed

through the bridge rectifier is passed through the zero current cross detector circuit

that senses the zero crossings of the current and give it to the microcontroller. The

microcontroller sends the instructions to the relays through the relay driver IC to

connect and disconnect the capacitors in order to improve the power factor.

3.11.2 Switching of capacitors for power factor correction We will set two upper and lower limits for the power factor.

Let initially one capacitor is on. Then for lower power factor (lower than LPF) and it

increases up to user limit. As the power factor crosses the UPF limit then 1st capacitor

is switched off. And it continues up to the user limit. Again when it crosses the LPF

limit the switching on process starts. As the 6th capacitor is switched on then next is

1st capacitor. Therefore 1st capacitor is switched on. And this way all capacitor is

equally utilized.

Page 55: Project Report

Page 55

Chapter 4

Implementation and Results

This chapter focuses on the implementation of the project and the practical results

obtained. The first result obtained were the measurement of the power factor. The

following shows the results of the project in which the voltage, current, power factor,

frequency and phase have been measured.

Fig 4.1- Measurement of the power factor, current, voltage, frequency and phase

4.1 Interfaces Mainly two interfacing is done

Page 56: Project Report

Page 56

4.1.1 18F877A and LCD It is a 4-bit data interface and the two control signals are also connected to the 89S51.

The control signals are explained as under

RS Register Select. Indicates whether an instruction or data is being sent

R/W indicates that when read and write operation is done.

E data enable .Data is latched when it changed from 1 to 0

4 bit Data Interface

P0.4 to P0.7 for Data Bits

P0.3 for Enable

Data is latched whenever it is changed from 1 to 0

P0.2 for Register Select

1 indicates an instruction

Figure 4.1 interface between EEPROM and 18F877A

On Startup, MCU takes previously stored data from EEPROM

When the Power is disconnected, a capacitor provides a short duration of 1-2

sec of +5V to store the readings on EEPROM

SCK

SDA

Page 57: Project Report

Page 57

Readings of Kilowatt Hours are stored in EEPROM

4.1.2 16F877A and LCD It is a 4-bit data interface and the 2 control signals are also connected to the

89S51. The control signals are explained as under

RS Register Select. Indicates whether an instruction or data is being sent

R/W indicates that when read and write operation is done.

E data enable .Data is latched when it changed from 1 to 0

Figure 4.2 interfacing between 18F877A and LCD

4 bit Data Interface

P0.4 to P0.7 for Data Bits

P0.3 for Enable

Data is latched whenever it is changed from 1 to 0

P0.2 for Register Select

1 indicates an instruction

4.1.3 18F877A and CS5463 The data is transferred serially b/w the 89S51 and the CS5460. The signals

consist of simply a SDI (serial data in) and SDO (serial data out) and SCL (Serial

Clock) and CS (chip select).

4Bit data interface

Page 58: Project Report

Page 58

Figure 4.3 Interfacing between CS5463 and PIC 18F877A

Serial Interface

– CS Chip Select

– SCLK Serial Clock

– SDO Serial Data Out

– SDI Serial Data In

CS is high SDI,SDO,SCLK are in high Impedance

CS is low, SDI,SDO,SCLK perform their respective functions

Start Condition/Command

C= Mode of Measurement

0 = Perform a single computation cycle

1 = Perform continuous computation cycles

1 1 1 0 C 0 0 0

SD0

O

SCK

CS

SDI

Page 59: Project Report

Page 59

4.2 SPI Meter Flow Diagram

Figure 4.4 MCU Flow diagram

4.3 Programming The compiler used for to program the pic microcontroller for SPI interfacing is

MicroC.

The CS5463 is programmed by burning the HEX file containing the parameter

for the Configuration of the IC.

The PIC 16F877A is burned using the SUPER PRO USB Programmer.

Get the

previous

reading from

EEPROM

Display the reading

on LCD

Give the

parameter

to CS5463

Increment the

reading

according to

the load

Determine the load

correspondence to that

value

GET the Value of

Current register

from IC

Display the reading

on the LCD

Store readings in EE prom

Page 60: Project Report

Page 60

4.4 LM35 Based Temperature Monitor ADC being and internal module and is used to read analog voltages in

digital representation. In the project we have used 16F877 having 10 bit resolution

internal ADC module having 8 channels A0-A5 and E0-E2.

Important parameter of the ADC module is that of its reference voltage (Vref) which

is the maximum voltage which can be read by ADC. In our case Vref=5V which is our

supply voltage. ADC resolution is another important parameter, which determines the

minimum value of analog voltage can read.

As our ADC is 10bit resolution having 5V reference so the voltage from

0V till 5V is divided into equal steps starting from 000 and ended by 1023 (210-1).

So if the max input voltage is 5V the ADC will read it as 1023. If it is 2.5V the

reading will be 512, if 0V reading will be 000 and so on.

The ADC step is simply calculated using the equation: Step= Vref/1024, in

our case its 4.883mV which is the minimum voltage our ADC can read, so:

An input of 4.883mV would give us a reading of 001 and input of 9.766mV would

give us a reading of 002, and so on.

4.4.1 LM35 Temperature Sensor: LM35 is a Three-Pin (Vcc, Output, and GND) high precision temperature

sensor. It has a resolution of 10mV/C starting at 0V

(I.e. an output of 0V represents a temperature of 0C). So,

10m--->1C

20mV--->2C

370mV--->37.0C

And so on.

The sensor that we have used for temperature sensing is shown in the following

figure.

Figure 4.5 LM35 Temperature sensor IC

Page 61: Project Report

Page 61

4.4.2 Converting ADC Reading to Celsius degrees:

As we know that our ADC has a step size of 4.883mV so converting our

digital reading back to voltage is simply done by multiplying the digital reading by the

step size:

Vin (in Volts) = Digital Reading * 0.004883

Now, knowing our sensor's sensitivity is 10mV/C, converting this voltage to Celsius is

simply done by dividing the input voltage by 0.01, So:

Temperature (C) = Vin/0.01 = Digital Reading * 0.4883

The simulation of temperature sensing with PIC microcontroller is shown in the

following figure.

Figure 4.6 – Temperature measurement with pic microcontroller using the LM35 sensor

Page 62: Project Report

Page 62

4.5 Detailed view of the meter implemented with pic microcontroller

We take the input from the AC main lines and pass it through the current transformer

which is in series with the load as shown in the figure below.

Figure 4.7- Block diagram of the meter implemented with pic microcontroller

The output of the current transformer is given to the analog input pin of the

microcontroller. After passing through the current transformer we then step down the

voltage to the microcontroller level through the resistors R1 and R2 and give that

voltage to the analog input pin of the PIC microcontroller. We also give this voltage to

the zero cross detector circuit in order to detect the zero crossings of the AC voltage

for measuring the power factor. In addition to it LM35 is also interfaced with the ADC

pins of the pic microcontroller in order to measure the temperature of the surrounding.

The microcontroller measures the voltage, power factor, current, temperature,

frequency and phase angle of the load and displays it on the LCD and also sends it

through the GSM modem into the power grid.

The following figure shows the simulations of the meter implemented purely with the

Pic microcontroller.

Page 63: Project Report

Page 63

Figure 4.8- Simulations of the meter implemented with the pic microcontroller

4.6 Load Management

Another important part of our project was load management. Load

management means to compensate the power according to the requirement of the load.

For load management we fixed certain limits that if our power consumption exceeds

from the fixed point then according to the requirement of the load our inverters should

be on. To toggle between the inverters we used relays that act as a switch. For

example if our power consumption is above 100W one relay becomes on and so its

corresponding inverter stats serving. Similarly if the power consumption is above 200

W another relay becomes on and so the third one. The overall communication between

the load management side and the meter is done by GSM module. GSM module on the

meter side sends text message to the grid side GSM module which communicates with

the Microcontroller and the load management takes place.

The following block diagram shows how load management occurs:

Page 64: Project Report

Page 64

Figure 4.9- Load management

The power measured on the meter side is sent to the grid side through GSM module.

The GSM module on the grid side receives the message and sends it to the

microcontroller. The microcontroller acts as a decision maker and if the power

measured is above 100 W relay one becomes on and one inverter starts serving. If the

power is above 200W relay 2 becomes on and 2nd inverter starts serving and so the

third one.

Similarly another functionality of our project is of prepaid. In this case we have 6

scratch cards. The user will sent text to the GSM module on grid side and will advance

pay for the required units. As the power consumes the units decrease in descending

order. This functionality avoids extra usage of power when not needed. In case of

needing more power another text message will be sent by the user and so on.

Page 65: Project Report

Page 65

4.7 Complete System Diagram

Fig 4.10- Complete System diagram

The above system shows the complete system diagram of our project. As clear from

the block diagram that the meter is installed in parallel with the load and measures the

power consumed by the load. It first shows the power consumed on the LCD and then

sends it through the GSM modem into the power grid. The grid side also has a GSM

modem that receives the data sent by the meter and shows it on its own LCD. Based

on this power received the grid automatically turns the generators on and off by

switching the relays in order to provide the power according to the need of the user.

The required results were accurately met. The power was measured in an accuracy of

95 percent and sent it successfully to the power grid through the GSM modem and

switched the relays accordingly.

Page 66: Project Report

Page 66

Chapter 5

Conclusions and Future Recommendations

5.1 Conclusions The meter with serial peripheral interface can measure energy up to 1000

watts

Displaying the readings on the LCD

The power factor was measured up to 95 percent efficiency

Automatic Power Factor Correction

The meter implemented purely with pic microcontroller measures the power

up to 700 watts

It sends the data through a GSM module into the power grid which receives

the data through another GSM modem

The grid switches the required inverters in order to provide the necessary

power to the users and to avoid the production of extra power

5.2 Recommendations

Increase of load wattage:

The current system can handle a load of up to 1000 watts. If the loads beyond 1000

watts are to be measured for power usage, then the analogue circuitry of the system

has to be changed e.g. current transformer of higher values are to be used which

will occupy more physical space. So the present system can be improved to handle a

load consuming more power.

Real Time Clock can be introduced:

An RTC can be included in the system in order to facilitate the timings of the

events occurring at a separate central clock

Page 67: Project Report

Page 67

Online System:

An online system can also be setup which makes it possible for the user to view the

energy usage anywhere and make e payments for bills also.

Page 68: Project Report

Page 68

Chapter 6

Appendices

Appendix A: Pin layouts

Appendix B: IC timing diagrams

Appendix C: Coding

Page 69: Project Report

Page 69

Appendix A

Pin layouts

A.1 CS5463

Fig A.1 CS5463 Pin diagram

A.1.1 Clock

Crystal Out & Crystal In:

Pin 1, XOUT Pin 24, XIN:

A gate inside the chip is connected to these pins and can be used with a

crystal to provide the system clock for the device. Alternatively, an external (CMOS

compatible clock) can be supplied into XIN pin to provide the system clock for the

device.

CPU Clock Output:

Pin 2, CPUCLK:

The output of on-chip oscillator which helps in driving the one standard CMOS load

Page 70: Project Report

Page 70

A.1.2 Control Pins and Serial Data I/O:

Serial Clock Input:

Pin 5, SCLK:

A clock signal on this pin determines the input and output rate of the data for

the SDI and SDO pins respectively. This input is a Schmitt trigger to allow for slow

rise time signals. The SCLK pin will recognize clocks only when CS is low.

Serial Data Output: Pin 6, SDO:

SDO is the output pin of the serial data port. Its output will be in high impedance

State when CS is high.

Chip Select: Pin 7, CS:

When low, the port will recognize SCLK. An active high on this pin forces the SDO

pin to a high impedance state. CS should be changed when SCLK is low.

Mode Select: Pin 8, MODE:

When at logic high, the CS5463 can perform the auto-boot sequence with the aid of an

external serial EEPROM to receive commands and settings. When at logic low,

CS5463 assumes normal “host mode” operation. This pin is pulled down to logic low

if left unconnected, by an internal pull-down resistor to DGND.

Interrupt: Pin 20, INT:

When INT goes low it signals that an enabled event has occurred. INT is

cleared logic 1) by writing the appropriate command to the CS5463.

Energy Output: Pin 18,21,21 E3, E1, E2 :

The energy output pin output a fixed-width pulse rate output with a rate

(programmable) proportional to real (billable) energy. Active-low pulses with an

output frequency proportional to the selected power. Con-figural outputs for active,

apparent, and reactive power, negative energy indication, zero cross detection, and

power failure monitoring. E1, E2, E3 outputs are configured in the Operational Modes

Register

Page 71: Project Report

Page 71

Serial Data Input: Pin 23, SDI:

The input pin of the serial data port. Data will be input at a rate determined by SCLK.

C. Measurement and Reference Input:

Differential Voltage Inputs:

Pin 9, VIN+ Pin10, VIN:

Differential analog input pins for voltage channel.

Voltage Reference Output:

Pin 11, VREFOUT:

The on-chip voltage reference is output from this pin. The voltage reference has a

nominal magnitude of 2.5 V and is reference to the VA- pin on the converter.

Voltage Reference Input: Pin 12, VREFIN:

This is the voltage input to this pin establishes the voltage reference for the on-

chip modulator.

Differential Current Inputs: Pin15, IIN+ Pin 16, IIN-:

Differential analog input pins for current channel.

Power Supply Connections:

Positive Digital Supply:

Pin 3, VD+:

The positive digital supply is nominally +5 V ±10% relative to DGND.

Digital Ground:

Pin 4, DGND:

The common-mode potential of digital ground must be equal to or above the

common-mode potential of VA.

Page 72: Project Report

Page 72

Negative Analog Supply: Pin 13, AGND:

The negative analog supply pin must be at the lowest potential.

Positive Analog Supply:

Pin, 14, VA+:

The positive analog supply is nominally +5 V ±10% relative to VA.

Power Fail Monitor: Pin 17, PFMON:

The power fail Monitor pin monitors the analog supply. Typical threshold level

(PMLO) is 2.45 V with respect to the VA- pin. If PFMON voltage threshold is tripped,

the LSD (low-supply detect) bit is set in the Status Register. Once the LSD

bit has been set, it will not be able to be reset until the PFMON voltage increases~100

mV (typical) above the PMLO voltage. Therefore, there is hysteresis in the

PFMON function.

Reset: Pin 19, Reset:

When reset is taken low, all internal registers are set to their default states.

A.2 16F877A

Fig: A.2 Pin diagram of Pic16f877A

Page 73: Project Report

Page 73

A.3 LCD

Fig A.3 LCD Pin diagram

Pin Description

Fig A.4 LCD pins description

Page 74: Project Report

Page 74

Appendix B

Timing Diagrams

B.1 CS5463 Timing Diagram

f

Fig B.1 Clock diagram of CS5463

Page 75: Project Report

Page 75

Appendix C

Coding

Meter Coding for power factor, voltage, current, phase and frequency

measurement

//# defined(__PCH__)

#include <18F452.h>

#DEVICE ADC=10

#include <math.h>

#include<stdlib.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP

#use delay(clock=40000000)

#use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C7)

//#endif

#define EN PIN_C2

#define RW PIN_C1

#define RS PIN_C0

unsigned int16 adc_value_volt,adc_value_current;

float Volts,max_volts,current,max_current,phase_angle,pf;

unsigned int8 frquency,one_second,frquency_timer_start;

float volt_array[30],current_array[30],time_difference;

unsigned int16 volt_array_pointer,current_array_pointer,i,j,max_volt_pointer,max_current_pointer;

int max_volt_reached;

void delay()

Page 76: Project Report

Page 76

{

long i;

for( i=0;i<=6555;i++)

{}

}

void interface()

{

output_d(0x3c);

output_bit(EN,1);

output_bit(RS,0);

output_bit(RW,0);

delay();

output_bit(EN,0);

}

void DISPLAY_CURSOR()

{

output_d(0x08);

output_bit(EN,1);

output_bit(RS,0);

output_bit(RW,0);

delay();

output_bit(EN,1);

}

void clear_display()

{

output_d(0x01);

Page 77: Project Report

Page 77

output_bit(EN,1);

output_bit(RS,0);

output_bit(RW,0);

delay();

output_bit(EN,0);

}

void blink()

{

output_d(0x0f);

output_bit(EN,1);

output_bit(RS,0);

output_bit(RW,0);

delay();

output_bit(EN,0);

}

void home ()

{

output_d(0x02);

output_bit(EN,1);

output_bit(RS,0);

output_bit(RW,0);

delay();

output_bit(EN,0);

}

void lcd(unsigned char ch)

{

output_d(ch);

Page 78: Project Report

Page 78

output_bit(RS,1);

output_bit(RW,0);

output_bit(EN,1);

delay();

output_bit(EN,0);

}

#int_EXT

void EXT_isr(void)

{

enable_interrupts(INT_TIMER2);

if(frquency_timer_start == 0 ) enable_interrupts(INT_TIMER1);

frquency++;

}

#INT_TIMER1 // This function is called every time

void frequency_isr() {

int i,j,count,leftv,rightv,lefti,righti,leftpf,rightpf,leftp,rightp,leftfreq,k,l,m,n,o,p,q,r;

char string2v[3];

char string3v[2];

char string2i[1];

char string3i[2];

char string2p[2];

char string3p[1];

char string2pf[1];

char string3pf[2];

char string2fr[2];

frquency_timer_start = 1;

one_second++;

Page 79: Project Report

Page 79

if(one_second ==19)

{

disable_interrupts(INT_TIMER2);

disable_interrupts(INT_EXT);

printf("%fV %fA %fDeg P.F=%f %u Hz\n\r", max_volts,max_current,phase_angle,pf,frquency);

// printf("%u Hz\n\r",frquency);

leftv=max_volts;

lefti=max_current;

righti=10*(max_current-lefti);

rightv= 10*((max_volts)-(leftv));

leftp=phase_angle;

rightp=10*(phase_angle-leftp);

leftpf=pf;

rightpf=10*(pf-leftpf);

leftfreq=frquency;

itoa(lefti,10,string2i);

itoa(righti,10,string3i);

itoa(leftp,10,string2p);

itoa(rightp,10,string3p);

itoa(leftfreq,10,string2fr);

itoa(leftpf,10,string2pf);

itoa(rightpf,10,string3pf);

itoa(max_volts,10,string2v);

itoa(rightv,10,string3v);

for(i=0;i<3;i++)

{

interface();

Page 80: Project Report

Page 80

delay();

}

DISPLAY_CURSOR();

//delay();

clear_display();

//delay();

blink();

delay();

//home ();

//delay();

for(j=0;j<3;j++)

{

lcd(string2v[j]);

}

//delay();

lcd(".");

for ( k=0;k<1;k++)

{

lcd(string3v[k]);

}

lcd("v");

//lcd(" ");

//delay();

Page 81: Project Report

Page 81

for(l=0;l<1;l++)

{

lcd(string2i[l]);

}

lcd(".");

for(m=0;m<1;m++)

{

lcd(string3i[m]);

}

lcd("A");

//lcd(" ");

for(n=0;n<2;n++)

{lcd(string2p[n]);}

lcd(".");

for(o=0;o<2;o++)

{

lcd(string3p[o]);

}

//for(o=0;o<)

output_d(0xc0);

output_bit(EN,1);

output_bit(RS,0);

output_bit(RW,0);

delay();

output_bit(EN,0);

Page 82: Project Report

Page 82

blink();

delay();

for(p=0;p<2;p++)

{

lcd(string2fr[p]);

}

lcd("Hz");

lcd(" ");

lcd("PF= ");

for(q=0;q<1;q++)

{

lcd(string2pf[q]);

}

lcd(".");

for(r=0;r<2;r++)

{

lcd(string3pf[r]);

}

//sleep();

frquency_timer_start = 0;

disable_interrupts(INT_TIMER1);

one_second = 0;

frquency = 0;

setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 );

volt_array_pointer = 0;

max_volt_reached = 0;

current_array_pointer = 0;

Page 83: Project Report

Page 83

enable_interrupts(INT_EXT);

}

}

#INT_TIMER2 // This function is called every time

void clock_isr() { // timer 2 overflows (250->0), which is

disable_interrupts(INT_TIMER2);

disable_interrupts(INT_EXT);

//output_high(PIN_D1);

//output_high(PIN_D0);

set_adc_channel(0); // Select channel 0 (AN0)

adc_value_volt=read_adc(); //Read A/D value

set_adc_channel(1); // Select channel 0 (AN0)

adc_value_current=read_adc(); //Read A/D value

Volts=(float)adc_value_volt*50/1024;

volts = volts * 18.2 / 1.41421356; //Multiplying by transformer ratio & / by root 2 for Vrms

current=(float)adc_value_current*5/1024;

current = current*current*1.38;

volt_array[volt_array_pointer] = Volts;

if(volt_array_pointer > 0 && max_volt_reached == 0)

{

if(volt_array[volt_array_pointer-1] > volt_array[volt_array_pointer])

{

max_volts = volt_array[volt_array_pointer-1];

//printf("%f Vrms ",volt_array[volt_array_pointer-1]); // send to RS232

for(i = 0 ; i<30 ; i++) volt_array[i] = 0;

Page 84: Project Report

Page 84

max_volt_pointer = volt_array_pointer;

volt_array_pointer = 0;

max_volt_reached = 1;

}

}

if(max_volt_reached == 0 ) volt_array_pointer++;

if(volt_array_pointer >29) printf("Overloaded volt\n\r");

current_array[current_array_pointer] = current;

if(current_array_pointer > 0 )

{

if(current_array[current_array_pointer-1] > current_array[current_array_pointer])

{

max_current = current_array[current_array_pointer-1];

for(j = 0 ; j<30 ; j++) current_array[j] = 0;

max_current_pointer = current_array_pointer;

time_difference = (max_current_pointer - max_volt_pointer) * (0.000004+ 0.0004185);

phase_angle = ((float)(time_difference/0.02))*360;

pf = cos(phase_angle*(2*3.142/360));

//printf("%fV %fA %fDeg %fP.F\n\r", max_volts,max_current,phase_angle,pf);

//printf("%fV %fA %eSec %fDeg\n\r", max_volts,current,time_difference,phase_angle);

// printf("%e Time Difference %lu %lu

\n\r",time_difference,max_current_pointer,max_volt_pointer);

current_array_pointer = 0;

max_volt_reached = 0;

max_volt_pointer = 0;

//output_low(PIN_D0);

Page 85: Project Report

Page 85

clear_interrupt(INT_EXT);

clear_interrupt(INT_TIMER2);

enable_interrupts(INT_EXT);

}

else enable_interrupts(INT_TIMER2);

}

else enable_interrupts(INT_TIMER2);

current_array_pointer++;

if(current_array_pointer >30) printf("Overloaded cur\n\r");

//output_low(PIN_D1);

}

void main()

{

setup_adc_ports(ALL_ANALOG ); // A/D Ports

setup_adc(ADC_CLOCK_DIV_2); // A/D Clock

setup_timer_2( T2_DIV_BY_4, 10, 1); //((1/Clock)*4)* 16 * 125 * 5 = Time

setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 ); //((1/Clock)*4)* 8 * 65,536 = Time = 52.4288e-3

enable_interrupts(INT_EXT); //INTE=1

ext_int_edge(L_TO_H);

enable_interrupts(GLOBAL);

do

{

} while (TRUE);

}

Page 86: Project Report

Page 86

Meter Coding with GSM

#include <16F877A.h>

#device adc=10

#use delay (clock = 20000000)

#fuses BROWNOUT, HS, NOWDT, NOLVP

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#byte LCDDATA = PORTD

#DEFINE RS PIN_C2

#DEFINE EN PIN_C3

#DEFINE led1 PIN_C5

#DEFINE BUZZER1 PIN_C1

#DEFINE CARD1 PIN_B1

#DEFINE CARD2 PIN_B2

#DEFINE CARD3 PIN_B3

#DEFINE CARD4 PIN_B4

#DEFINE CARD5 PIN_B5

#DEFINE CARD6 PIN_B6

void lcd_ini(void);

void lcd_data(char);

void lcd_com(char);

Page 87: Project Report

Page 87

void process_volt();

void process_current();

void process_temp();

void process_units();

void process_power();

void process_Meter_rev();

void process_cards();

void sms_1();

void sms_2();

void sms_3();

void sms_4();

void sms_5();

int32 adc_value1, adc_value2, adc_value3 ;

int digit,digit4;

int16 volts_value, amps_value, temp_value, power,cards ;

unsigned int32 METER_REV;

int digit3,digit2,digit1;

static int1 flag1,flag2,flag_a,flag_b,flag_c,flag_d;

char GPS_CHAR;

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

#int_EXT

void EXT_isr(void)

{ METER_REV--;

Page 88: Project Report

Page 88

delay_ms(10);

}

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

void main(){

set_tris_a(0xff);

set_tris_b(0B01111111);

set_tris_d(0x00);

set_tris_c(0B10000000);

setup_port_a(ALL_ANALOG);

setup_adc(ADC_CLOCK_INTERNAL);

METER_REV = 12;

OUTPUT_HIGH(BUZZER1);

lcd_ini();

output_low(led1);

delay_ms(500);

output_high(led1);

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

/* printf("AT");

PUTC(13);

delay_ms(500);

printf("AT+CMGF=1");

PUTC(13);

Page 89: Project Report

Page 89

delay_ms(500);

enable_interrupts(INT_EXT);

enable_interrupts(GLOBAL);

while(TRUE){

process_volt();

process_current();

process_temp();

process_units();

process_power();

process_cards();

delay_ms(10);

}

}

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

void process_volt(){

set_adc_channel(0);

delay_ms(1);

adc_value1 = Read_ADC();

delay_ms(1);

volts_value = (adc_value1*500)/1023;

lcd_data(volts_value);

}

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

Page 90: Project Report

Page 90

void process_current()

{ set_adc_channel(1);

delay_ms(1);

adc_value2 = Read_ADC();

delay_ms(1);

amps_value = (adc_value2*500)/1023;

lcd_data(amps_value);

}////////////////////////////////////////////

void process_temp(){

set_adc_channel(2);

delay_ms(1);

adc_value3 = Read_ADC();

delay_ms(1);

temp_value = (adc_value3*500)/1023;

lcd_data(temp_value);

}

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

void process_units(){

lcd_data(units_value);

Page 91: Project Report

Page 91

}

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

void process_power(){

lcd_com(0x96);

lcd_data ('P');

lcd_data ('O');

lcd_data ('W');

lcd_data ('E');

lcd_data ('R');

lcd_data (' ');

power = volts_value*amps_value;

lcd_data ('power');

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

if ((power <= 40000 ) && (power >= 30000 )){

sms_3();

} /////////////////////////////

else if ((power <= 29900 ) && (power >= 20000 )){

sms_2();

}

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

Page 92: Project Report

Page 92

else if ((power <= 19900 ) && (power >= 9001 )){

sms_1();

}

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

else if ((power <= 9000 ) && (power >= 0 )){

sms_4();

}

}

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

void process_cards(){

if(!input(card1)){

METER_REV = METER_REV+100;

flag1 = 1;

WHILE (! input (card1));

}

if(!input(card2)){

Page 93: Project Report

Page 93

METER_REV = METER_REV+300;

flag1 = 1;

WHILE(!input(card2));

}

if(!input(card3)){

METER_REV = METER_REV+500;

flag1 = 1;

WHILE(!input(card3));

}

if(!input(card4)){

METER_REV = METER_REV+1000;

flag1 = 1;

WHILE(!input(card4));

}

if(!input(card5)){

METER_REV = METER_REV+2000;

flag1 = 1;

WHILE(!input(card5));

}

if(!input(card6)){

METER_REV = METER_REV+5000;

Page 94: Project Report

Page 94

flag1 = 1;

WHILE(!input(card6));

}

}////////////////////////////////////////////

void sms_1(){

printf("AT");

PUTC(13);

delay_ms(500);

printf("AT+CMGF=1");

PUTC(13);

delay_ms(500);

printf("AT+CMGS=\"03439390001\"");

PUTC(13);

delay_ms(500);

printf("POWER= 100W");

PUTC(13);

delay_ms(500);

PUTC(26);

PUTC(13);

delay_ms(500);

}

void sms_2(){

printf("AT");

PUTC(13);

Page 95: Project Report

Page 95

delay_ms(500);

printf("AT+CMGF=1");

PUTC(13);

delay_ms(500);

printf("AT+CMGS=\"03439390001\"");

PUTC(13);

delay_ms(500);

printf("POWER= 200W");

PUTC(13);

delay_ms(500);

PUTC(26);

PUTC(13);

delay_ms(500);

}

void sms_3(){

printf("AT");

PUTC(13);

delay_ms(500);

printf("AT+CMGF=1");

PUTC(13);

delay_ms(500);

printf("AT+CMGS=\"03439390001\"");

PUTC(13);

delay_ms(500);

Page 96: Project Report

Page 96

printf("POWER= 300W");

PUTC(13);

delay_ms(500);

PUTC(26);

PUTC(13);

delay_ms(500);

}

void sms_4(){

printf("AT");

PUTC(13);

delay_ms(500);

printf("AT+CMGF=1");

PUTC(13);

delay_ms(500);

printf("AT+CMGS=\"03439390001\"");

PUTC(13);

delay_ms(500);

printf("NO POWER ");

PUTC(13);

delay_ms(500);

PUTC(26);

PUTC(13);

delay_ms(500);

Page 97: Project Report

Page 97

}

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

void lcd_ini(void)

{

delay_ms(300);

lcd_com(0x38);

lcd_com(0b00001100);

lcd_com(0x01);

delay_ms(50);

}

void lcd_com(char i)

{

OUTPUT_LOW (RS);

LCDDATA = i;

OUTPUT_HIGH (EN);

delay_us(100);

OUTPUT_LOW (EN);

}

void lcd_data(char i)

{

OUTPUT_HIGH (RS);

Page 98: Project Report

Page 98

LCDDATA = i;

OUTPUT_HIGH (EN);

delay_us(100);

OUTPUT_LOW (EN);

}

Grid Side Coding

LED_INI BIT P1.0

CARD1 BIT P2.0

CARD2 BIT P2.1

CARD3 BIT P2.2

CARD4 BIT P2.3

CARD5 BIT P2.4

CARD6 BIT P2.5

CR EQU 13

LF EQU 10

LCDDATA EQU P0

RS BIT P2.6

EN BIT P2.7

FUNC_SET EQU 00111110B

DISP_CONT EQU 00001100B

DISP_CLR EQU 10000001B

Page 99: Project Report

Page 99

TEMP1 EQU 4AH

OK BIT 24H

INV1 BIT P1.7

INV2 BIT P1.6

INV3 BIT P1.5

METER_2 BIT P3.7

METER_3 BIT P3.6

;=====================================

SETB CARD1

SETB CARD2

SETB CARD3

SETB CARD4

SETB CARD5

SETB CARD6

ACALL LCD_INI

MOV A,#0

ACALL LCD_LINE1

MOV DPTR,#TEXT1

ACALL LCD_PRINT

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MOV TMOD,#20H ;TIMER 1 , MODE 2

Page 100: Project Report

Page 100

MOV TH1,#-3

MOV SCON,#52H ;8-BIT , 1 STOP , REN ENABLED

SETB TR1 ;START TIMER 1

LCALL DELAY3

LCALL TX232

DB "AT",CR,0

LCALL DELAY3

LCALL TX232

DB "AT+CMGF=1",CR,0 ;TEXT MODE

MAIN:

START: SETB OK

ML01: ACALL RX

CJNE A,#'+',ML01

SJMP FIRST

LJMP START

FIRST: LCALL DELAY3

LCALL TX232

DB "AT+CMGR=1",CR,0 ;TEXT MODE

;ACALL DELAY3

ML011:

ACALL RX

Page 101: Project Report

Page 101

CJNE A,#'+',ML011

CPL LED_INI

ACT01:

MOV B,#15

ML02: ACALL RX

DJNZ B,ML02

MOV B,#13

MOV R0,#60H

ML03: ACALL RX

MOV @R0,A

INC R0

DJNZ B,ML03

MOV B,#29

ML022: ACALL RX

DJNZ B,ML022

;////////////////////////////////

DIS_1:

MOV A,#0

ACALL LCD_LINE1

MOV B,#13

MOV R0,#60H

ML04: MOV A,@R0

Page 102: Project Report

Page 102

ACALL LCD_DATA

INC R0

DJNZ B,ML04

MOV A,#0

ACALL LCD_LINE2

MOV B,#16

MOV R0,#6FH

ML044: MOV A,@R0

ACALL LCD_DATA

INC R0

DJNZ B,ML044

;///////////////////////////////////

LCALL DELAY3

LCALL TX232

DB "AT+CMGD=1",CR,0 ;TEXT MODE

ACALL DELAY3

CMM1:

MOV R0,#6FH

MOV DPTR,#MSG_A

LCALL COMP1

JB OK,CMM2

Page 103: Project Report

Page 103

CLR CARD1

ACALL DELAY4

SETB CARD1

ACALL DELAY4

SETB OK

LJMP MAIN

CMM2:

MOV R0,#6FH

MOV DPTR,#MSG_B

LCALL COMP1

JB OK,CMM3

CLR CARD2

ACALL DELAY4

SETB CARD2

ACALL DELAY4

SETB OK

LJMP MAIN

Page 104: Project Report

Page 104

CMM3:

MOV R0,#6FH

MOV DPTR,#MSG_C

LCALL COMP1

JB OK,CMM4

CLR CARD3

ACALL DELAY4

SETB CARD3

ACALL DELAY4

SETB OK

LJMP MAIN

CMM4:

MOV R0,#6FH

MOV DPTR,#MSG_D

LCALL COMP1

JB OK,CMM5

CLR CARD4

ACALL DELAY4

SETB CARD4

ACALL DELAY4

Page 105: Project Report

Page 105

SETB OK

LJMP MAIN

CMM5:

MOV R0,#6FH

MOV DPTR,#MSG_E

LCALL COMP1

JB OK,CMM6

CLR CARD5

ACALL DELAY4

SETB CARD5

ACALL DELAY4

SETB OK

LJMP MAIN

CMM6:

MOV R0,#6FH

MOV DPTR,#MSG_F

LCALL COMP1

JB OK,CMM7

CLR CARD6

ACALL DELAY4

SETB CARD6

Page 106: Project Report

Page 106

ACALL DELAY4

SETB OK

LJMP MAIN

CMM7:

MOV R0,#6FH

MOV DPTR,#MSG_G

LCALL COMP1

JB OK,CMM8

CLR METER_2

ACALL DELAY3

SETB OK

LJMP MAIN

CMM8:

MOV R0,#6FH

MOV DPTR,#MSG_H

LCALL COMP1

JB OK,CMM9

CLR METER_3

ACALL DELAY3

SETB OK

LJMP MAIN

Page 107: Project Report

Page 107

;================INVERTER SECTION===================

CMM9:

MOV R0,#6FH

MOV DPTR,#MSG_I

LCALL COMP1

JB OK,CMM10

CLR INV1

SETB INV2

SETB INV3

ACALL DELAY3

LJMP MAIN

CMM10:

MOV R0,#6FH

MOV DPTR,#MSG_J

LCALL COMP1

JB OK,CMM11

SETB INV1

CLR INV2

SETB INV3

ACALL DELAY3

LJMP MAIN

CMM11:

Page 108: Project Report

Page 108

MOV R0,#6FH

MOV DPTR,#MSG_K

LCALL COMP1

JB OK,CMM12

SETB INV1

SETB INV2

CLR INV3

ACALL DELAY3

LJMP MAIN

CMM12:

MOV R0,#6FH

MOV DPTR,#MSG_L

LCALL COMP1

JB OK,EXIT_F1

SETB INV1

SETB INV2

SETB INV3

ACALL DELAY3

LJMP MAIN

EXIT_F1:

LJMP MAIN

;=======================================

Page 109: Project Report

Page 109

COMP1:

MOV TEMP1,@R0

CLR A

MOVC A,@A+DPTR

JZ COMP1_L1

CJNE A,TEMP1,COMP1_EXIT

;CPL P2.3

INC R0

INC DPTR

;ACALL DELAY3

SJMP COMP1

COMP1_L1:CLR OK

RET

COMP1_EXIT:SETB OK

RET

;========================================

TX232: POP DPH

POP DPL

TX_NEXT: CLR A

MOVC A,@A+DPTR

JZ TX_RET

LCALL TX

INC DPTR

Page 110: Project Report

Page 110

SJMP TX_NEXT

TX_RET: MOV A,#1

JMP @A+DPTR

;===========================

TX_PRINT: CLR A

MOVC A,@A+DPTR

JZ TX_EXIT

ACALL TX

INC DPTR

SJMP TX_PRINT

TX_EXIT: RET

;=================================

DELAY1: MOV R7,#0

D1L1: DJNZ R7,D1L1

RET

DELAY2: MOV R6,#15

D2L2: MOV R7,#255

D2L1: DJNZ R7,D2L1

DJNZ R6,D2L2

RET

DELAY3: MOV R5,#5

Page 111: Project Report

Page 111

DL3: MOV R6,#255

DL2: MOV R7,#255

DL1: DJNZ R7,DL1

DJNZ R6,DL2

DJNZ R5,DL3

RET

DELAY4: MOV R2,#20

D1L3: MOV R3,#255

D1L2: MOV R4,#255

D11L1: DJNZ R4,D11L1

DJNZ R3,D1L2

DJNZ R2,D1L3

RET

;======== SERIAL DATA TRANSMIT ==================

TX: MOV SBUF,A

JNB TI,$

CLR TI

RET

;======== SERIAL DATA RECEIVE ==================

RX: JNB RI,$

MOV A,SBUF

CLR RI

RET

Page 112: Project Report

Page 112

;======== SET CURSOR POSITION ===================

LCD_LINE1: ADD A,#080H

SJMP LCD_COM

LCD_LINE2: ADD A,#0C0H

SJMP LCD_COM

LCD_LINE3: ADD A,#090H

SJMP LCD_COM

LCD_LINE4: ADD A,#0D0H

SJMP LCD_COM

;======= SERIAL PRINT ===========================

LCD_PRINT: CLR A

MOVC A,@A+DPTR

JZ LCD_EXIT

ACALL LCD_DATA

INC DPTR

SJMP LCD_PRINT

LCD_EXIT: RET

;======== LCD INI ===============================

LCD_INI: CLR RS

CLR EN

Page 113: Project Report

Page 113

ACALL DELAY2

MOV A,#FUNC_SET

ACALL LCD_COM

MOV A,#DISP_CONT

ACALL LCD_COM

LCD_CLEAR: MOV A,#DISP_CLR

ACALL LCD_COM

ACALL DELAY2

RET

;======== COMW ==================================

LCD_COM: CLR RS

SJMP LCD_WRITE

;======== DATAW =================================

LCD_DATA: SETB RS

LCD_WRITE: MOV LCDDATA,A

SETB EN

NOP

CLR EN

ACALL DELAY1

RET

;===============================================

Page 114: Project Report

Page 114

TEXT1: DB "SYSTEM INIT",0

MSG_A: DB "LHE1*350100",0

MSG_B: DB "LHE1*350300",0

MSG_C: DB "LHE1*350500",0

MSG_D: DB "LHE1*351000",0

MSG_E: DB "LHE1*352000",0

MSG_F: DB "LHE1*355000",0

MSG_G: DB "LHE2*360100",0

MSG_H: DB "LHE3*370100",0

;===============================================

MSG_I: DB "POWER= 100W",0

MSG_J: DB "POWER= 200W",0

MSG_K: DB "POWER= 300W",0

MSG_L: DB "NO POWER ",0

Temperature Sensor Code

#include <16f877a.h>

#device adc=10

#fuses XT,NOLVP,NOWDT,NOPROTECT

Page 115: Project Report

Page 115

#use delay(clock=4000000)

#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)

#include "lcd_flex.c"

#define LOAD PIN_B7

#define THRES 30.0

int16 digital_reading;

float temp;

void main()

{

setup_adc(ADC_CLOCK_INTERNAL);

setup_adc_ports(RA0_ANALOG);

set_adc_channel(0);

delay_ms(1);

lcd_init();

output_low(LOAD);

lcd_gotoxy(1,1);

lcd_putc("Temperature is:");

while(1) // infinite loop

{

digital_reading = read_adc();

Page 116: Project Report

Page 116

delay_us(100);

temp = digital_reading * 0.4883;

lcd_gotoxy(1,2);

printf(lcd_putc,"%2.1f C",temp);

if(temp>=THRES) output_high(LOAD);

else output_low(LOAD);

delay_ms(1000);

}

Page 117: Project Report

Page 117

References

[1] http://www.energyauthority.net/an-introduction-to-smart-grid

[2] http://en.wikipedia.org/wiki/Smart_meter

[3] http://www.eiwellspring.org/smartmeter/Smart_Meter_overview.htm

[4] http://en.wikipedia.org/wiki/Electricity_meter#History

[5] http://en.wikipedia.org/wiki/Smart_meter

[6] http://www.analog.com/static/imported-files/data_sheets/ADE7880.pdf

[7] http://www.findchips.com/?srt=1

[8] http://pdf1.alldatasheet.com/datasheet-pdf/view/119826/CIRRUS/CS5463.html

[9] http://pdfserv.maxim-ic.com/en/ds/MAXQ3180.pdf

[10] http://pdf1.alldatasheet.com/datasheet-pdf/view/161810/AD/ADE7769.html

[11] http://datasheets.maxim-ic.com/en/ds/78M6612.pdf

[27]http://www.powerfactorcorrectionllc.com/ALPFC_Apartments.pdf

[28 ] http://pec.org.pk/JICA_projBrief.aspx

[29] http://www.leonardo-energy.org/webfm_send/475.

[30] http://en.wikipedia.org/wiki/Load_management

[31] http://en.wikipedia.org/wiki/Load_management

[32] http://en.wikipedia.org/wiki/Load_management

[35] http://www.smssolutions.net/hardware/gsmgprs2