You are on page 1of 7

Measurement techniques in the e-meter library

emeter-ng

Nehaoua Fares (AMC ALGERIA)


origine : File: emeter-structs.h
Steve Underwood <steve-underwood@ti.com>
Texas Instruments Hong Kong Ltd.
$Id: emeter-structs.h,v 1.50 2009/04/27 09:05:26 a0754793 Exp $
Version 0.0.1
Sun May 14 2017
Table of Contents

Measurement techniques in the e-meter library


This e-meter library is designed to work with MSP430 devices using either the ADC12 or the
SD16 ADC. It provides a range of features to support most fully electronic e-meter
requirements, from single phase to three phase. It support the measurement of:
- Active power
- Reactive power
- Apparent (VA) power
- Power factor
- RMS voltage
- RMS current
- Mains frequency

Most meters which are required to measure reactive and apparent power or energy are only
required to give a general indication of load quality. For some applications, such as tri-vector
meters in India, the required accuracy for active, reactive and apparent power is similar. This
software can be built to offer good accuracy with lower complexity. It can also be built to
give accuracy suitable for tri-vector meters, and supports the data gathering and storage
features typical of these meters.
It supports a wide range of anti-tamper features;
- Reverse current detection
- Current imbalance (earthing) detection
- Limp mode operation
- Neutral current monitoring for 3-phase meters

Multi-rate and tri-vector features


Multi-rate features vary considerably. This software provides sophisticated multi-rate features,
for single and 3-phase meters. It does this will very modest flash and RAM usage. The
software currently stores all schedules, and recorded usage, in an external EEPROM or
FRAM. The schedules could be stored in a section of the MCUs flash, with a few changes to
the code.
This multi-rate software provides the following features:
- Multi-rate tariff gathering of usage information
- Assessment of the time and sizes of each days peak demand.
- Storing schedules and gathered information in an external serial EEPROM or FRAM.
- Downloading schedules from a remote computer
- Uploading the gathered information to a remote computer
- Displaying the schedules and gathered information on the meter's LCD display

Most of the limits in the following description are set be definitions in the source code. If
there is sufficient EEPROM space, changing these definitions will change the limits. This has
little effect on code size or RAM usage. It does, of course, affect the size of EEPROM
required.
- The software provides for up to 8 tariffs. Usage information is gathered separately for
each of these tariffs, between specified cutoff dates.
- Up to 8 daily schedules may be configured. Each schedule may specify up to 8 time slots.
Each time slot may be assigned to any of the tariffs. Typically only 3 schedules would be
required V weekdays, Saturdays and Sundays/public holidays.
- Each weekday may be assigned to one of the tariff schedules.
- A list of up to 32 public holidays may be configured. These override the normal weekday
tariff patterns. Holidays may be assigned to any of the tariff schedules.
- Up to 12 billing cut-off dates may be configured. Between these dates, the meter accumulates
the total energy used for each of the tariffs. The meter stores the last 12 sets of these
values, to allow the meter to be read infrequently. Note the actual cutoff point is midnight
on the day preceding the specified day.
- The meter measures the consumed energy in five minute steps. It accumulates six consecutive
five minute steps, to find the total energy consumed in the last 30 minutes. For each day,
the meter determines the time and size of the peak 30 minute consumption value. This allows
the time of peak demand to be found with reasonable accuracy. The last 31 daily peak times
and amounts are stored.

The measurement strategy


