Here’s an interesting application note from NXP: Filter-Based Algorithm for Metering Applications. Unfortunately the library appears to be closed source but the API is well described. @danbates is it too late to move to NXP processors? (although I haven’t researched what their licensing arrangement is).
It’s also a cautionary tale for anyone who thinks calculating VarHours is as simple as integrating sqrt(Apparent^2 - Real^2).
Per CT channel based phase correction. If the sample needed for the phase correction is in the future, the processing of the DMA buffer hangs back a few cpu cycles until it’s there.
The adc conversion settings put the sampling speed and hence phase correction resolution at 0.18˚ at 50Hz.
I’ve done a bit of testing on this method… needs more testing some time. The main thing I want to improve is the speed at which the maximum PF is found in the automated routine.