Phase difference calculation

ErnieM

Joined Apr 24, 2011
8,377
Voltage is easy, convert zero crossings to digital pulses. This can be as simple as using an optocoupler.

Current needs some sort of transducer, perhaps as simple as a low value series resistor. Again, an optocoupler can convert this signal to digital pulses.

From these signals the zero crossing events are well defined. Frequency and phase differences should be a simple affair to calculate.
 

donpetru

Joined Nov 14, 2008
185
It is not so simple. You have two solutions:
1) to use an optocoupler and MCU's internal timers (pretty complex software and and result in something very similar to what @ErnieM said above);
2) to use two ADC channels: one for voltage and one for current. You can capture current using a current-voltage sensor. If you use this option, then the software becomes simpler if the frequency of the signal captured is stored in the audio spectrum. If you want to capture higher frequencies, the problem is complicated because you may need an MCU stronger than that PIC.

In both cases, the software is not very easy to write. To simplify things you can calculate first input frequency, then find the period (let's say 20ms). Then use a software timer that is driven by the voltage signal and current signal is reset (this timer will correspond to the inductive load). After that, you use another timer that is activated by the current input and will be reset by the voltage input. This timer corresponds to capacitive load. The two timers MCU will interlock condition.
Period of operation of a timer will give the phase difference between voltage and current. But to know phase will have to find and period of the input signal, as I said above. Then you can use a simple mathematical formula to calculate the phase between voltage and current:

Phase = [(duration determined by one of two timers) / (Period of the input signal)] * 360 degrees

For example, if period of the input signal is 20ms and duration determined by one of two timers is 1ms, then:

Phase = ( 1/ 20 )* 360 = 18 degrees (by + or -, depending on which of the two timers is enabled).

That would be a possible solution.
 
Top