Traditional electricity meters simply measured the active energy consumed by the load. These
days meters are increasingly required to provide additional information, for monitoring or
charging purposes. The basic set of measurements which might be required are:
Active power and energy
Reactive power and energy
Apparent (VA) power and energy
RMS voltage
RMS current
Mains frequency A key reason for requiring reactive energy measurement is to be able to charge
with poor load quality at a punative rate. To take this further, some meters now also measure the
actual harmonic structure of the current waveform, for the first few harmonics.
The active energy consumed in a period, T, is Eactive= where v is the voltage
across the load, and i is the current passing through it. Traditional electro-mechanical
electricity meters measure the active energy consumption by directly implementing this
formula. It is possible to build a fully electronic meter, using analogue methods, which
implements it. However, more accurate, more stable and cheaper solutions are easier to
implement using digital methods. Precision analogue to digital converters (ADCs), which are
very stable over time and temperature, can be integrated with digital signal processing and
other functions to build a complete and very functional e-meter using just one IC.
To use digital methods to measure the active energy, the previous formula needs to be
restated in a suitable discrete time form Eactive = where v is the voltage across the
load, and i is the current passing through it, and N is the number of samples in the period T.
Note that this summation is calculating the dot, or inner, product of the voltage and current
sample vectors over the measurement period.
The RMS voltage and current must be calculated over some period, using the following
formulae
Vrms=(V.V)=
Irms =(I.I)=
Note again that these summations are calculating the dot, or inner, product of the voltage or
current sample vectors, with themselves, over the measurement period.
There are various ways in which reactive and apparent power may be evaluated, based on the
same voltage and current samples gathered for the active power measurement. Apparent
power can be calculated simply as:
Papparent= Vrms. Irms
and from the active and apparent powers, the reactive power may be evaluated as

Preactive=

Whilst simple, the accuracy of this method, at small currents, is limited, especially when a
shunt resistor sensor is used to measure the current. To see why, we must look at the
implications of the preceeding formulae.
In an e-emeter, the voltage signal is always large. In many places it is specified as always
being within a few percent of the nominal level. In some rural areas it may vary more, but the
voltage will never drop to a very low level, unless the power actually fails. The current, on the
other hand, varies between a cutoff point close to zero and full load. We need to achieve
sufficient accuracy over a current range that may be up to 1000:1. When the current is very
small, the percentage of each digitised sample which is noise from the electronics can be
significant. If a shunt sensor and a high gain front end is used, that noise will typically be
much larger than if a sensor with a large output, such as a CT, is used.
If the reactive power can be calculated from a (VI) type of calculation, the substantial noise
content of a small RMS current value could be avoided. One way to achieve this is to use an
accurate 90 degree phase shift to rotate the voltage samples. Then, the reactive energy during
a period, T, can be expressed as Ereactive=
A Hilbert transform could produce such a phase shift over a sufficiently wide frequency range,
but would be computationally expensive. However, we can measure the mains frequency
accurately, and obtain an accurate estimate for the number of samples of delay required to
produce a precise 90 degree phase shift at the current mains frequency. We can implement
this phase shift easily, by delaying for required whole number of samples and using a single
pole FIR filter to shift by the fractional amount. This will only shift the fundamental
frequency by 90 degrees, but this may not be a problem. the voltage waveform never contains
significant harmonic energy. It is only the current waveform which is often rich in harmonics,
due to the nature of the load.
Once precise values for the active and reactive energy are known, the apparent (VA) energy
consumed in a period T is
Another method which achieves similar results may be derived as follows:
Q=V.Isin()
= V.I.cos( + )
= V.I.cos( - )
- =V.I.(cos( + ) - cos( - ))
A little trignometry can reduce this to
- =2.V.I.sin ( )sin( ))
The value Q, which we are trying to find, is buried in this equation as V.I.sin ( ) so
Q=

Q=

This requires more computation, but avoids the need to buffer many samples of the voltage
signal. If RAM is very limited, this may be a solution.
Fully electronic electricity meters generally use one of two strategies for energy accumulation.
Both start out by calculating the dot product of the voltage and current waveforms. One
method uses a continuous integration technique, integrating every product of a V and I
sample. This technique is used in many metering ASICs, as it suits their architectures well.
The other method processes the accumulated data in timed blocks, typically around one
second long. This fits the architectures of MCUs and programmable DSPs much better. This
is the method used in the current software. Both methods are capable of similar accuracy, and
response times. However, the character of their outputs is a little different. The output of the
continuous method smoothly adjusts to step changes in the load. The output of the block
method jumps in response to step changes in the load. However, the total energy accumulated
through such as a step change is the same for both methods (assuming they are correctly
implemented).
For a device using the ADC12, the meter samples each of the waveforms 3276.8 times per
second. For a device using the SD16, the meter samples each of the waveforms 4096 times
per second.

