Oy, my aching brain.
I figured a software PLL would be just the thing to replace all the messy zero-crossing code I had to detect the period on a fairly slow moving sensor input (8Hz - 160Hz).
This discussion of PLLs is pretty interesting, but the implementation is based on a frequency modulated oscillator, which doesn't quite fit what I'm doing (the monotonically increasing t will overflow quickly in fixed-point). Then there's
this one, which looks good. It doesn't actually calculate the reference signal voltage (i.e., no need for trig), but the low-pass filter definition is a mystery. I spent the morning at the Berkeley engineering library looking at Roland Best's book on PLLs, but didn't come away sufficiently enlightened. b0 and b1 are defined in terms of T, tau1 and tau2. T is 1 over the sample rate, but what the heck are those tau values?
This seems to be a very clever condensation of C.R. Bond's implementation of Roland Best's basic algorithm. The treatment of pi as a power of 2 is especially tricky. Unfortunately, when I throw a 100Hz signal at my implementation (with a 100Hz center frequency), it fails to lock, and I'm not sure why that is. How does one debug a software PLL?
Questions for the EEVBlog graybeards:
1) Will "any old" low pass filter work? Best says that the -3db point of the filter has to be 10x to 20x below the sample frequency. Is that the only requirement? If my samples arrive at 6KHz, can I slap in a low-pass biquad filter at 300Hz (Q=.707) and expect my PLL to work?
2) The typical PLL definition involves two gain coefficients. Kd governs the gain of the phase detector and K0 is the gain of the low-pass filtered phase error. How does one come come up with reasonable values for Kd and K0?
3) Are there other software PLL implementations that I should be looking at?