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!!
You cannot smoothly dim a normal incandescent light bulb with zero-crossing control of normal 50/60Hz single-phase mains- the filament (even a really fat high-power one) will visibly flicker to an objectionable degree with even a small number of possible levels of control. Similarly, radiant heating is problematic with zero-crossing control because the temperature can change significant within a small number of cycles. In those cases, phase control is typically used.
Normally for zero crossing control we would like a cycle length of several seconds or more (up to maybe 30-60s), so that the number of half-cycles is at least in the low hundreds. That limits the applications to those where the low-pass filter formed by the heat capacity of the various elements will smooth out the power, so generally those applications with a time constant in the 1minute + range.
Phase control has problems that zero-crossing switching does not have (more EMI, there may filtering required for EMC compliance, undesirable audible noise from lamp filaments, nonlinear response power-vs-trigger angle). On the other hand, zero crossing switching of high current loads can cause visible light flickering (otherwise independent lights that happen to be powered from the same mains circuit).
For phase control or for zero crossing switching you need zero crossing detection. In the case of zero crossing switching, the micro can delegate that job to the triac driver and just tell it roughly when it wants the triac on or off, and the driver and triac will respond with some latency depending on when the zero crossing happens to hit.
There's a third alternative- the simplest- random switching, where the triac just switches on whenever it is asked to (and switches off at the zero crossing, since that's all it can do).
If you implement a zero-crossing detector for a micro and drive the triac with a non-zero-crossing opto (or use a random switching SSR) then you can select any of the three options with firmware.
Best Answer
What is it exactly that you are trying to do? Do you mean three phase voltage as in the power grid? If you need to get the frequency of a three phase voltage of the power grid, there are basically two options.
First is to do what you call zero crossing detection: you calculate the number of zero crossings per time unit. That is an easy way to get the frequency, but it takes a relatively long time. For example 1 second to get an accuracy of one hertz.
The second option is to get a moderately long vector of samples of the voltage. Something like 5..10 waves or more. Then Hann-filter the vector and run a correlator to it. You know, multiply it with 0.01 Hz sine and cosine signals and calculate the power; then repeat for 0.02 Hz, then 0.03 Hz and so forth. Of course you probably already have a fairly good estimate of the signal's frequency; if you know it's about 60 Hz, then you can start the correlator at 59.00 Hz and step from there.
As a side note: someone might suggest you to do a fast Fourier transform (FFT), but what is FFT anyway? It's a series of correlator banks. If you already roughly know the frequency, there's no need to calculate the whole frequency spectrum from zero to Fs/2. Just correlate the range of frequencies that you need based on the rough estimate.
The power grid is noisy, so any immediate samples you get are too noisy to detect any phase information with any accuracy. You need longer sample periods and/or filtering.
Phase has no relevance to your titled question. But you can calculate different kinds of phase information from the voltage samples; you pick one of the voltages as the phase reference and compare others to it. And if it's energy meters you're involved with, doing the same with currents also opens up the possibilities of calculating active, reactive and apparent powers and energies.