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) 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. 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?