Phase Locked Loop Shivkumar .V. Iyer 1 Abstract Any grid connected inverter requires accurate information of the phase angle and frequency of the grid through a Phase Locked Loop (PLL). The report will describe through simulations, every aspect of the implementation of a PLL in software which in hardware would be through a Digital Signal Processor (DSP) or an equivalent embedded processor. The outline of the report is as follows: 1. The need for a PLL and the basic concept behind a software PLL. 2. The concept of transformation that forms the basis of a software PLL with a single-phase sys- tem. 3. The closed loop to generate the synchronization. 4. Transformation applied to a three-phase system. 5. The effect of unbalance with respect to oscillations in the phase angle and the need for a notch filter. 6. The design of a notch filter. 7. The working of a PLL in practical conditions. This tutorial is accompanied by a number of simulation cases. It is recommended to try out the simulation cases while reading the tutorial. About the software: Python Power Electronics is a free and open source circuit simulator for power electronics and power systems professionals. It is available under the BSD 3.0 license agree- ment which is available with this tutorial and in every case as a LICENSE.txt file. Users of this tutorial are advised to read the license file. It should be noted that this tutorial is for learning and edu- cational purposes. Implementation of the examples cited in this tutorial directly in a prototype cannot 1
34
Embed
Phase Locked Loop - Python Power Electronics...Phase Locked Loop Shivkumar .V. Iyer 1 Abstract Any grid connected inverter requires accurate information of the phase angle and frequency
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Phase Locked Loop
Shivkumar .V. Iyer
1 Abstract
Any grid connected inverter requires accurate information of the phase angle and frequency of the
grid through a Phase Locked Loop (PLL). The report will describe through simulations, every aspect
of the implementation of a PLL in software which in hardware would be through a Digital Signal
Processor (DSP) or an equivalent embedded processor. The outline of the report is as follows:
1. The need for a PLL and the basic concept behind a software PLL.
2. The concept of transformation that forms the basis of a software PLL with a single-phase sys-
tem.
3. The closed loop to generate the synchronization.
4. Transformation applied to a three-phase system.
5. The effect of unbalance with respect to oscillations in the phase angle and the need for a notch
filter.
6. The design of a notch filter.
7. The working of a PLL in practical conditions.
This tutorial is accompanied by a number of simulation cases. It is recommended to try out the
simulation cases while reading the tutorial.
About the software: Python Power Electronics is a free and open source circuit simulator for
power electronics and power systems professionals. It is available under the BSD 3.0 license agree-
ment which is available with this tutorial and in every case as a LICENSE.txt file. Users of this
tutorial are advised to read the license file. It should be noted that this tutorial is for learning and edu-
cational purposes. Implementation of the examples cited in this tutorial directly in a prototype cannot
1
be guaranteed to work and the readers are responsible for taking precautions to prevent damage to
their equipments and injury to themselves. For any queries, feel free to contact me at pythonpower-
[email protected] or visit the project website http://www.pythonpowerelectronics.com/.
The purpose of this tutorial and others that will be released is to provide education through simu-
lation to engineers on several aspects of power systems. Starting from simple concepts, the tutorials
will progress to advanced control in power systems and understanding practical problems in present
day electrical systems. The tutorials are not mathematically intense and this is intentional as the ob-
jective is to help engineers who are busy with their day jobs to advance their knowledge. The reports
are written with figures and visuals as far as possible to make understanding easier. The report in its
style is similar to a presentation where each page has a figure and a description accompanying it. This
is to facilitate easier reading as opposed to an academic paper. Readers are encouraged to follow the
project on the website, social media and go through the examples and documents provided.
2
Grid
f1f2
vg vc
PLL
PLL
θ
θθvg/20
Voltage
Figure 1: Phase synchronization with a grid
2 The need for a PLL
The above figure shows a power electronic converter connected to an ac grid. At present, the topology
of the converter and the nature of the coupling is not relevant. In order to function, the converter
needs the accurate information of the frequency f1 and the phase angle information (θ ) of the grid
from which it can regulate its own output frequency f2 to be equal to f1 and its phase angle to be in
sync with the grid phase angle. The desired output of the PLL is therefore the phase angle information
of the grid which is then used to regulate the output of the converter. The reason why this is essential
is that the grid frequency is likely to drift from its nominal value by around 1% under even normal
operating conditions. This is because the frequency of the grid is related to the state of loading of a
power system - power generated versus power demanded. During peak load demand, the frequency
tends to drop below nominal while during light load periods, the frequency could be closely regulated
to the nominal value. For all these frequency drifts, the PLL should continue to generate the accurate
phase angle information of the grid so that the converter output voltage phase angle remains in sync
with the changing grid. The next figure shows what happens if converter frequency is not equal to
grid frequency.
3
Figure 2: Operation with and without a PLL
The figure above shows the difference between the operation when the converter frequency is
exactly the same as the grid frequency (both are 60 Hz) and when the converter frequency is 60.5 Hz.
This can be found in the spreadsheet need for pll.csv and the associated control file vconv openloop
.py. The parameters of the circuit is in the spreadsheet need for pll params.csv while the variables for
the control file can be found in vconv openloop desc.csv. You can change the frequency of either the
grid in the circuit parameters section or the converter in the file vconv openloop.py . In the first case,
when frequencies are equal, a stable operation is observed. In the second case, the current has a low
frequency envelope besides very high peaks. Typically, when two voltage with different frequencies
f1 and f2 are connected together, the current that flows through them will have two componentsf 1+ f 2
2
andf 1− f 2
2. The second component results in a low frequency envelope. Quite obviously, the second
case is not a permissible mode of operation. To explain this in simple terms, if two objects were to
have different speeds, with time the distance between them would be huge. If two sinusoids were to
have different frequencies, at some point of time, they would be out of phase with each other and at
another point of time, they would be exactly in phase with each other.
4
Reference
V , t1
V , t2
Vm cos(ωt1)Vm cos(ωt2)
ω
Vm
Figure 3: A sinsuoid in a stationary reference frame
3 Concept of phasors and reference frames
In order to explain what a PLL is, let us first examine the concept of phasors, transformations and ref-
erence frames. The above figure shows a co-sinusoid of frequency ω and magnitude Vm. To represent
this as a phasor, examine the figure on the right. The co-sinusoid is a vector of magnitude Vm rotating
at an angular frequency ω . The instantaneous value of the co-sinusoid is the projection of the vector
on the x-axis which is the reference frame. At different points of time, the vector will occupy different
positions in the two-dimensional plane as shown at time t1 and t2. The projection on the x-axis will
result in different instantaneous values which as can be seen are Vm cos(ωt1) and Vm cos(ωt2). As
expected from a co-sinousoid of magnitude Vm, the instantaneous value from the projection is also
restricted between −Vm and +Vm. In this manner, a voltage can be represented in the above manner in
which it is called a phasor (similar to vector). The phasor has two properties - magnitude and angular
frequency of rotation. In the above figure, the reference frame is the x-axis and is stationary. With
respect to this stationary axis, the phasor V is rotating with an angular frequency ω . In simple terms,
this is similar to standing on a platform watching a train go by without stopping. You see all the
compartments of the train with their passengers one after the other until the train is gone.
5
Reference Reference
Reference
Reference
V , t1V , t1
V , t2V , t2
ω
ω
ω
ω
ω
ω
ωr
ωr
φ1φ1φ1
φ2
Figure 4: A sinsuoid in a rotating reference frame
Let us now examine the concept of a rotating reference frame rather than the stationary x-axis
reference frame. In the above figure, the first case is of a reference frame rotating at an angular
frequency of ωr which is different from the angular frequency of rotation of the voltage phasor. With
respect to this rotating reference frame, the instantaneous value of the voltage is Vm cos(ω −ωr)t. Two
instances have been shown at time t1 and t2. Since ωr and ω are different, at different times, the phase
angle difference between them may be different as shown to be φ1 and φ2. With respect to this rotating
reference frame, the voltage vector now appears to be a low frequency co-sinusoid. This is seen as
similar to sitting in a moving train and watching a faster train go by in the same direction. The faster
train will appear to be a slow moving train just because you are sitting in a train that is almost as fast.
On the right is shown a special case of the rotating reference frame - the angular frequency of the
reference frame is the same as that of the voltage vector (ω). The result is that they always maintain
the same phase angle difference φ1 between them at all time instants. And therefore, the instantaneous
value of the voltage with respect to this reference frame is Vm cosφ1. In this special case, with respect
to the reference frame rotating at angular frequency ω , a phasor of the same angular frequency appears
as a constant or a dc signal. In simple terms, this is like sitting in a moving train and watching another
moving train appear stationary just because it is moving at the same speed.
This is the concept of the PLL. In order to synchronize with the grid, we generate a rotating
reference frame and through closed loop control, adjust the angular frequency of this rotating reference
frame such that the grid voltage phasor appears as a dc signal. This is when the rotating reference
frame has the same angular frequency as that of the grid and has locked on to the grid.
6
To achieve phase locking, we use a trigonometric relation that will be described. As with the
previous figures, let us assume that the grid voltage is a co-sinusoid:
V g =Vm cos(ωt)
Suppose, we could generate a sinusoid from the above signal - basically a signal that is 90◦ lagging to
it:
Vgsin =Vm sin(ωt)
How this will be done will be described in the later sections. Suppose, the rotating reference frame
was also a co-sinuoid:
Vr = cos(ωrt)
And suppose, we could generate a signal 90◦ lagging to the above signal:
Vrsin = sin(ωrt)
This is much easier as the reference frame is something we generate but it will be described later
anyway. We now have two sets of quadrature signals:
Vm cos(ωt),Vm sin(ωt) and cos(ωrt),sin(ωrt)
There are two combinations of trigonometric equations that are particularly interesting:
The most important is the relation 2. We are going to try to control the angular frequency ωr of the
rotating reference frame. When ωr is equal to ω , the second term is equal to zero. This is the condition
for a successful phase-locking with respect to the grid and this will be used in the closed loop control
as will be described next.
7
Vm cos ωt
Vm sin ωt
cos
sin -1
*
*
+
+
+
+
∫
∫
Ki
Kp
ωr
ωnom
ωrt
Figure 5: Closed loop strategy of a PLL
4 Concept of a PLL
The block diagram above shows the closed loop control of a PLL. The top-left part is the expression
2 described in the previous page. As stated, that expression which is Vm sin(ωt −ωrt) should be zero
when the PLL has locked on. Therefore, we use this expression and feed it to a Proportional Integral
(PI) controller. By doing so, we use the nature of a PI controller such that by designing the closed loop
appropriately, the input to the PI controller is forced to zero. The output of the PI controller becomes
the angular frequency of the rotational reference frame. Since we know that drifts in frequency of the
grid are typically very small in the range of 1-2%, we add the nominal frequency ωnom to the output of
the PI controller to speed-up the closed loop tracking. For a 60 Hz system, ωnom would 377 rad/s while
for a 50 Hz system, ωnom would be 314 rad/s. To briefly describe how it works, refer to the previous
figure on rotational reference frames. When Vm sin(ωt−ωrt) is positive, it means the reference frame
angular frequency is lower than the grid angular frequency. The output of the PI controller when
fed this positive signal will also be positive causing the angular frequency of the reference frame to
increase. This in turn will decrease Vm sin(ωt −ωrt) and force it to zero. The angular frequency is
integrated to get the phase angle of the rotating reference frame.
With this basic description, we will now describe how we obtain from the grid voltage, a signal
that lags behind it by 90◦.
8
Figure 6: Integration of the grid voltage signal
Given any co-sinusoid or sinusoid, the simplest process to generate a signal that lags behind by
90◦ is by integrating it. As an example,
∫
Vm sin(ωt)dt =−Vm cos(ωt)/ω +C∫
Vm cos(ωt) =Vm sin(ωt)/ω +C
There are two problems with the above integration - one simple and the other a little more difficult.
The first is that integration produces a signal that is attenuated by the factor ω . This means if you
integrate the grid voltage, the result is a signal that is 377 times smaller if the grid is 60 Hz. This is
fairly simple to solve because the angular frequency of the rotational reference frame will be equal
to the angular frequency of the grid in steady state. Even if the desired signal is not exactly equal in
magnitude to the input grid voltage, that is good enough. This will be described in the next section.
The next problem is that of offsets. If the input grid voltage has any measurement offsets caused
due to temperature, aging of the measurement devices or any other noise, the integration will result in
a continuously increasing or decreasing signal. Over time, this will disrupt the control loop. As for
the integration offset C, this may result in a signal with an offset, purely based on the initial value of
the grid voltage. To examine this, check out the simulation file vgrid integration.csv with parameters
vgrid integration params.csv. A single voltage source of 120 V rms is measured. The control file
signal integral.py with variables in signal integral desc.csv contains the integration. The file also
contains a low pass filter which will be describe later. Use it without the low pass filter. The results in
the figure above show the performance of the integral. The first one shows the dc offset when the grid
voltage is a sinusoid. The second one shows the integral to be continuously increasing when a 0.1 V
dc offset is added to the grid voltage.
9
-
+∫
LPF
vgrid
vinteg
|LPF|ωω f = 20 rad/s
ω f
s+ω f
Figure 7: Implementation of low pass filter
To prevent the problems shown in the previous page, we use a Low Pass Filter (LPF). Since, it is
dc offsets in the measured grid voltage that are a problem, we need a LPF with a low cut-off frequency
that lets the dc offset pass through but will attenuate the fundamental 60 Hz component of the grid
voltage. This dc offset is now fed back to the input of the integrator as shown. The figure on the right
shows how the low pass filter is designed as a first order filter. In order to implement it digitally, the
filter is discretized as follows:
LPF(s) =ω f
s+ω f
LPF(z) =ω f
2T
z−1z+1
+ω f
=ω f T (z+1)
2(z−1)+ω f T (z+1)
LPF(z−1) =ω f T (1+ z−1)
2(1− z−1)+ω f T (1+ z−1)=
Y (z−1)
U(z−1)
(2+ω f T )y(n)− (2−ω f T )y(n−1) = ω f T [u(n)+u(n−1)]
y(n) =(2−ω f T )y(n−1)+ω f T (u(n)+u(n−1))
2+ω f T
Here, the bilinear transformation s = 2T
z−1z+1
is used to perform the discretization. T is the sampling
period of the LPF. In the example chosen, T = 100 microseconds. Substitute T = 0.0001 and ω f = 20
rad/s to get the filter co-efficients.
10
Figure 8: Effect of a low pass filter on integration offsets
The figure above shows the integration with the low pass filter. As can be seen both problems have
disappeared. There is no offset even though the grid voltage remains a sinusoid as in the previous case.
The integrated signal is stable even though the grid voltage has a 0.1 V dc offset. You could also try
to change the filter cut-off frequency or the sampling period to check out how the low pass filter
performs. As you increase the cut-off frequency, the LPF lets through not just the dc offset and very
low frequency signals if there are any but also lets through the fundamental 60 Hz component. There
will be a frequency ω f for which distortions may begin to creep in. As for the sampling period, as
you increase the period, you reduce the resolution of the filter. As you decrease the sampling period,
you begin to get quantization errors that will result in instability. The theory behind signal processing
is vast if you care to read. However, this simulation allows you to play around with values.
11
Figure 9: Single phase PLL - frequency and phase angle
5 Simulation of a single phase PLL
To try out the single phase PLL with all the blocks mentioned above, try out the circuit file sin-
gle phase pll.csv with parameters single phase pll params.csv and the control file single phase pll.py
with control variables single phase pll desc.csv. The above figures show the performance of the PLL.
The figure on the left shows how the angular frequency gradually settles to 377 rad/s. The initial os-
cillations can be attributed to various reasons - tuning of PI controller gains, the time taken to generate
a signal that lags behind the grid voltage by 90◦ etc. The figure on the right shows the phase angle
generated during steady state when compared to the grid voltage attenuated by a factor of 20. The
phase angle increases from 0 to 2π over a cycle of the grid voltage. The phase angle can be seen to be
a smooth sawtooth waveform despite minor oscillations in the angular frequency in the left plot due
to the smoothing action of the integrator.
Try out variations in the PI controller gains to check how the response changes and when it be-
comes completely unstable. Also, try out changing the frequency and phase angle of the grid voltage.
12
Figure 10: Single phase PLL - transformed voltages
The above figures show how the PLL performs in the closed loop control. As stated before, the
objective is to force Vm sin(ω −ωr)t to zero. The figure on the left shows this expression over time.
In steady state, the quantity is indeed forced close to zero. There are oscillations on the quantity even
in steady state which is the reason why there are oscillations in the angular frequency in steady state
(see the previous figure on the left). The initial oscillations in the expression Vm sin(ω −ωr)t show
how they are related to the excursions in the angular frequency. As stated before when Vm sin(ω −ωr)t is positive, it means ωr is less than ω and therefore ωr needs to increase and vice versa. The
other expression Vm cos(ω − ωr)t is plotted on the right. In steady state, when ωr is equal to ω ,
this expression gives the peak value of the grid voltage. This can be particularly useful in control
algorithms that require the grid peak voltage. The only problem is that it has oscillations. To use it in
control, it is advisable to pass it through another LPF as described in the previous section.
We can now look the operation of a three-phase PLL. As before we start with the concept of a
three-phase PLL.
13
V a
V b
V c
ω
ω
ω
Figure 11: Three phase voltages
6 Three phase PLL
The figure above shows a three-phase system of voltages va, vb, vc with vb lagging behind va by 120◦
and vc lagging behind vb by 120◦ as follows:
va =Vm cos(ωt)
vb =Vm cos(ωt −2π/3)
vc =Vm cos(ωt −4π/3)
As with the case of a single phase voltage, these three-phase voltages can be represented as vectors
rotating at an angular frequency of ω and the instantaneous values of the voltages are the projection
of the vectors shown on a stationary x-axis as shown. As with the case of a single-phase PLL, the
objective of a three-phase PLL is to generate a rotating reference frame that rotates with the same
angular frequency ω such that the projections of the vectors on the rotating reference frame are con-
stants. Since there are three vectors, let us suppose that we want this rotating reference frame to be
aligned with vector V a or phase a.
A simple and instinctive solution would be apply a single-phase PLL on phase a or for that matter
on all three phases thereby having accurate phase angle information of all phases. There is a simpler
solution due to the three-phase nature of the system. To begin with, it is possible for the voltages to
be unbalanced. As a worst case, it could be possible that one phase is opened and this phase could
be phase a. So applying a single-phase PLL to just one phase may not be a good solution. Applying
three single-phase PLLs to all three phases would work but we will soon see that is unnecessary.
14
V aV a
V b
V b
V cV c
ω
ω
ωω
ω
ω−0.5V b−0.5V b
−0.5V c−0.5V c
√3
2V b −
√3
2V c
V α
V β
Figure 12: Primary voltage and quadrature signal
In a single-phase PLL, in order to apply the trigonometric relation that results in Vm sin(ω−ωr)t, it
was necessary to generate a signal that was 90◦ lagging to the grid voltage. This we did by integrating
and passing it through a low pass filter. In a three-phase system, this is not necessary. Suppose, we
keep voltage va separate and want to generate a signal that is 90◦ lagging to it. We can do so by using
the voltages vb and vc as follows:
vb − vc =Vm cos(ωt −2π/3)−Vm cos(ωt −4π/3)
=Vm(−0.5cos ωt +0.866∗ sin ωt +0.5cos ωt +0.866sin ωt)
= 2Vm(0.866sin ωt) = 1.7321Vm cos(ωt −π/2)
So, by simply performing vb − vc, we have achieved a signal that lags behind va by 90◦. We have a
factor 1.7321 but we perform another calculation so that this is not a problem.
va −0.5vb −0.5vc =Vm[cosωt −0.5cos(ωt −2π/3)−0.5cos(ωt −4π/3)]