www.DataSheet4U.com

AN939

et4U.com

To get an accurate picture of power consumption for an

AC system, we need to make frequent measurements,

preferably many times that of the supply frequency. In

this application, we use a sampling rate of 400 Hz,

which provides 8 samples per full cycle of the line

frequency (for AC supply frequency of 50 Hz). For a

sampling rate Fs, we get N samples in N/Fs seconds. By

multiplying this expression for time by average power,

we obtain an expression for energy consumed in terms

of wattseconds (the second expression in Equation 1).

From here, we can use simple math to calculate

kilowatthours.

Of course, it is difficult for a microcontroller to make

direct measurements when the supply voltage is

coming straight off the mains: say, 230V at up to 50A.

This makes it necessary to indirectly measure line

voltage and current at a level consistent with a micro-

controller, then rescale these measurements to arrive

at the original value. The best way to do this is to

reduce the voltage to a level and dynamic range that is

compatible with digital circuitry. (Measuring current

here is essentially the same as measuring voltage, in

that we will use a transducer that generates a voltage

proportional to the load current.) The actual voltage

and current readings can then be derived.

EQUATION 2:

CALCULATING CONSUMED

ENERGY FROM INDIRECT

MEASUREMENTS

Σ⎛ N ⎞

Energy Consumed

(wattseconds) =

⎜

⎝

k

=

1Vdk •

Idk⎟⎠

•

(Kv

•

Ki)

Fs • Kd2

We could accumulate a running total indefinitely and

directly interpret it for energy consumed over time. How-

ever, it’s more practical to accumulate up to some fixed

amount, then increment a counter to indicate energy

consumption. For our application, we will accumulate

10 Wh (0.01 kWh) before incrementing the counter. This

value represents the resolution limit of the meter. It is

equivalent to 36,000 wattseconds (10 Wh x 60 x 60); this

means that we increment the counter every time that the

right side of Equation 2 reaches 36,000.

We can also rearrange Equation 2 to define the power

consumed entirely in terms of Vd and Id. Since we have

already defined Fs, Kv, Ki and Kd in constant terms, we

can give the whole quotient on the right side of the

equation a constant value, D (Equation 3).

For this application, the derived voltage reading, Vd, is

related to the actual instantaneous line voltage Vi by

EQUATION 3: REDEFINING POWER IN

the expression, Vd = Vi Kd/Kv or Vi = Vd Kv/Kd, where Kd

TERMS OF Vd AND Id ONLY

is the digitization constant

tion and Kv is the voltage

for the ADC in

proportionality

tchoisnsatapnptliDcfaoa-rtaSheet4U.com

When 0.01 kWh is consumed:

the circuit design. For this particular application, Kd is

204.6, the digital value from the ADC that represents

1V. Kv is the factor by which the input line voltage is

reduced by a voltage divider; in our design, it is 300.

ΣN

k = 1Vdk • Idk

=

3600 • Fs • Kd2

Kv • Ki

=D

Similarly, the derived current reading, Id, is related to Ii

by the expression, Id = Ii Kd/Ki or Ii = Id Ki/Kd, where Ki

is the current proportionality constant specific to this

design; it is calculated by dividing the CT turn ratio by

the product of the current amplifier gain and the input

burden resistance. For this application, based on a

5000-turn CT, the value of Ki works out to be

approximately 8.7. Kd is the same as before.

Note:

The calculation of Ki when using a shunt is

somewhat different. The actual circuit

design for current measurement, and the

design considerations for using a shunt,

are discussed in more detail in “Hardware

Design”, starting on page 10.

In simple terms, any time that the accumulated sum of

the voltage and current products equals or exceeds D,

we increment the kWh counter. We also save any

remainder in excess of D to be used in the next round

of accumulation.

Note that anything which might influence the value of

the constants may also affect the value of D and

requires changes to the amplifier design. This includes

the use of a shunt instead of a CT, or even changing the

CT turn ratio, both of which may change Ki.

By substituting the attenuated values of Vd and Id for

the Vi and Ii in the original power measurement

equation, we get an expression that relates the con-

sumed power directly to the indirect voltage and current

measurements, as shown in Equation 2.

DataShee

DataSheet4U.com

DS00939A-page 2

DataSheet4 U .com

© 2005 Microchip Technology Inc.