Simulating an analog phase locked loop

in this video I’m gonna simulate a phase lock loop using VSS which stands for visual system simulator it’s part of the niña WR design environment have a new project opened here the goal of this video is to explore some of the basic properties in phase locked loops now this is the reference that I highly recommend reading music title on the offer for good introduction of phase locked loops here on page six we are presented with the topology of your basic phase lock loop so the system contains a phase detector a loop filter and a voltage controlled oscillator the output of the VCO local control oscillator is being fed back into the phase detector X of T is your input it’s in AC waveform with a frequency in a phase so it’s a single tone and Y of T ideally would also be a single tone an AC waveform and the frequency of the output equal the frequency of the input so in that case we would say the frequency or the output would be locked to that of the input and in many situations you also want to walk the phase of the output to the input or at least have a fixed gaze relationship between the output and the input so back to our project make sure the project tab is highlighted and then right click on system diagrams click on new system diagram before those PLL DLL and then this opens up our design space click on elements tab down here but on the PLL icon expand VCO their-their voltage controlled oscillator we’re going to construct our phase detector using a multiplier so here’s math tools malts the multiplier bring that in there and then need our low pass filter will use a little fast Butterworth connect so connect the output of the VCO to the input of your detector we need our reference signal so we need a sinusoid so sinusoid source connect and now our output is going to be right here let’s put test points at the points in this network we want to look at the signals so just point to put one on the output that make sense the ends what makes sense and put a test point right here at this pick this node which is the signal that’s being fed into the input of the VCO so this is the control voltage for the VCO but it’s also the error signal so this signal is going to be proportional to the error the phase there between the output and the input and now we need to set the type of data each of these signal processing blocks should be processing so to do that you click on these arrows double click and click on real data arrow will turn from white to yellow and color now I’ve already simulated this phase lock flu to prepare for this video and I can tell you that you’re gonna get an error unless you put a delay in this feedback loop so I’m going to do that to save us from having to look at an error message signal processing delay under square stem click company and ctrl R to rotate and rotate it the proper orientation and now connect the output to input output this input delay leave is 1 that’s fine but suppress data tight like working on the arrow to real data ok now we have a bunch of parameters that we need to set here so let’s look at the input signal frequency we want to be one megahertz let’s make this a variable F in the phase we’ll make this phase in here’s equation let’s set F n to be 1 e to the 6 1 megahertz equation again days in equals zero radians this F P is the cutoff frequency of the filter so I’m gonna go see equation looks up the cutoff frequency to the console megahertz the 20 kilohertz for a VCO frq is the free running frequency of the VCO that would be the frequency that the output signal would have if there is zero volts controlling the same so if you have no control voltage then you would have a tone oscillating at this frequency which is called the three running frequency the VCO if that is 1 mega Hertz power it’s just six out of

six DBM leave that kv is an important parameter it’s a gain of the VCO is the voltage to frequency transfer coefficient gain to the VCO let’s set this to the point 5 e to the 6 so the units of this guy arm hurts for both if you’ve ever wondering you know what these parameters mean you can double-click on an element and then click down here in the element health and it will tell you all the different parameters so that’s kV what we just changed that’s the frequency voltage transfer coefficient so scalar and Hertz per volt actually let’s make that a parameter too so let’s click on this and okay under school DCO make an equation for that this way it’s easy to identify this is a parameter it’s 0.5 e to the 6 let’s put all of our variables over here so when I say variables I mean we’re gonna change these variables and see how the dynamics of the phase lock loop change this is give me this is in red so something patients on your arm here okay I might have had at zero instead of an O or something anyway I just copied and pasted to correct that okay now let’s set up our measurement down here in project tab I click graphs I right-click click on new graph rectangular create right click add new measurement the measurement pipe is fine Ejim type of system WV FM default is time domain waveform everything’s perfect block diagrams get a test point let’s do the output and microseconds times man let’s make the same 40 takeoff weight for full window right click add new measurement so our next test point this will be our input leave everything else the same click on this little box and make this next test when you apply to come this legend and we’re going to change it so go to measurement tab instead of use default go output apply next input apply next air apply go to traces blue curve let’s change the way to make a little thicker you can change the colors if you want you can change us to green the air signal kind of makes sense to be red so I’ll change it to red the weights change that and apply we’re not quite ready yet we need to set the sampling frequency now so go to options default system options simulator let’s stop our simulation after 15 micro microseconds so right now it’s a nanosecond since it canceled need a certain units options project options global units time to microseconds ok options default system options stop the simulation after 15 microseconds this data rate let’s make 100 megahertz and over sampling which one so if ESS is a sample time domain simulator and you have to have a sampling frequency or infinite frequency is 1 megahertz so we’re going to vastly over sample so our sampling frequency is 100 times your input frequency and that way when we look at the graphs they’ll appear to be continuous time waveforms you’re not going to see the discretization due to a low sinking rate it ok save PLL yes cross our fingers that this thing will work and hit one stop simulation and it does the screen is kind of hard to see in a double quick let’s make this make this brown mobility there okay so what you’re actually seeing is the phase lock we’re doing exactly what it needs to do its locking to specific phase now the input frequency is 1 megahertz and the free running frequency of the VCO is 1 megahertz the input frequency let’s use me the input and the output signals are in phase when you first turn the system on and it’s ramping up you can see the blue curve the brown curve are their minimum happens at the same time point but what happens is later and later as you go on I like eight microseconds later the blue curve is leading the brown trace so the blue curve is the output and this brown curve is the input so the output is leading the input and

