Electronic – AC Power measureless using MCU, calculations problems

accurrent measurementpowervoltage measurement

I'm done from the hardware design sensing the current & the voltage levels using my MCU (AVR) & some circuitry
enter image description here

Beside I wrote the firmware to handle the ADC data & so on
But I'm, having some troubles in some points :

I need to calculate instantaneous power
enter image description here

The values I get from ADCs are X & Y as an example,
so multiplying them inst. power = X*Y

is this right ??

The second problem is calculating the average power which is the first part of the above equation \$\frac{1}{2}V_M I_M cos(\Theta_V – \Theta_I)\$, How to obtain it from this ??

The last question is : how to calculate the power consumption KWH ??
is there also any other calculations I need to handle ?

Note : I'm measuring AC power , 220 ~240 V , 50 or 60 HZ

Best Answer

As you say, instantaneous power is the product of the instantaneous voltage and current. Average power is simply that averaged over time. Note that the instantaneous power can be both positive and negative.

To get a reasonable average, you want eliminate the 50 or 60 Hz components. One way to do this is to keep a running average over whole line cycles. This will be easier if you look at the voltage zero crossings and average all the values between one and the next. You could then additionally low pass filter those readings a bit to reduce random noise and to make the result more smooth.

Another way that doesn't rely on detecting individual power line cycles is to heavily low pass filter the instantaneous power values so that 50 Hz is attenuated to the point you don't care. That of course will work at least as well with 60 Hz then too. Let's say you are sampling the voltage and current at 10 kHz rate, which is 200 readings per 50 Hz line cycle. 3 poles of low pass filtering with a filter fraction of 1/1024 should do it. That assumes each pole follows the algorithm:

FILT <-- FILT + FF(NEW - FILT)

where FF is the filter fraction. Note that the multiply by FF is then really accomplished by a right shift of 10 bits, which is easy to do in a microcontroller. The step response of that filter is .1% after 200 iterations, or one 50 Hz line cycle. The step response after 5000 iterations, or 1/2 second, is 87%. That is about right for displaying to a human observer.