Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Measuring Power Factor With a Micro

Status
Not open for further replies.
My final goal with this project is as follows: Id like to measure (in real-time) frequency, voltage, apparent power, and power factor (among others that may be added later) of the feed for my house. It is a 200A service, in Canada, so 60Hz.

In this post, Im going to go through all of my thought process and what I have now. It wont take too long, but Id like to put up everything Ive done so that, if Ive done something wrong, or there's a better way, it can be addressed.

First, I needed a way to measure frequency. Im using a dsPIC30F4011 (learnt it in a class a couple semesters ago so Im familiar with it), and a zero-cross circuit a friend & I came up with. The input-capture module of the chip measures the time between zero-cross pulses, and determines the frequency. This part works no problem.

The reason I used a zero-cross circuit was to create a 5v pulse that wouldnt hurt the micro. I read about simply hooking a 1M resistor from an IO pin to mains, but thatd require an isolation transformer for me to scope around, and I was afraid of the second half of the AC waveform causing a negative voltage on the pin, and damaging the micro.

I read an excellent zero-cross article after doing some research at sound.westhost.com, and came across **broken link removed** schematic. I sim'd it and it appears to work. I sent it to a friend, who sent back a **broken link removed**, which he scoped and it worked in real life (with an iso xformer).

Now, to measure voltage, I have a couple options. I could rectify the voltage, attenuate and measure the DC voltage, and calculate backwards, but I fear this wont be as accurate as it could be. The other option I read about, was sampling the AC wave, faster than 60Hz of course, and using the instantaneous values to calculate the RMS value. This would also allow me to see the peak value. I would prefer to go this route, but Im not sure I understand the process of calculating the RMS voltage. If anyone has any uC code, app notes, or can offer any insight into coding for this, thatd be very helpful.

Next, measuring current. Initially I researched an Analog Devices chip, the ADE7757. However, a problem arises out of this - I would need a freaking huge sense resistor! I managed to find one that would work, from Mouser, but its a bit too expensive. Not to mention the fact that Id have to get an electrician in to hook the darn thing up.

So breaking the line is out. That leaves me with using a current transformer. I found one that had a split core, and could be attached around the wire, but it was $100, again, out of my price range. Further research lead me to using a Rogowski coil plus an integrator, to obtain a voltage proportional to current. I will likely make my own coil, as I can just borrow a clamp-on ammeter to calibrate it. Fortunately, this is another hurdle somewhat solved. Again, any input on the topic is welcome!

However, I havent reached my biggest problem: how do I calculate power factor? I realize it is the ratio of real power to apparent power. Apparent power can be calculated from E*I, once I measure it. But what is real power? In my research, a lot of people suggested measuring the phase shift between the current and power waves - using a comparator and XORing the outputs to create a pulse - but I fear the current pulse could be non-sinusoidal if there are SMPSs or things like that (and measuring an entire house, Id expect this).

What should I do here? Ive done a lot of reading and am getting weary eyed, so my biggest question is simply what is the best way in my situation to calculate PF?
 
Last edited:
Hello,


Long story short, if you are dealing with only sine waves you can measure power factor by measuring the difference between the phase of the voltage and the phase of the current, and you can measure the phases by measuring the zero crossings of each.
Knowing the frequency (or measuring that too) you calculate the cosine of the angle between E and I.
 
Last edited:
Another Short Story

To calculate real power you simply multiply the instantaneous current by the instantaneous voltage. That automatically accounts for phase angle (power factor), waveform distortion, spikes, etc. between the two waveforms.

To do this you would sample the current and voltage simultaneously at a reasonably high sample rate (depending upon how short a spike you might want to resolve, 100 samples/cycle or 6,000 samples/s should probably suffice) with two A/D converters, and then multiply each digital sample pair with a micro. The average of these multiplied samples is the RMS power.

Edit: To calculate apparent power you would calculate the rms voltage of each waveform separately and them multiple the two rms values. From the real power and the apparent power, you can calculate the PF.
 
Last edited:
Hello,


Long story short, if you are dealing with only sine waves you can measure power factor by measuring the difference between the phase of the voltage and the phase of the current, and you can measure the phases by measuring the zero crossings of each.
Knowing the frequency (or measuring that too) you calculate the cosine of the angle between E and I.

that only works for passive loads. what the power companies are interested in is real power verses apparent power. the apparent power is what causes the losses in the system.

in other words a home will only get charged for power used but so a huge capacitor across the line will still waste a lot of power in the system (the most obvious being the resistive losses in the lines) if it does not blow the breakers.

this is exacerbated by today's high frequency loads causing additional skin effect losses.
 
that only works for passive loads. what the power companies are interested in is real power verses apparent power. the apparent power is what causes the losses in the system.

in other words a home will only get charged for power used but so a huge capacitor across the line will still waste a lot of power in the system (the most obvious being the resistive losses in the lines) if it does not blow the breakers.

this is exacerbated by today's high frequency loads causing additional skin effect losses.


As long as the waves are sine it should work and it should be possible to calculate the real power. If they are not then of course the average power has to be measured using sampled data.
 