it turns out it’s by 90 degrees because of the multiplier pipe phase detector we using this red curve is the error signal now there’s some transient that’s happening so some signal is being fed into the VCO which is increasing the frequency a little bit so it’s accumulating some days and then there’s this little oscillation and then the air goes to zero when this thing is locked so when this air at zero the blue curve is leading or shows that the output Italy in the input by 90 degrees let’s now click on this and I want to see how this curve changes when I change I don’t know let’s change the cutoff frequencies we’re going to set the cutoff frequency of her low-pass filter to be a variable and look at different values of the cutoff frequency and see how that changes we leave dynamics that’s what I just did I clicked on this tuner tool and in quick to say hey it ups a variable I go back to my graph the fun tune here it is now Nam is the value it is right now so point five me to the six point five megahertz max is the maximum value that this thing can be set at I don’t know except this to be to meet at a six so you can also tune this with a slider if you want and so you can find the value between a maximum and then on the straight point one e to the 6 okay so now let’s change let’s lower actually let’s increase the caller frequency so that we’re letting higher and higher frequencies and see what happens there so kind of look at this curve I’m going to increase the cutoff frequency and then we’ll see how everything changes so I’ll change it to point seven e to the six 0.7 nerds okay what happened is it reach steady state faster so that the system responded faster this red curve is the air and it before it kind of took some more time to reach steady state this time it took less than four microseconds but what you pay the price you pay for a faster long time is for these oscillations in the air these oscillations in the air are going to translate to phase noise phase noise means that the output tone isn’t pure here’s our reference again the outfit tones get a little more like this so ideally you’d have this perfect single tone with one frequency at the output but when that air is oscillating it’s going to kind of spread this signal and frequency and kind of degrade the spectral purity about signals you have some phase noise basically put on this to see so that’s what happens when you increase the cutoff frequency will consult it now it’s decrease it so I’m gonna click off here my tuned tool would decrease it to still pretty low 0.2 me to the six point three six point three megahertz now we’re going to see is the transients going to take longer a full seemed a lot see it doesn’t even lock we’re at 15 microseconds it’s barely over you know it’s not quite locked there so to change this time in bird up options default system options would stop after 25 micro seconds so this thing is finally locked at around 25 microseconds so it took a lot longer but but you benefit is that this red curve there curve is going to have less oscillations it really even has a converge just plug that answer let’s go to functions let’s make this so I just set the simulation time would be 35 microseconds way out here that the air signal is finally converged you don’t see those oscillations so we’ll have a higher or the output tone will be a lot less phase noise and again when this thing is locked the blue curve which is again the output will be locked in phase 2 the input curve will be basically the output will leave the input by 90 degrees okay so let’s change our cutoff frequency back

