Connect with us

Measuring power factor with microcontroller

Discussion in 'Electronic Design' started by [email protected], Oct 28, 2007.

Scroll to continue with content
  1. Guest

    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?
  2. Guest

    You're not taking into account the non-linear effects of many loads.
    You're in for a lot more math than just multiplying.
    Why not just buy a PF meter?
  3. Guest

    I actually read the Wikipedia article and was lost as to how to deal
    with the non-linearities. This is just a power-meter I'm building and
    really doesn't need to measure PF, so it may be easier to leave it out.
  4. John Larkin

    John Larkin Guest

    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.
    No, that's not right. The apparent power calculation must be
    independent of the E:I phase angle.
    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.

  5. Phil Allison

    Phil Allison Guest


    ** The definition of VA = rms voltage x rms current.

    You will at lest need to compute the " true rms " value of the current wave
    over one cycle and multiply this number by the similar voltage one.

    The voltage wave could be assumed to be sine to a reasonable approximation
    for the purpose - then you only need to scale the peak value.

    ........ Phil
  6. Tim Wescott

    Tim Wescott Guest

    This is what I would recommend.
    This would start working into what the customer expects, too -- do they
    just care about leading/lagging and harmonic content, or do they want a
    detailed spectrum (with phases!) of the various harmonics?
    It can make a huge difference. I've scratched the surface here:
    Or perhaps one should say "where one must define the meaning carefully".

    The meanings in common use have certainly expanded since I was in school.


    Tim Wescott
    Wescott Design Services

    Do you need to implement control loops in software?
    "Applied Control Theory for Embedded Systems" gives you just what it says.
    See details at
  7. John Larkin

    John Larkin Guest

    I sold roughly 12,000 16-channel power survey meters that were used
    for a lot of end-use load surveys, by utilities and research
    institutes. They sampled each channel at 26.9947 Hz.

    My newer stuff, with more compute power, samples at 263.032 Hz.

    One survey did a bunch of fast-food restaurants. The deep-fat friers
    used burst-mode zero-crossing temperature controllers for the heaters;
    you know, maybe 5 cycles on, 11 cycles off or whatever. There were
    heated (pun!) debates about what the pf might be in that situation.

  8. default

    default Guest

    Technique we used in the 70's to get PF - and in those days circuits
    were always inductive, but the basic idea will work for either leading
    or lagging:

    Phase angle can be derived from a few op amps rather simply. Current
    and Voltage are put directly into two op amps with no feedback so you
    are using the full open loop gain of the amps (200K or more - but
    protecting the input with some diodes and resistors so the input
    doesn't exceed the supply voltages). (can also be done with logic
    IC's like CMOS inverters, since you just need a lot of gain to make
    square waves from sine waves)

    Current is sensed with a current transformer on the power line to the
    device under test - voltage with a step down transformer or directly
    with dropping resistors.

    You get a square wave out of both amps - the zero crossing on each is
    used to make a charge pump. One amp sends voltage through a resistor
    to an integrating cap the other terminates the charging until the next
    cycle. (basically an AND gate) The voltage on the cap reflects the
    power factor - at unity there is no charging of the cap at 90 degrees
    there's maximum charging.

    We used a buffer amp to drive a meter to read PF in degrees directly.
  9. Phil Allison

    Phil Allison Guest


    ** Shame how it does not work for a non-linear load.

    Where there simply is no phase angle.

    ( snip drivel)

    ** Bollocks - PF is a number, less than or equal to one.

    Even Wiki is way up on you.

    ........ Phil
  10. Guest

    My sample rate is a little over 13ksps; that's including separate
    voltage and current samples. I may raise it, but this might be
  11. John Larkin

    John Larkin Guest

    Good grief, I've done AC power meters at 27 Hz! But if you've got the
    CPU horsepower, why not?

Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day