English
Language : 

AN939 Datasheet, PDF (3/18 Pages) Microchip Technology – Designing Energy Meters with the PIC16F873A
Sampling Voltage and Current
Calculating power assumes that the voltage and
current are sampled exactly the same time. Obviously,
using a single ADC with one sample-and-hold circuit
makes this impossible. We can do the next best thing,
however, by using an interpolated voltage value that
very closely approximates what the voltage would be
when the current is sampled. The principle is graphi-
cally represented in Figure 1. Although current is
shown here as a regular sine wave and in phase with
voltage, this is not a requirement; current can have any
waveform and phase relationship.
In this method, we assume that it takes some time t to
sample an analog voltage and convert it to a digital
value. If t is sufficiently small, we can use linear approx-
imation to calculate the value exactly in the middle of
an interval of 2t. We will work on the assumption that a
segment of sine curve spanning 2° can be thought of as
linear. For AC power in many countries, the frequency
is 50 Hz; 2° represents an interval of about 111 μs. If we
assume a practical conversion time of 35 μs, the time
between voltage measurements would be 70 μs. This
is about 1.26°, well within our margin for linearity.
To calculate the voltage for a particular current
measurement:
1. Measure the first voltage sample at time t0.
2. After an interval of t, measure the current
(time t1).
3. After another interval of t, measure the voltage
again (time t2).
4. Calculate the voltage at t1 as (Vdt0 + Vdt2)/2.
The actual shape of the current waveform does not
affect this calculation.
FIGURE 1:
V, I
INTERPOLATING VOLTAGE
FOR A CURRENT SAMPLE
Voltage is sampled
at these points
V
Value for
voltage here is
calculated
for the current
sampling time
Current is
sampled halfway
between voltages
I
AN939
Calibration
To compensate for errors introduced by passive
components, we need to individually calibrate the
meter. We will discuss two varieties here:
• Gain calibration, to compensate for gain errors
(in Kv and Ki) introduced by normal variations in
the values of different resistors, CT ratios and
so on.
• Phase calibration, to compensate for extraneous
phase shifts introduced by the current
measurement technique (from the CT, from the
small but unwelcome inductance generated by a
shunt and so on).
GAIN ERROR CALIBRATION
In theory, the proportionality and digitization constants
should adequately calibrate the meter. In practice,
individual component variations may cause differences
between calculated and actual energy consumption. To
account for this, we introduce a gain calibration factor,
Cg, to Equation 3. This constant acts to adjust for
changes in both Kv and Ki. The accumulated
voltage/current sum is then compared to D, also
adjusted by the calibration constant C (Equation 4). In
theory, C and Cg are the same value. For practical
applications, the two constants will have different
values to reflect the actual calibration. This is
discussed in more detail in “Firmware” (page 5).
The value of Ki may also be slightly different at the
extremes of the current measurement range. To
account for this, we need two different gain calibration
constants: one for the low end of the dynamic range
and one for the upper end. In practice, this is done for
each current measurement channel, for a total of four
different values of Cg. The meter firmware chooses the
appropriate value to use when a measurement is
taken.
EQUATION 4: GAIN CALIBRATION
CONSTANT
N
Σ Cg
•
k
=
1Vd k
•
Idk
=
C
•
D
0°
Interval of 2° or less
90°
© 2005 Microchip Technology Inc.
DS00939A-page 3