>On 02/07/2011 09:50 PM, mir_aculous wrote:
>>> On Feb 7, 8:39=A0pm, Tim Wescott<t...@seemywebsite.com> wrote:
>>>> On 02/07/2011 02:44 PM, robert bristow-johnson wrote:
>>>>
>>>>
>>>>> since the input to the NCO directly controls frequency, you need to
>>>>> model (and it's simple, just an integrator) the transfer function
>> from
>>>>> frequency to phase, since it's (usually) the phase difference that
>>>>> comes outa the phase discriminator. =A0the integrator that is
>> inherent
>>>>> to the NCO usually obviates the need for the "P" in the PID
>>>>> controller.
>>>>
>>>> Eh? =A0Most phase-locked loops that I do use a PI controller.
>>>
>>> ooops. i meant that in the actual guts of the controller, you would
>>> lose the "I", because of the inherent I in the NCO (if what comes outa
>>> the phase discriminator is the difference of phase, not the difference
>>> of frequency).
>>>
>>>> =A0One rarely
>>>> needs differential, but one occasionally needs an extra low-pass
filter
>>>> if you really want to clean up jitter.
>>>>
>>>
>>> what i meant was this identity:
>>>
>>>
>>> sin(w0+phi)*cos(w0) =3D 0.5*sin(phi) + 0.5*sin(2*w0+phi)
>>>
>>> because the integrator might take care of it, you might not need the
>>> LPF, but we want the sin(phi) term to survive as it is pretty close to
>>> phi and measures our phase difference.
>>>
>>>>> another way to mathematically model a phase discriminator is to look
>>>>> at it as the LPFed output of a multiplier between the two waveforms
>>>>> that are virtually the same frequency. =A0when the PLL is "locked",
>> tha=
>>> t
>>>>> means the two waveforms will be 90 degrees outa phase.
>>>>
>>>>> of course, when they get more and more out of phase, there is a non-
>>>>> linearity in the phase discriminator, if you do it this way.
>>>>
>>>>> if you need your oscillator output to be in the same phase as the
>>>>> input, then use the same phase going into the NCO for two quadrature
>>>>> (that is 90 degrees outa phase with each other) table lookups.
>>>>
>>>> That depends on the phase detector. =A0If you're locking to edges
>> (which
>>>> is fairly easy to do with the right counter resources) then you can
>> make
>>>> your phase detector act pretty much like a regular old
phase/frequency
>>>> detector. =A0If you're locking to data, then you're locking to data
and
>>>> limited by the data stream -- and that's not going to be like locking
>> to
>>>> a sinusoid.
>>>
>>> agreed. but multiplying two square waves together (and LPFing) can
>>> get that same phi term that goes to zero when the two are 90 degrees
>>> outa phase. i seem to remember seeing an old design (i wonder if it
>>> *was* a 4016 or similar) where the phase discriminator was essentially
>>> an XOR gate. it's sorta similar.
>>>
>>> r b-j
>>>
>>>
>>>
>>
>> Before, I get confused further about the implementation process, I want
to
>> tell you all that my ultimate goal is to track the carrier and the code
in
>> a direct sequence spread spectrum signal.
>>
>> First, I want to implement the basic PLL where I can input a signal such
as
>> an FM signal and try to lock on to the carrier. If that works then I
can
>> move on towards my goal of locking on to the carrier of a DSSS signal
and
>> then doing clock/code tracking by implementing a code tracking loop as
>> given in many gps related books. But first, the basic loop to track a
>> sinusoid.
>>
>>> since the input to the NCO directly controls frequency, you need to
>>> model (and it's simple, just an integrator) the transfer function from
>>> frequency to phase, since it's (usually) the phase difference that
>>> comes outa the phase discriminator. the integrator that is inherent
>>> to the NCO usually obviates the need for the "P" in the PID
>>> controller.
>>
>> r-b-j, can you explain a little more about the direct implementation
that
>> you are talking about. This is what I understand so far.
>>
>> phase_error = LPF ( input sample * VCO sample ), which makes sense as
it
>> ultimately splits down to a phase term and another high frequency term
>> which is low pass filtered. So, once I have this phase term what do I
do
>> next?
>
>Robert is giving you a very limited view of phase detectors. Some do,
>indeed, multiply the incoming signals (either as sinusoids, or as square
>waves, in which case you find that an XOR gate acts the same as a
>multiplication). Some compare edges (search on "three state phase
>detector" or "phase-frequency detector"). Some PLL's are extracting
>clock from data, and there are various ways to do that (search on "data
>driven PLL" or "Costas loop"). In the case of DSSS, you run at least
>three correlators, an 'early' one, an 'on time' one, and a 'late' one.
>You compare the relative magnitudes of the outputs of the early and late
>correlators and use that to correct the loop.
>
>> Can you put it down in a mathematical equation as it's easier to
understand
>> that way.
>
>You describe the behavior in terms of a difference equation, then you
>take the z transform of the difference equation. If, for instance, you
>have a phase-increment NCO, then at each iteration of your clock you
>find that your NCO phase goes
>
>p_O(n) = p_O(n-1) + p_i(n)
>
>where p_O is the oscillator phase, and p_i is the commanded phase from
>the loop filter. Taking the z transform of this you get
>
>P_O = P_O * z^-1 + P_i
>
>or
>
>z P_O = P_O + z P_i
>
>or
>
>P_O z
>--- = -----
>P_i z - 1
>
Extending, on this and using a loop filter with transfer function shown
below (assuming all the gains are set to 1 for cleaner representation),
H(s) = (tau2.s+1)/(tau1.s) , I get the difference equation as
u(n) = e(n)[2.tau2/Ts + 1](Ts/(2.tau1)) -
e(n-1)[1 - 2.tau2/Ts](Ts/(2.tau1))+
u(n-1)
where, u(n) is the loop filter output at time t=n,
e(n) is the output of the phase detector,
tau1, tau2 are the loop filer constants,
Ts is the sampling width or 1/Fs where, Fs is the sampling
frequency
Finally, as you mentioned earlier u(n) is the input to the VCO thus,
VCO(n) = VCO(n-1) + u(n)
For DSSS, I found out that a common phase detection scheme is
e(n) = arctan(Q/I) where, Q and I are outputs of the inphase and
quadrature components of the prompt correlator.
>You model the phase detector by a similar process (and find that it's
>just a gain, or a system that can be linearized to get a gain when the
>loop is locked), then you make a loop filter that will get you your
>desired loop performance.
>
>See http://www.wescottdesign.com/articles/zTransform/z-transforms.html
>and http://www.wescottdesign.com/actfes/actfes.html.
>
>--
>
>Tim Wescott
>Wescott Design Services
>http://www.wescottdesign.com
>
>Do you need to implement control loops in software?
>"Applied Control Theory for Embedded Systems" was written for you.
>See details at http://www.wescottdesign.com/actfes/actfes.html
>