Last edited:
As long as the waves are sine it should work and it should be possible to calculate the real power. If they are not then of course the average power has to be measured using sampled data.

i did say that: "that only works for passive loads." only purely passive loads are pure sine waves unless you are using active PFC as well
 
To calculate real power you simply multiply the instantaneous current by the instantaneous voltage. That automatically accounts for phase angle (power factor), waveform distortion, spikes, etc. between the two waveforms.

To do this you would sample the current and voltage simultaneously at a reasonably high sample rate (depending upon how short a spike you might want to resolve, 100 samples/cycle or 6,000 samples/s should probably suffice) with two A/D converters, and then multiply each digital sample pair with a micro. The average of these multiplied samples is the RMS power.

Edit: To calculate apparent power you would calculate the rms voltage of each waveform separately and them multiple the two rms values. From the real power and the apparent power, you can calculate the PF.

This is an excellent explanation of what I need, thank you! Now I understand what I need to do.

My concern is this - wont the power factor be varying constantly? If instantaneous power is simply current * voltage at any given time, for example when current is near-zero, wont this make the value swing a lot?

Heres a picture to better explain what I mean (borrowed from wiki article on rogowski coils):
**broken link removed**
CH1 - 230V Voltage
CH2 - Current Shunt Output
CH4 - Rogowski Coil Output (Amplifier output G=500; Based on AD8220)

Where the green follows along the axis, until it spikes (and then the negative spike) - wouldnt PF be zero if I = 0 (and therefore real power = 0)?

One more question - I know I have to integrate the output of the coil, but will that take care of the negative spikes? Or when I connect it to the A/D, can I just use absolute values to correct for the negative swings? Or better yet - how do I handle the negative voltages (from the negative half-cycle) being interfaced to the A/D?

EDIT I found a Microchip App note regarding measuring frequency, voltage, etc, but they too show simply a resistor hooked from the line to an IO pin. Seems iffy to me.
 
Last edited:
i did say that: "that only works for passive loads." only purely passive loads are pure sine waves unless you are using active PFC as well


Well you said that only works with passive loads and the power company is interested in real vs apparent power and that doesnt make sense because with sine waves (as i stated) that is just fine as you can calculate real power if they are sine waves so why would you say that? Did i misunderstand what you were trying to say?


ParkingLot:
The instantaneous power is the instantaneous I times E, but the average power is that integrated over time using the mean value...
p(t)=i(t)*v(t)
P=(1/T)*Integral[0 to T] p(t) dt

You could for example integrate over one cycle.
 
Last edited:
Well you said that only works with passive loads and the power company is interested in real vs apparent power and that doesnt make sense because with sine waves (as i stated) that is just fine as you can calculate real power if they are sine waves so why would you say that? Did i misunderstand what you were trying to say?


ParkingLot:
The instantaneous power is the instantaneous I times E, but the average power is that integrated over time using the mean value...
p(t)=i(t)*v(t)
P=(1/T)*Integral[0 to T] p(t) dt

You could for example integrate over one cycle.

passive loads are any combination of resistive (real), capacitive (apparent), and inductive (apparent)

line losses are I²R bases on instantaneous current which could just be a big inductive load (like an unloaded industrial motor).

for home electronics think of this:

100VAC 1W resistive load draws 10mA and would dissipate 0.1mW in a 1 ohm source.

100VAC rectified and filtered with a 1W load draws 70mA 10% of the time at the peaks of the line cycle. the result is to dissipate 0.5mW in the 1 ohm source for the same consumer wattage.

take the number of devices you leave plugged in and multiply by the number of addresses in your town, etc and you begin to see why they are interested in having EVERYTHING PFC! (remember 1W is the most stringent energy star standby requirement, it is worse for older equipment)
 
My concern is this - wont the power factor be varying constantly? If instantaneous power is simply current * voltage at any given time, for example when current is near-zero, wont this make the value swing a lot?

Heres a picture to better explain what I mean (borrowed from wiki article on rogowski coils):
**broken link removed**
CH1 - 230V Voltage
CH2 - Current Shunt Output
CH4 - Rogowski Coil Output (Amplifier output G=500; Based on AD8220)

Where the green follows along the axis, until it spikes (and then the negative spike) - wouldnt PF be zero if I = 0 (and therefore real power = 0)?

One more question - I know I have to integrate the output of the coil, but will that take care of the negative spikes? Or when I connect it to the A/D, can I just use absolute values to correct for the negative swings? Or better yet - how do I handle the negative voltages (from the negative half-cycle) being interfaced to the A/D?

EDIT I found a Microchip App note regarding measuring frequency, voltage, etc, but they too show simply a resistor hooked from the line to an IO pin. Seems iffy to me.
Yes, the instantaneous power and apparent PF will vary over a cycle, and will be zero at least two points each cycle, since that is the nature of AC. That's why I said you must average the instantaneous power over a cycle to get the (RMS) real power, and use the average (RMS) value of current and voltage to calculate the apparent power. You then determine the PF which equals (real power/apparent power).

You have to maintain the polarity on the plus and minus portions of the voltage and current waveforms, before you A/D convert and multiply. Using absolute values will give errors when there is phase-shift between the current and voltage.

