I'm using a microcontroller and its built in A/D to measure energy

usage, watts, and PF on 120VAC 60Hz. I'm sampling the voltage and

current with the A/D. I have a circuit working as a level shifter so

that 1/2 of the A/D's full scale is 0, allowing it to measure negative

voltage and current. That's all well and good.

The problem is with measuring PF. I'm measuring watts by multiplying

each voltage sample by the corresponding current sample, and summing

them over a period of time. This seems to work well. (never mind

for right now that the current and voltage sampling are not occurring

at the exact same time; I've accounted for this)

One trick is to just add a little phase lag into the voltage signal

conditioning path, enough to correct for the sampling lag between

voltage and current. Another is to alternate voltage:current samples

with current:voltage samples.

I thought that the

apparent power could be calculated by taking the absolute value of

each voltage/current product, but this doesn't seem to work.

No, that's not right. The apparent power calculation must be

independent of the E:I phase angle.

My PF

measurements are way off for some known loads. However, it does

indicate 99 or 100% for purely resistive loads.

So, what am I doing wrong? How do you calculate apparent power with

discrete V and I samples?

What I usually do is square individual voltage samples, lowpass filter

them, then square root the filter output to get true RMS volts. Then

do the same for current. Now multiply those results to get apparent

power, VA's.

PF = real power / apparent power.

You can simplify the math by lowpass filtering the absolute values of

E and I, rather than doing the true RMS stuff. You'll get the same

result for sine waves, just as an averaging AC voltmeter is as good as

a TRMS meter for sine waves. You can also do block averages instead of

lowpass filtering.

This technique gives a pretty good number, but loses the

leading/lagging sign. We've been thinking about this lately, working

on algorithms to do it better. But they turn out to be fairly

compute-intensive, Hilberts or dsp pll stuff, or FFTs maybe, so we'll

probably do that math in an FPGA.

What's your sample rate? That's a very interesting issue here.

There are lots of situations where the meaning of PF is debatable.

John