# [time-nuts] PI Math question

Dennis Ferguson dennis.c.ferguson at gmail.com
Fri Apr 18 17:10:24 EDT 2014

```On 16 Apr, 2014, at 09:50 , WarrenS <warrensjmail-one at yahoo.com> wrote:
> With the values of K1, K2 & K3 constant,
> and the initial state of I#1, I#2 and Last_Input all zero
> assuming there is no rounding, clipping or overflow in the math
> and that if I've made any obvious dumb typo errors that they are corrected,

If we assume that your 'Input' value is a real-valued measurement with
an unlimited range then I think your algebra is correct.  All those
rearrangements will produce the same value of 'Output'.

Note, though, that 'Input' doesn't have to be a value like that, and
"overflow in the math" may be unavoidable.  It depends on the nature
of the sensor producing the value.  For the particular case that might
be relevant here, suppose 'Input' is the output of a phase error detector
with an output limited to a range proportional to [-180, 180] degrees
(i.e. is truncated to a fraction of one cycle) and the job of the controller
is to try to keep that value at 0.  Because the output of the sensor "wraps
around" at +/- 180 you will want to do certain computations (in this case,
differences between 'Input' values) with modular arithmetic.

For an example of the difference this makes, assume that your first 8
'Input' values are

40 80 120 160 -160 -120 -80 -40

noting that (((-160) - (160)) mod 180) == 40.  If you run these values
through your first and last set of equations I think you'll find the
value of 'Output' diverges at the wrap-around.

I think the practical issue here is that if the basic PI phase-locked
loop, as expressed by your last set of equations, has a long time
constant it may fail to lock if the phase detector output wraps around
like that and the initial frequency error is large enough to make the
wrap-arounds occur frequently.  The addition of the FLL term with its
modular difference, as your first set of equations has it, will widen
the capture bandwidth of the loop by keeping the integral term moving
in the right direction until you get to a point where the frequency is
close enough that the PLL becomes effective, at which point the behaviour
of the loop becomes that of the PLL alone.  The latter is what you've
demonstrated.

Dennis Ferguson
```