Hooking an I/O pin directly to the line is dangerous, thus a transformer or other isolation circuit is recommended.
 
Last edited:
passive loads are any combination of resistive (real), capacitive (apparent), and inductive (apparent)

line losses are I²R bases on instantaneous current which could just be a big inductive load (like an unloaded industrial motor).

for home electronics think of this:

100VAC 1W resistive load draws 10mA and would dissipate 0.1mW in a 1 ohm source.

100VAC rectified and filtered with a 1W load draws 70mA 10% of the time at the peaks of the line cycle. the result is to dissipate 0.5mW in the 1 ohm source for the same consumer wattage.

take the number of devices you leave plugged in and multiply by the number of addresses in your town, etc and you begin to see why they are interested in having EVERYTHING PFC! (remember 1W is the most stringent energy star standby requirement, it is worse for older equipment)

Oh but a rectifier does not draw a sine current, and i said they both had to be sine waves for this to work, and it definitely does work with sine waves. If he doesnt have sine waves then it has to be done on an instantaneous basis as we have beem talking about.
 
Yes, the instantaneous power and apparent PF will vary over a cycle, and will be zero at least two points each cycle, since that is the nature of AC. That's why I said you must average the instantaneous power over a cycle to get the (RMS) real power, and use the average (RMS) value of current and voltage to calculate the apparent power. You then determine the PF which equals (real power/apparent power).

You have to maintain the polarity on the plus and minus portions of the voltage and current waveforms, before you A/D convert and multiply. Using absolute values will give errors when there is phase-shift between the current and voltage.

Hooking an I/O pin directly to the line is dangerous, thus a transformer or other isolation circuit is recommended.

Hi there,


Im not sure you stated that correctly. You do know that you cant take the average voltage and multiply by the average current and get the power right?
In other words, in general:
Integral[0 to T](vt*it) dt is not equal to (Integral[0 to T](vt) dt)*(Integral[0 to T](it) dt)
Of course for some waveforms this works, but it's not a general rule that can be applied to just any waveform we might find. We'd have to restrict the waveform to do it that way.
 
Im not sure you stated that correctly. You do know that you cant take the average voltage and multiply by the average current and get the power right?
In other words, in general:
Integral[0 to T](vt*it) dt is not equal to (Integral[0 to T](vt) dt)*(Integral[0 to T](it) dt)
Of course for some waveforms this works, but it's not a general rule that can be applied to just any waveform we might find. We'd have to restrict the waveform to do it that way.
Yes, I do know that, in general, you can't multiply the average (RMS) voltage and average (RMS) current to get real power. That multiplication gives you the apparent power.

I said (perhaps it was not clear) that you multiply the instantaneous voltage and instantaneous current over many samples of the waveform cycle and average the samples over a cycle to get the real power. As long as the sample rate is sufficent to record the highest frequency of interest, there are no restrictions as to the waveform's shape or relative phase.
 
Last edited:
Oh but a rectifier does not draw a sine current, and i said they both had to be sine waves for this to work, and it definitely does work with sine waves. If he doesnt have sine waves then it has to be done on an instantaneous basis as we have beem talking about.

I did say that, and you MISSED THE POINT!

I was trying to describe the difference between linear and nonlinear power usage. And even a full wave rectified circuit WILL draw close to a sinusoidal current at a nearly perfect power factor with a RESISTIVE load.

The point is that it is not practical to speak of power factor in terms of phase angle these days since much of the load on the distribution system is nonlinear and the reason the power companies are eager to impose PFC an ALL electronics!
 
Last edited:
I did say that, and you MISSED THE POINT!

I was trying to describe the difference between linear and nonlinear power usage. And even a full wave rectified circuit WILL draw close to a sinusoidal current at a nearly perfect power factor with a RESISTIVE load.

The point is that it is not practical to speak of power factor in terms of phase angle these days since much of the load on the distribution system is nonlinear and the reason the power companies are eager to impose PFC an ALL electronics!


Well maybe so, but i feel that i can reserve the right to talk about power factor or any other subject for that matter under any and all constraints that i deem interesting enough to talk about. Maybe you can start another thread, "Power Factor with Non Linear Loads".
 
Well maybe so, but i feel that i can reserve the right to talk about power factor or any other subject for that matter under any and all constraints that i deem interesting enough to talk about. Maybe you can start another thread, "Power Factor with Non Linear Loads".

that is fine but you should not be telling the poor guy that he can measure power factor like that unless you KNOW he is trying to measure a linear load AND make sure he knows that the technique will NOT work for his electronics. The only stuff in the home that can get away with that are major appliances, even a lot of them are relying on brush-less DC motors these days so you can not measure the PF on them either.
 
I told the "poor guy" that it only works with sine waves, what more do you want?
Should i never talk about this method again because many modern devices are non linear?
 
Last edited:
Hello there,


From what Wikipedia seems to say it looks as if the output of the R. Coil will be 90 degrees out of phase with the actual current. This means that purely resistive loads would measure as absorbing no power at all. The output of the coil would have to be phase shifted i guess in order to get it to work, and possibly amplified too.
It does look like an ordinary current transformer would work however.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top