[time-nuts] PLL Math Question

Bob Stewart bob at evoria.net
Thu Mar 13 12:41:20 EDT 2014

Hi Jim,

Thanks for your thoughts.  Perhaps there are a few things that I know about my particular system that have been discounted.  I have mentioned them in passing, but haven't collected them coherently for this thread.  It's an 8-bit PIC, thus floating point calculations have to be "improvised", and memory is limited to 4096 total instructions with 512 bytes of variable space.  I'm using a nav receiver at the moment (no sawtooth correction), and the 1PPS is pretty noisy.  The hardware is a fixed quantity, which includes a 10-bit PWM dithered to 14 bits.  There is a voltage divider on the EFC to limit the range, and a thermistor for thermal correction.  Think of it as a contest or a challenge.  The only prize is success.

The noisy 1PPS has been a big concern, and the reason for the moving average/low-pass filter.  I have considered using a slotted-disk instead, or at least a smaller MA with a slotted-disk.  The OCXO has shown itself to be extremely stable in both phase and frequency.  Without eliminating the noise from the 1PPS, the OCXO would be needlessly moved around thus passing that noise through.  Given the stability of the OCXO, I don't think that being 32 seconds behind (two 16 second moving averages at the moment) creates a problem.  I do actually have a usable integrator designed for a  PI system, but I'm trying to avoid using it.  My preference is a state machine implementation.

My approach to this is along the lines of 
1. Warmup 
2. Check and adjust the frequency "close enough"
3. If there is a frequency adjustment, decide when to (re)enable phase control
4. Compare the phase angle to the setpoint to discover which way to herd the phase
5. Use the smoothed slope and distance from setpoint to control the gain of any change applied to the DAC
6. Adjust for temperature change
7. Rinse and repeat from 2.

Perhaps this is so close to PI that it makes no difference that I'm not using a transliteration of Wescott's code?  I really do not relish the idea of implementing floating point operations in 8-bit unsigned characters on someone else's control code on this PIC if I can get it to work properly my way.


> From: Jim Lux <jimlux at earthlink.net>
>To: time-nuts at febo.com 
>Sent: Thursday, March 13, 2014 7:57 AM
>Subject: Re: [time-nuts] PLL Math Question
>On 3/12/14 10:06 PM, Chris Albertson wrote:
>> On Wed, Mar 12, 2014 at 9:13 PM, Daniel Mendes <dmendesf at gmail.com> wrote:
>>> This is a FIR x IIR question...
>>> moving average = FIR filter with all N coeficients equalling 1/N
>>> exponential average = using a simple rule to make an IIR filter
>> Isn't his "moving average" just a convolution of the data with a box car
>> function?  That treats the last N samples equally and is likely not
>> optimal.   I think why he wants is a low pass filter.
>A moving average (or rectangular impulse response) *is* a low pass filter.  The frequency response is of the general sin(x)/x sort of shape, and it has deep nulls, which can be convenient (imagine a moving average covering 1/60th of a second, in the US.. it would have strong nulls at the line frequency and harmonics)
>This method is like
>> the hockey player who skates to where to puck was about 5 seconds ago.  It
>> is not the best way to play the game.  He will in fact NEVER get to the
>> puck if the puck is moving he is domed to chase it forever..   Same here
>> you will never get there.
>That distinction is different than the filter IIR vs FIR thing. Filters are causal, and the output always lags the input in time.  if you want to predict where you're going to be you need a different kind of model or system design.  Something like a predictor corrector, for instance.

More information about the time-nuts mailing list