1
\$\begingroup\$

I wrote a simulation for second-order PLL and I would like to test it with an input to see whether my PLL can track the phase. I would like to change the phase of my sinusoidal signal with step with magnitude 10 rad. Therefore that's what I did:

  F=60;
    t=0:Ts:2-Ts;
    idx=find(t>=0);
    theta(idx)=pi/180*10*ones(1,length(idx));
    in=sin(2*pi*F*t+theta);
    out=pll(in);
    plot(t,out,t,theta)

However, these two phases differ a lot. I am wondering can anyone tell me if there is any problem with the above script.

Here are the commands inside the for loop:

Error(ii)=Kd*in_norm(ii)*VCO_out(ii-1);     % Calculate the Error

prop_out(ii)=Kp*Error(ii);

integ_out(ii)=KI*Error(ii)*Ts+integ_out(ii-1);

lf_out(ii)=integ_out(ii)+prop_out(ii);

phi_out(ii)=lf_out(ii)*Ts*K0*2*pi+phi_out(ii-1);

VCO_out(ii)=sin(2*pi*Fout*(ii-2)*Ts+phi_out(ii));

enter image description here

\$\endgroup\$
12
  • \$\begingroup\$ You should add a picture of the input/output plot, and give more details of your PLL implementation. \$\endgroup\$
    – jbord39
    Jul 14, 2016 at 21:01
  • \$\begingroup\$ I implemented a PLL by using first order loop filter as one proportional and one integral term. My sole question is do you think above code is creating step change in phase correctly if it is correct I will suspect that my code is wrong. \$\endgroup\$
    – justin
    Jul 14, 2016 at 21:05
  • \$\begingroup\$ It sure would be easy to determine this if you just showed the simulation results including the signals theta, in, out vs. t. Also, what sort of phase detector does this PLL use? \$\endgroup\$
    – jbord39
    Jul 14, 2016 at 21:09
  • \$\begingroup\$ I get different graph for different parameters but this looks to be the best one, \$\endgroup\$
    – justin
    Jul 14, 2016 at 21:15
  • \$\begingroup\$ The input is not even changing in the image you show \$\endgroup\$
    – jbord39
    Jul 14, 2016 at 21:17

1 Answer 1

1
\$\begingroup\$

I think you need to run the simulation longer, at a minimum (there could also be issues with the code). But take for example the image I attached below.

basic pll lock on

You can see the input (top signal) and output (bottom signal). The bottom signal does not even begin to lock on until the second period. Even then it takes some time for it to properly lock on (10+ cycles, not shown).

I would also just implement theta as a function of time, rather than mapping it to the linear indices of time (it's simpler to me):

F=60;
step=1/(f*4)
t=0:step:1; #240 datapoints, 60 cycles of runtime
theta(t)=t*720; #linear phase shift of 2 cycles over 60 cycles
in=sin(2*pi*F*t+theta);
out=pll(in);
plot(t,out,t,theta)

I don't have access to MATLAB so I can't check if this is correct. Simulation results would be nice to help debug as well.

\$\endgroup\$
1
  • \$\begingroup\$ As I mentioned above there is labeling problem in the graph and the above graph represents output and input phase as a function of time. That's why input is not changing. \$\endgroup\$
    – justin
    Jul 14, 2016 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.