I’ve a Coretex M4 with a single ADC which is operating at 25KHz for two channels. It DMA burst reads repeatedly for 0.25s which is enough to capture the lowest period/frequency of the AC, the idea being to capture as a minimum at least one full period for apparent voltage & current and a bit more to capture the real current (which will start somewhere within the voltage period), then use this to calculate power factor.
The code thus looks for the zero-cross points for voltage, works out the apparent power, then looks for the zero-cross points for current, calculates the current RMS for this and works out the real power using the voltage worked out earlier.
Q1. Is this correct?
Q2. I should have minimal phase addition from the measuring side (all resistor shunt based) but how would I factor this in if needed to? I do have the time between the voltage and current zero-cross points, and the frequency of the voltage, something tells me these should be used in some way to factor phase caused by the measuring equipment?
code.c.zip (971 Bytes)