to 0.5 e to the 6 that’s a pretty good value so options default system option gets go back to 15 microseconds this one to see everything alright so we’re kind of back to where we where we began now I want to lock to right now when this phase lock loop is starting up the phase of the input is equal to the phase of this VCO and eventually the VCO will levy input by 90 degrees let’s see let’s make sure that this thing will lock if the inputs are different in phase so I’m gonna make input phase a variable and I’ll take off the cutoff frequency low pass filter so now we’re going to change the phase of the reference signal and make sure we can still get a lock so now I hit tune max phase I want to deal with you know about pi 3.14 the minimum of negative two point one for it looks good let’s make sure it’s the same okay good with tune and now I’m going to change the input phase difference with respect to the phase of the VCO would be point five I’m just a number and you can see that eventually it locks and the blue curve is still 90 degrees meeting the drum curve Alfred let’s change the phase to negative three point one four or so the negative one point five and let’s see how this thing changes what locks pretty fast there because what I just did is I set the blue curve to be 90 degree more or less to lead 90 degrees ahead of the output yam x8 excuse me I set the output to lead 90 degrees ahead of the input and so I’m gonna take long to walk it all was almost already at lock but we’ve almost already locked so there’s that I change the phase back to zero and then re simulate anything should be the same now how does this change when I change the value of VCO game K underscore VCO give us the gain of the VCO when I say gain that’s not like voltage gain but it’s the voltage to frequency transfer coefficient okay so let’s make that a variable – by the way you can make other you can look at multiple variables I’m just selecting one at a time to make things a little bit simpler – video okay so now I go back to graph become tune stuck them in to be point -6 okay so let’s sit our namah let’s increase K I don’t know right now it’s at point 5 megahertz 5.8 megahertz what does that do well maybe there’s some more oscillations make the transient might take a little bit longer for this to lock I don’t really see much of an advantage right now the advantage of increasing K happens when the input frequency is not equal to the free running frequency to do Co but you can see it’s starting to kind of get more unstable let’s look what happens if you have a really large K to eat it is 6 when I say K that’s the letter that’s the symbol that stands for the gain of the VCO I’m just okay still oscillating or maybe I can’t get it to resume we’ll try oh it’s the Max is set just change the max to 5 so I thought I clicked you know 2 megahertz but it was higher than the set max anyway I had to change the mass go again sort of 3 megahertz for K full there you can start to see it’s just unstable the output signal is not a pure sinusoid at all it’s going all over the place and frequency and phase and the air is oscillating so when you increase K you decrease the stability of this system or you can say you decrease the attenuation of the system I’m gonna

change came back to 0.5 when I say it okay not you don’t decrease you increase K you decrease the what is it called I’m spacing on it so I’m not gonna go damping factor house it is okay everything’s back set how we had it let’s make sure good now things get interesting when the input frequency is different than the free running frequency of the VCO so I’m gonna make the input frequency the variable and I’ll made let’s look at on the cutoff frequency so we’ll make these two variables let’s see will this lock to an input frequency that’s 1.05 megahertz yes it does so what’s happening now you can see there is this transient that happens while this loop is locking to the input and then you have this steady-state error that’s just like a DC value the blue curve the output is indeed being locked to the frequency of the input but it is no longer leading the input by 90 degrees kind of hard to tell if we’re just looking at this in a time domain but this blue curve is not leading this dark round curve by 90 degrees and then on top of all that and the reason why this is happening is that we have a error signal that red curve is right here so the error signal is this it’s not just an air signal but it’s also being fed into the VCO is a control voltage so it locks in frequency but not in phase let’s increase the input frequency for 1.05 mega at one point one mega you go with the noise the same and you can see it locks in frequency again now however the error which gives you an idea of the phase error between the input and output it has increased you can see this red curve was lower before and it rose when we separated the input frequency from the free running frequency the VCO itself we’ll track at 1.3 megahertz it’s fun I know so now we’re not getting a walk and all I did was I increased the input frequency or the frequency of the input signal to 1.3 megahertz and this system is just not locking its out so I did capture range let’s see if the cutoff frequency e if I increase the cutoff frequency can we capture it you know let’s find out so I’m increasing it to 1 megahertz nope I’ll go back to point 5 okay so that’s that’s kind of the basics of how this thing walks in frequency let’s now turn off cutoff frequencies a variable let’s look at again the gain of the VCO which I’m calling K underscore DC over just K and so variable and let’s get our input frequency closer to our output so for to our VCO free running frequency so I’m going back to one point one megahertz or infant frequency yes this thing walks this thing off so the blue curve over here is one point one megahertz it locks in frequency but it’s now no longer 90 degrees reading the output trace and here’s our air we want to get these oscillations in the air lower you know we can lower the cutoff frequency what happens if we increase the gain at the VCO of K what I’m expecting to happen is this red curve the air will decrease which means you’re decreasing the phase air right now I just kind of click on it and it’s around 0.2 it’s oscillating it’s about point two is kind of a DC value RK is 0.5 mega Hertz let’s go as 1 mega Hertz I’m doubling K look at this red curve and see what happens well it’s taking longer to lock but I think it’s going to lock so we need to

