**Part Number:** EVM430-F6736

Hello All,

I couldn't able to understand the mathematics behind the below code in file "emeter**-background.c**" as provided in reference code in **slaa517e**

/* A mains frequency measurement procedure based on interpolating zero crossings, to get a fast update rate for step changes in the mains frequency */ /* Interpolate the zero crossing by successive approx. */ z = V_sample - phase->metrology.last_V_sample; x = 0; y = 0; for (k = 0; k < 8; k++) { y <<= 1; z >>= 1; x += z; if (x > V_sample) x -= z; else y |= 1; } /* Now we need to allow for skipped samples, due to spike detection */ z = y; while (phase->metrology.since_last > 1) { z += y; phase->metrology.since_last--; } /* z is now the fraction of a sample interval between the zero crossing and the current sample, in units of 1/256 of a sample */ /* A lightly damped filter should now be enough to remove noise and get a stable value for the frequency */ phase->metrology.mains_period += ((int32_t) (phase->metrology.cycle_sample_count - z) << 12) - (phase->metrology.mains_period >> 4); /* Start the next cycle with the residual fraction of a sample */ phase->metrology.cycle_sample_count = z;

It would be helpful if anyone can provide some insight on this.

Thanks & Regards

Shahul