Time Domain Based Active Power Calculation
Time Domain Based Active Power Calculation
Contents
1 Introduction 1 Introduction................................................................1
This application note describes the active energy calculation 2 Basic Math................................................................1
method used for single phase power meter based on the 8-bit 2.1 Active, reactive, apparent, and total
microcontroller. It will discuss: apparent power...............................................1
• The mathematical background for energy calculation in 2.2 Basic math – discrete form............................4
the time domain
• Different phenomena affecting calculation accuracy and 3 Active Power Accuracy Affecting
how to deal with them Phenomena.................................................................5
• The calculation algorithm used in the power meter by 3.1 Sampling frequency.......................................5
LH60 Single Phase Power Meter Reference Design
(DRM133) 3.2 Zero cross detection.......................................5
3.3 Variable type used.........................................5
The described calculation method is suitable for active energy
calculation for power meters compliant with EN50470. 3.4 Calculation granularity..................................6
Active energy calculation method is suitable for power meters 3.5 Offset removal...............................................7
which are suitable to measure (5)60A current range with B 3.5.1 High pass filter.................................7
class accuracy.
3.5.2 Fixed value subtraction. . .................7
3.5.3 Signal mean value
calculation and removal..................7
2 Basic Math 3.6 Phase error correction.....................................8
4 Calculation Flow Diagram.........................................9
Figure 1. Equation 1
Reactive power [VAR] is equal to the voltage multiplied by the magnetizing (reactive) current:
Figure 2. Equation 2
Apparent power [VA] is equal to the vector sum of active and reactive power, otherwise known as the triangle method, as
shown in Figure 4.
Figure 3. Equation 3
S
Q
φ
P
Figure 6. Equation 4
Figure 7. Equation 5
Reactive energy is the sum of reactive power in time:
Figure 8. Equation 6
Figure 9. Equation 7
While the theory is now clear, there are some differences in real system situations. Due to various factors, we are not working
with accurate voltage and current signals u(t) and i(t).
N
Cc Vref/2
Rdiv
voltage signal u
L_INP
I load
Figure 10. Voltage and current conditional circuits and connection to the MCU
The signal measured by the ADC is influenced by many errors. For simplicity, we omit error variation during temperature,
aging, and so on here. The dominant errors in power meter signal condition circuits are signal offset, signal gain, and phase
shift. Equations for real life voltage and current signals can be stated as follows:
If we put real voltage and current signals to Figure 1 and derive it, the result is much more complex and dependent on other
parasitic parameters, like offset and phase error.
This application note describes active power calculation on an 8-bit platform, so the native variable length is 8 bits. Using
wider variables increases the computationL power needed for arithmetic operations, which results in a higher CPU load,
therefore using adequate variable length is essential. The AD converter provides 16-bit long result, so by multiplying current
and voltage, we have a 32-bit wide result. If we multiply the 32-bit result with the 16-bit wide gain factor G, the result will be
48 bits, a length which is not supported in the C compiler. We must find a scale factor and keep the variables used for
calculation in a reasonable format.
Here we are referring to 230 V at 5(60)B power meter and from the following table we see the current signal dynamic range
where we have to provide accurate power calculation:
Table 1. Power meter dynamic range
Istart Imin Itransition Ireference Imax
Current [A] 0.02 0.25 0.5 5 60
Accuracy [%] One pulse in 30 1.5 1 1 1
min
The dynamic range needed with 1.5% accuracy for a worst case scenario is 60:0.25 = 240:1. But if we want to have, for
example, approximately 2% accuracy for Istart, where dynamic range is 60:0.02 -> 3000:1, which is not mandatory by
regulations, we need at least 6 bits for beginning -> 32*3000 = 96000 -> approximately 17 bits. This leads to a 24-bit wide
variable to work with for active power calculation.
Although C compilers for an 8-bit core support only 16- or 32-bit long variables, it can be useful to build your own 24-bit
long math libraries to lower the CPU load. Optimized ASM mathematic routines may also be more effective. For the
algorithm, we must consider that if we use a high sampling frequency, calculation may eat significant CPU power only for
energy calculation.
Table 2 shows the CPU cycles needed for 16- and 32-bit standard C library multiplication, 32*32 to 64 bit assembly-
optimized function, and CPU load related for 3200 multiplications per second, which is actual power meter ADC sampling
rate. CPU is running 19.2 MHz bus clock.
Table 2. CPU load for various mathematic routines
19.92 MHz CPU @ 3200 Cycles / multiplication Cycles / sec @ 3200 CPU load [%]
samples/s
16*16 -> 16 @ C lib 220 704000 ~3.5
32*32 -> 32 @ C lib 620 1984000 ~10
32*32->64 @ASM optimized 635 2032000 ~10.2
32+32-> @ 32 C lib 229 732800 ~3.6
Table 2 shows that just one simple multiplication may take around 10% of CPU power, therefore we have to write code
cautiously. A twice as wide calculation by optimized ASM routine may take a similar length of time as 32*32->32.
2. Figure 15 shows that a suitable value of n may be on the borders of the sine wave to fulfill the assumption. The
sampling rate used in LH60 Single Phase Power Meter Reference Design (DRM133) gives us 64 samples per sine
wave, which makes n = 64 a good option.
3. Calculation granularity also affects the time of periodic energy counter update and related power LED pulse jitter. The
LED pulse output was used for accuracy testing previously. The n=64 interval means that the LED output is updated
every 20 mS in the worst case signal jitter scenario. If the desired power meter accuracy step is 0.1%, we must measure
for at least 20 seconds to negate jitter error. Finally, we proposed n = 32 with related half wave measure interval
wherethe assumptions of Figure 20 and Figure 21 are fulfilled as well.
Half sine wave granularity n=32 for power and energy calculation is the optimal compromise of CPU computational power
demand and power pulse LED signal jitter.
For the filter to work without significant errors for small signals, coefficients (a, b) and result y must be in 32-bit arithmetic.
This leads to the two multiplications x*b and y*a [32*32->32] and two sum operations [32+32->32] for each sample. This
leads to 1698 cycles per sample, which is the same as 30% of CPU computational power. We must filter both current and
voltage samples to make the total CPU load 60% for offset removal only.
Using ASM and making some changes, we can get lower CPU load, but still it is not an acceptable CPU load. Therefore,
using an FIR filter on 8-bit core is not optimal for 3200 samples/sec.
On real samples, we get a non-zero value over sine wave period, which is equivalent to mean value. In design, we typically
average this value over several seconds. As a result, we have the voltage mean value, which is subtracted from incoming
samples.
This method provides a precise, adaptive method for removing offset together with light CPU load.
tv
ts
DC BIAS 0.6V
I
R1
C
R2
N VOLTAGE
Un Uo
GNDA GNDA
UR1
Un
UR2
φCc
UC
Steps 7-10 are performed once per second and are referred to values showed on the display:
• Depending on the pdFiltOn variable, active and reactive power samples are averaged on the four taps average filter.
• Active and reactive power values are updated on the display.
• Apparent power is calculated using the triangle method from active and reactive power.
smp.i smp.uu
16b, s 16b, u
i.offset u.offset
1. - -
smp.i smp.u
16b, s 16b, s
2. Σ (i)
64
Σ
32
u*i DERIV. Σ
32
u*i Σ (u)
64
Σ (u/2^3)2
32
smp.q smp.p
40b, s 40b, s
+ +
Σi Σu
positiv negativ reminder reminder positiv negativ
16b, s 16b, s
3. s.qRem s.pRem
s.qRem % 2^16 s.pRem % 2^16
i.offset -- i.offset ++ s.qRem / 2^16 s.pRem / 2^16 u.offset -- u.offset ++
s.q s.p
32b, s 32b, s
s.p
5. CALIB. CALIB.
s.q 32b, s
32b, s s.p
frequency
Σ Σ s.p Σ
update
6. s.q calibration pulses s.uRms
100 100 100
s.uRms
s.qdisp s.pdisp
32b, s 32b, s
update
7. AVERAGE AVERAGE
counters
s.qdispf s.pdispf
pdFiltOn pdFiltOn
CALIB.
8.
S = P^2 * Q^2
32b, s 32b, s 32b, s 32b, s
Irms = S / Urms
9.
d.q d.s d.p cnt.ep d.iRms d.uRms
Asia/Pacific:
Freescale Semiconductor China Ltd.
Exchange Building 23F
No. 118 Jianguo Road
Chaoyang District
Beijing 100022
China
+86 10 5879 8000
[email protected]