actually zoom out so options default system options of 30 microseconds eventually this thing does lock so the blue curve the output is eventually be of the same frequency as the input but it takes a lot longer to acquire but if we click now this air signal the red curve is around I’m looking at the second number down and this box is about 0.1 so we have the air by increasing our gain of our VCO so what if you keep increasing the gain of our VCO or voltage-controlled oscillator well it’s going to take longer and longer to lock and at some point just gonna go totally unstable so let’s double or you co gain again double K and it’s just not locking the system gone unstable so I’m going to go back to options project project options option or people system elements we’re back to 15 microseconds you’ve done this thing is unstable good so let’s lower our value of K you can get a walk again so we’re at one more time point five megahertz okay let’s see what happens when we lower K too much but slower 2.1 megahertz if K is lower too much you kind of get this characteristic signal I can keep simulating on and on but it’s never gonna lock in the end what happens is when the gain of the VCO is too small you don’t get enough DC voltage to drive the VCO towards lot if you wanna learn more about that that’s on this paper and I think this paper was just excellent too far you kind of get these it’s kind of trying to get locked and it’s not acquiring a signal here’s an actual simulation and we’re kind of seeing that I’ll simulate a little their founders their options both system options let’s go to 13 get this attempt to lock but the gain is just too too small for this thing to lock correctly so there’s a sweet spot you don’t want K to be too small won’t give you too large right let’s go to point 5 e to the 6 see we get a lot though something funny is going on let’s stop it options and let’s just watch it stop the simulation ok 20 microseconds okay so I changed K back to point 5 megahertz what happens Amida increase the frequency the input frequency from one point one to one point two measures do we still get a lock so we don’t get a walk we’re outside the capture range so there’s a certain range of frequencies with which of phase-lock we can walk to or Lisa’s basic implementation and everything is with respect to the free running frequency of the VCO itself when I’m changing the input frequency to 1.2 that’s point 2 megahertz greater than the free running frequency the VCO which we set to be one megahertz let’s increase K – 1 e to those six one megahertz so if I increase K I get a capture again but of course there’s a limit to how much you can increase K again caving the gain of the VCO all right so that’s kind of the basics you can play with this phase lock loop stuff all day and really just pretty interesting okay I’m gonna change the input frequency let’s go to one point

one e to the 6 let’s leave the cutoff frequency as it is and let’s change the VCO gain to 1 e to the 6 which it is that’s great make sure again here’s our graph the problem with this with this circuit is that it will lock in frequency but not in phase that air is not at zero which means you have a phase error between the out from the input sometimes you actually in many cases you want to lock not just frequency but fades so how can you do that look when we add to this thing to make this go from a type 1a is likely to a pipe 2 we’re going to add API controller capital T capital I if you want to hook it up kiai controller is using control theory then we’re going to use them right here in our phase lock loop and it’s basically gonna model a charge problem but it also models a integrator that you can construct with an op-amp there’s a few components to this so I’m gonna go to signal processing meet a couple game blocks here’s my game block need a summer and we’re going to need an integrator guy controllers grater so gonna put them in the grader right there there we go and adding all this stuff is gonna give us a very good vantage they’ll see you for coming in two arrows and I’ve got a set to real data okay we gotta set the games correctly will already design this so you know if they should do these values the purpose here isn’t to show the design of all these the games and all these walks but just can’t exploit the properties of phase lock loop so we’re good there we’re going to yes look here this is the air this is what’s coming out of the phase detector and I’m going to go to options again default system options what’s up this I know it’s going to take a bit longer to lock so 35 microseconds drafts and let’s see if this thing achieves lot usually this simulates a lot faster but because I have this video capture going on that’s looking a bit longer there we go so I’m seeing that it pretty much locks before 20 microseconds in the fog road and go back in June we don’t need a whole 35 ok now first glance this might look very similar to the behavior of the phase lock loop before we flip this VI controller that was a very big difference very important difference and before I say that let’s just do one quick overview what’s going on here’s our input signal has a frequency of one point one megahertz this is our phase detector multiplier and low-pass filter and the cutoff frequency of the low-pass filter is set to be 0.5 megahertz this then goes to a TI controller which has an integrator and to gain blocks and and adders I think of this is just another filter then your and then this goes into our voltage controlled oscillator which has a three running frequency of one megahertz an output power that’s such a 60 BM and has a gain voltage for Hertz volts per Hertz that is denoted K underscore VCO that is one megahertz four volts and we’re looking at the output we want this to be a sinusoidal waveform a tone that’s locked in fades and frequency to our input we’re looking

at the output the input in our error signal when this signal is zero that means this in this are locked in phase that means that this is actually leading I say this I mean the output is leading the input by 90 degrees and have to take the error 0 the red curve here and look it goes to zero the blue curve is the outlet and look it’s not just tracking the frequency of the input but it’s also tracking the phase there’s a fixed phase relationship it’s leading the outlet from 90 degrees and that it takes the trade off of using this filter it means is that it takes a bit longer for this thing to acquire long let’s see what happens if I increase the input frequency to 1.2 megahertz so it acquires LOC at about 15 microseconds but when it requires locked the air is zero the output of the VCO is locked to the frequency and phase of the input as you can see right here in the air goes to zero