The meter configuration


Dithering with the ADC12
A typical meter must maintain good accuracy over a current range of 200:1 or more. If the
gain is set such that maximum current is close to clipping in the ADC12, the waveform for
the minimum current occupies only the first 3 or 4 bits of the converter's output. It might
seem this is insufficient to allow accurate measurement. Some meters use current range
switching to overcome this problem, but this has disadvantages - unless the ADC can monitor
all the gain stages at once, the measurement process is paralysed for a period when range
switching occurs; significant additional analogue circuitry is required, adding cost and
increasing board size; additional calibration is required during production. The ADC12 is
very linear, and the steps in its output characteristic are very evenly spaced. With such a good
converter, dithering may be used to greatly extend its effect resolution. With correct dithering,
MSP430's with an ADC12 converter can be used to build accurate single gain stage class 1
meters.
Dithering is the process of adding a controlled noise signal to a waveform to be quantised.
Adding noise will reduce the accuracy of a single quantised sample. However, for most
repetitive waveforms it can substantially increase the average accuracy over many samples,
by providing a measure of interpolation between the steps of the converter. Depending on the
application, the noise waveform might be additive white gaussian noise, triangular PDF noise,
or a small triangular or sawtooth waveform. In the metering application a small triangular
waveform is easy to generate. However, if the cycles of this waveform correlate with the
mains waveform cycles, that correlation might degrade the effect of the dithering. By
randomising the dithering a little, an effective dithering waveform which is also easy to
produce at low cost is possible.

Gathering the data


An interrupt routine is called each time the ADC conversion of a set of values (i.e. all the
voltage and current values for single time sample) is complete. The meter software spends a
considerable portion of its time within this routine, as it is where most of the calculations are
performed.

Correcting the phase relationship between the voltage and current


For meters using the ADC12, the timing relationship between individual ADC samples is
fixed by the sequential sampling process within the ADC. The software must correct for the
time delay between ADC samples, and the phase shifts in the external circuitry (particularly
for CT sensors). An single stage FIR (an interpolator/extrapolator) is used to provide
corrections of up to +-1/2 a waveform sample. Short sample buffers are used to extend the
correction beyong 1/2 a sample. For meters using the SD16, the ADC hardware itself
provides a facility to adjust the relative timing of the samples by up to 1 sample. This is used
for the phase correction in these meters.

Dealing with DC in the signals


Any DC content in the voltage and current signals must be removed. A dot product is similar
to correlation. If only one of the waveforms has some DC content, this does not correlate and
has no effect on the output. However, if both have some DC content, this correlates and does
affect the final result. For the power calculation it might be acceptable to remove DC from
only one of the signals. However, calculating the RMS voltage and current requires
calculating the dot product of each signal with itself. DC will, therefore, always corrupt these
calculations. The software actually removes the DC from all the sampled waveforms.
The software uses an extremely low pass single pole IIR filter to estimate the DC content of
the signals. The software maintains a 32 bit output from the filter. The filter damps so heavily
that ripple and noise is confined to the lower 16 bits. The upper 16 bits is a clean and stable
estimate of the DC content of the waveform. The filter takes several seconds to fully respond
to a step change in the DC level. If the current waveform changes to a new and very distorted
shape (which can be very distorted with complex electronic loads), the DC content of the
waveform might show a step change. However, as noted earlier, the power reading will only
be corrupted if the voltage waveform also has DC content. Load changes will not normally
cause DC changes in the voltage waveform, so the power reading will always be accurate.

Calculating the dot products


