I am trying to sense the power factor angle using microcontroller.
To do this with any degree of accuracy and for unknown load conditions is a lot tricker than you think. Consider the following: -
- Say your load current doesn't look anything like a sinewave - let's say it looks like the current drawn by a conventional transformer and bridge rectifier - when does the current begin - it begins right as the voltage is reaching its peak and ends just after the voltage peak - the diode bridge draws a thin-ish pulse of current to restore the charge in the smoothing capacitor. What will be the phase angle of the current relative to the voltage waveform? Can you use a simple timer based on zero-crossing? No you can't because it won't relate to real power-factor angles at all.
- What if your current wobbled as it passed through zero i.e. it passed thru zero then went back below then continued upwards to its normal peak - what would you take as the reference zero cross? Would either accurately reflect power or the real angle associated with power-factor? No, not necessarily.
- What about the amplitude of the current waveform? When it is tiny, noise could have a bearing - what will this do with respect to false triggers on the zero cross? Probably throw out any meaningful reading into the garbage. Maybe comaparotor hysteresis will help?
- Comparator hysteresis won't help - this will give you a zero-cross slightly above zero and therefore the zero-cross will be amplitude dependent.
It's tricky for sure. If I were doing it I'd recall that power, for a good sinewave supply voltage is voltage x the fundamental frequency of the current. For a sinewave supply, any harmonics that distort the current DO NOT contribute to power as measured by the utility companies.
On this basis, I'd apply equal low-pass filtering to both voltage and current before doing anything. The filtering doesn't need to be applied to the voltage but, applying it to both keeps both current and voltage waveforms in sync regarding the time delays incurred by such filters and I shouldn't need to say why this is important.
How many orders of low-pass filtering? I'd say minimum 6 and realistically, to keep both filters spot-on I wouldn't waste time doing it in the analogue realm - I'd go straight for converting volts and amps to digital and apply as much digital LP filtering as possible.
Where does this get you? Ultimately I'm trying to calculate real power by multiplying V and I to get real watts. I don't need to filter V and I to do this but, if i want to understand what the RMS value of current is at the fundamental frequency of the supply voltage (the only frequency applicable to power calculations based on a decent voltage waveform) I need to use the filtered waveforms.
So, I've got power (sampled V waveform x sampled I waveform, then averaged per cycle) and I've got RMS volts and RMS amps (based on samples squared, then averaged then square rooted). Don't stick close to nyquist - lets see a thousand samples per cycle in order to capture all the harmonic nuances of the current and avois aliasing.
Next I divide power by the product of the rms values of I and V and this gives me power factor - a value that is zero for current being 90 degrees out of phase to voltage and 1 for volts and amps being totally in-phase - remember I'm talking about the fundamentals being in phase here, not all the harmonics of current - they play no part when the driving voltage is a sinewave.
Power factor converts to phase angle by taking Arc cos and you now have phase angle.
I have designed utility electricity meters in case you wondered!!