COMSATS Institute of Information Technology Lahore Automated Remote Metering System (ARMS) Project Advisor Mr. Muhammad Nadeem (Assistant Professor) Project Members: Muhammad Shahbaz [email protected]Muhammad Iyaz Khan [email protected]Muhammad Asad Rafique [email protected]Muhammad Fahad Malik [email protected][email protected]SESSION Spring 2003- 2007 Department of Electrical Engineering COMSATS Institute of Information Technology Defence Road, Off Raiwind Road, Lahore.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
A project thesis submitted in the partial fulfillment of the requirements for the degree of
Bachelor of Science in Computer Engineering
by
Muhammad Shahbaz BCE/L-S03-32
Muhammad Iyaz Khan BCE/L-S03-26
Muhammad Asad Rafique BCE/L-S03-21
Muhammad Fahad Malik BCE/L-S03-24
Year Spring 2003- 2007 Supervisor External Examiner Head of Department Dated Dated
Department of Electrical Engineering
COMSATS Institute of Information Technology
Defence Road, Off Raiwind Road, Lahore.
Department of Electrical Engineering
COMSATS Institute of Information Technology
Defence Road, Off Raiwind Road, Lahore.
Dedicated To
Our Loving Parents, Teachers, Class fellows and Friends who
encouraged and motivated us in completing the project and
also dedicated to all junior Students of Electrical Engineering
Department of COMSATS Institute of Information Technology,
Lahore.
Acknowledgements
Thanks to Almighty Allah, the most merciful and beneficial for showing us the right
path and giving us the strength to accomplish this task.
We are grateful to Mr. Muhammad Nadeem (Assistant Professor)
COMSATS Institute of Information Technology, Lahore for providing full support
and guidance in the completion of our project. We also grateful to Mr. Mohsin Ali
(Deputy General Manager) and Mr. Salman Aizad (Deputy Manager)
SIEMENS Pakistan Engineering Co.Ltd. for the encouragement and help towards
our project. We thank them whole-heartedly for their sincere instructions, advices
and motivation from the beginning to the accomplishment of our project.
We are thankful to our families and beloved parents whose hands always rose in the
prayers for our success.
Muhammad Shahbaz
Muhammad Iyaz Khan
Muhammad Asad Rafique
Muhammad Fahad Malik
To Almighty Allah Who created the universe
and gives meaning to our lives Through His love
Abstract:
Today the world is facing the environment that offers challenges. Ideas are polishing the minds of the Engineers, Scientists and Analysts who are involved in the development of industry as well as providing feasible products to the users. Demand actually requires accessing the devices characteristics remotely in a reliable way. In the 21st century everyone is talking about modernization and development but without electricity it seems to be unaccomplished. The users are growing exponentially and load on power providing divisions (e.g. WAPDA) is increasing, so organizations as well as customers must be facilitated by giving them an innovative solution; i-e, concept of Automated Remote Metering System
(ARMS).As energy meter gets older they may become less accurate due to its mechanical design (based on Ferrari Wheel Principle) and are the main source of dissipating the power so it makes good prospective sense to move to this new technology. Collecting data from power meters is a laborious task. Conventionally the meter is read by human being and written onto a notepad. The data then has to be typed into a computer before it can be processed. Collecting data electronically has many advantages over the traditional method such as: the digital data can be read and understood by computers and stored in database and also other devices can be stored in media such as disks or CDs and multiple copies can be easily made for reliable data storage. By keeping all these things in the mind, the idea of Automated Remote Metering System
(ARMS) has been flourished comprising of four modules: Digital Field Unit (Power Meter), Data Concentrator (Brick), Wireless Communication Link and Database System Unit (developed at area’s sub-station). The system developed automates the whole process that is, measuring the power from digital electric meter, send the consumed units (Postpaid electric meter) and card number (Prepaid electric meter) to area sub-station and the process of bill generation. It also eliminates human error in reading meters, improves meter reading accuracy, an accurate usage based bill resulting in better customer satisfaction, protection against electricity theft and meter tampering. This metering system is feasible for residential, commercial and industrial applications because of the versatility and low-cost afforded by system design. It also can measure and record energy usage at different times of the day, so utilities can bill customers for energy based on time of usage. As system is automated so data is transmitted to the utility via a wireless communication link. Improved accuracy and lower power consumption are other benefits of ARMS. This system is charging system whereby customers will be charged more for power used at peak time and less for power used at off-hours. The system design also changes the economics of manufacturing energy meters. Another consideration is the demand for mechanical-meter replacements that are as inexpensive as possible. In parts of the developing world where many new customers are being connected to the grid, the low cost of the project is its main attraction as well. In the first part Digital Field Unit (Power Meter) had been developed which is of two types Postpaid and Prepaid, that has no mechanical part (elimination of old Ferrari wheel) and it measures the current and voltage, convert it into a digital form and then compute the instantaneous power. In prepaid meter case we interfaced the keypad to enter the card number whereas in postpaid consumer will have the monthly bill. Secondly, Data Concentrator (Brick) which is master module of the Field unit had also been developed that acquisite the data from the power meter at selected intervals and send this data via Wireless Communication Link for this we interface the mobile phone and send the data in SMS text format to area sub-station. Lastly, Database System Unit is developed at area’s sub-station that stores the customer information (meter no, customer name and address) consumed units and computes the electricity bill automatically. The data is received in the database through the serially interfaced mobile phone by reading the mobile phone through AT commands. Database is developed using Visual Basic 6 and a graphical user interface is provided for entering the customer’s information and for generation of electricity bill.
1.1.1 What is Electricity? ..........................................................................................................7
1.2 Power Generation........................................................................................................7 1.2.1 Methods of Generation.....................................................................................................8
2.4.1 Digital Field Unit (Power Meter)...................................................................................14 2.4.2 Data Concentrator (Brick)..............................................................................................14 2.4.3 Wireless Communication Link ......................................................................................14 2.4.4 Database System (Developed at area sub-station) .........................................................14
Digital Field Unit (Power Meter) ....................................................................... 15
3.1 Introduction...............................................................................................................15 3.1.1 Types of Digital Field Unit ............................................................................................15 3.1.2 Block Diagram of Digital Field Unit .............................................................................16
3.2 Energy Measurement Module...................................................................................16 3.2.1 Description of Energy Measurement Module ................................................................16 3.2.2 Features (IEC Specification) ..........................................................................................17 3.2.3 Function of Energy Measurement Module.....................................................................19 3.2.4 SPI - Interface ................................................................................................................21 3.2.5 Register Access ..............................................................................................................22 3.2.6 Power Calculation ..........................................................................................................24 3.2.7 Shunt Resistance (RSH) Calcualtion .............................................................................24 3.2.8 Application Circuit.........................................................................................................27
7.1 Tools Used ................................................................................................................68 7.1.1 OrCAD...........................................................................................................................68 7.1.2 PROTEUS---ISIS...........................................................................................................71 7.1.3 Controller Programming Tool.......................................................................................73 7.1.4 DataBase Development Tool ........................................................................................76 7.1.5 Microsoft Visual Basic 6................................................................................................78
7.2 Implementation of Digital Field Unit (Power Meter) ...............................................84
7.2.1 Digital Field Unit (Postpaid Meter) ...............................................................................84 7.2.2 Digital Field Unit (Prepaid Meter) .................................................................................85 7.2.3 PCB Layout of Postpaid Meter ......................................................................................86 7.2.4 PCB Layout of Prepaid Meter.......................................................................................86
7.3 Implementation of Data Concentrator (Brick)..........................................................87
7.3.1 Schematic of Data Concentrator ....................................................................................87 7.3.2 PCB Layout of Data Concentrator .................................................................................88
C.1 DataBase Code For Storage of Data,ConsumerPersonal Info and Computation of Electricity Bill...............................................................................................................106 C.2 Data Logger........................................................................................................11063
4
LIST OF FIGURES
Fig 2.1 : Overview of ARMS................................................................................................163 Fig 3.1 : Block Diagram (Field Unit)......................................................................................16 Fig 3.2 : Block Diagram of SA9903B.....................................................................................17 Fig 3.3.1 : Analog Input (Current Sensor) Internal Configuration..........................................19 Fig 3.3.2 : Analog Input (Voltage Sensor) Internal Configuration .........................................19 Fig 3.4 : Current & Voltage Sense Inputs (IIP, IIN and IVP).................................................20 Fig 3.5 : Current Level Resistors ............................................................................................20 Fig 3.6 : SPI-Interface............................................................................................................20 Fig 3.7 : SPI-Waveforms ........................................................................................................22 Fig 3.8 : Active & Reactive Register ......................................................................................23 Fig 3.9 : Wrapping of Active & Reactive Register .................................................................23 Fig3.10 :Shunt Resistance.......................................................................................................25 Fig 3.11 : Application Circuit .................................................................................................27 Fig 3.12 : Block Diagram of Microcontroller .........................................................................28 Fig 3.13 :Block Diagram of Microcontroller with ports .........................................................29 Fig 3.14 : Block Diagram of Microcontroller with ROM & RAM.........................................30 Fig 3.15 : Block Diagram of Microcontroller highlighted PORTS.........................................31 Fig 3.16 : PIC16F877A Pin Diagram......................................................................................33 Fig 3.17 : PIC16F877A Block Diagram .................................................................................34 Fig 3.18 :Flow Chart to Compute Delta Value .......................................................................36 Fig 3.19 :Main Display Menu .................................................................................................37 Fig 3.20 : Initial Display for Prepaid Meter ............................................................................37 Fig 3.21 : Timer Expires .........................................................................................................38 Fig 3.22 : Keypad ‘#’ Button ..................................................................................................38 Fig 3.23 : Enter Card Menu.....................................................................................................38 Fig 3.24 : Code Entry Menu....................................................................................................39 Fig 3.25 : Confirmation of Code.............................................................................................39 Fig 3.26 : Application Flow Chart of LCD.............................................................................39 Fig 4.1 : Block Diagram of Data Concentrator .......................................................................44 Fig 4.2 : Transmitt Status and Control Register......................................................................45 Fig 4.3 : Receive Status and Control Register ........................................................................45 Fig 4.4 :Baud Rate ..................................................................................................................46 Fig 4.5 :DB-9 Male &Female Connectors ..............................................................................47 Fig 4.6 : M95040.....................................................................................................................49 Fig 5.1 : AT + CSMS..............................................................................................................52 Fig 5.2 : AT + CMGF .............................................................................................................53 Fig 5.3 : AT + CSCA ..............................................................................................................53 Fig 5.4 : AT + CNMI ..............................................................................................................54 Fig 5.5 : AT + CMGS .............................................................................................................55 Fig 5.6 : AT + CMGR.............................................................................................................55 Fig 5.7 : AT + CMGL .............................................................................................................56 Fig 6.1 : Block Diagram of DataBase System ........................................................................58 Fig 6.2 : ARMS Database Tables' Diagram............................................................................61 Fig 6.3 : Depicts the MSComm Component in VB6 Enviroment...........................................63 Fig 6.4 : Depicts the Timer Component in VB6 Enviroment .................................................64 Fig 6.6 : ARMS Meter Information Form...............................................................................65 Fig 6.7 : ARMS Customer Information Form.........................................................................66 Fig 6.8 : ARMS Prepaid Electricity Bill Form........................................................................67 Fig 6.9 : ARMS Postpaid Electricity Bill................................................................................67 Fig 7.1 : Schematic of Postpaid Meter ....................................................................................84 Fig 7.2 : Schematic of Prepaid Meter......................................................................................85 Fig 7.3 :PCB Layout of Postpaid Meter..................................................................................86 Fig 7.4 : PCB Layout of Prepaid Meter ..................................................................................86 Fig 7.5 : Schematic of Data Concentrator ...............................................................................87 Fig 7.6 :PCB Layout of Data Concentrator.............................................................................88
5
LIST OF TABLES
Table 3.1 : IEC Standards .......................................................................................................18 Table 3.2 : Register Addresses................................................................................................23 Table 3.3 : Copper Wire Specifications ..................................................................................26 Table 3.4.1 : Clear Display Data Field....................................................................................40 Table 3.4.2 : Return Home Data .............................................................................................40 Table 3.4.3 : Entry Mode Set ..................................................................................................41 Table 3.4.4 : Display ON/OFF Control...................................................................................41 Table 3.4.5.1 : Cursor Or Display Shift ..................................................................................42 Table 3.4.5.2 : Cursor Or Display Shift ..................................................................................42 Table 3.4.6 : Function Set .......................................................................................................42 Table 3.4.7 : Set CGRAM Address.........................................................................................43 Table 3.4.8 : Set DDRAM Address ........................................................................................43 Table 4.1 : Baud Rate Formula ...............................................................................................46 Table 5.1 : AT + CSMS ..........................................................................................................52 Table 5.2 : AT + CMGF..........................................................................................................53 Table 5.3 : AT + CSCA ..........................................................................................................53 Table 5.4 : AT + CNMI ..........................................................................................................54 Table 5.5 : AT + CMGS..........................................................................................................54 Table 5.6 : AT + CMGR .........................................................................................................55 Table 5.7 : AT + CMGL .........................................................................................................56 Table 6.1 : Attributes of Entities in DB ..................................................................................60
6
CHAPTER # 1
Introduction
1.1 Electricity (History)
History of Electricity is fascinating. Benjamin Franklin did not "invent" power. In fact, the story of
power did not begin when he flew his kite during a thunderstorm or when light bulbs were installed
in houses all around the world.
The truth is that power has always been around because it naturally exists in the world. Lightning,
for instance, is simply a flow of electrons between the ground and the clouds. When you touch
something and get a shock that is really static moving toward you.
Hence, electrical equipment like motors, light bulbs, and batteries aren't needed for electric power
to exist. They are just creative inventions designed to harness and use electric power.
In the rich story of electric power, the first discoveries were made back in ancient Greece. Greek
philosophers discovered that when amber is rubbed against cloth, lightweight objects will stick to
it. This is the basis of static shock.
Basic electricity is described in many ways. When an electrical current flows through a conductor,
a magnetic field (or "flux") develops around the conductor. The highest flux density occurs when
the conductor is formed into a coil having many turns. In electronics and basic electricity, a coil is
usually known as an inductor. If a steady DC current is run through the coil, you would have an
electromagnet - a device with the properties of a conventional magnet, except you can turn it on or
off by placing a switch in the circuit. There's reciprocity in the interaction between electron flow
and magnetism. If you sweep one pole of a magnet quickly past an electrical conductor (at a right
angle to it), a voltage will be momentarily "induced" in the conductor. The polarity of the voltage
will depend upon which pole of the magnet you're using, and in which direction it sweeps past the
conductor. This phenomenon becomes more apparent when the conductor is formed into a coil of
many turns. The relationship in basic electricity is the fundamental operating principle of a
generator. The output, known as alternating current, is the type of power that electric utility
companies supply to businesses and homes. A practical generator would likely have two coils
mounted on opposite sides of the spinning magnet and wired together in a series connection.
Because the coils are in a series, the voltages combine, and the voltage output of the generator will
be twice that of each coil. [1]
7
1.1.1 What is Electricity?
Power is a form of energy. It is the flow of electrons. All matter is made up of atoms, and an atom
has a center, called a nucleus. The nucleus contains positively charged particles called protons and
uncharged particles called neutrons. The nucleus of an atom is surrounded by negatively charged
particles called electrons. The negative charge of an electron is equal to the positive charge of a
proton, and the number of electrons in an atom is usually equal to the number of protons. When the
balancing force between protons and electrons is upset by an outside force, an atom may gain or
lose an electron. When electrons are "lost" from an atom, the free movement of these electrons
constitutes an electric current.
Power is a basic part of nature and it is one of our most widely used forms of energy. We get
power, which is a secondary energy source, from the conversion of other sources of energy, like
coal, natural gas, oil, nuclear power and other natural sources, which are called primary sources.
Many cities and towns were built alongside waterfalls (a primary source of mechanical energy)
that turned water wheels to perform work. Before power generation began slightly over 100 years
ago, houses were lit with kerosene lamps, food was cooled in iceboxes, and rooms were warmed
by wood-burning or coal-burning stoves. Beginning with Benjamin Franklin's experiment with a
kite one stormy night in Philadelphia, the principles of power gradually became understood. In the
mid-1800s, Thomas Edison changed everyone's life -- he perfected his invention -- the electric
light bulb. Prior to 1879, power had been used in arc lights for outdoor lighting. Edison's invention
used power to bring indoor lighting to our homes. [2]
1.2 Power Generation
HOW IS POWER GENERATED?
An electric generator is a device for converting mechanical energy into electrical energy. The
process is based on the relationship between magnetism and power. When a wire or any other
electrically conductive material moves across a magnetic field, an electric current occurs in the
wire. The large generators used by the electric utility industry have a stationary conductor. A
magnet attached to the end of a rotating shaft is positioned inside a stationary conducting ring that
is wrapped with a long, continuous piece of wire. When the magnet rotates, it induces a small
electric current in each section of wire as it passes. Each section of wire constitutes a small,
separate electric conductor. All the small currents of individual sections add up to one current of
considerable size. This current is used for electric power.
The importance of dependable electricity generation, transmission and distribution was revealed
when it became apparent that electricity was useful for providing heat, light and power for human
needs. Centralized power generation became possible when it was recognized that alternating
8
current electric power lines can transport electricity at low costs across great distances by taking
advantage of the ability to transform the voltage using power transformers.
Electricity has been generated for the purpose of powering human technologies for at least 120
years from various sources of energy. The first power plants were run on wood, while today we
rely mainly on petroleum, natural gas, coal, hydroelectric and nuclear power and a small amount
from hydrogen, solar energy, tidal harnesses, wind generators, and geothermal sources.[3]
1.2.1 Methods of Generation
Turbines
Rotating turbines attached to electrical generators produce most commercially available electricity.
Turbines are driven by a fluid which acts as an intermediate energy carrier. The fluids typically
used are:
� Steam - Water is boiled by nuclear fission or the burning of fossil fuels (coal, natural gas,
or petroleum). Some newer plants use the sun as the heat source: solar parabolic troughs
and solar power towers concentrate sunlight to heat a heat transfer fluid, which is then used
to produce steam.
� Hydal - Turbine blades are acted upon by flowing water, produced by hydroelectric dams
or tidal forces.
� Wind - Most wind turbines generate electricity from naturally occurring wind. Solar
updraft towers use wind that is artificially produced inside the chimney by heating it with
sunlight.
� Hot gases - Turbines are driven directly by gases produced by the combustion of natural
gas or oil.
Combined cycle gas turbine plants are driven by both steam and gas. They generate power by
burning natural gas in a gas turbine and use residual heat to generate additional electricity from
steam. These plants offer efficiencies of up to 60%.
Reciprocating Engines
Small electricity generators are often powered by reciprocating engines burning diesel, biogas or
natural gas. Diesel engines are often used for back up generation, usually at low voltages. Biogas is
often combusted where it is produced, such as a landfill or wastewater treatment plant, with a
reciprocating engine or a microturbine, which is a small gas turbine.[4]
9
Photovoltaic Panels
Unlike the solar heat concentrators mentioned above, photovoltaic panels convert sunlight directly
to electricity. Although sunlight is free and abundant, solar panels are expensive to produce and
have only a 10-20% conversion efficiency. Until recently, photovoltaics were most commonly
used in remote sites where there is no access to a commercial power grid, or as a supplemental
electricity source for individual homes and businesses. Recent advances in manufacturing
efficiency and photovoltaic technology, combined with subsidies driven by environmental
concerns, have dramatically accelerated the deployment of solar panels. Installed solar capacity is
growing by 30% per year in several regions including Germany, Japan, California and New Jersey.
1.3 Electricity Demand
The demand for electricity can be met in two different ways. The primary method thus far has been
for public or private utilities to construct large scale centralized projects to generate and transmit
the electricity required to fuel economies. Many of these projects have caused unpleasant
environmental effects such as air or radiation pollution and the flooding of large areas of land.
Distributed generation creates power on a smaller scale at locations throughout the electricity
network. Often these sites generate electricity as a byproduct of other industrial processes such as
using gas from landfills to drive turbines.
1.4 Electricity Retailing
Electricity retailing began at the end of the 19th century when the bodies who generated electricity
for their own use made supply available to third parties. In the beginning, electricity was primarily
used for street lighting and trams. The general public were allowed to purchase electricity only
after large scale electric companies were started.
The provision of these services was generally the responsibility of electric compaines or municipal
authorities who either set up their own departments or contracted the services from private
entrepreneurs. Residential, commercial and industrial use of electricity was confined, initially, to
lighting but this changed dramatically with the development of electric motors, heaters and
communication devices.
The basic principle of supply has not changed much over time. The amount of energy used by the
domestic consumer, and thus the amount charged for, is measured through an electricity meter that
is usually placed near the input of a home to provide easy access to the meter reader.
10
Customers are usually charged a monthly service fee and additional charges based on the electrical
energy (in kWh) consumed by the household or business during the month. Commercial and
industrial consumers normally have more complex pricing schemes. These require meters that
measure the energy usage in time intervals (such as a half hour) to impose charges based on both
the amount of energy consumed and the maximum rate of consumption, i.e. the maximum demand,
which is measured in kW.
1.4.1 Creating a Market
In 1990 there was a significant development in the way electricity was bought and sold. In many
countries, the electricity market was deregulated to open up the supply of electricity to
competition. In the United Kingdom the Electricity Supply Industry was radically reformed to
establish competition. This trend continued in other countries (see New Zealand Electricity
Market) and the role of electricity retailing changed from what was essentially an administrative
function within an integrated utility to a become a risk management function within a competitive
electricity market.
Electricity retailers now provide fixed prices for electricity to their customers and manage the risk
involved in purchasing electricity from spot markets or electricity pools. This development has not
been without casualties. The most notable example of poor risk management (coupled with poor
market regulation) occurred in California in the summer of 2001, when Pacific Gas and Electric
and Southern California Edison were driven into bankruptcy by having to purchase electricity at
high spot prices and sell at low fixed rates.
Customers may choose from a number of competing suppliers. They may also opt to pay more for
"green" power, i.e. electricity sourced from renewable energy generation such as wind power or
solar power. An electricity provider is often known as "the electric company" or "the power
company". [5]
11
CHAPTER # 2
Automated Remote Metering System
Automated Remote Metering System (ARMS) is an innovative solution to the problems faced by
power providing divisions like WAPDA that automates the whole process of measuring the energy
from the meter, sending the consumed units and computation of electricity bill. This system
provides facilitation to the organizations as well as to the customers by its improved accuracy,
lower power consumption and its low cost. The system also provides the best possible customer
service, high reliability, enhanced customer convenience, controls meter reading costs, easy access
in remote areas, time saving, ease to resolve complaints, theft prevention, more convenient and
effective, stable and flexible architecture, providing effective maintenance and development
possibilities, less expensive for support and maintenance.
2.1 Problem Statement
On average, utilities find theft and current diversion to cost up to 10 percent of revenues, and have
various programs in place to address this issue. Ratepayers use a variety of ingenious and devious
techniques to steal power from utilities. For instance, one method of tampering is to use a magnet
around the meter, attempting to distort the recording of data. Another method of tampering is to
pull a meter out and turn it upside down – but the ARMS defeat this ploy. Another issue is the
collection of data from power meters as this is a laborious task. Conventionally the meter is read
by human being and written onto a notepad. The data then has to be typed into a computer before it
can be processed. Collecting data electronically has many advantages over the traditional method
such as: the digital data can be read and understood by computers and stored in database and also
other devices can be stored in media such as disks or CDs and multiple copies can be easily made
for reliable data storage. Transmission loss is the main issue of the time but the efficiency of the
system can be measured by comparing the amount put into the system with the cumulative total of
amounts withdrawn from the system, with the difference being assessed as transmission loss. By
keeping all these things in the mind, the idea of Automated Remote Metering System (ARMS) has
been flourished comprising of four modules: Digital Field Unit (Power Meter), Data Concentrator
(Brick), Wireless Communication Link and Database System Unit (developed at area’s sub-
station). The system developed automates the whole process of measuring the power from electric
meter, send the consumed units and card number (prepaid electric meter) to area sub-station and
the process of bill generation.
12
2.2 Scope of the Project
The installation of accurate and secure metering system at delivery points is the fundamental
requirement, the best solution is through state-of-art changes being proposed by customized
development for micro-processor based energy metering and to thereafter retrieve maximum
possible data regarding customer behavior and characteristics of power supply from the utility.
Through the reduced need for on-site manual meter readings and other efficiencies, the system is
expected to pay for itself within few years of installation.
Another factor which needs to be considered, is the fact that starting from power houses right to
consumer mains, more than 95 per cent of the installed meters are working on the old principle. As
these meters have a tendency to slow down with passage of time, the utilities as a consequence get
incorrect information for calculation of return on their investments. This misleading information
shall make all assessments about the system untrue and definitely on the lower side.
The system proposed would be a real time system that can translate from the metering to the billing
process. As and when required, the system can be integrated with a new application such as energy
pooling system, customer relationship management system, geographical interface system and so
forth. Hence, the focus is on a system that not only retrieves the data but can also perform
following tasks:
� Manage the meters
� Conducts energy audit, outage
� Supports event alarming, detect system device status
� Remote meter configuration
� Supports billing and auto estimate and adjustments
� Supports future expansions/replacements of the meters at a minimal cost to the utility
ARMS is a significant improvement over the current visual/manual meter reading method which is
prone to errors at various stages of reading and recording meter data.
2.3 Advantages
There are several advantages to be enjoyed by a utility implementing an ARMS System as well as
its customers. A few of these advantages are listed here
• Eliminates human error in reading meters
• Improves meter reading accuracy
• Lowers estimate based meter reading
• Automatic process of measuring the power, sending the data and generating the bill
13
• An accurate usage based bill results in better customer satisfaction
• Theft and meter tampering detection
• Difficult to access meters can be read easily
• Shortened time interval between reading a meter and generating a bill
2.4 ARMS Topology
By keeping all these things in the mind, the idea of Automated Remote Metering System (ARMS)
has been flourished comprising of four modules: Digital Field Unit (Power Meter), Data
Concentrator (Brick), Wireless Communication Link and Database System Unit (developed at
area’s sub-station). The system developed automates the whole process of measuring the power
from electric meter, send the consumed units and card number (prepaid electric meter) to area sub-
station and the process of bill generation.
Fig 2.1 : Overview of ARMS
14
2.4.1 Digital Field Unit (Power Meter)
Digital field unit is basically a power meter that has no mechanical part(elimination of old Ferrari
wheel) and measure the current and voltage, convert it into a digital form and then compute the
instantaneous power which is the power at a certain instant. The basic component in the field unit
is the energy measuring IC with SPI interface that perform the measurement of Active Power. The
heart of this unit is the microprocessor, which is providing the interface with LCD and energy
measuring IC and is also responsible for acquisition of the data and perform computation of power.
2.4.2 Data Concentrator (Brick)
A data concentrator called brick is the master module of the Field Unit, usually 4-5 Field Units are
linked with this module via SPI interface. Data Concentrator extracts the data that is the consumed
units(prepaid & post-paid meter) and the scratch card code(prepaid meter) from the field units on
the selected intervals and store them on to the on board non-volatile memory and transfer this data
to the area sub-station’s database through terminal equipment via wireless communication link.
2.4.3 Wireless Communication Link
The wireless communication between Data Concentrator and the Database system is done by using
GSM network. For this AT Commands are used and cell phone is interfaced with microcontroller
serially that sends the data to the area sub-station.
2.4.4 Database System (Developed at area sub-station)
Finally, a database system is developed on the host side where the data from all the field units is
stored and computed for the billing process, which is at the area sub-station. This unit provides a
permanent storage for the data (consumed units), customer information which is taken initially
along with its complete record. Also there is an automatic system for the computation of electricity
bill.
15
CHAPTER # 3
Digital Field Unit (Power Meter)
3.1 Introduction
Digital field unit is basically a power (remote) meter, which consists of three parts:
• Energy Measurement Module
• Controlling Module
• Display System
3.1.1 Types of Digital Field Unit
There are two types of Digital Field Unit:
1) Postpaid Meter 2) Prepaid Meter
1) Postpaid Meter
Postpaid Meter is type of Field unit in which there is a monthly billing system and user paid at the
end of the month. In this case the consumed units are sent to the area sub-station at selected
interval. Details are in the next section.
2) Prepaid Meter
The construction and the power measuring mechanism of Prepaid Meter is just like the postpaid
meter but the only difference is in the working and its functionality in which user has the facility to
enter a card code just like the mobile phone cards and have its balance in form of units. For this a
keypad is interfaced with the unit as shown in the block diagram. In this case the scratch card code
along with the consumed units is sent to the area sub-station at selected interval.
In the first part Digital Field Unit (Power Meter) had been developed which is of two types
Postpaid and Prepaid, that has no mechanical part (elimination of old Ferrari wheel) and it
measures the current and voltage, convert it into a digital form and then compute the instantaneous
power. In prepaid meter case we interfaced the keypad to enter the card number whereas in
postpaid consumer will have the monthly bill.
16
3.1.2 Block Diagram of Digital Field Unit
Fig 3.1 : Block Diagram (Field Unit)
3.2 Energy Measurement Module
Energy is measured by measuring the voltage and current, convert it into a digital form and then
compute the instantaneous power which is the power at a certain instant. The active energy register
is read after every 1 sec and its value will be sent to the Microcontroller via SPI interface in the
controlling module, for this we are using SA9903B as a metering IC. The instantaneous active
power values are continuously integrated to an active energy register, the value of which is
periodically accessed by the Microcontroller via an SPI (Serial Peripheral Interface). The
Microcontroller uses the retrieved active register value to calculate the active power consumed.
3.2.1 Description of Energy Measurement Module
The heart of the energy measurement module is the SAMES’s SA9903B IC which is a single phase
bi-directional energy/power metering integrated circuit that performs measurement of active and
reactive power, mains voltage and mains frequency. Measured values for active and reactive
energy, the mains voltage and frequency are accessible through a SPI bus from 24 bit registers. But
we are measuring only the Active Energy. The integrated circuit includes all the required functions
for single-phase power and energy measurement such as two over sampling A/D converters for the
voltage and current sense inputs, power calculation and energy integration. The SPI interface of the
SA9903B has a tri-state output that allows connection of more than one metering device on a
single SPI bus. This innovative universal single-phase power/energy metering integrated circuit is
* Prepaid Power Meter
17
ideally suited for energy calculations in applications such as electricity dispensing systems (ED's),
residential municipal metering and factory energy metering and control.
Fig 3.2 : Block Diagram of SA9903B[6]
3.2.2 Features (IEC Specification)
� Bi-directional active and reactive power/energy measurement
� RMS Voltage and frequency measurement
� SPI communication bus
� Meets the IEC 61036 Specification requirements for Class 1 AC Watt hour meters
� Less than 1% error over a dynamic range of 1:1000 for active measurement
� Meets the IEC 61268 Specification requirements hour meters
� Protected against ESD
� Total power consumption rating below25mW
� Adaptable to different current sensor technologies
� Operates over a wide temperature range
� Precision on-chip voltage reference [6]
IEC 61036 Specification requirements for Class 1 Accuracy
The primary international standard to which all electric meters must conform is IEC 61036. This
document specifies electrical, mechanical, and environmental requirements, and calls out two
accuracy classes: Class 1, with a 1% nominal accuracy over most of the usable current range, and
Class 2, with a 2% nominal accuracy. See Table 3.1 for a summary of the more important
requirements for compliant electric meters. The IEC Microelectronics Collection contains more
than 700 documents concerning bare aluminum conductors; cables, wires, waveguides, R.F.
18
connectors, and accessories for communication and signalling such as coaxial cable, wire and
symmetric cables, connectors for R.F. cables, waveguides and their accessories; capacitors and
resistors for electronic equipment; degrees of protection by enclosures; electric cables and their
characteristics; electrical installations for outdoor sites under heavy conditions, including open-cast
mines and quarries; electrical and electronic test and measuring instruments, systems and
accessories; electrical relays; electromechanical components for electronic equipment such as
connectors, switches, and mechanical structures for electronic equipment; electronic tubes; fibre
optics for interconnecting devices and passive components, fibre optic systems specifications, and
fibres and cables; high-voltage, low-voltage, and miniature fuses; high-voltage testing techniques;
instrument transformers; interference from overhead power lines, high voltage equipment, and
electric traction systems; magnetic alloys and steels; magnetic components and ferrite materials;
piezo electric devices for frequency control and selection; power capacitors; printed circuits;
recommendations for overhead lines; secondary cells and batteries including those with alkaline;
semiconductor devices and integrated circuits; and switchgear and control gear.[7]
ELECTRICAL REQUIREMENTS
ELEMENT LIMIT, CLASS 1 LIMIT, CLASS 2
Power dissipation, other than current circuit 2W, 10VA
Power dissipation, current circuit 4.0VA 2.5VA
Operating voltage range 90% to 110% nominal
Absolute maximum voltage range 0% to 115% nominal
Absolute maximum overcurrent, one-half cycle 30 IMAX
EMC REQUIREMENTS
ELEMENT LIMIT
Electrostatic discharge, contact 8kV
Electrostatic discharge, air 15kV
Immunity to electromagnetic fields 10V/m, 80MHz to 1GHz
Electrical fast transient, load = IB 2kV, all leads
Electrical fast transient, no load 4kV, all leads
Immunity to conducted disturbances 10V, 150kHz to 80MHz
ACCURACY REQUIREMENTS
ELEMENT LIMIT, CLASS 1 LIMIT, CLASS 2
Nominal accuracy, 10% IB—IMAX 1.0% 2.0%
Low current accuracy, 5% IB—10% IB 1.5% 2.5%
Nominal accuracy, 20% IB—IMAX, with reactive 1.0% 2.0%
Low current accuracy, 10% IB—20% IB, with reactive 1.5% 2.5%
Accuracy derating due to 10% voltage variation 0.7% 1.0%
Accuracy derating due to voltage variation, pF = 0.5 inductive 1.0% 1.5%
Accuracy derating due to 2% frequency variation 0.5% 0.8%
Accuracy derating due to frequency variation, pF = 0.5 inductive 0.7% 1.0%
Accuracy derating due to temperature variation 0.05%/°K 0.10%/°K
Accuracy derating due to temperature variation, pF = 0.5 inductive
0.07%/°K 0.15%/°K
Accuracy derating due to self-heating at IMAX, pF = 1 0.7% 1.0%
Accuracy derating due to self-heating at IMAX, pF = 0.5 inductive 1.0% 1.5%
Table 3.1 : IEC Standards[7]
19
VDD
VDD
IV
P
Voltage
Sensor Inputs Av
GND
While IEC 61036 (or a minor variant) is recognized as the standard for electric meters, the
requirements for multifunctional meters are not nearly so universal.
3.2.3 Function of Energy Measurement Module
Analog Input Configuration
The input circuitry of the current and voltage sensor inputs is illustrated in figure 3.3.1 and 3.3.2.
These inputs are protected against electrostatic discharge through clamping diodes. The feedback
loops from the outputs of the amplifiers Ai and Av generate virtual shorts on the signal inputs.
Exact duplications of the input currents are generated for the analog signal processing circuitry.
The current and voltage sense inputs are identical. Both inputs are differential current driven up to
±25µA peak. One of the voltage sense amplifier input terminals is internally connected to GND.
This is possible because the voltage sense input is much less sensitive to externally induced
parasitic signals compared to the current sense inputs.[6]
Fig 3.3.1 : Analog Input (Current Sensor) Internal Configuration[6]
Fig 3.3.2 : Analog Input (Voltage Sensor) Internal Configuration[6]
VDD
VDD
VDD
IIP
II
N
Current
Sensor Inputs Ai
20
IIP
IIN
IVP
Current
ADC
Current
ADC
Voltage
ADC
Voltage Sense Input (IVP)
The mains voltage is divided to 14V at nominal mains voltage by means of resistors R1, R2, R3
and R4 as shown in the application circuit (fig 2.11). The current into the voltage sense input is set
at 14µA with resistor R5 from the voltage divider. The voltage sense input of the AD converter
saturates at an input current of ±25µA peak.
Fig 3.4 : Current & Voltage Sense Inputs (IIP, IIN and IVP)[6]
Current Sense Input (IIP and IIN)
Application circuit (fig 2.11) shows the typical connections for the current sensor input. The
resistor R6 and R7 define the current level into the current sense inputs of the SA9903B as shown
in the fig 2.2.3.3. At rated current the resistor values should be selected for input currents of 16µA .
Values for resistors R6 and R7 may be calculated as follows:
R6 = R7 = (I / 16µA ) x RSH / 2
Where:
I = Max line current or if a CT is used
I = line current / CT ratio
RSH = Shunt resistor or termination resistor
Fig 3.5 : Current Level Resistors[6]
21
The voltage drop across RSH should not be less than 20mV at rated currents, but not higher than
200mV. The ideal value should be approximately 100mV. In case a current transformer is used for
current sensing the value of RSH should be less than the resistance of the CT's secondary winding.
The mains voltage is divided to 14V at nominal mains voltage by means of resistors R1, R2, R3
and R4. The current into the voltage sense input is set at 14µA with resistor R5 from the voltage
divider. The voltage sense input of the AD converter saturates at an input current of ±25µA peak.
Reference Voltage (VREF)
The VREF pin is the reference for the bias resistor. With a bias resistor of 24k optimum conditions
are set.
Serial Clock (SCK)
The SCK pin is used to synchronize data interchange between the micro controller and the
SA9903B. The clock signal on this pin is generated by the micro controller and determines the data
transfer rate of the DO and DI pins.
Serial Data in (DI)
The DI pin is the serial data input pin for the SA9903B. Data will be input at a rate determined by
the Serial Clock (SCK). Data will be accepted only during an active chip select (CS).
Chip Select (CS)
The CS input is used to address the SA9903B. An active high on this pin enables the SA9903B to
initiate data exchange.
Serial Data out (DO)
The DO pin is the serial data output pin for the SA9903B. The Serial Clock (SCK) determines the
data output rate. Data is only transferred during on active chip select (CS). This output is tri-state
when CS is low.[6]
3.2.4 SPI - Interface
Description
A serial peripheral interface bus (SPI) is a synchronous bus used for data transfers between a micro
controller and the SA9903B. The pins DO (Serial Data Out), DI (Serial Data In), CS (Chip Select),
22
SCK
DI
CS
DO
1 1 0 A5 A4 A3 A2 A1 A0
0 D23 D22 D21 D1 D0 D23 D22 D1 D0 High Impedance
Read Command Register Address
Register Data
and SCK (Serial Clock) are used in the bus implementation. The SA9903B is the slave device with
the micro controller the bus master. The CS input initiates and terminates data transfers. A SCK
signal (generated by the micro controller) strobes data between the micro-controller and the SCK
pin of the SA9903B device. The DI and DO pins are the serial data input and output pins for the
SA9903B, respectively.
Fig 3.7 : SPI-Waveforms[6]
3.2.5 Register Access
The SA9903B contains four 24 bit registers. The content represents active energy, reactive energy,
and mains voltage and mains frequency. The register addresses are shown in the following table
(Table 3.2):
SDO
SPI-Slave
CS
SCLK
SDI
Fig 3.6 : SPI-Interface[6]
23
ID Register Header Bits A5 A4 A3 A2 A1 A0
1 Active 1 1 0 X X 0 0 0 0
2 Reactive 1 1 0 X X 0 0 0 1
3 Voltage 1 1 0 X X 0 0 1 0
4 Frequency 1 1 0 X X 0 0 1 1
Table 3.2 : Register Addresses[6]
Registers may be read individually and in any order. After a register has been read, the contents of
the next register value will be shifted out on the DO pin with every SCK clock cycle. Data output
on DO will continue until CS is inactive.
Active and Reactive Register Values
The active and reactive registers are 24 bit up/down counters, that increment or decrement at a rate
of 320k samples per second at rated conditions.
23 22 21 20 10 9 8 7 6 5 4 3 2 1 0
Active or Reactive Energy Register Fig 3.8 : Active & Reactive Register[6]
The register values will increment for positive energy flow and decrement for negative energy flow
as indicated in figure below. The active and reactive registers are not reset after access, so in order
to determine the correct register value; the previous value read must be subtracted from the current
reading. The data read from the registers represents the active or reactive power integrated over
time. The increase or decrease between readings represents the measured energy consumption. [6]
Fig 3.9 : Wrapping of Active & Reactive Register[6]
24
At rated conditions, the active and reactive registers will wrap around every 52 seconds. The micro
controller program needs to take this condition into account when calculating the difference
between register values.
3.2.6 Power Calculation
Instantaneous power signals are generated by multiplying the current and voltage signals, for
active power = V x I x Cos(ø) and for reactive power = V x I x Sin(ø). The power signals are
continuously added to the respective energy registers. Positive power will be added to the energy
register contents and negative energy will be subtracted.[9]
Using the Register Values
Active and Reactive energy register
The active and reactive energy measured per count can be calculated by applying the following
formulae:
Energy per Count = Vrated * Irated / 320k
Where
Vrated = Rated mains voltage of meter
Irated = Rated mains current of meter
The active and reactive power measured by the SA9903B is calculated as follows:
P=Vrated * Irated * N / INTtime / 320k
Where
Vrated = Rated mains voltage of meter
Irated = Rated mains current of meter
N = Difference in register values between successive reads (delta value)
INTtime = Time difference between successive register reads (in seconds)[9]
3.2.7 Shunt Resistance (RSH) Calcualtion
A shunt is simply a resistor of very low value (frequently less than one ohm) that is used to help
measure current. As shown in fig 2.10 the shunt resistor Rsh is placed in parallel with a meter to
decrease its sensitivity by a known amount. The shunt does that by bypassing or "shunting" most
of the current around the meter. The shunt resistor there fore lets your take a standard meter, such
as a 0-1miliammeter, and turns it into, say, a 0-20-amp meter.
25
Fig3.10 :Shunt Resistance
Making the Shunt
The shunt is made from a short length of copper wire. All wire has resistance, so we can use that
property to make a shunt resistor. To make a shunt, you first need to determine how much current
will flow through it. For example, if your meter is going to measure 20 amps full scale, then the
shunt wire must be safely able to carry that amount of current.
Let's say you are going to make a 20-amp shunt using a surplus analog 0-1 millimeter (mA) whose
face plate is graduated from 0-1. Go to a copper-wire table and select an appropriate gauge wire.
Remember that the smaller the wire gauge, the more current it can safely carry. For most hobby
applications, 250 circular mils per amp are more than adequate. To find the circular mils per amp
for the shunt wire, divide the circular mils for the selected wire (found in the copper wire table) by
the current you intend to pass through the wire:
Circular Mils per amp = (circular mils for wire) / (current through the wire)
By using the copper wire table, you will find that 12-gauge wire has a cross-sectional area of 6530
circular mils. By dividing that by 20 amps, we get 326 circular mils/amp, which should work fine.
12 gauge wire is very common, and can be purchased in most hardware stores. To find the
resistance of the shunt, use this equation:
Rsh=Rm / (n-1)
Where Rsh is the resistance of the shunt, Rm is the resistance of the surplus meter, and n is the
shunt's multiplication factor. In our example, since we are using a 0-1mA meter and 1
mA=0.001amps, n=20amps / 0.001amps, or 20,000.Next, let's suppose that the resistance of your
meter was 81 ohms. Plugging that resistance and n=20,000 into above equation, we get
Rsh = 81 / 20,000 - 1) = 0.00405 Ohms
That's not very much resistance, is it! A shunt having that resistance will pass 19.999 amps through
Rsh
RL
R
m
26
it, and 0.001A (1 mA) will pass through the meter for a full scale reading. Next, we need to
calculate the length of our copper wire shunt. Note that as stated in the copper-wire table, 12 gauge
wire has a resistance of 1.619 ohms/1000ft. Therefore, the length of the shunt wire (Ls) can
therefore be determined using:
Ls=Rsh / (XV/1000ft.) = 0.00405 / (1.619/1000ft.) = 2.5 ft.
So the 12-gauge wire shunt should be 2 feet 6 inches long when using a 0-1mA meter having an
internal resistance of 81 ohms to measure 20 amps full-scale.[12]
Following is the table which gives the Copper Wire Specifications
AWG Diam. Mills
Circular Mills
Ohms/1000ft at 25 C
mm Closest
British SWG
18 40.3 1624.09 6.38 1.024 20
20 32.0 1024.00 10.13 0.813 22
21 28.5 812.25 12.77 0.724 23
22 25.3 640.09 16.20 0.643 24
24 20.1 404.01 25.67 0.511 26
26 15.9 252.81 41.02 0.404 29
28 12.6 158.76 65.31 0.32 31
30 10.0 100.00 103.71 0.254 34
32 8.0 64.00 162.00 0.203 37
34 6.3 39.69 261.30 0.142 38.39
36 5.0 25.00 414.80 0.127 41
38 4.0 16.00 648.20 0.102 43
Table 3.3 : Copper Wire Specifications[12]
27
3.2.8 Application Circuit
Fig 3.11 : Application Circuit[6]
28
3.3 Controlling Module
3.3.1 Microcontroller
It is a highly integrated chip that contains all the components comprising a controller. Typically
this includes a CPU, RAM, some form of ROM, I/O ports, and timers. Unlike a general-purpose
computer; which also includes all of these components, a Microcontroller is designed for a very
specific task, to control a particular system. As a result, the parts can be simplified and reduced,
which cuts down production costs. Microcontroller is sometimes called an embedded
Microcontroller, which just means that they are part of an embedded system, i.e. one part of a
larger device or system.
So a Microcontroller combines these components onto the same microchip.
o The CPU core
o Memory (both ROM and RAM)
o Some parallel digital I/O
Fig 3.12 : Block Diagram of Microcontroller
CPU
The CPU is the integration of a number of useful functions into a single IC package. These
functions are:
• The ability to execute a stored set of instructions to carry out user defined tasks.
• The ability to be able to access external memory chips to both read and write data from
and to the memory.
29
Fig 3.13 :Block Diagram of Microcontroller with ports
The above figure (fig 312) illustrates a typical Microcontroller device and the different sub units
integrated onto the Microcontroller microchip. The heart of the Microcontroller is the CPU
core. In the past this has traditionally been based on an 8-bit microprocessor unit. For example,
Motorola uses a basic 6800 Microprocessor core in their 6805/6808-microcontroller devices. In
recent years, Microcontrollers have been developed around specifically designed CPU cores for
example, the Microchip PIC range of Microcontrollers.[13]
Memory
Memory can be obtained as either:
• Read Only Memory (ROM). This is memory that can only be read, the data being
stored in the memory device during its manufacture.
• Erasable Programmable Read Only Memory (EPROM). This is similar to ROM
type memory but the user can program it. The contents of the memory can be
erased from the memory by exposing the memory chip to ultraviolet radiation for a
short period of time. It can therefore be used many times over.
• Electrically Erasable Programmable Read Only Memory (EEPROM). Similar to
EPROM but has part or all of the memory contents erased by the microprocessor.
ROM
Typically, the amount of ROM type memory will vary between around 512 bytes and 4096 bytes,
although some 16-bit Microcontrollers such as the Hitachi H8/3048 can have as much as 128
Kbytes of ROM type memory.
ROM type memory is used to store the program code. ROM memory can be ROM (as in One Time
Programmable memory), EPROM, or EEPROM.
30
RAM
The amount of RAM memory is usually somewhat smaller, typically ranging between 25 bytes to
4 Kbytes. RAM is used for data storage and stack management tasks. It is also used for register
stacks (as in the microchip PIC range of Microcontrollers).
I/O
I/O is Input or Output (Input/Output). It can be:
• A number of digital bits formed into a number of digital inputs or outputs called a
port. These are usually eight bits wide and thus referred to as a BYTE wide port.
i.e. byte wide input port, byte wide output port.
• A serial line from the microprocessor (Transmit or TX) and a serial line to the
microprocessor (Receive or RX) allowing serial data in the form of a bit stream to
be transmitted or received via a two wire interface.
• Other I/O devices such as Analogue to Digital Converters (ADC) and Digital to
Analogue Converters (DAC), Timer modules, Interrupt controllers etc.
Fig 3.14 : Block Diagram of Microcontroller with ROM & RAM
RAM Area
CPU ADC
PORT
A
SERIAL PORT
Rx ROM Area
PORT B PORT C
8
8
5 8
PORT
D 8
PORT E 3
Tx
31
Fig 3.15 : Block Diagram of Microcontroller highlighted PORTS
The digital I/O ports are the means by which the Microcontroller interfaces to the environment.
Digital I/O tends to be grouped into byte wide ports (8 digital bits) that can be configured as either
input bits or output bits. There are some exceptions, such as the microchip PIC 16C54 with one 6-
bit RA port and a byte wide RB port. The number of I/O port bits varies, depending upon the size
of the Microcontroller. Some very simple 8-bit Microcontroller have as few as 4 bits of I/O, whilst
those at the high-end range can have as many as 33 bits of I/O (some 16 bit Microcontrollers could
have around 78 bits of I/O). Most Microcontrollers will also combine other devices such as:
• A Timer module to allow the Microcontroller to perform tasks for certain time
periods.
• A serial I/O port to allow data to flow between the Microcontroller and other
devices such as a PC or another Microcontroller.
• An ADC to allow the Microcontroller to accept analogue input data for processing.
Applications
The Microcontroller is a very common component in modern electronic systems. Its use despread
that it is almost impossible to work in electronics without coming across it. Microcontrollers are
used in a wide number of electronic systems such as:
• Engine management systems in automobiles.
Tx
RAM Area
CPU ADC
TIMER
16-BIT
PORT
A
SERIAL PORT
8
Rx ROM Area
PORT B PORT C
8
8
5 8
PORT
D 8
PORT E 3
32
• Keyboard of a PC.
• Electronic measurement instruments (such as digital millimeters, frequency
synthesizers, and oscilloscopes)
• Printers.
• Mobile phones.
• Televisions, radios, CD players, tape recording equipment.
• Hearing aids.
• Security alarm systems, fire alarm systems, and building services systems.
3.3.2 PIC Microcontroller
PIC is a family of RISC microcontrollers made by Microchip Technology, derived from the
PIC1650 originally developed by General Instrument's Microelectronics Division.
Microchip Technology does not use PIC as an acronym; in fact the brand name is PICmicro. It is
generally regarded that PIC stands for Peripheral Interface Controller, although General
Instruments' original acronym for the PIC1650 was "Programmable Intelligent Computer". The
original PIC was built to be used with GI's new 16-bit CPU, the CP1600. While generally a good
CPU, the CP1600 had poor I/O performance, and the 8-bit PIC was developed in 1975 to improve
performance of the overall system by offloading I/O tasks from the CPU. The PIC used simple
microcode stored in ROM to perform its tasks, and although the term wasn't used at the time, it is a
RISC design that runs one instruction per cycle (4 oscillator cycles). In 1985 General Instruments
spun off their microelectronics division, and the new ownership cancelled almost everything —
which by this time was mostly out-of-date. The PIC, however, was upgraded with EPROM to
produce a programmable channel controller, and today a huge variety of PICs are available with
various on-board peripherals (serial communication modules, UARTs, motor control kernels, etc.)
and program memory from 512 words to 32k words and more (a "word" is one assembly language
instruction, varying from 12, 14 or 16 bits depending on the specific PICmicro family).[13]
PIC Architecture
Some highlights of the PIC Microcontroller architecture
• Harvard architecture with a separate program memory bus (14 bits wide) for instructions
and a data memory bus (8 bits wide).
• RISC architecture with 35 instructions, each occupying a single 14 bit program memory
word and a two-stage pipeline allowing most instructions to be executed in a single cycle
(the 16F8X models have 1K program flash memory words on the chip; other models have
up to 8K words).
33
• internal ram memory implemented in two switch able file register banks with 80 bytes
each (they are switched by bit 5 of the Status register; other PIC models may have up to 4
banks); the first 12 file registers are special purpose (and named Special File Registers or
SFR), including the Status register word, Program Counter (PC), interrupt control and
timer.
• 64 bytes of EEPROM memory for storing constant data.
• Hardware controlled stack, 8 levels deep (up to 8 nested subroutine calls)
• 5 types of internal and external interrupts, programmable timer and Watchdog timer.
PIC16F877A is one of the most commonly used Microcontrollers especially in automotive,
industrial, appliances and consumer applications. The main features of this Microcontroller are as
follows.
It is commonly said that Microcontroller is an “entire computer on a single chip”, which implies
that it has more to offer than a single CPU (microprocessor). This additional functionality is
actually located in micro controller’s subsystems, also called the “integrated peripherals”.
Every Microcontroller is supplied with at least a couple of integrated peripherals – commonly;
these include timers, interrupt mechanisms and AD converters. More powerful Microcontrollers
can command a larger number of more diverse peripherals. In this chapter, we will cover some
common systems and the ways to utilize them from BASIC programming language.[13]
Pin Diagram
Fig 3.16 : PIC16F877A Pin Diagram[13]
34
Block Diagram
Fig 3.17 : PIC16F877A Block Diagram[13]
Interrupt Mechanism
Interrupts are mechanisms, which enable instant response to events such as counter, overflow, pin
change, data received, etc. In normal mode, Microcontroller executes the main program as long as
there are no occurrences that would cause an interrupt. Upon interrupt, Microcontroller stops the
execution of main program and commences the special part of the program that will analyze and
handle the interrupt. This part of program is known as the interrupt (service) routine.[13]
35
3.3.3 Computation of Consumed Units
In the controlling module the Microcontroller was programmed to read data from the metering IC
every second. The active register of the metering IC is not reset after it has been accessed, thus
when the Microcontroller reads the data from the active register, this value is stored and then
subtracted from the next reading to determine the actual instantaneous power value. The difference
between the current value and previous value is called a delta value. The active register of the
metering IC also wraps around every 52 seconds and this is rectified in software.[6] For each
reading the new delta value is added to the previous delta values and the accumulated value is
compared to a threshold value. The threshold value is the amount of energy measured by thes
meter before a pulse is generated. The threshold value is calculated by dividing the energy
represented by a light emitting diode (LED) pulse by the energy per register count i.e.
Threshold = Epp/Epc,
Epc (Energy per count) = Imax* Vnom /32000,
Where Epp is the energy per pulse, Epc is the energy per count, Imax is the maximum load current
and Vnom is the nominal voltage.
The active register increments at 320000 samples per second, therefore a single count of the energy
corresponds to an amount of energy expressed in Ws (Watt seconds). The pulse rate required for
the meter is usually expressed in pulses/kWh.A single pulse on an LED is a fraction of a kWh and
is converted to energy in Ws/pulse[9] i.e.
Epp (Energy per LED pulse) = 1000*3600/Mpr
Where Mpr is the pulse rate of the meter in pulses/kWh.
Pulse
A single unit (kWh) is divided into 100 fractions where each fraction represents 0.01 kWh and is
also called a Pulse. In this implementation, every second a reading is taken and compared with the
threshold value. When the threshold value is reached, a pulse is generated on an LED, denoting
0.01kWh power consumption, thus a 100 pulses result in 1kWh power consumption. Every time a
pulse is generated, the power consumption value is integrated with the previous value and
stored.[10]
36
3.3.4 Evaluation of a Delta Value ----- Software Dependant
Delta value is the difference between the current value and the previous value that lies in the
register which is been accessed. There are three cases from which we measured the Delta value.
Also it is not always the case that Delta Value is a multiple of Threshold Value to find the Pulse so
in order to have accuracy in the computations Delta Value is divided by the Threshold and integer
value (quotient) is stored in a variable called ‘check’. There is also a variable called ‘remain’
which stores the remainder of the Delta Value and the Threshold Value.[14] The operation is
shown in the flow chart given below. Three cases for the evaluation of Delta value are:
Oldresult > presentresult (previous value is greater than the current value)
Oldresult < presentresult (previous value is smaller than the current value)
Oldresult == presentresult (previous value is equal to the current value)
Flow Charts to Evaluate Delta Value
When previous value is greater than the current value then delta value is computed as:
A.1 Field Unit Code for Energy Measurement,Control and dispaly of
Data(Postpaid)
#include <pic.h> //#include<pic1687x.h> #include<string.h> // Basic Defines // LCD Definitions #define LCD_EN RB4 // Enable #define LCD_RS RB5 // Register select #define LCD_RW RB6 // Read/Write Option #define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0)) #define threshold 654546 //SPI Definations #define SCK RB0 // CLOCK #define CS RB1 // Enable __CONFIG (XT & WDTDIS & PWRTDIS & BORDIS & UNPROTECT & LVPDIS & DEBUGDIS); //Array declared for 24 bit register values const long unsigned int rftable[24]={8388608,4194304,2097152,1048576,524288,262144,131072,65536,32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1}; //Global Variables Declaration unsigned int vari=0; long unsigned int result=0; long unsigned int presentresult=0; long unsigned int oldresult=0; long unsigned int deltavalue=0; long unsigned int units=0; long unsigned int remains=0; int check=0,pulse=0; const char acadd[10]={1,1,0,0,0,0,0,0,0,0}; char k=0; char i1=0; char i2=0; char sw=0; //Message to be dispalyed on LCD const char msg1[]=" ARMS"; // PIC LCD Functions void DELAY(unsigned char n) { while (--n); } void DelayMs (unsigned char x) {
91
unsigned char i; unsigned char count; count = 159; while (x > 0) { for (i=0; i<6; i++) { while (count > 0) count --; } x--; } } /*------------LCD Char Function--------*/ //sends one character or number to the display for setup and messages void lcd_write(char data) { LCD_EN = 1; PORTD = data; DelayMs (1); LCD_EN = 0; } /*------------LCD Message Function--------*/ //sends a series of words to display by calling character //function and checking the line number void lcd_message (const char *ptr, unsigned char line) { if (line == 1) { LCD_RS = 0; lcd_write(0x80); //select first row } else if(line==2) { LCD_RS = 0; lcd_write(0xC0); //select seond row } else if(line==26) { LCD_RS = 0; lcd_write(0xC6); //select seond row } else if(line==3) { LCD_RS=0; lcd_write(0x90); //select third row } else if(line==36) { LCD_RS=0; lcd_write(0x96); //select third row } else if(line==46) { LCD_RS=0; lcd_write(0xD6); //select fourth row } else {
92
LCD_RS=0; lcd_write(0xD0); //select fourth row } LCD_RS = 1; while(*ptr) { lcd_write(*ptr++); //sendind string } } void lcd_init(void) //initialises display to be on, clear etc { LCD_RW = 0; //clear RW-essentially tied to ground LCD_RS = 0; //clear RS LCD_EN = 0; //clear enable lcd_write (0x38); //set display, 8-bit, 2-line, 5x7dots DelayMs (1); //wait 5ms lcd_write (0x0C); //display on, cursor on, blinking on DelayMs (1); //wait 5ms lcd_write (0x06); //Entry Mode Set, Increment Mode, Cursor Shift On DelayMs (1); //wait 5ms lcd_write (0x01); //clear display DelayMs (1); //wait 5ms lcd_message(msg1,1); //calls function for message to be dispalyed on LCD lcd_message("Units:",2); lcd_message("Pulse:",3); lcd_message("Remain",4); } void init(void) { // This disables the A/D module to allow digital I/O //ADCON0 = 0; //ADCON1 = 0x07; //PORTD bits are connected to data bits of LCD TRISD = 0x00; // Control Signals for LCD TRISB4=0; // EN TRISB5=0; // RS TRISB6=0; // R/W TRISB0=0; //FOR SCK TRISB1=0; //FOR CHIP SELECT TRISB2=0; //ADDRESS BIT FOR REGISTER SELECT (DATA IN FOR SA9903B)--DI TRISB3=1; //FOR DATA IN (DATA OUT FOR SA9903B)--DO RB0=1; RB1=RB2=0; } // Function for converting interger into ascii //It is used to convert units consumed into string to be dispayed on LCD //At line3 of LCD units are dispalyed
93
void init_timerzero(void) { //Initialization of TIMER INTERRUPT (TMR0) GIE=1; // Global Interrupt PSA=0; // Pre-Scaler Assignment(Prescaler assigned to the TMR0) PS0=1; // 1:8 PS1=0; PS2=0; T0CS=0; // TMR0 Clock Source Select Bit (Internal instruction cycle clock CLKOUT) T0IE=1; // TMR0 Overflow Interrupt Enable Bit (Enables The TMR0 Interrupt) TMR0=5; // Initialise the TMRO interrupt from 5 } void itoa_lcd_msg(long unsigned int int_value, unsigned char line) { char ascii_str[11]; int loop = 0; int remainder = 0; for(loop=0;loop<10;loop++) { remainder = int_value % 10; ascii_str[9-loop] = remainder + 48; int_value = int_value / 10; } lcd_message(ascii_str,line); } void main (void) { init (); //calls all initilisation function lcd_init(); //calls LCD initialisation function init_timerzero(); while(1){ while(CS==0) { if(oldresult>presentresult) { deltavalue = remains + ((16777215 - oldresult) + presentresult); check = deltavalue / threshold; pulse=pulse+check; if(pulse>=100) { units++; pulse=pulse-100; } } else if(oldresult<presentresult) { deltavalue=presentresult - oldresult + remains; check = deltavalue / threshold; pulse=pulse+check; if(pulse>=100) { units++; pulse=pulse-100; } } else {}
94
remains = deltavalue%threshold; oldresult=presentresult; itoa_lcd_msg(units,26); itoa_lcd_msg(pulse,36); itoa_lcd_msg(remains,46); } } // end of while loop } // end of main // IINTERRUPT FUNCTION static void interrupt timer() { T0IF=0; // TMR0 Overflow Interrupt Flag Bit (cleared) TMR0=5; // Initialise the TMRO interrupt from 5 vari++; if(vari%4==0) { if(k==0) { if(vari<77) { CS=1; RB2=acadd[i1]; i1++; } else if(vari<269) { result=(rftable[i2]*RB3) + result; i2++; sw=0; } else { if(sw==0) { CS=0; i1=0; i2=0; presentresult=result; result=0; sw=1; } } } SCK=!SCK; k=!k; if(vari==4000) vari=0; } }
95
A.2 Field Unit Code for Energy Measurement,Control and dispaly of Data
(Prepaid)
//#include <pic.h> #include<pic1687x.h> #include<string.h> #define THRESHOLD 16777215 #define FU_DO RC0 #define FU_CS RC1 #define CODE_CS RC2 #define CODE_OUT RC3 #define timeout 500 // LCD Definitions #define LCD_EN RB4 // Enable //#define LCD_EN RB7 // Enable E2 FOR 8*24 LCD #define LCD_RS RB5 // Register select #define LCD_RW RB6 // Read/Write Option #define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0)) #define threshold 654546 // KeyPad Definations #define COL0 RE0 #define COL1 RE1 #define COL2 RE2 #define ROW0 RA0 #define ROW1 RA1 #define ROW2 RA2 #define ROW3 RA3 //SPI Definations #define SCK RB0 // CLOCK #define CS RB1 // Enable __CONFIG (XT & WDTDIS & PWRTDIS & BORDIS & UNPROTECT & LVPDIS & DEBUGDIS); //Array declared for 24 bit register values const long unsigned int rftable[24]={8388608,4194304,2097152,1048576,524288,262144,131072,65536,32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1}; const unsigned int utable[16]={32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1}; //Global Variables Declaration unsigned char ke=255; unsigned int temp_ke=0; unsigned char pk=0; unsigned int vari=0; long unsigned int result=0; long unsigned int presentresult=0; long unsigned int oldresult=0; long unsigned int deltavalue=0; unsigned int units=100; long unsigned int remains=0; long unsigned int fu_units=0; //variable used to transfer data to memory in form of binary bits unsigned char check=0; unsigned char npulse=0;//,opulse=0; const char acadd[10]={1,1,0,0,0,0,0,0,0,0}; unsigned int i=0; unsigned char i1=0; unsigned char i2=0; unsigned int incr=0; unsigned int cd=0;
return '7'; else if(COL1==1) return '8'; else if(COL2==1) return '9'; else ; ROW0=0;ROW1=0;ROW2=0;ROW3=1; if(COL0==1) return '*'; else if(COL1==1) return '0'; else if(COL2==1) return '#'; else ; return 255; } /*------------LCD Char Function--------*/ //sends one character or number to the display for setup and messages void lcd_write(char data) { LCD_EN = 1; PORTD = data; // DelayMs (1); LCD_EN = 0; } /*------------LCD Message Function--------*/ //sends a series of words to display by calling character //function and checking the line number void lcd_message (const char *ptr) { LCD_RS = 1; while(*ptr) { lcd_write(*ptr++); //sendind string } LCD_RS = 0; } void lcd_init(void) //initialises display to be on, clear etc { LCD_RW = 0; //clear RW-essentially tied to ground LCD_RS = 0; //clear RS LCD_EN = 0; //clear enable lcd_write (0x38); //set display, 8-bit, 2-line, 5x7dots DelayMs (); //wait 5ms lcd_write (0x0C); //display on, cursor on, blinking on DelayMs (); //wait 5ms lcd_write (0x06); //Entry Mode Set, Increment Mode, Cursor Shift On DelayMs (); //wait 5ms lcd_write (0x01); //clear display DelayMs (); //wait 5ms } void lcd_initial_msgs (void) //LCD start-up messages
98
{ //LCD_RS= 0; lcd_write(0x80); //select first row lcd_message(" ARMS "); //calls function for message to be dispalyed on LCD lcd_write(0xC0); //select second row lcd_message("Units:"); lcd_write(0x90); //select third row lcd_message("Pulse:"); lcd_write(0xD0); //select fourth row lcd_message("Remain"); } void init(void) //PORTS Initialization + assigning { // This disables the A/D module to allow digital I/O ADCON0 = 0; ADCON1 = 0x07; //PORTD bits are connected to data bits of LCD TRISD = 0x00; // Control Signals for LCD TRISB4=0; // EN TRISB5=0; // RS TRISB6=0; // R/W
TRISB0=0;RB0=1; //FOR SCK TRISB1=0;RB1=0; //FOR CHIP SELECT TRISB2=0;RB2=0; //ADDRESS BIT FOR REGISTER SELECT (DATA IN //FOR SA9903B)--DI TRISB3=1; //FOR DATA IN (DATA OUT FOR SA9903B)--DO TRISC4=1; TRISC0=0; //FOR DATA OUT TO MASTER(controller in data concentrator //module) RC0=1; TRISC1=1; //CHIP SELECT INPUT FROM MASTER TRISC2=1; //FOR DATA IN FROM MASTER(controller in data concentrator module) TRISC3=0;RC3=1; //CLOCK from slave to master // Used for Keypad initialization COLUMNS & ROWS are used as input TRISE0=1; //COL 0 TRISE1=1; //COL 1 TRISE2=1; //COL 2 TRISA0=0; //ROW 0 TRISA1=0; //ROW 1 TRISA2=0; //ROW 2 TRISA3=0; //ROW 3 RA0=RA1=RA2=RA3=0; } //Initialization of TIMER INTERRUPT (TMR0) void init_timerzero(void) { //Initialization of TIMER INTERRUPT (TMR0) GIE=1; // Global Interrupt PSA=0; // Pre-Scaler Assignment(Prescaler assigned to the TMR0) PS0=1; // 1:16 PS1=1; PS2=0;
99
T0CS=0; // TMR0 Clock Source Select Bit (Internal instruction cycle clock CLKOUT) T0IE=1; // TMR0 Overflow Interrupt Enable Bit (Enables The TMR0 Interrupt) TMR0=5; // Initialise the TMRO interrupt from 5 } // Function for converting interger into ascii //It is used to convert units(consumed) into string to be dispayed onto LCD //At line3 of LCD units are dispalyed void itoa_lcd_msg(long unsigned int int_value) { char ascii_str[11]; unsigned char remainder = 0; for(loop=0;loop<10;loop++) { remainder = int_value % 10; ascii_str[9-loop] = remainder + 48; int_value = int_value / 10; } lcd_message(ascii_str); } //Keypad scanning calls to recharge card void keypad (void) { lcd_write(0x90); //select third row lcd_message("Enter Card ? "); lcd_write(0xD0); //select fourth row lcd_message("1 for Y&2 for N "); while(COL0==1||COL1==1||COL2==1){} ke=255; while(1) { i=0; while(ke==255&&i<timeout) //if no key pressed, scan keypad again and again //untill timeout ke=key(); if(i>=timeout) ke=200; lcd_write(0xD0); //select fourth row lcd_message("1 for Y&2 for N "); if(ke=='1') { lcd_write (0x01); //clear display DelayMs (); //wait 5ms lcd_write(0x80); //select first row lcd_message(" ARMS "); //calls function for message to be //dispalyed on LCD lcd_write(0xC0); //select second row lcd_message("Enter 5 No. code"); //while(1){} temp_ke=0; for(incr=149;incr<=153;incr++) //accept 5 digit code from user { while(COL0==1||COL1==1||COL2==1){} ke=255; i=0; while(ke==255&&i<timeout) ke=key(); for(pk=incr;pk<153;pk++) temp_ke= ke*10+temp_ke; if(i>=timeout)
100
{ ke=200; break; } lcd_write(incr); //select third row lcd_message(&ke); } //end 5 digit code accept if(incr==154) //if 5 digit code is completely entered { lcd_write(0xD0); //select fourth row lcd_message("sure ? 1(y) 2(n)"); //are you sure to patch while(COL0==1||COL1==1||COL2==1){} ke=255; i=0; while(ke==255&&i<timeout) ke=key(); if(i>=timeout) ke=200; if(ke=='1') //if YES, i m sure to patch then patch it { lcd_write (0x01); //clear display DelayMs (); //wait 5ms lcd_write(0x80); //select first row lcd_message(" ARMS "); //calls function for //message to be dispalyed on LCD lcd_initial_msgs(); break; } while(COL0==1||COL1==1||COL2==1){} if(ke!=200) ke='1'; } //end if(incr==154) else //entered 5 digit code is not complete ke=200; } else { while(COL0==1||COL1==1||COL2==1){} lcd_write (0x01); //clear display DelayMs (); //wait 5ms lcd_write(0x80); //select first row lcd_message(" ARMS "); //calls function for message to be //dispalyed on LCD lcd_write(0x90); //select third row lcd_message("Timer Expires!!!"); i=0; while(ke==200&&i<=timeout/2){} lcd_initial_msgs(); break; } }// end while(1) }// end function keypad() void main (void) { init (); //calls all initilization function init_timerzero(); //calls Initialization of TIMER ZERO INTERRUPT (TMR0) lcd_init(); //calls LCD initialisation function lcd_write(0x80); //select first row lcd_message(" ARMS "); //calls function for message to be dispalyed on LCD lcd_write(0xC0); //select second row
101
lcd_message("You Have 10Units"); keypad(); lcd_initial_msgs(); while(1) { ROW0=0;ROW1=0;ROW2=0;ROW3=1; if(COL2==1) //if # is pressed then input for card { lcd_write(0xC0); //select first row lcd_message(" ");//calls function for message to be dispalyed //on LCD keypad(); } if(vari<3500 && vari>270) //if no communication with SA9903B then //calculate UNITS { calculation(); } //if(opulse!=npulse) ////////////////// JAHLEAT //{ LCD_RS=0; lcd_write(0xC6); //select seond row (6th location) itoa_lcd_msg(units); lcd_write(150); //select third row (6th location) itoa_lcd_msg(npulse); lcd_write(0xD6); //select fourth row (6th location) itoa_lcd_msg(remains); //opulse=npulse; //} } // end of while loop } // end of main // IINTERRUPT FUNCTION static void interrupt timer(void) { T0IF=0; // TMR0 Overflow Interrupt Flag Bit (cleared) TMR0=5; // Initialise the TMRO interrupt from 5 vari++; i++; // FU_CK = !FU_CK; if(i2>0) { FU_DO = fu_units%2; fu_units = fu_units/2; i2--; } else if(i2==0&&FU_CS==0) { fu_units = units; i2=30; FU_DO=0; } else { if(i2>32) { cd = (utable[i2-33]*FU_CS) + cd; i2++; } else if(i2==0&&CODE_CS==0) { df=0; i2=33; FU_DO=0;