Has anyone tried to make a phase locked loop out of one of the SCT timer? Has anyone succeeded?
I'd like to make SCT0 run in sync with the mains, because using the comparators as zero-cross detectors isn't that great on a noisy mains supply.
I tried computing the phase difference as SIN(2*PI*COUNT/MATCHREL)*COS(sampled input)-COS(2*PI*COUNT/MATCHREL)*SIN(sampled input) and then using the phase difference to adjust MATCHREL, but I can't get it to lock.
Any ideas? Is my sample rate (1600Hz) too low, or is the latency due to the period only updating after the next LIMIT event too long?
(The input is already a sinewave from the mains, and the cosine is found by taking a sample from quarter of a cycle ago.)