final project report-parggah and gilbert (4)
TRANSCRIPT
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
1/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
1
Contents
CHAPTER ONE-PROJECT OVERVIEW.................................................................... 4
Table1-1 Ghantt Chart for September 2007December 2007.......................................... 6
Table 1-2 Ghantt Chart for February 2008May 2008.................................................... 6
CHAPTER TWO- LITERATURE REVIEW................................................................ 8
2.1.1 Units of measurement .............................................................................................. 8
2.1.2 Types of meters ........................................................................................................ 8
2.1.3Electromechanical meters ....................................................................................... 9
2.1.4 Electronic meter ..................................................................................................... 11
2.1.4.1Solid state meter................................................................................................... 11
2.1.4.2 The prepayment meter......................................................................................... 11
2.1.4.2.1Keypad operated prepayment meters................................................................ 12
2.1.4.2.2Smart card operated prepayment meters.......................................................... 12
2.3.1 Types of relays......................................................................................................... 15
2.4.1 The I2C Protocol .................................................................................................... 18
CHAPTER 3 OVERVIEW OF MICROCONTROLLERS ..................................... 27
3.1General Architecture of microcontrollers243.1.1Memory unit 253.1.2 Types of memory.253.1.3 CPU..26
3.1.4Busses...263.1.5I/O.273.1.6ADC..273.2 PROGRAMMING.273.3 Types of Microcontrollers.283.3.1PIC Microcontrollers...283.3.2Programming of the PIC microcontrollers..31CHAPTER FOUR-DESIGN .......................................................................................... 36
4.1 Design considerations ............................................................................................... 36
4.2 Design Options .......................................................................................................... 42
4.2.2 How to deal with Please call an ECG personnel message .............................. 43
4.2.4 Warning .................................................................................................................. 44
4.3 System block diagram............................................................................................... 47
4.4 Principle of operation ............................................................................................... 47
4.5Improvement over existing system .......................................................................... 48
4.5.1 Mode of warning .................................................................................................... 48
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
2/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
2
4.5.2 The concept of negative credit .............................................................................. 49
4.5.3Security features...................................................................................................... 49
4.6 System Design............................................................................................................ 50
4.6.2 QRB sensor module ............................................................................................... 51
4.6.2.1 QRB sensor holder .............................................................................................. 52
4.6.3 Microcontroller module......................................................................................... 53
4.6.3.1 Packaging............................................................................................................. 54
4.7 Design of the card terminal unit .............................................................................. 55
4.7.2 Packaging................................................................................................................ 57
4.8 Design of a DSP based prepayment meter.............................................................. 58
4.8.1 Circuit diagram of DSP based prepayment meter design.................................. 58
4.8.2 Comparing a DSP based system to credit based prepayment system............... 59
4.9 Printed circuit board design of microcontroller module....................................... 604.10 Programming........................................................................................................... 61
4.10.1 Flow chart for program....................................................................................... 61
4.10.2 Operation of the program ..................................................................................... 62
4.10.3 The various functions in the program................................................................ 63
CHAPTER FIVE-IMPLEMENTATION ..................................................................... 65
5.1 Design options implemented .................................................................................... 65
5.2 Calculations made ..................................................................................................... 65
5.3 Construction .............................................................................................................. 665.3.1 The power supply module ..................................................................................... 66
5.3.2 The QRB sensor module........................................................................................ 68
5.3.3 The microcontroller module ................................................................................. 69
5.3.4 The card terminal unit........................................................................................... 69
5.4 Tests performed ........................................................................................................ 70
5.4.1 The bridging problem........................................................................................ 70
5.4.2 Placement of black mark and QRB sensor.......................................................... 71
5.4.3 Test for functionality of the various modules ...................................................... 71
5.4.4 Test for the amount of power consumed by the embedded unit........................ 72
5.5 Limitation and Errors of the system ....................................................................... 73
5.6 Component list .......................................................................................................... 74
5.6.1Cost of the embedded unit..................................................................................... 75
5.6.2 Cost of the card terminal unit............................................................................... 75
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
3/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
3
5.7 The process of retrofitting the credit energy meter with the embedded unit...... 76
CHAPTER SIX ............................................................................................................... 77
6.1 RCOMMENDATION............................................................................................... 77
6.2 Conclusions................................................................................................................ 77
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
4/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
4
CHAPTER ONE-PROJECT OVERVIEW
1.1 Introduction
Every utility company provides service, from which revenue is generated. The Electricity
Company of Ghana (ECG) uses energy meters as the only direct revenue interface
between the company and its customers.
An energy meter is a device that measures the amount of electrical energy supplied to a
residence or business. There are several types of energy meters, one of which is the
electromechanical meter (credit meter), which is largely used by ECG for the purpose of
revenue generation. This is done by recording the value measured by the meter for the
previous month or quarter to prepare invoices for the customers.
However, the mode of revenue generation of the electromechanical meter is credit based,
where the customer uses the electricity before paying. This hinders the effective
generation of revenue.
Owing to this fact, the company introduced the prepayment metering system to provide
an almost immediate revenue generation. The company has partly achieved this by
replacing the credit meters with prepayment meters. However, the cost of changing to the
prepayment system is very high due to the following reasons
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
5/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
5
Firstly the prepayment meters must be imported at a high cost because they are not
manufactured locally.
Secondly, upon installation of the prepayment meter, the credit meter, although in good
working condition, becomes redundant and the company incurs extra cost disposing off
them.
A very cost effective solution would be to upgrade the credit meter to the status of the
prepayment meter, which this project seeks to achieve.
1.2 Problem statement
To convert the electromechanical credit energy meter to a prepayment energy meter.
1.3 ObjectiveThis project seeks to upgrade the credit meter on site to a prepayment meter by
retrofitting it with embedded unit. This prepayment energy meter will be interactive to
use, have security features and allow the customer some amount of power on credit when
his credit finishes.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
6/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
6
1.4 Project plan
Table1-1 Ghantt Chart for September 2007December 2007
Table 1-2 Ghantt Chart for February 2008May 2008
Month September October November December
Week 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Activity
A
B
C
D
Month February March April May
Week 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
Activity
E
F
G
H
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
7/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
7
A Formulation of objectives
B Research on energy meters
C Learning of microcontrollers, PIC and C programming
D Design, programming and simulation
E Building
F Testing
G Packaging and testing
H Report writing
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
8/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
8
CHAPTER TWO- LITERATURE REVIEW
2.1 Energy meters
An energy meter is a device that measures the amount of electricity supplied to a
residence or a business.
2.1.1 Units of measurement
The most common unit of measurement on the electric meter is the kilowatt-hour, which
is the amount of electrical energy used by a load of one kilowatt over a period of one
hour.
Other units of measurement include kilovars-hour, which measures reactive power and
finally, the ampere-hour which also measures the amount of charge in coulombs used. [1]
2.1.2 Types of meters
Broadly, there are two categories of meters. These are the electromechanical meter and
the electronic meter. [1]
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
9/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
9
2.1.3Electromechanical meters
This is the most common type of electricity meter. This meter operates by counting the
revolutions made by an aluminum disc that is made to rotate at a speed proportional to
the power consumption of the customer.
Picture of an electromechanical meter
The aluminium disc is acted upon by two coils. One coil is connected in such a way that
it produces magnetic flux in proportion to the voltage and the other coil is in proportion
to the current. The field of the voltage coil is delayed by 90 degrees using a lag coil. This
produces eddy current in the disc and the effect is such that a force is exerted on the disc
in proportion to the product of the instantaneous current and voltage.
A permanent magnet exerts an opposing force that is proportional to the speed of rotation
of the disc. This acts as a brake which prevents the disc from rotating when power stops
flowing, rather than allowing the disc to spin faster and faster. This causes the disc to
rotate at a speed proportional to the power being used.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
10/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
10
The meter described above is the single-phase energy meter. There are other
configurations like the three-phase.[1]
2.1.3.1 Reading
The aluminium disc is supported by a spindle that has a worm gear that drives the
register. The register is a series of dials that records the amount of energy used.
The amount of energy used represented by one revolution of the disc is denoted by the
symbol Kh, which is given in units of watt-hours per revolution. The value 7.2 is
commonly seen. Using the value ofKh, one can determine their power consumption at
any given time by timing the disc with a stopwatch. If the time in seconds taken by the
disc to complete one revolution is t, then the power in watts is P = 3600 Kh / t. For
example, ifKh = 7.2, as above, and one revolution took place in 14.4 seconds, the power
is 1800 watts. This method can be used to determine the power consumption of
household devices by switching them on one by one. [1]
Most domestic electricity meters must be read manually, whether by a representative of
the company or by the customer himself.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
11/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
11
2.1.4 Electronic meter
2.1.4.1Solid state meter
These are newer meters that measure the amount of power consumed and display the
result on an LCD. Aside measuring the power, the solid state meter measures other
parameters such as power factor and the reactive power used. [1]
Picture of the solid state meter
2.1.4.2 The prepayment meter
There are a number of reasons why a utility company could consider installing a prepaid
metering system. They include improved cash flow, no need for account posting or
additional billing systems (1-2% savings), elimination of bad debts (5-12% average, with
up to 40% in some developing countries), elimination of disconnection and reconnection
fees and ease of installation.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
12/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
12
There are also advantages to the customer, including budget management, control of
energy usage, no cost for disconnection/reconnection and no waiting for reconnection, no
deposits.
Prepaid energy meters using keypad based systems, disposable card systems (one-way)
and two-way smart card systems are in use in various parts of the world for over a
decade. [1]
2.1.4.2.1Keypad operated prepayment meters
Electronic prepaid energy meters came initially with keypad systems for inputting the
credit. Security of keypad payment system is very low. The main reason is that the
algorithm of key creation is stored inside the meter and is available to hackers. Keypad
systems were created when highly secure smart card payments did not exist.
Although keypad systems are getting obsolete, it may still be cost-effective for remote
villages, where two-way vending may not be feasible. [1]
2.1.4.2.2Smart card operated prepayment meters
With Smart Card operated systems, customers purchase a reusable power debit card for
the amount of energy they desire. These special, easy to use cards are individualized,
keyed to each customer's meter and account number. The customer simply passes the
card a few inches in front of the meter, and using an integrated card reader, the meter is
reset to the number of kilowatt-hours contained on the card. The system works very much
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
13/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
13
like a bank debit card. Because the meter is completely sealed and has no moving parts,
maintenance is reduced and reliability is improved. Modern Smart Card operated meters
are "stand alone", requiring no separate in-house keypad or onsite programming. The
card captures transaction and power usage information, sending automatic input into the
utility's accounting system at the sales terminal each time the customer purchases
additional power. The card also captures data critical for load forecasting.
Disposable card type prepaid meters are also in use in certain utilities. The vending
infrastructure for this scheme is much simpler, but it does not offer the advantage of
capturing customer usage data.
Smart card operated meters can be used either as prepaid or postpaid. In some countries,
prepaid option is socially not acceptable. In such cases, each consumer is assigned 50-day
credit. After each month, the consumer has to recharge a card to pay off his negative
balance. After full payment, his 50-day credit is restored. Credit can be time-based or
amount-based. Mixed option like 50-day but not more than certain kWh is also possible.
[1]
Picture of the Prepayment meter
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
14/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
14
2.2Circuit breaker
A circuit breaker is an automatically operated electrical switch that that is designed to
protect an electrical circuit from damage caused by a voltage overload or a short circuit.
Unlike the fuse which is used only once, the circuit breaker can always be reset after it
has tripped to resume normal operation. It uses the shunt trip for this purpose. When there
is a voltage overload, the live and the neutral terminals are connected together through a
shunt resistor and that causes it to trip and open the circuit as a form of protection.
Picture of the Circuit Breaker
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
15/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
15
2.2.1 Types of circuit breakers
There are many types of circuit breakers to suit various design situations. But for the
purpose of this project, the miniature circuit breaker will be chosen. The other type of
circuit breaker is the moulded case circuit breaker both of which are for low current
applications.
For higher voltage applications, we have other circuit breaker like the vacuum circuit
breaker and the air circuit breaker.
[1]
2.3 Relays
A relay is an electrical switch that opens and closes under the control of another circuit. It
operated by an electromagnet to open or close one or many sets of contacts.
Knowing the resistance of the coil, and its rated voltage, you can compute the current
requirement of the relay coil. And from that information, calculate the power needs of the
relay.
2.3.1 Types of relays
There are several types of relays. These include latching relay, reed relay, mercury-
wetted relay, polarized relay, solid state relay, among many others. The choice of relay
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
16/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
16
depends on the design of the project. For the purpose of this project, the solid state relay
was chosen for the reason that it has no moving parts.[1]
Picture of the Solid State Relay
2.4 Memory card
Memory cards are the simplest type of smartcard. Memory cards only have some amount
of memory inside the card and this memory can be normally read and written. There is
normally nothing really intelligent inside those cards. Typically the memory inside this
kind of cards is EPROM, EEPROM or FLASH memory. This card type is very widely
used as telephone cards (telecards) and as prepayment cards where no processing is to be
done by the card. For the purpose of this project, the memory card used conforms to the
ISO 7816 standard. The standard specifies the pin outs and the communication protocols
for the card. Below is the pin out of the memory card as specified by the ISO7816
standard?
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
17/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
17
Connector Layout of the Smart Card
Pins marked with n/c are application specific pins defined in application standards. The
standard supports two transmission modes:
Asynchronous transmission: In this type of transmission, characters aretransmitted on the I/O line in an asynchronous half duplex mode. Each character
includes an 8bit byte.
Synchronous transmission: In this type of transmission, a series of bits istransmitted on the I/O line in half duplex mode in synchronization with the clock
signal on CLK.
There is a selection of different protocols available for communicating with the card.
There is a method for selecting which communication protocol to use (one card can
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
18/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
18
support one or more protocols).The most commonly used protocol seems to be
asynchronous half duplex character transmission protocol. In contact systems, such as
reading the data from a serial EEPROM over a two-wire (I2C) or three-wire SPI or
Microwire bus, the power, clock, and data lines are connected separately. Some wired
smartcards use RS-232 type asynchronous communications, and in this case supply
power and communication through different wires. [2] This project will consider the I2C
protocol.
2.4.1 The I2C Protocol
A brief discussion of the I2C protocol is discussed below
2.4.1.1 The physical I2C bus
This is just two wires, called SCL and SDA. SCL is the clock line. It is used to
synchronize all data transfers over the I2C bus. SDA is the data line. The SCL & SDA
lines are connected to all devices on the I2C bus. There needs to be a third wire which is
just the ground. There should be a 5volt wire from which power will be distributed to the
devices. Both SCL and SDA lines are "open drain" drivers. What this means is that the
chip can drive its output low, but it cannot drive it high. For the line to be able to go high
you must provide pull-up resistors to the 5v supply. There should be a resistor from the
SCL line to the 5v line and another from the SDA line to the 5v line. You only need one
set of pull-up resistors for the whole I2C bus, not for each device, as illustrated below:
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
19/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
19
The value of the resistors is not critical. Anything from 1k8 (1800 ohms) to 47k (47000
ohms) can be used. 1k8, 4k7 and 10k are common values, but anything in this range
works fine. If the resistors are missing, the SCL and SDA lines will always be low -
nearly 0 volts - and the I2C bus will not work.
2.4.1.2 Masters and Slaves
The devices on the I2C bus are either masters or slaves. The master is always the device
that drives the SCL clock line. The slaves are the devices that respond to the master. A
slave cannot initiate a transfer over the I2C bus, only a master can do that. There can be,
and usually are, multiple slaves on the I2C bus, however there is normally only one
master. Slaves will never initiate a transfer. Both master and slave can transfer data over
the I2C bus, but that transfer is always controlled by the master.
2.4.1.3 The I2C Physical Protocol
When the master (the controller) wishes to talk to a slave it begins by issuing a start
sequence on the I2C bus. A start sequence is one of two special sequences defined for the
I2C bus, the other being the stop sequence. The start sequence and stop sequence are
special in that these are the only places where the SDA (data line) is allowed to change
while the SCL (clock line) is high. When data is being transferred, SDA must remain
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
20/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
20
stable and not change whilst SCL is high. The start and stop sequences mark the
beginning and end of a transaction with the slave device.
Data is transferred in sequences of 8 bits. The bits are placed on the SDA line starting
with the MSB (Most Significant Bit). The SCL line is then pulsed high, then low. The
chip cannot really drive the line high, so it simply "lets go" of it and the resistor actually
pulls it high. For every 8 bits transferred, the device receiving the data sends back an
acknowledge bit, so there are actually 9 SCL clock pulses to transfer each 8 bit byte of
data. If the receiving device sends back a low ACK bit, then it has received the data and
is ready to accept another byte. If it sends back a high then it is indicating it cannot accept
any further data and the master should terminate the transfer by sending a stop sequence.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
21/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
21
2.4.1.4 Speed of the I2C bus
The standard clock (SCL) speed for I2C up to 100KHz. Philips do define faster speeds:
Fast mode, which is up to 400KHz and High Speed mode which is up to 3.4MHz. But
this needs a small delay of a few uS between each byte transferred.
2.4.1.5 I2C Device Addressing
All I2C addresses are either 7 bits or 10 bits. For 7 bits, it means that you can have up to
128 devices on the I2C bus, since a 7bit number can be from 0 to 127. When sending out
the 7 bit address, still always send 8 bits. The extra bit is used to inform the slave if the
master is writing to it or reading from it. If the bit is zero are master is writing to the
slave. If the bit is 1 the master is reading from the slave. The 7 bit address is placed in the
upper 7 bits of the byte and the Read/Write (R/W) bit is in the LSB (Least Significant
Bit).
The placement of the 7 bit address in the upper 7 bits of the byte is a source of confusion.
It means that to write to address 21, you must actually send out 42 which is 21 moved
over by 1 bit. It is probably easier to think of the I2C bus addresses as 8 bit addresses,
with even addresses as write only, and the odd addresses as the read address for the same
device.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
22/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
22
2.4.1.6 The I2C Software Protocol
The first thing that will happen is that the master will send out a start sequence. This will
alert all the slave devices on the bus that a transaction is starting and they should listen in
incase it is for them. Next the master will send out the device address. The slave that
matches this address will continue with the transaction, any others will ignore the rest of
this transaction and wait for the next. Having addressed the slave device the master must
now send out the internal location or register number inside the slave that it wishes to
write to or read from. This number is obviously dependant on what the slave actually is
and how many internal registers it has. Some very simple devices do not have any, but
most do, including all of our modules. Having sent the I2C address and the internal
register address the master can now send the data byte (or bytes, it doesn't have to be just
one). The master can continue to send data bytes to the slave and these will normally be
placed in the following registers because the slave will automatically increment the
internal register address after each byte. When the master has finished writing all data to
the slave, it sends a stop sequence which completes the transaction. So to write to a slave
device:
1. Send a start sequence
2. Send the I2C address of the slave with the R/W bit low (even address)
3. Send the internal register number you want to write to
4. Send the data byte
5. [Optionally, send any further data bytes]
6. Send the stop sequence.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
23/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
23
As an example, you have an SRF08 at the factory default address of 0xE0. To start the
SRF08 ranging you would write 0x51 to the command register at 0x00 like this:
1. Send a start sequence
2. Send 0xE0 (I2C address of the SRF08 with the R/W bit low (even address)
3. Send 0x00 (Internal address of the command register)
4. Send 0x51 (The command to start the SRF08 ranging)
5. Send the stop sequence.
2.4.1.7 Reading from the Slave
Before reading data from the slave device, you must tell it which of its internal addresses
you want to read. So a read of the slave actually starts off by writing to it. This is the
same as when you want to write to it: You send the start sequence, the I2C address of the
slave with the R/W bit low (even address) and the internal register number you want to
write to. Now you send another start sequence (sometimes called a restart) and the I2C
address again - this time with the read bit set. You then read as many data bytes as you
wish and terminate the transaction with a stop sequence. So to read the compass bearing
as a byte from a CMPS03 module:
1. Send a start sequence
2. Send 0xC0 (I2C address of the CMPS03 with the R/W bit low (even address)
3. Send 0x01 (Internal address of the bearing register)
4. Send a start sequence again (repeated start)
5. Send 0xC1 (I2C address of the CMPS03 with the R/W bit high (odd address)
6. Read data byte from CMPS03
7. Send the stop sequence.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
24/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
24
The bit sequence will look like this:
That's almost it for simple I2C communications, but there is one more complication.
When the master is reading from the slave, its the slave that places the data on the SDA
line, but its the master that controls the clock. What if the slave is not ready to send the
data! With devices such as EEPROMs this is not a problem, but when the slave device is
actually a microprocessor with other things to do, it can be a problem. The
microprocessor on the slave device will need to go to an interrupt routine, save its
working registers, find out what address the master wants to read from, get the data and
place it in its transmission register. This can take many uS to happen, meanwhile the
master is blissfully sending out clock pulses on the SCL line that the slave cannot
respond to. The I2C protocol provides a solution to this: the slave is allowed to hold the
SCL line low! This is called clock stretching. When the slave gets the read command
from the master it holds the clock line low. The microprocessor then gets the requested
data, places it in the transmission register and releases the clock line allowing the pull-up
resistor to finally pull it high. From the masters point of view, it will issue the first clock
pulse of the read by making SCL high and then check to see if it really has gone high. If
its still low then its the slave that holding it low and the master should wait until it goes
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
25/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
25
high before continuing. Luckily the hardware I2C ports on most microprocessors will
handle this automatically.
Sometimes however, the master I2C is just a collection of subroutines and there are a few
implementations out there that completely ignore clock stretching. They work with things
like EEPROM's but not with microprocessor slaves that use clock stretching. The result is
that erroneous data is read from the slave. Beware!
2.5 Phototransistor reflective object sensor
Phototransistor reflective object sensor is a device consisting of an infrared emitting
diode and an NPN silicon phototransistor, mounted side by side in a black plastic
housing. The phototransistor responds to radiation from the emitter only when a
reflective object passes within its field of view. One of the many types of this sensor is
the QRB1133 with its diagram shown below. [3]
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
26/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
26
Picture of the QRB1133 Circuit representation of the QRB113
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
27/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
27
CHAPTER 3 OVERVIEW OF MICROCONTROLLERS
3.1 General architecture of microcontrollers
Microcontroller is an integrated circuit that incorporates a central processing unit (CPU),
a memory unit, and input/output (I/O) ports. A microcontroller is usually embedded in an
electronic device to serve as a means of controlling the functions of the particular
electronics device.
A typical microcontroller is manufactured as a single chip and has the following parts:
1. has a central processing unit2. a memory unit3. a bus system4. an input / output interface5. serial communication6. a timer unit7. a watchdog8. an analog to digital converter9. programmability
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
28/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
28
3.1.1 The memory unit
The function of the memory unit is to store binary data in groups of bits called words.
Each word is a memory location, and it is assigned a unique address. The size of the
memory determines how much data can be stored in it. Thus, the bigger the memory size,
the greater the number words it can store. Data stored in a particular word is referenced
by a process known as addressing. Addressing refers to the act of selecting a particular
memory location.
Getting the desired data from memory is called reading, while the act of putting data
into the memory of the microcontroller is called writing. Therefore, to read or write data
to memory, the target location is first specified by addressing and the data is either read
or written to that location. A read / write (W/R) control line specifies whether a read or a
write operation is to be carried out. When this control line is high, data is read from
memory, and when it is low data is written to the selected location.
3.1.2 Types of memory
There are two types of memory, the volatile and the non-volatile memories
The volatile type of memory loses its data when there is no power supply to it. The non-
volatile memory on the other hand is able to retain its data even in the absence of power.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
29/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
29
RAM (Random Access Memory) is a volatile memory, while the non-volatile memories
are the ROM (Read Only Memory), PROM (Programmable Read Only Memory),
EPROM (Erasable Programmable Read Only Memory) and EEPROM (Electronically
Erasable Programmable Memory).
3.1.3 The central processing unit (CPU)
The central processing unit is that component on the microcontroller that has built-in
logic to enable it perform functions such as memory access, shift operations and the
arithmetic and logical operations. The CPU has collections memory cells called registers
that help it carry out these functions.
3.1.4 Busses
The busses are made up of a set of parallel wires that serve as a path that interconnect the
various units of the microcontroller- the memory unit, the I / O and the CPU.
There are two types of busses. These are the data bus and the address bus. The address
bus consist of as many parallel wires as needed to carry the addresses and the data bus is
responsible for carrying data to and from the memory to the CPU.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
30/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
30
3.1.5 The input / output (I/O)
The input/output unit of the microcontroller serves as the interface between the
microcontroller and the outside world. The I/O is connected to the bus on one side from
the microcontroller. These connections are seen as the pins from the component. These
pins are the output pins. The input connects to the inside of the microcontroller.
3.1.6
Analog-Digital converter
The microcontroller can only process digital data, and since most of the signals are
analog signals, they must first be converted into digital signals. This conversion is done
with the analog-digital converter.
There are other components that help the microcontroller to carry out its functions. These
are the timer unit and the watchdog. [4]
3.2 Programming
Instructions must be given to the microcontroller in order for it to complete any required
task. A program is a series of instructions written to give the micro controller step-by
step procedure to complete the required task. The procedure of writing a program and
loading it into the micro controller is termed programming the micro controller.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
31/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
31
Programs for the microcontroller can be written is several languages, of these are
Assembler and BASIC etc.
Assembler is a low level language and it is difficult to use, but programs written in
assembler take up the least memory space and have the fastest execution times and Basic
are very simple programming languages which takes a fair amount of memory space and
have good execution times.
3.3
Types of microcontrollers
There are many microcontrollers from different manufacturers. These include the PIC,
the BASIC stamp, AVR, ATMEL, and many more.
3.3.1 PIC microcontroller
The low cost and high performance of the PIC microcontroller makes it an ideal option
for use in the energy metering system. Several types of the PIC exist, but the operation of
an energy meter requires that some important information should be kept when there is
no power. This calls for the use of a PIC with a non volatile form of memory. The
PIC16F877 with 256byte of EEPROM became the obvious choice.
The PIC16F877 is made up several features. These include:
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
32/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
32
Program memory (flash)
This is based on the flash technology and is used for storing microcontroller programs.
The flash is 8K in size. Flash can be programmed and erased several times. This makes
the PIC microcontroller suitable for device development and testing.
EEPROM
Data stored in the EEPROM is not retained even when power is removed from the unit.
This makes the PIC suitable for storing critical data like the units of electricity consumed
and the units remaining. Thus the reliability of the PIC is enhanced by this ability.
RAM
Because the RAM loses data when power supply is interrupted, it is used for storing non-
critical data during program execution.
PORTS
The ports provide the physical connections between the microcontroller and external
devices. 16F877 has ports A, B, C, D and E .The numerous number of port makes the
number of external devices that can be connected to it many.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
33/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
33
CPU
The function of the CPU is to execute the micro controller program and coordinate the
functions of the other blocks in carrying out the instruction
The Diagram of the PIC16F877 [5]
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
34/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
34
3.3.2 Programming of the PIC microcontroller
The PIC16F877 microcontroller can be programmed in any of the three languages-
Assembler and Basic, but for this project, it will be programmed in C due to the
availability of development tools like the FED PIC C compiler
The FED PIC C compiler is a full integrated development environment for writing
programs for the PIC microcontroller. It has a simulator that allows
easy programming of external real devices like LCD , EEPROM, led, switches, buzzers,
keypad etc .Due to this, it becomes a convenient development tool for design problems
involving the PIC micro controller since the whole project can be simulated using the
simulator and debugged on errors. A diagram of a typical design environment using this
compiler is shown below: [6]
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
35/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
35
Snap Shot Of The Code Simulation
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
36/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
36
CHAPTER FOUR-DESIGN
4.1 Design considerations
The following were considered in design process of this project.
4.1.1 From customers view
A survey in the form of questionnaires was conducted at Ayiduase with 50 customers of
ECG who use the prepayment meter. The aim of this exercise was to find out what the
general public felt about the current prepayment meters.
The questionnaires were prepared with the following questions.
Comparing the prepaid meter to the credit meter, which one is better? Is there anything about the prepaid meter that you dont like? If yes please state
them
For the first question, 38 out of the 50 said they liked the prepaid meters with 12 saying
the credit meter was better because the prepaid read very fast and you have to pay before
u use it.
The second question was the focus. The following was what the response
All 50 of the customers complained about the mode of warning when their creditgot to 20. According to them, they see no reason why the meter should shut power
while they still have as many as 20 credits. Those customers who operate internet
cafs and other computer related business complained about loosing precious data
while they still had credit.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
37/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
37
28 0f the 50 complained of not getting credit to buy on weekends. According tothem they do not know any place where they can recharge their cards on
weekends and so pay the unfair penalty of sleeping in the dark or using the
generator, which is too expensive.
30 of the 50 said the meters were not interactive to use. It does not display anymessage when an error occurs, and they have to try and figure out what the
problem is. They also complained that the meter only displays their available
credit when it gets to 50 thus giving them no prior knowledge of how fast they
consume before being hit all of a sudden with the appearance of a deadly 50 in
red. According to them they would like to know their amount of credit all the
time.
Based on the responses obtained from the survey, the following design considerations
were developed.
Replace the mode of warning with an alarm which will sound when thecustomers credit gets to a threshold thus shutting the customer only when he has
exhausted all his credit.
Provide means for the customer to use some fixed amount of power on credit.This amount of power will be determined by the company after which the
customer will be shut if he fails to buy credit. The number of power units
consumed on credit will be deducted from the customers purchased credit as soon
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
38/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
38
as he inserts the recharged card, and until he has paid all his debt, power will not
be restored. Also the number of power units consumed on credit will be displayed
as negative values to signify that the customer owes that amount of power. This is
to take care of those customers whose credit gets finished on weekends.
Use a liquid crystal display (LCD) to interact with the user by displayingappropriate messages that will make the use of the system very interactive. For
example, if you insert the card wrongly, a message will be displayed to warn you.
Also the LCD will be appropriate to use to display the negative credit. It will also
display credit all the time so that customers will know the amount of credit they
have so as to know and control their rate of power consumption.
4.1.2 From tests performed
From tests performed and from the experiences of the ECG technician, the following
were identified
The current prepayment meter uses only a circuit breaker to do the switching.That is the circuit breaker is used to shut off power when the customers credit
finishes and to switch power back on for the customer when he buys credit.
The problem identified was that the circuit breaker has a minimum delay of
about 8 sec to trip when a signal is sent to it from the microcontroller that the
customers credit is finished. This means that the customer will have free power
for that delay period since the system cannot record that power used. Also when
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
39/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
39
the circuit breaker is switched on manually, the customer will enjoy free power
for about eight seconds even if he has no credit. This is due to that eight second
delay.
The current prepaid meters have minimal security in terms of card reading. Eachmeter is given a unique card from only which the meter is supposed to read. But
it has become a known fact that the operation of the meter is affected by placing
a phone card or any other card other than that unique card of the meter.
According to ECG technicians, the meter fails to shut power off while a wrong
card is inserted and the customers units are finished. The intelligent part of the
system thus loses track of all the power that the user consumes as long as the
wrong card is still inserted.
At very low voltages, it has been observed that the electronic aspect of theexisting prepayment meter goes off but the electromechanical aspect of the meter
continues to record power consumption. Since the electronic meter will store the
credit of the customer when it goes off and so the credit cannot reduce while the
electromechanical continues to record power, there will be a disparity between
power consumption displayed by the two units when normal voltage is restored
(electronic unit comes back on). The company solves this by obtaining the
difference in the two readings and billing the customer. This has led to lots of
controversies.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
40/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
40
From these findings, the following design considerations were made.
A double switching configuration will be used. This will involve a single pole double throw relay and the circuit breaker. The load will be connected to the
normally closed contact of the relay and the shunt trip of the circuit breaker will
be connected to the normally open contact of the relay. The relay which has no
delays will only be limited by the response time of the PIC micro controller at
power up which is 72ms.When there is no credit, the PIC energies the coil of the
relay which then moves to the normally open contact, thus disconnecting the
load.
This implies no power consumption. The normally open contact will then trip the
circuit breaker in about 8s preventing the loss of power to ECG which will be
dissipated in the circuit.
A high security feature will be implemented to detect the insertion of wrongcards. This feature will count the number of times the system has recognized the
presence of a wrong card and when that count reaches a preset value, the
customer shall be penalized by disabling further reading of any card by the
system, whether correct or wrong cards. When a card is inserted, the system will
display the message Please call an ECG personnel with a beep. Unless a
special card called Reset card is inserted by an ECG personnel to reset the
count, the meter shall not read any more cards. When the Reset card is inserted,
the system will display the message Reset card in.Security memory
cleared!With a beep. This will also serve as a source of revenue for the
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
41/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
41
company since recalcitrant customers will have to pay a fine before the system is
reset. It will also serve as a deterrent to other customers to desist from tampering
with ECGs meters.
The electronic unit needs constant five volts supply to operate. This calls for theuse of a five volts voltage regulator (LM7805).According to the datasheet of this
regulator, an input voltage range of five to eighteen volts is required to produce a
constant five volts at the output. An input voltage less than five will not be
sufficient to turn on the voltage regulator thereby putting off the electronic unit.
After consultation with the company, it came to light that the minimum phase
voltage possible is around 120V, and the maximum phase voltage possible is
250V.thus a transformer which could produce at least 5V DC to the voltage
regulator is required.
A 220/240-12V transformer was chosen based on the following calculations
Turns ratio = 240/12 = 20
100V across the primary, secondary voltage will be 100/20 = 5V
Transformer has tolerance of 5% thus can withstand voltage up to
1.05 240 = 252V.
252V across primary, secondary voltage will be 252/20 = 12.6V
The calculations above show that the electronic unit will be up and functioning at
voltages between 100 and 252V which exceeds the minimum and maximum
voltages specified by the company.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
42/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
42
4.1.3 Ease of installation
The process of retrofitting the electromechanical meter with the embedded unit must be
as easy as possible. Thus, a technician must be able to mount the unit accurately and with
much ease.
4.2 Design Options
This project does not seek to impose any design on ECG. Due to this fact, all possible
design options will be discussed and the company will have the option of choosing which
designs it want to implement. The following are the various design options
4.2.1 Method of initializing the embedded unit with the credit meter ID
All credit meters installed by ECG have a nine digit id number. Due to the fact that each
credit meter should be converted to prepaid and should have a card specific to it, then
each retrofitting unit and card should be initialized with the nine digit id of the target
credit meter so that functions such as the card authentication can be done. This can be
done in two ways discussed below
The credit meter ID is hard coded as part of the retrofitting units microcontrollercode and the card also initialized using a special unit called the card terminal. For
this system to work, ECG must present the data base of the entire targeted credit
meter IDs so that they can be incorporated in the code before manufacturing. This
means that ECG will be presented with tagged retrofitting units and cards bearing
the ID of the target credit meters.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
43/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
43
Uninitialized retrofitting units will be presented to ECG along with a special cardcalled initialization card and the card terminal. The card terminal which has a key
pad interface will be used to program the initialization card with the credit meters
ID and when inserted into the retrofitting unit, the unit will read the credit meter
ID into its non-volatile memory (EEPROM) from which authentication can be
done. The specific card for the retrofitting unit is also initialized with the card
terminal .This flexibility give the company the option of doing the initialization
on site or on the companys premises .The card terminal unit can also be equipped
with a lot of function which have to be on demand from the company, example
will be to give it the ability to sell credit to customers.
4.2.2 How to deal with Please call an ECG personnel message
The system is equipped with a security feature which upon detecting three insertion of a
wrong card, displays the message Please call an ECG personnel and disables the
system from feather reading any card. This the system does by increasing a memory
location. To allow the system to read from a card again, then that memory location must
be cleared. This can be done in two way as follows
The customer comes to ECG to report the problem, he pays a fine and providesthe necessary information on a form so that the companys scheduled
maintenance team equipped with a Reset card would be able to locate his
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
44/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
44
house/store .When the Reset card is inserted in the meter, the security memory is
cleared.
The customer reports to ECG with his card, he is charged a fee after which aspecial code is put on his card. Upon his insertion of his card into the system, the
security memory is cleared.
4.2.3 Power on delay
It has been observed that for the first few seconds when power is restored, there arevoltage surges. The system can be designed with a delay mechanism built into it that will
delay power supply to the house for a predetermined time within which the voltage surge
dies down.
4.2.4 Warning
An improvement of this system over the existing prepayment system is beeping when the
customers credit gets to a threshold instead of completely cutting off power. The system
beeps slowly when the credit gets to a threshold value which will be set by the company
and beeps faster when the customer has exhausted all his credit and is about to enter the
negative credit zone. The beeping can be implemented in two ways
The system can be designed in such a way that once the credit gets to a thresholdand the system starts beeping, the customer has to insert his card into the system
before the beeping will stop else the system will continuously beep until either
credit is added or the system is shut down.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
45/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
45
The system can be designed in such a way that when the credit gets to a threshold,the system beeps for a number of times and stops.
4.2.5 Behaviour of the retrofitted meter upon failure of electronic unit
Based on the configuration of the relay, there are two ways in which the retrofitted meter
will behave upon failure of the electronic unit:
When the load is connected to the normally closed terminal of the relay, failure ofthe electronic unit will not interrupt power supply to the household, and the
power consumed, therefore, will be measured by the electromechanical meter.
The advantage of this is that, prior to failure; the electronic unit will consume a
maximum of 0.1135W if the customer has credit and 1.0135W for 8s when the
customer runs out of credit. Thus this configuration will minimize power
consumption by the electronic unit.
The disadvantage is that when the electronic unit fails, the company reads the
power measured by the electromechanical meter to prepare a bill for the
customer. This has led to lots of controversies between the company and
customers who claim the company is trying to cheat them because the bill is too
much.
The load can be connected to the normally open contact of the relay. Upon failureof the electronic unit, power to the household will be interrupted and the
customer will have to report to the company for immediate replacement of
electronic unit. It is however advised that this option be chosen only if the
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
46/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
46
company chooses to initialize the electronic units with the credit meter ID which
is option two of section 4.2.1 since the company will have spare uninitialized
units which can easily be initialized with the customers credit ID
Also with this configuration, the relay will have to be energized to supply power
to the customer. Thus when the customer has credit, the electronic unit will
consume 1.0135W and when the customer runs out of credit, 0.1135W will be
consumed for 8s.Thus this configuration will consume more power than the
option above.
The advantage however is that the there will be no controversy between the
company and the customer since the company will not have to prepare any bill
for the customer due to the fact that both electromechanical and electronic units
will be off in this case.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
47/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
47
4.3 System block diagram
The embedded unit will consist of a QRB sensor, LCD, buzzer, Pic microcontroller, card
reader socket, relay and circuit breaker. The components will be connected as shown in
the block diagram below
Shunt Trip
4.4 Principle of operation
The sensor continuously throws infrared rays onto the rotating reflective disc of the credit
meter. The reflected rays are detected until the rays hit a black non reflective mark on the
surface of the disc. The logical output of the sensor changes which then interrupts the
microcontroller to increase a count variable. When this count is equal to the number of
revolutions that make up one credit, a credit is deducted.
LCD(LIQUID CRYSTALDIODE)
ALARM(BUZZER)
SENSORQRB1133/QRB1134
RELAY
CARD READER
PIC16F877
CIRCUIT BREAKER
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
48/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
48
When the credit is finished, the system does not shut down immediately, rather the
customer is allowed some fixed amount of power on credit, which will be deducted the
next time credit is bought. This is in view of the fact that terminals where credit is sold do
not operate on weekends and are closed from 6.00pm on working days. Thus if a
customers credit finishes, he will not be denied power supply. The microcontroller shuts
down the system through the relay when the customer exhausts the power on credit.
The system warns the customer when his credit reaches a threshold. It does this by
sounding an alarm.
Also the customer can buy credit onto his memory card, insert it into the card reader of
the unit, the microcontroller verifies the authenticity of the card by matching the ID of the
card with that of the meter. If it matches, the credit is loaded into memory and the credit
on the card is cleared. If it does not, the card is not read.
4.5Improvement over existing system
4.5.1 Mode of warning
The prepayment meter currently in use by ECG completely shuts down the customer
when the credit gets to twenty. This is to serve as a warning that the credit is getting
finished.
Even though a laudable idea, completely shutting down the customer only to remind him
of his finishing credit has led to some dissatisfaction among some users. A better
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
49/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
49
alternative would be to sound an alarm to warn the user, and this has been incorporated
into the project.
4.5.2 The concept of negative credit
In view of the fact that terminals where credit is sold are not open on weekends, it might
the case that a users credit will get finished on the weekend or in the evening. The
current prepayment meter shuts the consumer when his credit gets finished. A better
alternative would be to allow the user a fixed amount power on credit to cater for the
special cases where credit gets finished on the weekend. The power used on credit will be
deducted the next time he buys credit.
4.5.3Security features
Each embedded unit comes with a specific card that will be given to the customer. This
card contains an identification number (ID) that corresponds to a number stored in the
memory of the unit. When the card is inserted, the unit checks its ID, if there is a match,
the card is read. If not, it increments a count variable.
If count variable gets to three, the unit refuses to read anymore cards and must be reset by
the card of an instructor.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
50/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
50
4.6 System Design
The system consist of three main modules
The power supply module The QRB sensor module The microcontroller module
The various modules with their circuit diagrams are presented belo
4.6.1Power supply module
The power supply module will comprise the following component connected as shown in
the circuit diagram below
220/240 9v step down transformer Bridge rectifier( 4 diodes) Smoothing capacitor Voltage regulator LM7805
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
51/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
51
4.6.2 QRB sensor module
The QRB sensor module will comprise the following
The QRB1133/1134 sensor 220,4.7k resistors 10k variable resistor.
The circuit diagram for the module is shown below.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
52/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
52
4.6.2.1 QRB sensor holder
The QRB sensor must be placed under the rotating disc at a suitable distance of 5mm for
effective detection of rotation; also the sensor must be positioned such that it will always
be directly under the black mark. This necessitated the design of a holder that will keep
the sensor at the desired position. The design is shown below.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
53/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
53
4.6.3 Microcontroller module
The various components are connected as shown below and controlled by the PIC
microcontroller.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
54/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
54
4.6.3.1 Packaging
The embedded unit and the retrofitted credit meter have to be packaged. The design of
the package is show below.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
55/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
55
4.7 Design of the card terminal unit
The purpose of the card terminal is to write credit on the targeted meters card and also
write the reset code on a reset card. The terminal unit built for this project comes with
four push down buttons which will be used for writing either the reset code on a reset
card or for writing credit on the meters card. Two buttons are used to select the mode-
either reset code or credit code, and the other two are for writing and reading from the
card once the mode is selected. It has an LCD display for to show the values being
written to or read from the card. It has a card slot where the card is inserted.
The function and how it operates are outlined below
The four buttons are labeled as
1. Reset2. Write3. Read4. Credit
When it is desired to write or read from a reset card, then after insertion of the card, the
reset button should be pressed once since it generates an interrupt. Once the
microcontroller is interrupted, then the message Reset code will be displayed on the
LCD. At this moment if a write operation is desired, the write button should be pressed or
if it is a read, then the read button should be pressed. When finished, the reset button has
to be pressed once again to leave the reset code block.
On the other hand if it is desired to read or write credit to a card for a meter, then after
insertion of the card, the credit button should be pressed. Once pressed, the desired
operation is then selected using the write or read button.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
56/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
56
4.7.1 Circuit diagram of terminal unit
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
57/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
57
4.7.2 Packaging
The package for the card terminal unit is shown below.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
58/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
58
4.8 Design of a DSP based prepayment meter
A DSP based prepayment system can easily be achieved by replacing the QRB sensor in
the microcontroller module shown above with a DSP chip. The DSP chip should then be
programmed to send a signal to the microcontroller when it measure one kilowatt of
power. The circuitry remains unchanged. The revise circuit diagram is shown below.
4.8.1 Circuit diagram of DSP based prepayment meter design
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
59/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
59
4.8.2 Comparing a DSP based system to credit based prepayment system.
The DSP based prepayment meter undoubtedly is more accurate in measuringpower than the credit based prepayment meters. This is in view of the fact that the
DSP based meter takes power factor measurement into consideration which the
credit based meter totally neglects.
The credit based meter is more robust and can withstand high conditions ofvoltage and current than the DSP based system.
A test conducted at the lab and confirmation from VRA technicians revealed thatwhen the DSP based meter is bridged, the meter does not read at all and the
customer uses power free of charge but from test also conducted at the lab and
form confirmation from ECG technicians, when the credit based meter is bridged,
the meter at least reads more than half of the power used
An important advantage of the credit based prepayment meter over the DSP basedmeter is that when the DSP based meter gets damaged probably due to voltage
surge, the customer uses power for free and the company has no way of
determining how much power the customer has used but with a credit based
prepayment system, when the digital part of the meter gets damaged also due to
voltage surge, the mechanical aspect of the meter which is more robust keeps
recording the power used by the customer. Thus the company can prepare a bill
for the customer based on the readings of the mechanical part of the meter.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
60/79
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
61/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
61
4.10 Programming
4.10.1 Flow chart for program.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
62/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
62
4.10.2 Operation of the program
At the very first time of using the unit, initialization of the various variables isdone once in the meters operative life. The variable initialization includes
activities like clearing the EEPROM, setting counters to zero; etc. Then system
enters an infinite loop.
If an interrupt occurs,count is incremented. When count gets to N, which is themeter constant indicated by the letter N on the flow chart, then a credit is
deducted. The interrupt is the electrical pulse coming from the
QRB1133/QRB1134 sensor.
Check credit and see if it is equal to or less than five, and then sound the alarm.
If credit is finished (plus the extra credit also exhausted), then shut down power
supply to the household.
If count is not equal to N or credit is not finished, then get credit from the card
through the card reader.
Else, Check card reader for credit. If there is a card, read value on card intoEEPROM, then restart loop. If there is no card, just restart loop.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
63/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
63
4.10.3 The various functions in the program
Initialize ()
This function is responsible for initializing all the various components. This includes
clearing EEPROM and clearing variables.
This function is executed only once in the meters life.
Interrupt ()
This function increments the counting of the number of revolutions. It does this by
employing a sensor.
LCDNum ()
This is the LCD driver for outputting to the LCD.
Subtract ()
When the interrupt function counts to a predetermined meter constant, the main ()
function calls subtract to do the deduction of credit.
Shut ()
When subtract determines that the credit is finished, it informs main () which call shut()
to open relay. Thus shutting customer off
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
64/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
64
getUnits ()
This function is responsible for reading credit on the card when a card is inserted.
Buzzer ()
This function is for warning. When subtract () determines that the credit is at or below
some threshold. It informs main () which then calls the buzzer () to warn the customer.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
65/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
65
CHAPTER FIVE-IMPLEMENTATION
5.1 Design options implemented
1. The credit meter ID is hard coded as part of the micro controller code.2. An ECG personnel has to insert a Reset card into the system to clear security
memory.
3. The system beeps for some number of times and stops.5.2 Calculations made
The credit meter used for this project has the following information from the meter
1. 240v (voltage)2. 15-60A(current)3. 200Revs/KWh
Form this information the following calculations were made.
Watt (power) = voltage current neglecting power factor
Watt = 240 60 = 14400W = 14.4KW at full load
Number of revolutions at full load = power at full load 200Rev/KWh
Number of revolutions at full load per hour = 14.4 200 = 2880revs/h
Number of revolutions at full load per second = 2880/3600 = 0.8revs/sec
Number of revolutions at full load per millisecond = 0.8/1000 = 0.0008revs/ms
From the pic16F877 data sheet, the rising time for the PIC is 72ms
Number of revolutions in 72ms = 72 0.0008 = 0.0576revs
The radius of the aluminium disc in the meter was measured and found to be 4cm
Circumference of the disc = distance moved in one revolution
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
66/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
66
Circumference = 2 r
Circumference = 2 4 = 25.13 cm
Distance moved in 72ms
1rev = 25.13cm
0.0576rev = (0.0576 25.13) = 1.44cm 2cm
Thus it can be deduced that when a black mark of length 2cm is placed under the disc,
then there is no possibility of losing a revolution since the rising time of the circuit is
only limited by the rising time of the PIC microcontroller.
5.3 Construction
5.3.1 The power supply module
The power supply module was constructed as shown by the circuit design with the
following calculations in mind.
Transformer Rating: 9volts
Silicon diodes
Current requirement of the circuit = 22.7mA
Current that the power supply must be capable of delivering = (0.52 + 20% of 22.7) mA
AC frequency = 50Hz
Unsmoothed AC voltage = (9 - 1.4); since each of the two conducting diodes reduces the
9volts
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
67/79
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
68/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
68
5.3.2 The QRB sensor module
The QRB sensor circuit was constructed as shown in the QRB sensor circuit diagram.
After the construction of the QRB sensor holder, it was fitted in the meter with the black
mark as shown below
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
69/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
69
5.3.3 The microcontroller module
The circuit was constructed as shown in the circuit diagram. All the other modules were
added and packaged as shown below
5.3.4 The card terminal unit
The circuit was constructed and packaged as shown
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
70/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
70
5.4 Tests performed
5.4.1 The bridging problem
A DSP (digital signal processing) based prepaid meter was obtained from a company
(source cannot be disclosed) and tested for the bridging problem
The bridging problem asserts that when the two live wires to and from the meter are
bridged, the meter is completely bypassed and does not read anything.
The meter was connected to a 200V ac supply and a load of 5A was given to it for 10min,
the dials of the meter moved signifying that the meter was measuring the power
consumed.
After connecting the two lives of the meter with a wire (bridging), it was observed that
for a time period of 30min, the dials of the meter did not move however the display was
on but dim. This signifies that the meter was truly bypassed.
The same test was performed with the credit meter obtained from ECG. Without
bridging, the dials of the meter moved 18 revolutions for a period of 5min.
However after bridging, the dials of the meter moved slow about 1 revs for the 5min
period. The dial of the meter did not show the slightest sign of movement when the
incoming live wire was disconnected and rather connected together with the outgoing live
wire.
A solution to the bridging problem is to employ sealing. Sealing is just covering all
possible holes that can be used to bridge the meter with an impenetrable substance. The
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
71/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
71
only way to bridge the meter then will be to break the seal which can easily be detected
by the company for the culprit to pay a heavy fine.
5.4.2 Placement of black mark and QRB sensor.
The only way for the circuit to determine the amount of power used was through the
interrupt caused by the detection of a black mark placed under the disc of the meter by
the QRB sensor. But since the black mark has weight, then it was anticipated that it
would increase the weight of the disc thereby causing unacceptable reading. Even the
whole process of opening the meter and placing the black mark together with the sensor
could cause some errors to be introduced .This led to a test to find out how accurate the
meter will measure power after placing the black mark.
The meter was connected to a 200V ac supply and a load of 5A was given to it. Sixteen
revolutions were counted in a period of 5min.The meter was then opened and the black
mark and the sensor were placed and the meter was subjected to the same load and
voltage. The number of revolutions were counted and found to be exactly 16 signifying
that the placement of the black mark and sensor did not introduce any unacceptable error
in the measurement of power by the meter.
5.4.3 Test for functionality of the various modules
The various modules were tested after their construction to verify their functionality.
-
7/31/2019 Final Project Report-Parggah and Gilbert (4)
72/79
Retrofitting the electromechanical meter to make it a prepayment meter By Eric Johnson Parggah and Gilbert MensahComputer Engineering KNUST
72
The power supply module was connected to an ac source and a multi meter was
connected across its terminals, the reading of the multi meter was the expected reading of
12v
The output of the QRB sensor module was connected to an LED and the sensor was
interrupted with both a reflective aluminium plate from a tin of milk and a non reflective
black tape. It was observed that with the reflective substance, the LED was on and with
the non reflective tape, the LED was off. This verified the fact that the QRB sensor
detects non reflective objects from reflective objects.
The micro controller circuit was powered and a switch which was connected as the
interrupt was pressed five times. It was observed that the value displayed on the LCD
connected to the circuit reduced by one-a desired behavior. After the value reduced to -5,
the relay connected to the circuit was energized and after 8s tripped the circuit breaker
thus verifying the functionality of the circuit.
All modules were put together and the overall functionality of the system was tested and
found to be correct.
Also the card terminal was tested and all functionalities were verified.
5.4.4 Test for the amount of power consumed by the embedded unit
The system was