# [time-nuts] First success with very simple, very low cost GPSDO

Magnus Danielson magnus at rubidium.dyndns.org
Sun Apr 13 15:42:26 EDT 2014

```Warren,

On 13/04/14 19:24, WarrenS wrote:
>
> Magnus wrote
>
>> You are over-focusing ...
> At least on that we totally agree.
> The same can be said of you in over-focusing on what comes before the
> Phase error term Vdp. The PI code we've been discussing does not care.
> Can we just focus to see if you can find a mistake in my understanding

Here we disagree, and it's not that I want to disagree with you, let me
assure you.

The thing is that one has to have a split vision, as there is different
base-cases to consider. If we where only discussing the dynamics of the
loop while being locked, then F and P does about the same thing. That I
have already said and there we agree. If we where *only* looking at that
case, then we are in full agreement that F does not really add any value
over P. To do this part of the analysis, the code-snippet I provided is
sufficient, even if we is cheating a little.

However, as I am trying to pointing out, it's when the loop is in
frequency acquisition, that's where the F contribution aids the loop by
providing a FLL. In order to analyze this behaviour, you will have to
analyze the complete loop.

This is why I have a split vision. Just analysing the loop for frequency
acquisition behaviour using the AC dynamics of the locked-in behaviour
simply does lead oneself astray, me too.

> The output (Vf) is the sum of the integrator (Vi) and P*Vdp   (line 4)
> The output of the integrator (Vi) is the sum of the integral of  I*Vdp
> and the integral of F*derivative_of_Vdp  (Line #3)
> The integral of the derivative cancel  (reference below)
>
> So the above can be simplified to
> The output Vf is the sum of three terms:
> P*Vdp
> I * integral_of_Vdp
> F*Vdp
>
> The P and F gains above both have the exact same effect and can further
> be simplified to:
> The output Vf is the sum of two terms:
> (P+F)*Vdp
> I * integral_of_Vdp
>
>
> As far as I can tell, your code:
>>> Vdf = Vdp - Vdp_pre
>>> Vdp_pre = Vdp
>>> Vi = Vi + I*Vdp + F*Vdf
>>> Vf = Vi + P*Vdp
>
> Gives the exact same output as:
>> Vi = Vi + I*Vdp
>> Vf = (P + F) * Vdp + (I * Vi)
> Which is nothing more than a standard PI controller
> Do we still disagree?? If so where?

We still disagree, since you are looking at the AC behaviour of the PIF
loop contoler while I loop at the DC behaviour of the complete loop.

> reference
> http://www.mathmistakes.info/facts/CalculusFacts/learn/doi/doi.html
> that says in part;
> the fundamental theorem of calculus can be loosely expressed in words as:
> "the integral of a derivative of a function is that original function", ...

Which only annoys me as I keep this part of my math knowledge active and
well-maintained. That statement isn't mathematical exact on the DC term,
which is what I'm looking at. Also, you need to look at the behaviour of
the complete *loop* rather than part of it. I only showed the modified
part of the loop as the other part is assumed known.

So, let's provide a model for the complete loop.

x is the input or reference phase of an oscillator of angular frequency
omega_0.
y is the output of the oscillator and loop.

The oscillator has the angular frequency omega_1, which is omega_0 +
omega_e where omega_e is the oscillators angular frequency error. Thus:

y = (omega_1 + K_o * Vf)/s

where is the LaPlace variable, 1/s is the LaPlace behaviour of an
integrator, in this case the phase-accumulation of the oscillator.

The phase comparator is modelled as

w = x - y
Vdp = K_d * w

This separation becomes handy as one builds the overall loop equation.

OK, so lets model the diffrentiation, it becomes s, which is the
LaPlace:ian model for a diffrentiation. The detected frequency thus becomes:

Vdf = s*Vdp

Modelling the PIF loop now becomes (using the 1/s for the integrator)

Vf = P*Vdp + I*Vdp/s + F*Vdf/s

Now, inserting Vdf into the Vf formula clearly have s/s thus cancelling
the effect, which is valid of the AC analysis that the LaPlacian loop
analysis allows. The open loop analysis gives (when dropping the static
part of oscillators behaviour, as this is an AC analysis)

G(s) = y/w = 1/s * K_o * (P + I/s + F) * K_d = K_o*K_d*((P+F)s+I)/s²

H(s) = y/x = G(s) / (1+G(s))
= K_o*K_d*((P+F)s+I)/(s^2 + K_o*K_d*((P+F)s+I)

considering that a standard loop has the roots

s^2 + 2*d*omega_n*s + omega_n^2 = s^2 + K_o*K_d*(P+F)*s + K_o*K_d*I

we get

omega_n^2 = K_o*K_d*I
2*d*omega_n = K_o*K_d*(P+F)

So, in the PLL sense, as usual I is the sole control of the loops
bandwidth and P and F is equivalent in contributing to the loops damping.

However, as we dropped the fixed component of the oscillator, we assumed
that oscillator was in perfect agreement with the reference in terms of
frequency, so that part of the loop behaviour isn't very well modelled.
So, let's look at that part.

The reference source has the angular frequency of omega_0, so we then
model the oscillator as

x = omega_0/s

the loops oscillator is as before

y = (omega_1 + K_o * Vf)/s = omega_1/s + K_o*Vf/s

The phase comparator response thus becomes

w = x - y = omega_0/s - omega_1/s - K_o*Vf/s

considering that the loop oscillators angular frequency can be modelled
as the sum of the reference oscillators frequency and an error term

omega_1 = omega_0 + omega_e

we can reformulate the response as

w = -omega_e/s - K_o*Vf/s

We can understand this as the phase error between the input and output
is a linear ramp due to the omega_e frequency error until we have K_o*Vf
DC-level equivalent to -omega_e, at which case there remains a phase
error. Achieving this is the frequency acquisition, which for a PI (or
PIF) loop involves letting the integrator have it's state match-up.
Achieving this in an orderly manor is where the F contribution from the
derivate comes into play. Let's see what happens as we go further
through the phase comparator and loop:

Vdp = K_d*w = -K_d*omega_e/s - K_d*K_o*Vf/s
Vdf = Vdp*s = -K_d*omega_e - K_d*K_o*Vf

This looks all nice and dandy, but we have forgotten one aspect. The
phase detector wraps around in phase. This causes effective behaviour of
the phase detector part to have very high AC content, but very weak DC
part, which through the I term goes into the integrator. However, turns
out that the detected frequency can be made relatively independent of
the phase-wrapping.

If we look at the Vi terms we have (disregarding that the Vdp DC term is
weaker than this model)

Vi = (I*Vdp + F*Vdf)/s = -I*K_d*omega_e/s² - I*K_d*K_o*Vf/s²
- F*K_d*omega_e/s - F*K_d*K_o*Vf/s

For large frequency error, s will be large, so the I parts will be small
while the F part will be larger, while as the integrator state shifts
towards cancelling the omega_e error, s becomes smaller and then the I
part of the PLL dominates.

Your normal loop analysis does not show this, but if you want to
understand lock-in behaviour, you need to do this type of complementary
analysis.

While there still is a few hand-wavings, I hope I spread some insight
into the different types of analysis one can do and while the F
contribution seems like meaningless in one type of analysis, it's quite
a different deal when doing the other type of analysis.

If you don't need or care about improved lock-in behaviour, skip the F
term refinement, but if you want improved lock-in behavious, then you
should look at this approach in parallel with a number of other approaches.

Cheers,
Magnus
```