On Mon, 21 Aug 2000, Andrew Kunz wrote: > Thanks, Scott. > > That'll be interesting reading. I'm working the PLL from the angle of changing > time between steps rather than amplitude in order to keep phase locked (my only > input is a zero-crossing detector). I also have to generate multiple waves, > since I'm generating "real" power not just a 110V household socket. Perhaps, however I don't discuss the PLL part of it at all. I'm not sure how your system is implemented. On one design I had to phase lock to a ~50-60 power sine wave too. I found that zero-crossing information was unreliable. The reason was that this was part of a power quality instrument and (almost) by definition the "sine wave" is suspect. The jitter in zero crossing could be very large. So instead, I wrote a single frequency 'DFT'. In other words, I did something like this: Assume f = f0 for one cycle's worth (delta t = 1/f) of sine wave samples compute the quadrature components: sine_power = sum of (sine samples * sin(t*i)) cosine_power = sum of (sine samples * cos(t*i)) In other words, the integral of the unknown waveform multiplied by sine and cosine functions was computed. You may also view this as two narrow FIR band pass filters center about the frequency 'f'. Now you can find the arc tangent of the ratio: phase ~= arctan(sine_power/cosine_power) to find the phase. This can then server as the control input to a PID algorithm. The control output of course being the frequency. A simple proportional algorithm could go something like: If the phase is positive decrease the frequency slightly else increase the frequency slightly But beware, this can (will) have trouble locking. At the minimum, you'll need a little part of 'D' in PID. As you might expect, computing the division and then following that by arctan is expensive (but doable...). So instead, I might suggest using the raw sine_power and cosine_power terms. You may be lucky to just get away with only the sine_power term. However, if your sine wave amplitude varies then the cosine computation can help normalize the calculation. Scott -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu