For a series resonant LC tank I am trying to implement a measurement of the phase angle between Voltage and current of the capacitor.

I can measure the time between zero crossing of Voltage and current but :

My main problem is I can not find a good way to decide if the current is lagging or leading the voltage.

My rough plan is:

I capture the Voltage rising edge through an isolated zero cross detector. (ICR1). Just after that I observe the following capture regiters.

ICR2 Rising edge capture register of current

ICR3 falling edge capture register of current

My state logic

if ICR1=TRUE then stCheckLeadingLagging=1

if stCheckLeadingLagging=1 and ICR2=TRUE then stCheckLeadingLagging=2

if stCheckLeadingLagging=1 and ICR3=TRUE then stCheckLeadingLagging=3

if stCheckLeadingLagging=2 then decrease frequency by 60Hz /C leading over resonance

if stCheckLeadingLagging=3 then increase frequency by 60Hz /C lagging under resonance

The increment and decrement values of frequency can be adjusted according to the amount of time measured between Voltage zero crossing and current zero crossing.

Does it make sense? or is there a more effective way?