The dot product calculations consist of multiplying two 12 bit (ADC12) or two 16 bit (SD16)
numbers, and accumulating the results. With a sampling rate of 3276.8/s or 4096/s and an
accumulation period around one second, 48 bit arithmetic is the smallest multiple of the
CPU's native 16 bits that can be used. The samples are multiplied using 16x16=>32 bit
arithmetic. The 32 bit values are them accumulated into 48 bit results. C compilers do not
generally support 48 bit arithmetic. Some support 64 bit, but this is wasteful on a small MCU.
Therefore some simple assembly language routines are used to support the handling of 48 bit
values. The 48 bit values are stored in three element arrays of 16 bit integers.
Three dot products are evaluated for each measured channel - V.I, V.V and V.I. From these,
the backend processing can calculate the active, reactive and VA power, the RMS voltage and
the RMS current.

Tracking the mains waveform cycles.


From a measurement accuracy point of view, it is satisfactory to calculate the consumed
energy using fixed length blocks of samples. However, unless these align with a whole
number of cycles of the mains waveform there will be some block to block jitter in the
readings. The total accumulated energy would be correct, but this jitter has a bad
psychological effect on customers. To avoid this, the software does not use fixed length
blocks. It counts one second's worth of samples, and then looks for the next positive going
zero crossing in the mains waveform. It ends the block at that point. By synchronising to
whole cycles of the waveform, to within one sample, the block to block jitter is reduced to the
point where noise dominates. This method is robust in the presence of large noise spikes on
the mains, which might be mistaken for zero crossings. Such spikes can only affect the block
timing a little, and cause minor jitter in the particular blocks where they occur. They cannot
affect the overall accuracy, or cause short blocks which might flood the meter's back end
processing.
When the end of a block of samples is declared, the currently accumulated dot products, and
the exact number of gathered samples, N, is recorded, as follows:
- The dot product for the RMS voltage \form#16
- The dot product for the RMS current \form#17
- The dot product for the active power \form#18
- The dot product for the reactive power \form#19

A flag is also set to tell the back end processing that new data is available. The counts are
cleared, and the accumulation process begins again.
To evaluate the mains frequency, the number of sample between positive zero crossings of
the waveform is counted, and filtered using a single pole IIR filter. By using a 32 bit result
register in the filter, and filtering the cycles lengths into the top 16 bits, the mains frequency
is estimated to about 0.01Hz accuracy over many cycles of the mains waveform. To minimise
the effects of noise spikes, and the mains power switching on and off, excessively long or
short mains cycles are not counted.
We calculate the power factor from the power, voltage and current measurements. This
technique does not indicate whether the power factor is leading or lagging. To determine this,
the software monitors the current waveform at each positive going zero crossing of the
voltage waveform. If the current is above the voltage, the current must be leading the voltage.
If the current is below the voltage waveform, the current must be lagging the voltage. To
ensure stable assessment of lead vs lag, the software lightly integrates the decisions.

Energy pulses
To satisfy customer requirements it is usually necessary for an e-meter to have an LED or
LCD segment which flashes once for each small increment in consumed energy. An
increment might typically be 1/1000kWh or 1/1600kWh. This has nothing to do with the
actual measurement process of modern fully electronic meters. It is provided mostly for
historic reasons. However, it must always give stable and accurate pulses - it is this pulse rate
which will generally be used to evaluate the meter's performance. To provide sufficient
timing accuracy in the pulses to avoid significant jitter, these pulses are generated within the
ADC interrupt routine. The LED can, therefore, flash within 244us or 305us (depending on
the ADC type) of the exact time that it should.
During each ADC interrupt, the power measured during the previous sampling block is
accumulated pulse by pulse. The LED is flashed when the accumulated value reached the
value of one pulse. The duration of the LED pulse is also controlled within the ADC interrupt
routine to be a fixed number of ADC interrupts.

Processing the blocks of gathered data


When the back end, non-interrupt, code sees the new data available flag set by the ADC
interrupt code, it uses the gathered data to find the actual power, voltage and current. These
calculations have fairly relaxed timing constraints, since there is a full second within which to
generate each set of answers.
From this information the following are calculated, using appropriate scaling factors
determined during calibration:

RMS voltage is scalingfactor

RMS current is scalingfactor


Active power is scalingfactor

Reactive (imaginary) power is scalingfactor or scalingfactor


Apparent (VA) power is Vrms.Irms
Power_factor [cos(phi)] is

You might also like