5199 Full Document
5199 Full Document
5199 Full Document
Johan Björnstedt
Magnus Ström
Abstract
The use of microsources in the power grid often requires assistance of power electronics to
convert the produced DC to AC. A big issue is to get the converters operating together with
the power grid, without any communication between them.
In this project a control algorithm for the converters is developed and tested in a standalone
microgrid containing three converters and a synchronous generator. The controller is based
on droop control in order to avoid communication between the converters. The behaviour at
the converters DC-side is not taken into consideration, the focus is on voltage- and frequency
control at the common AC-side.
Models of converter, generator, grid and load are developed in order to carry out numerical
simulations in the software MATLAB/SIMULINK. The control algorithm is then implemented in
a digital signal processor, controlling each converter.
We would like to thank the staff at IEA for their kindness and hospitality and special thanks
to all the people who have contributed with their opinion to the subject. Bengt Simonsson and
Getachew Darge at IEA have provided us with practical help in the laboratory. Bengts
comments have made us laugh a lot of times and Getachew has shown a lot of patience with
us, despite we has turned his laboratory up side down.
Most of all we would like to thank our teacher and supervisor Dr Per Karlsson, for inspiring,
guiding, assisting and supporting us throughout the project. Like Bengt, Per always had a lot
of clever comments for everything. We also would like to express our gratitude to Per for
inviting us to become co-authors to the paper “Stability of Voltage and Frequency Control in
Distributed Generation on Parallel-Connected Converters Feeding Constant Load” which will
be published at the 11th European Conference on Power Electronics and Applications (EPE
2005).
Finally, we would like to thank our families for always supporting us and encouraging our
studies through the years.
During the last decade, distributed generation systems are rapidly gaining popularity.
Distributed generation can provide standby generation (emergency power), peak shaving
capability and cogeneration. It also improves the efficiency of the power grid by having
multiple microsources added to the system. Distributed generation systems can also help to
improve power quality and power supply flexibility, maintain system stability and reduce the
transmission and distribution cost. In Sweden, approximately 8-9% of the produced
hydropower is lost due to transmission and distribution losses. Annually, this power loss
almost corresponds to one nuclear reactor, i.e. 500 MW. These power losses in the power
system impose a large cost on society, both financial and environmental. By putting the
microsources closer to the end-user a reduction in the transmission and distribution cost can
be achieved.
The use of distributed generation in the power grid is not a problem-free process. Interfacing
microsources with the power systems involves implications on the structure and operating
procedures of both the units and the system in which they are imbedded. The main concerns
focus on operating procedures, control systems, islanding, and safety issues.
1.1 Technologies
Due to the fact that all microsources operate at varying frequency or even delivers DC, these
sources require power electronic to interface to the power grid and its loads. In almost all
cases there is a DC source, which must be converted to AC at the required frequency,
magnitude and phase angle. The power electronic interface introduces new control issues and
new possibilities. One large class is related to the traditional cogeneration problem. A system
with clusters of micro generators could be designed to operate in both island mode and as a
satellite system connected to the power grid. In such systems load swings become a major
issue. A load step will affect the system. In the case of a power electronics based source, the
DC-link voltage will decrease in response to the increased load. For example, micro turbines
and fuel cells have controllers that use the decrease in DC voltage to provide an increased
energy input.
3
4 Introduction
respond effectively to system changes without requiring data from other sources or loads at
different locations. To prevent overloading of the microsource, it is important to ensure that
the converters share load in proportion to their nominal power, without communication.
Figure 2.1 A schematic principal of the 2-level converter used in this project.
2.1 Semiconductors
A typical configuration of a VSC is a six pulse self commutated converter containing six
power semiconductors with anti-parallel connected diodes. These power semiconductor
devices can, for example be
Typical switching frequencies for a VSC are between 2- 15 kHz. The MOSFET is the
preferred semiconductor for low power / low voltage applications since it has low conduction
losses for low voltages, and low switching losses. The MOSFET also has a parasitic anti-
parallel diode, that may be used as a built in free-wheeling diode, if its reverse recovery time
is acceptable. However, the on-state resistance of a normal MOSFET has strong dependency
on the blocking voltage. This makes the IGBT the preferred choice for applications in the
medium/ high voltage range. Both the MOSFET and the IGBT are voltage controlled which
allows simple gate drive circuits. The GTO has high switching losses and requires a more
complicated driver since it is current controlled. The GTO is mainly used for high power
applications due to its low forward voltage drop and its high blocking voltage. This thesis is
not focusing on any special semiconductor switch, although IGBT:s are used during the
experiments.
5
6 Three Phase Voltage Source Converter
times the fundamental line frequency. This is due to the fact that the capacitor charges and
discharges during the voltage variation. The DC-link voltage ripple will be higher when a
smaller capacitor is used [5]. The pulse pattern of the output voltage of the converter are
controlled by Pulse Width Modulation, PWM, which is described in the section Carrier Based
Modulation.
The DC-link is capacitive and therefore the output filter has to be inductive, which is also the
reason why the converter acts a current source. To smooth the rough output voltage, star
connected shunt capacitors are placed between the inductors and the grid. To get the same
current ripple, in per unit, for all converters the inductors are chosen so that the inductance is
proportional to the inverse of the nominal power of the converter. Then the capacitors of the
filter are chosen so that the filters has a resonance frequency that is ten times the grid
frequency, i.e. 500 Hz, this is done to avoid oscillations between the filter and the grid. For
the same reason the sampling frequency of the converter should be at least 10 kHz to provide
a Nyquist frequency of 5 kHz.
3 Converter Control
The converter is vector current controlled and the current references are determined from the
active and reactive power references resulting from voltage and frequency droop control.
Figure 3.1 shows the principle schematic of the control system.
The converter is intended to control the voltage and frequency based only on instantaneous
measurement at the converter terminal. When the converter is connected to a strong power
grid, the grid is giving the frequency and voltage, but when several converters are connected
together in a standalone system the measurements are based only on quantities produced by
the converters themselves. The voltage is measured over the output filter capacitor.
To avoid overloading the converters, it is important to ensure that the converters share load
proportional to their nominal power. This is achieved in conventional power systems, with
multiple generators, by introducing a droop function based on the frequency of each
generator. This permits each generator to adapt to changes in total load in a manner
determined by its frequency droop characteristics. Similarly, a droop in the voltage with
reactive power is used to ensure correct reactive load sharing. The same philosophy could be
used to ensure correct distribution of total power between parallel connected converters in a
standalone system.
7
8 Converter Control
icd
C i2d (3.4)
dvcd
Cvcq i
dt 1d
icq
C i2q (3.5)
dvcq
Cvcd i
dt 1q
By assuming that the q-axis is aligned with the grid voltage vector in the dq synchronous
reference frame, the grid voltage only has a q component, see Appendix A. When i2d
increases without increasing i1d, and given by definition that vcd is zero, Equation (3.4) gives
that ω has to increase. In the same manner Equation (3.5) for increasing i2q gives that the
voltage decreases. From these investigations two droop controllers can be derived as shown
in Figure 3.6.
Q* K * (3.6)
P* K
v v v
*
(3.7)
The droop functions derived in Figure 3.3 is used to control the converter if it is connected
directly to a load or in a grid with only converters. However, when converters are connected
to a strong grid and are intended to share the load in proportion to their nominal power, this
control algorithm is not appropriate. Therefore the grid behaviour is investigated to develop a
control method for such a case.
Grid Characteristic
For a system operating in sinusoidal-steady-state, the apparent power, S, flowing into a line,
see Figure 3.4a, can be described as, [2]
⎛ U V ⎞* ⎛ U Ve j ⎞ U 2 j UV
⎟ U ⎜ ⎟ e j ( (3.8)
S P jQ U I U ⎜ *
)e
⎠ ⎝ Ze ⎠ Z
⎝ Z Z
j
Thus, the active and reactive power flowing into the line is
U UV
P cos( ) cos( (3.9)
Z Z
)
and
U UV
Q sin( ) sin(
(3.10)
)
Z Z
With the impedance Ze j
R jX , the equations above can be rewritten as,
U
P R(U V cos( )) XV sin( ) (3.11)
R2 X
2
and
Q
U RV sin( ) X (U V cos( (3.12)
R2 X ))
2
which leads to
XP RQ
V sin( )
U (3.13)
RP XQ
U V cos( )
U (3.14)
For overhead lines the resistance, R, can be neglected because X>>R. Also if the power angle
is small, then sin() ≈ and cos() ≈ 1. From these approximations Equation (3.13) and
(3.14) are rewritten
XP
UV (3.15)
XQ
UV
U (3.16)
These equations show that the power angle depends primarily on active power, P, while the
voltage difference depends primarily on reactive power, Q. Since the power angle depends on
the frequency, the active power can be controlled by controlling the frequency.
Thus, by adjusting P and Q independently, frequency and voltage amplitude of the power
grid is changed. These conclusions form the basis for droop control with active and reactive
power
Q* K v v
v (3.17)
P* K
n (3.18)
where K is the gain, n and vn are the nominal frequency and the nominal grid voltage,
respectively, P* and Q* are the references for active and reactive power respective of the
converter.
These droop functions are commonly used to control synchronous generators in the power
system and involves load sharing based on locally measured voltage and frequency. To make
the converter behave as a synchronous generator the droop functions in Figure 3.3 and Figure
3.5 are combined.
Converter Control
In order to make the converter behave as a synchronous generator a control method
containing two steps is developed. Such a system is shown in Figure 3.6, where all four droop
functions, derived above, are combined. Then the slow grid droop functions are giving the
references for the fast converter droop functions. This means that the fast droop functions in
Figure 3.3 are slowly shifted vertically by the droop functions in Figure 3.5 and the desired
behaviour is achieved.
To derive the equations for the entire system Equation (3.17) is combined with (3.6) and
Equation (3.18) with (3.7)
Q* K v v K
v n
*
(3.19)
P* K n K v* v (3.20)
the references for the fast droops are then calculated as
v* K
v n
f4 (3.21)
q, f 2
Kv
* Kv (3.22)
f4 K qn q, f 2
vv
where the indexes f indicates different filter bandwidths. The measured voltage is very rough
and is therefore filtered with first order LP-filters with low bandwidths. The different cut-off
frequencies are chosen to achieve the behaviour with fast and slow droops. When the
references, * and v*, are calculated, P* and Q* are obtained according to the fast droop
functions
Q* K * (3.23)
P* K
v v *
q, f 1 (3.24)
vq
In order to obtain correct load sharing, according to the converters nominal power Sn, the gain
parameters are chosen as
K Sn
(3.25)
n
Kv Sn
v (3.26)
n
v
where and v are the maximum deviation in frequency and voltage, respectively.
The converter is based on a current controller so the determined active- and reactive power
references need to be recalculated to current references. Thus,
Q*
i
*
d (3.27)
v q, f 3
P*
iq* (3.28)
v q, f 3
K sin m (3.29)
ˆ
where is the actual voltage vector position, ˆ is the estimated position, K is a gain
parameter and m describes the rotation polarity of the vector. In cases where the rotation
polarity is unknown m = 2 otherwise m = 1.
The signal can be used to drive the frequency and angle estimation to their true values,
using the following algorithm
&ˆ 1 (3.30)
&
ˆ ˆ 2 (3.31)
the gain parameters are 1 2 mK and 2 mK . The estimated angle is obtained as
2
the integral of the estimated frequency corrected by the term 2. Under the condition that the
error angle is small, i.e. ˆ , Equation (3.30) and (3.31) can be linearized as
&ˆ 1 ˆ (3.32)
&
ˆ ˆ 2 (3.33)
ˆ
where 1 1mK
and 2 2 mK . In order to obtain robustness and avoid oscillations both
poles are placed at s where is a positive constant [3]. For complete small signal
analysis and pole placement, see [4].
Discrete Time Implementation
From Figure 3.7 it is seen that the position error angle can be expressed as
~
v
u * Ri * ˆLi *
ˆ d
d d q (3.34)
vq vq
Instead of using measured voltage and current components, their reference values are used in
order to reduce noise. This does not introduce any errors, provided that the current controller
gives no static error.
Finally, the frequency and angle can be described from Equations (3.32) and (3.33) as
ˆLi
ˆ q u d Rid
2 (3.35)
& * * *
vq
2
&
ˆ ˆ u *
Ri *
ˆLi * (3.36)
d d q
vq
Transformation from the continuous time domain to the discrete time domain is performed by
applying forward Euler method on Equation (3.35) and (3.36)
ˆ k 1 ˆ k u d ,k Rid ,k ˆ k Liq,k
2 Ts * (3.37)
* *
vq
2 Ts
ˆ ˆ ˆ T u *
Ri* Li* (3.38)
ˆ
k 1 k k s d ,k d ,k k q,k
vq
where Ts is the sampling period and k is the sample number (at time t = kTs) and is the
estimator bandwidth. By using Equation (3.37) and (3.38) the frequency and angle are
estimated. The frequency is then used in the droop controller to calculate references and the
angle is used in the current controller to align the voltage vectors of the converter with the
vectors of the grid.
3.3 Filter Design
To suppress noise and avoid transients in the measured voltage signal, it has to be low-pass
filtered. As can be seen from Figure 3.1 the filtered voltage signal is used for calculations in
both the fast and the slow droops for converting power reference to current reference and in
the converter. In order to make the system stable different cut-off frequencies has ben
calculated from the small signal models, see [4].
Consider the Laplace transfer function of a first order low-pass filter, with the cut-off
frequency 0
Y s
H s 0
(3.39)
s 0
X s
which relates the filtered signal Y(s) to the measured X(s). This has the following time
domain equivalent
dyt
yt xt (3.40)
dt 0 0
Now, the differential equation can be descretized using explicit Euler method
yk yk 1
Ts y0 k 0 (3.41)
xk
yk (xk yk )0Ts yk 1
(3.42)
Figure 3.8 Block diagram of the proposed first order low-pass filter.
System Equations
The simplified circuit of a grid connected converter is displayed in Figure 3.9. The grid and
the converter are modelled as three-phase voltage sources with inductors, one in each phase,
connected in series between them. The converter phase voltages are denoted as ua(t), ub(t) and
uc(t). The phase voltages of the grid are denoted va(t), vb(t) and vc(t). The phase current
through the inductance are denoted as ia(t), ib(t) and ic(t). The equivalent inductance and
resistance of the inductor are denoted as L and R, respectively.
With Kirchhoffs voltage law applied on the circuit in Figure 3.9, the three-phase system
differential equations are
ua t di t
va t t R L a (3.43)
ia
dt
u t v t i t R L
dib t (3.44)
b b b
dt
u t v t i t R L
dic t (3.45)
c c c
dt
The grid voltages equal
va (t) 2
V cost (3.46)
3
2 ⎛ 2
v (t) V cos t
⎞b ⎜ ⎟ (3.47)
⎝ ⎠
3 3
2 ⎛ 4
v (t) V cos t
⎞c ⎜ ⎟ (3.48)
⎝ ⎠
3 3
where V is the phase to phase rms voltage, and ω is the grid angular frequency.
u t v di
v t i
t R L
t
dt
u t t i
di t 3.49)
t R L (3.50)
dt (
dt
⎨
⎪u t Ldi qt Li t t R t
(3.53)
i v
⎪ q
dt
d q q
⎩
⎧
i i
did d ,k T d ,k 1
⎪ s (3.54)
dt
⎪
⎨
di i i
⎪ q q,k q,k 1
⎪ dt Ts
⎩
Furthermore, linear current variation during one sample period [k-1,k] is assumed in P-
controller, yielding that the current can be approximated with their average levels
⎧
⎪ id ,k id ,k id ,k 1
⎪
2 (3.55)
⎨
i i
⎪i
q, q,k q , k 1
⎩ 2
k
Since the sampling frequency usually is several times faster than the dynamics of the grid, the
voltage can be assumed to be constant within one sample period, i.e.
⎧⎪vd ,k vd ,k 1
⎨ (3.56)
⎪⎩vq,k vq,k 1
which results in
⎧ i*
i i* i* i
i
q ,k q,k
L d ,k d ,k
⎪u L R d ,k d ,k vd ,k
d ,k Ts 2 2
⎪
1 (3.59)
⎨ i
*
i i
*
i
*
⎪ i i
q,k q, k d ,k d ,k d ,k q,k
⎪uq,k 1 L L R vq,k
⎩ Ts 2 2
⎪
n0
k 1 (3.61)
⎨
⎪i
q,k i n iq n
q
*
⎪
⎩ n0
⎧ ⎛
1 k 1 ⎞ i* i
d
i
q,k
⎪u* K ⎜ i* *
n i n⎟K q, v
i Ti n0 k
(3.62)
d ,k 1 p d d, d c d ,k
⎪
⎨ ⎠ 2
,k⎛⎝
k
⎪ 2i
⎞
1 k 1 i*
u*
K
⎜ i*
i
i q
*
ni n⎟K d ,k d ,k
v
⎪ q,k 1 p ⎜ q,k q,k Ti n0 q ⎟⎠ c q,k
⎩ ⎝
where
⎛ L R⎞
K p ⎜ ⎟
⎝ Ts 2 ⎠
⎛ L R⎞ ⎛ L 1⎞
Ti R
⎜ 2 ⎟ 1 ⎜ RT 2 ⎟ (3.63)
T ⎝s ⎠ ⎝ s ⎠
Kc L
The reference voltage is then transformed from dq-frame to αβ-frame. Then the αβ reference
voltage is transformed to three-phase voltage references.
Anti Windup
If a control error e(t) remains for a longer time it is likely that the integral part becomes too
large and introduces windup and saturates the control signal. Mathematically, the saturation
can be seen as a nonlinear reduction in gain
⎧umax
u umax
r
u ⎨ umin u max (3.64)
⎪ u
u
⎪
u u umin
⎩ min
In such a case the integral part of the controller must be limited. This is done by giving the
integral part the value of the output control signal subtracted with the proportional part. It can
best be described by the following code,
I_temp = K*(Ts/Ti)*(i_ref - i) + I;
u_ref = K*(i_ref - i) + I;
The weak aspect of sinus modulation is that the maximum DC-link voltage is not utilized in
an optimal way. Consider the three phases where one phase is at its maximum and in the
same moment the other two phases are at their half negative U dc , see Figure 3.11. The
maximum phase potential will then be U dc /2, and thus also the maximum phase voltage of the
load. This means that the maximum phase-to-phase voltage is less than U dc , which indicates
that sinusoidal modulation does not take full advantage of the DC-link voltage. Since there is
no common ground, there are two independent references in the -frame but there are three
phase voltage references. The third degree of freedom is used to control the potential v0 to
optimize the modulation. The potential can only be influenced with a zero sequence signal,
thus an arbitrary signal uz* can be subtracted from the phase potential references. The adjusted
references becomes
⎧u * u * u *
a a z
⎪u* u * u*
⎨ (3.65)
⎪ b* b
*
z
*
⎪⎩u c uc uz
To maximize the use of the DC-link voltage the signal uz* are used. If uz* is selected according
to Equation (3.66), the phase references will be symmetric, i.e. the most positive and the most
negative of the three phase references will have the same instantaneous level.
*
max u* , u * , u * min u* , u* , u*
uz a b c a b c (3.66)
2
Udc/2
uabc* [V]
-Udc/2
0 0.005 0.01 0.015 0.02
t [s]
The phase voltages and the phase potentials are no longer equal since the phase potentials
contain the symmetric signal uz*. The phase voltages of the load are still sinusoidal, since the
phase-to-phase voltage references are sinusoidal, but the phase potential references are not.
Figure 3.12 shows the generation of the signals when using triangular PWM. The voltage
references vary slowly compared to the triangular carrier wave if the pulse ratio between the
switching frequency and the fundamental voltage references is sufficiently high. The high
pulse ratio results in that the voltage harmonics that the PWM converter produces only appear
near multiples of the carrier frequency i.e. the switching frequency. The LC-filter is absorbing
most of the PWM switching harmonics and prevent the harmonics from getting to the utility
grid or the load.
Generator: Sn = 2 kVA
The DC-link voltage is 270 V and the phase-to-phase voltage on the AC side is 145 V. The
gains for the droop functions are determined from the maximum deviation in frequency and
voltage, set to =0.005 and v=0.04. The current controller gain is set to 0.2 times the
deadbeat gain to get a stable controller. The estimator bandwidth and the filter cut-off
frequency are set to
23
24 Simulations
These equations are then implemented in SIMULINK to obtain a model of the output filter.
In the same manner the grid model is designed with an inductance in series with a resistance.
The generator is modelled with an emf in series with an inductor and a resistor.
4.2 Dynamic Properties of Active and Reactive Load Changes
The microgrid model shown in Figure 4.1 is designed in S IMULINK. The grid parameters are
chosen to Lg=0.3mH and Rg=0.1.
a)
148
146
v1qf [V]
144
142
140
b)
315
1 [rad/s]
314
313
c)
2000
1000
P1 [W]
-1000
d)
2000
Q1 [VAr]
1000
-1000
0 0.5 1 1.5 2 2.5 3
t [s]
Figure 4.3 Converter 1 a) output voltage, b) frequency, c) active power and d) reactive power.
a)
148
146
v2qf [V]
144
142
140
b)
315
2 [rad/s]
314
313
c)
2000
1000
P2 [W]
-1000
d)
2000
Q2 [VAr]
1000
-1000
0 0.5 1 1.5 2 2.5 3
t [s]
Figure 4.4 Converter 2 a) output voltage, b) frequency, c) active power and d) reactive power.
When the active power is connected the frequency drops and the sources starts to deliver
active power corresponding to the frequency drop and each individual droop function. It is
also obvious in Figure 4.3 and Figure 4.4 that the voltage drops at the same time but then
recovers fast to the nominal voltage 145V. This is caused by the cross coupling between id
and iq in Equation (3.4) and (3.5) for the converter.
At t= 2.0 s reactive power is connected and the voltage therefore drops. In the same manner
as for active power, the cross coupling makes the frequency increase temporary and it is then
stabilized at a value, determined by the active power.
Although the estimated frequency and the measured voltage are filtered with low bandwidth,
the step response is very fast when the power is changed.
As seen in Figure 4.3 and Figure 4.4 the two source converters share the total load according
to their nominal power. This is taken care of by the droop controller. The total reactive power
produced by the converters is less than 1875 VAr because the capacitors in the output filters
make a contribution to the total produced reactive power.
Synchronous Generator
In this simulation three converters are connected together with a synchronous generator in a
microgrid. A droop controller just like the slow droops controlling in the converters controls
the generator. Frequency is controlled by controlling the torque feed into the generator and to
regulate the voltage the field current is adjusted.
a)
148
146
v1qf [V]
144
142
140
b)
315
1 [rad/s]
314
313
c)
2000
1000
P1 [W]
-1000
d)
2000
Q1 [VAr]
1000
-1000
0 0.5 1 1.5 2 2.5 3
t [s]
Figure 4.5 Measurements from converter 1 connected in a microgrid with 3 converters and a generator.
a) output voltage, b) frequency, c) active power and d) reactive power.
a)
148
146
[V]
144
qf,gen
142
v
140
b)
315
gen [rad/s]
314
313
c)
2000
Pgen [W]
1000
-1000
d)
2000
Qgen [VAr]
1000
-1000
0 0.5 1 1.5 2 2.5 3
t [s]
Figure 4.6 Measurements from synchronous generator connected together with three converters.
a) output voltage, b) frequency, c) active power and d) reactive power.
Figure 4.5 and Figure 4.6 shows the result from converter 1 and the generator. Just like
before, a load of 1875 W at t=1.0 s and 1875 VAr at t =2.0 s is connected.
The frequency is now much more stable because the generator has inertia and does not
change speed fast. When rotating generators are connected in the grid it gets easier for the
converter controllers, they do not have to control the frequency alone. At the same time the
voltage also gets more stable. The load sharing controlled by the droops still works well.
5 Experimental Verifications
To verify the simulation results the controller is implemented in a DSP-processor controlling
the converters.
Figure 5.1 Converter station 1 and 2. At the bottom of the picture the output filters with inductors and
capacitors can be seen.
In order to study the behaviour of the converters, when connected in a grid with rotating
generators, a 2 kVA synchronous generator driven by a DC-machine is used, see Figure 5.2.
The generator is droop controlled with the droop functions shown in Figure 3.5.
29
30 Experimental Verifications
sampling_period = 1.0E-4
_floating_point_type(64,IEEE)
_integer_type(32)
group "Model"
enable flt
Sn flt
endgroup
Note that there has to be an empty line before endgroup.
In the SDF file it is only the type of dSPACE board and the filename that has to be changed.
[RTP]
Type=DS1104
BoardName=ds1104
File=regsys.ppc
TraceFile=regsys.trc
[System]
Version=1.0
Status=Start
RTP=RTP
SystemType=SingleProcessorSystem
To compile the files, open a DOS window and go to the directory where the experiment is
saved. Then type down1104 regsys, where 1104 is the type of dSPACE card and regsys
is the experiment name.
ControlDesk
After compilation and downloading, the parameters listed in the TRC file are available in
ControlDesk.
To create a new experiment chose File-New Experiment, then type the name of the
experiment and the working root. Open the files created before and chose File - Add All
Opened Files, to add the files to the experiment.
Figure 5.4 Example of layout in ControlDesk.
A new layout is created by choosing File - New - Layout. Then different instruments are
chosen from the instrumentation list, see Figure 5.4. Instruments are inserted in the layout by
clicking at them in the list and then draw a box in the layout. The instrument is then marked
by a red rectangle, indicating that no signal is connected to it. Signals are connected to the
instrument by dragging them from the variable list to the instrument. To do this the
instrumentation panel Edit mode is selected. To run the program the Animation mode is
selected.
The variables displayed in the plots can also be saved to a file. To do this the instrument
Capture settings is chosen from the instrument list. The data capture is started
manually or by a trigger variable chosen from the variable list. Different settings can be used,
for example rising or falling edge, trigger level and delay. When the button Save is pushed a
MAT-file is created. To use the MAT-file in MATLAB the following lines are useful.
time=double(filename.X.Data’);
signal1=double(filename.Y(1).Data’);
signal1description=filename.Y(1).Name
C-code
SIMULINK models can be compiled and downloaded direct to dSPACE. Disadvantage with
this method is that the user does not have full control over the generated code. The code gets
very large and the executing time therefore very long. With the model earlier created in
SIMULINK it would be impossible to run the generated code with the desired sample
frequency. Therefore the controller is hand coded in C. The execution time is then about 30
s. With a sampling time of 100 s there is plenty of time for further calculations.
The code is structured so that all calculations are made in the PWM-interrupt. The interrupt
occur once each switching period. Due to this construction the sample frequency equals the
switching frequency. The sampling then occurs at the negative peak of the triangular wave,
see Figure 3.12.
/* write PWM Duty cycle to slave DSP and test for error */
ds1104_slave_dsp_pwm3_duty_write(task_id, index, duty1, duty2, duty3);
Then it is time to read the signals from the A/D-converter. In the version of dSPACE used in
this project there are four muxed and four unmuxed channels. In this case only one of the
muxed channels is used. All A/D-converters are started at the same time and then their values
are read. When more than one of the muxed channels is used they have to be started with
delay to synchronize all the read values.
The measured signals are adjusted according to the scaling factors of the measuring cards.
ds1104_adc_start(DS1104_ADC2|DS1104_ADC3|DS1104_ADC4|DS1104_ADC5);
ds1104_adc_read_mux(scantable, 4, u);
Udc = u[3];
ia = ds1104_adc_read_conv(2);
ib = ds1104_adc_read_conv(3);
valfa = ds1104_adc_read_conv(4);
vbeta = ds1104_adc_read_conv(5);
Udc = Udc*408;
ia = ia*25;
ib = ib*25;
valfa = valfa*v_adj;
vbeta = vbeta*v_adj;
The signals read from the voltage measurement card are in the -frame. By definition the
voltage over the capacitor, in the output filter, is only in the q direction. Due to this fact the
voltage vq can easily be calculated as the absolute value of the -components. The phase
voltages are also calculated.
Only the a- and b-phase currents are measured and assuming symmetry, the current in phase
c is calculated. Then the phase currents are converted to the -frame and later on to the dq-
frame. To do this the angle theta_hat_old, calculated at previous sample, is used.
/*--------------------Calculation of vq-----------------------------*/
vq = sqrt((valfa*valfa)+(vbeta*vbeta));
/*--------------------Vectors to abc--------------------------------*/
va = sqrt(0.66666667)*valfa;
vb = -sqrt(0.16666667)*valfa + sqrt(0.5)*vbeta;
vc = -sqrt(0.16666667)*valfa - sqrt(0.5)*vbeta;
/*--------------------Calculation of i_alfa,beta--------------------*/
ic = -ia-ib;
sym = (ia+ib+ic)/3;
ia = ia-sym;
ib = ib-sym;
ic = ic-sym;
ialfa = sqrt(3/2)*ia;
ibeta = sqrt(0.5)*(ib-ic);
/*--------------------ab to dq--------------------------------------*/
id = ialfa*sin(theta_hat_old) - ibeta*cos(theta_hat_old);
iq = ialfa*cos(theta_hat_old) + ibeta*sin(theta_hat_old);
Filters with different cut-off frequencies are used to filter the voltage vq.
/*--------------------Low-pass Filter-------------------------------*/
Different kinds of protection are used. It is important to have protection so the switching does
not start without any DC-link voltage, Udc, which would lead to short circuit like behaviour,
until the DC-link capacitors are charged, if the converter is connected to the grid at the AC
side. The over voltage protection is based on the unfiltered signal to be able to trip fast if an
error occurs. Under-voltage is not so critical and is therefore based on a filtered voltage to
avoid tripping when a large step in power is made. Then the unfiltered voltage reaches almost
zero for a moment. Under-voltage protection is operating only when the switching is on,
otherwise it would be impossible to start the converter.
When a fault occurs enable is set to zero and then the switching stops. The variable
error_type indicates which kind of fault it is.
The frequency and angle estimator described in Equation (3.37) and (3.38) is then
implemented. The estimated frequency is limited between 49 and 50 Hz to make the start up
easier. When the converter is running the frequency never reaches these limits.
The angle is linearly increased and to avoid overflow in the processor the angle is subtracted
with 2 every period.
When the switching is off, converter_on==0, the frequency is fixed to 50 Hz plus a term
w_adj. w_adj is given by the synchronization algorithm, described later on.
/*--------------------Estimator-------------------------------------*/
w_hat=w_hat_old+((ra_w*ra_w*Ts)*(-ud_ref_old+(R*id_ref_old)-
(w_hat_old*L*iq_ref_old)))/Eqn;
theta_hat=theta_hat_old+w_hat_old*Ts+((2*ra_w*Ts)*
(-ud_ref_old+(R*id_ref_old)-(w_hat_old*L*iq_ref_old)))/Eqn;
if(w_hat<(2*PI*49))
w_hat = 2*PI*49;
if(w_hat>(2*PI*51))
w_hat = 2*PI*51;
if(theta_hat_old>(2*PI))
{
theta_hat = theta_hat - (2*PI);
theta_hat_old = theta_hat_old - (2*PI);
}
if(converter_on ==0)
{
w_hat = (2*PI*50)+w_adj;
}
//LP-filter4 5Hz
wf4 = ((w_hat-wf4_old)*w4*Ts)+wf4_old;
The droop controller is implemented according to Equation (3.21), (3.22), (3.19), and (3.20).
When aut==1 the droop controller is in action, aut==2 means that the power reference
values are set to zero and the converter is operating at no load. In this case the old current
references, and the integral part, of the current controller are set to zero to make the controller
start without any old values. The error from the previous values could otherwise result in
large transients. The references can also be manually set. This is used when the converter is
operating as load, the desired load is defined by P_ref_man and Q_ref_man.
The determined power references are recalculated to current references and these are limited
to the maximum output current imax.
/*--------------------Droop controller------------------------------*/
if(aut==1)
{
//Slow droops
vq_ref = vqf2_old + (Kw/Kv)*(wn-wf4_old);
w_ref = wf4_old - (Kv/Kw)*(Eqn-vqf2_old);
//Fast droops
P_ref = Kv*(vq_ref-vqf1);
Q_ref = -Kw*(w_ref-w_hat_old);
}
//Idling
else if(aut==2)
{
P_ref = 0;
Q_ref = 0;
id_ref_old = 0;
iq_ref_old = 0;
ud_I = 0;
uq_I = 0;
}
/*--------------------P,Q to idq------------------------------------*/
id_ref = Q_ref/vqf3_old;
iq_ref = P_ref/vqf3_old;
//Current limitation
if(id_ref > imax)
id_ref = imax;
According to Equation (3.62) and (3.63) the current controller is implemented together with
the anti-windup introduced in Equation (3.64).
/*--------------------Current controller----------------------------*/
ud_I_temp = K_adj*K*(Ts/Ti)*(id_ref-id) + ud_I;
uq_I_temp = K_adj*K*(Ts/Ti)*(iq_ref-iq) + uq_I;
//Anti-windup
if(ud_ref>umax)
{
ud_ref = umax;
ud_I = umax - (K_adj*K*(id_ref-id));
}
else if(ud_ref<umin)
{
ud_ref = umin;
ud_I = umin - (K_adj*K*(id_ref-id));
}
else
{
ud_I = ud_I_temp;
}
if(uq_ref>umax)
{
uq_ref = umax;
uq_I = umax - (K_adj*K*(iq_ref-iq));
}
else if(uq_ref<umin)
{
uq_ref = umin;
uq_I = umin - (K_adj*K*(iq_ref-iq));
}
else
{
uq_I = uq_I_temp;
}
The calculated voltage references are transformed back to the -frame and then to phase
voltage refererences. Then the phase voltage references are symmetrized to be able to use as
much of the DC-link voltage as possible and avoid overmodulation, see Equation (3.65) and
(3.66) and Figure 3.11. The resulting phase potential references are then recalculated to PWM
duty cycle. The duty cycle is defined between zero and one, where one equals half the DC-
link voltage.
/*--------------------dq to ab--------------------------------------*/
ualfa_ref = ud_ref*sin(theta_hat_old) + uq_ref*cos(theta_hat_old);
ubeta_ref = -ud_ref*cos(theta_hat_old) + uq_ref*sin(theta_hat_old);
/*--------------------Vectors to abc--------------------------------*/
ua_ref = sqrt(0.66666667)*ualfa_ref;
ub_ref = -sqrt(0.16666667)*ualfa_ref + sqrt(0.5)*ubeta_ref;
uc_ref = -sqrt(0.16666667)*ualfa_ref - sqrt(0.5)*ubeta_ref;
/*--------------------Symmetry--------------------------------------*/
max=ua_ref;
if(ub_ref>max)
max=ub_ref;
if(uc_ref>max)
max=uc_ref;
min=ua_ref;
if(ub_ref<min)
min=ub_ref;
if(uc_ref<min)
min=uc_ref;
uz_ref=(max+min)/2;
ua_ref = ua_ref-uz_ref;
ub_ref = ub_ref-uz_ref;
uc_ref = uc_ref-uz_ref;
Values are written to the D/A-converter to be ready when the strobe pulse comes at the next
sampling instant.
/*--------------------DAC-------------------------------------------*/
ds1104_dac_write(1,(valfa/300));
ds1104_dac_write(2,(ualfa_ref/300));
At the end of the interrupt the values calculated during this sampling interval are set as old
values for the next sampling interval. Then the execution time is read.
/*--------------------Uppdate variables-----------------------------*/
vqf1_old = vqf1;
vqf2_old = vqf2;
vqf3_old = vqf3;
w_hat_old = w_hat;
theta_hat_old = theta_hat;
wf4_old = wf4;
ud_ref_old = ud_ref;
id_ref_old = id_ref;
iq_ref_old = iq_ref;
exec_time=RTLIB_TIC_READ();
In the beginning of the main program initialization is performed for the DSP card, the digital
IO, communication between master- and slave-DSP and the D/A-converter. For further
information about initialization see dSPACE help/DS1104 RTLib Reference [13].
The infinite loop of the main program takes care of start and stop of the PWM interrupt and
the initial values are also set here.
station==1 should be selected at the station started first in the standalone grid, then the
synchronization is inactive at startup. To be able to synchronize the other stations the zero
crossings for the measured voltage va and the reference voltage ua_ref are detected. The
number of samples between the two zero crossings are counted, if the number of samples
equals a phase error less than 3.6 degrees, i.e. 200 s, the switching starts. If the error is
larger than 3.6 degrees the frequency of u_ref is adjusted. The frequency is increased in
proportion to the phase error and therefore approaches 50 Hz when the error becomes
smaller. The reason for choosing 3.6 degrees is that this equals two samples. A smaller error
is hard to detect. The gain in the frequency adjustment is chosen to get a smooth
synchronization.
/*--------------------Synchronization-------------------------------*/
if(fas==0 && station!=1)
{
if(va>20)
{
trigg1 = 1;
}
if(ua_ref>20 && trigg1==1)
{
trigg2 = 1;
}
//va zero crossing
if(trigg1==1 && va<10 && va>-10 || count!=0)
{
count = count+1;
}
//ua_zero crossing
if(trigg2==1 && ua_ref<10 && ua_ref>-10 && count!=0)
{
error = count;
count = 0;
}
if(error!=0)
{
//start the switching if the error is less than 3.6 degrees
if(((error*Ts)/20e-3)<0.01)
{
fas = 1;
on = 1;
}
else
{
w_adj = ((2*PI*error*Ts)/20e-3);
error = 0;
trigg1 = 0;
trigg2 = 0;
}
}
}
v1qf [V]
144
142
140
b)
315
1 [rad/s]
314
313
c)
2000
1000
P1 [W]
-1000
d)
2000
Q1 [VAr]
1000
-1000
0 0.5 1 1.5 2 2.5 3
t [s]
Figure 5.7 Connecting first active then reactive load. Converter 1 a) output voltage, b) frequency, c) active
power and d) reactive power.
a)
148
146
v2qf [V]
144
142
140
b)
315
2 [rad/s]
314
313
c)
2000
1000
P2 [W]
-1000
d)
2000
Q2 [VAr]
1000
-1000
-0 0.5 1 1.5 2 2.5 3
t [s]
Figure 5.8 Connecting first active then reactive load. Converter 2 a) output voltage, b) frequency, c) active
power and d) reactive power.
The most important thing to note is that the voltage and frequency control operates well. In
less than half a second both voltage and frequency has stabilized after the step in power.
Although there are some oscillations in voltage and frequency, they are well within their
limits. The maximum deviations are v 0.05 and 0.004 which equals a voltage
between 137.8 and 152.3 V and a frequency between 312.9 and 315.4 rad/s.
The cross coupling between P and Q is obvious in Figure 5.7 and Figure 5.8.
Also the case with connecting reactive load first and then active load has been studied. In this
case, see Figure 5.9, the cross coupling gets more obvious but the controller has no problem
controlling both voltage and frequency.
a)
148
146
v1qf [V]
144
142
140
b)
315
1 [rad/s]
314
313
c)
2000
1000
P1 [W]
-1000
d)
2000
Q1 [VAr]
1000
-1000
0 0.5 1 1.5 2 2.5 3
t [s]
Figure 5.9 Connecting first reactive then active load. Converter 1 a) output voltage, b) frequency, c) active
power and d) reactive power.
v1qf [V]
144
142
140
b)
315
1 [rad/s]
314
313
c)
2000
1000
P1 [W]
-1000
d)
2000
Q1 [VAr]
1000
-1000
1 1.5 2 2.5 3 3.5 4
t [s]
Figure 5.10 Disconnecting active and reactive load at the same time. Converter 1 a) output voltage, b)
frequency, c) active power and d) reactive power.
v1qf [V]
144
142
140
b)
315
1 [rad/s]
314
313
c)
2000
1000
P1 [W]
-1000
d)
2000
Q1 [VAr]
1000
-1000
0 0.5 1 1.5 2 2.5 3
t [s]
Figure 5.11 Synchronous generator together with three converters in a microgrid. Converter 1 a) output
voltage, b) frequency, c) active power and d) reactive power.
5.6 Synchronization
To be able to connect converter to a grid, a synchronization algorithm is needed. The grid
voltage is measured and the controllers of the converters are running, but with the switching
turned off. The zero crossings are detected and the phase difference between the converters
coordinate system and the grid coordinate system is measured. To synchronize the two
coordinate systems the frequency of the converter is increased proportional to the phase error.
When the phase error is less than a two samples, equal to 3.6 degrees, switching is turned on.
a)
148
146
v2qf [V]
144
142
140
b)
318
2 [rad/s]
316
314
312
c)
500
P2 [W]
-500
d)
500
Q2 [VAr]
-500
0 1 2 3 4 5 6 7
t [s]
Figure 5.12 Synchronisation of converter 2 a) output voltage, b) frequency, c) active power and d) reactive
power.
At t= 1.0 s the synchronization algorithm is turned on and the frequency is adjusted to bring
the two coordinate systems in phase. In about 3.6 seconds the phase error is small enough and
the switching starts. The converter operates at no load for 0.5 s and then the controller is
turned on and is ready to take up load. This gives a very smooth synchronization with only a
small amount of power transmitted at connection.
The disadvantage of this method is that the frequency of the converter is always increased, no
matter how big the phase error is, this means that in some cases the coordinate system needs
to be adjusted a full period. This can take up to a few seconds, especially when a smooth
synchronization is desirable.
When using converters, the increased level of harmonics may become a problem. The amount
of harmonics as well as their spectrum depends on the type of converter applied and the type
of modulation used. The PWM converter that is used generates harmonics around multiples
of its switching frequency. Traditionally there have been no limits or recommendation to the
harmonics at switching frequencies. Older thyristor converters generate 5 th, 7th, 11th, 13th (and
so on) harmonics of the 50 Hz fundamental frequency. The total harmonic distortion (THD)
of the current is usually high and above the standard limits without proper filtering. In this
case with an output filter on the converter, with a cut-off frequency at 500 Hz, the multiples
of the switching frequency are suppressed. This can be seen from Figure 5.15.
6 Conclusions
A control algorithm for parallel connected converters in a standalone grid was developed. The
use of microsources connected together to a grid often needs power electronics to convert the
produced DC to AC at the correct frequency and voltage. Communication is often impractical
because the mobility of the sources is lost. To overcome this problem a droop controller is
developed. The droop controller is controlling both frequency and voltage based on locally
measured quantities. The voltage and current output from the converter is measured and the
frequency is estimated from these measurements and the converter control signals. With
droop control the converters take up load proportional to their nominal power without any
communication. The controller is based on the fact that the frequency in the grid depends on
the produced active power and the voltage depends on the reactive power.
The first case studied was a standalone microgrid with only converters. One converter was
acting as load and the other two as sources. When a step in power was performed frequency
and voltages decreased and the sources started to produce power. Load sharing was operating
well and both frequency and voltage was stable and well within the limits. Disconnection of a
load was also handled well by the converters.
Then the case with a synchronous generator, connected together with the converters, was
investigated. The generator was droop controlled just like the converters. This case is more
likely in a real power grid, which mostly contains rotating generators. The generator was
keeping the frequency more stable, which means that the converter control becomes easier.
This results in a good control and load sharing also with rotating generators.
A problem with droop control is when the distance between the sources is long and the
impedance increases. Then the voltage is not the same in the entire grid and leads to an error
in load sharing of reactive power. Controlling the active power is much easier due to the fact
that the frequency is the same in the entire grid, when operating in steady state.
The line voltage and current appears to be almost sinusoidal according to the spectrums
made, the harmonics have very low magnitudes, meaning the curves are almost sinusoidal.
51
References
[1] M. Alaküla, “Power Electronic Control” Department of Industrial Electrical
Engineering and Automation, Lund Institute of Technology, Lund, Sweden 2003.
[2] J. D. Glower, M. S. Sarma, “Power System – Analysis and Design” 3:rd edition, 2002.
[3] L. Harnefors, H. P. Nee, “A General Algorithm for Speed and Position Estimation of
AC Motors”, IEEE trans. Power Electronics, vol 47, no. 1, pp. 77-83, Feb. 2000.
[7] M.C. Chandorkar, D.M. Divan and R. Adapa, “Control of Parallel Connected Inverters
in Standalone AC Supply Systems”, IEEE trans. Industry Applications, vol. 29, no. 1,
pp.136-143, Jan./Feb. 1993.
[9] Y. Li, M. Vilathgamuwa and P.C. Loh, “Design, analysis, and Real-Time Testing of a
Controller for Multibus Microgrid System”, IEEE trans. Power Electronics, vol. 19,
no. 5 pp. 1195-1204, Sept. 2004.
[10] A. Engler, “Applicability of Droops in Low Voltage Grids”, Der Journal, no. 1,
Jan.2005.
[11] S. Wijnbergen and S.W.H. de Haan, “Power Electronic Interface with Independent
Active and Reactive Power Control for Dispersed Generators to Support Grid Voltage
and Frequency Stability”, EPE 2003 Conf. Proc., Toulouse, France, Sept. 2-4, 2003,
CD-ROM page 8.
[12] P. Karlsson and J. Svensson, “Voltage Control and Load Sharing in DC Distribution
Systems”, EPE 2003 Conf. Proc., Toulouse, France, Sept. 2-4, 2003, CD-ROM page
10.
[13] DS1104 R&D Controller Board, RTLib Reference, Release 3.4, dSPACE GmbH, May
2002.
53
Appendix A – Vector Transformation
The transformations derived in this appendix are used when analyzing three phase systems
dynamically. By using this transformation, the voltage and current instantaneous values can
be transformed between three-phase system and αβ-frame, and, between αβ-frame and dq-
frame. The transformations are power invariant.
where K is a scaling. It is often selected equal to 2 3 to achieve power invariance. Also, the
sum of the three-phase voltages will be zero when no conductor is connected to the neutral
point of the three-phase system, i.e.,
v1t v2 t v3 t 0
(A.2)
Then Equation (A.1) can be expressed as a matrix equation
⎡ v t ⎤
⎡⎢v1t ⎤
⎢⎥ ⎥ T v t (A.3)
⎣v t ⎦
⎢2 ⎥
⎢⎣v3 t ⎥⎦
where
⎥⎦
⎡ 2 ⎤
⎤ ⎢ 0 ⎥
0 0 ⎥ ⎢ 3 ⎥
⎥ 1 1 ⎥ (A.5)
⎡ 3
1
T
1 ⎢
⎢
T⎢ 2 2 1 ⎥
⎢0 ⎢ 6 2⎥
⎢1 1⎥
⎣⎢ 2 ⎥⎦
⎢ ⎥
⎣ 6 2⎦
55
56 Appendix A – Vector Transformation
The transformation equation from the αβ-frame to the dq-frame becomes, in matrix form
⎡vd t ⎤ ⎡v t ⎤
⎢v t ⎥ Rdq t ⎥ (A.6)
⎢v
⎣ q ⎦ ⎣ ⎦
and the inverse are
⎡v t ⎤ ⎡vd t ⎤
⎢v t ⎥
R dq t ⎥ (A.7)
⎢v
⎣ ⎦ ⎣ q ⎦
/*-----------------------------------------------------------------------*/
#define PI 3.141592654
/*cut of frequency*/
Float64 w1 = 2*PI*4;
Float64 w2 = 2*PI*1;
Float64 w3 = 2*PI*0.5;
Float64 ra_w = 2*PI*5.3558;
Float64 w4 = 2*PI*5;
/*constants*/
Float64 Eqn = 145;
Float64 wn = 2*PI*50;
Float64 delta_v = 0.04;
Float64 delta_w = 0.005;
Float64 Udc = 0;
Float64 K, Kc, Ti;
57
58 Appendix B – Controller C-
code
volatile Float64 Sn = 4500;
volatile Float64 K_adj = 0.2;
volatile Float64 enable = 0;
volatile Float64 aut = 1;
volatile Float64 P_ref_man = 100;
volatile Float64 Q_ref_man = 100;
volatile Float64 on = 0;
volatile Float64 station = 1;
volatile Float64 tid = 0;
/*Variables*/
Float64 duty1, duty2, duty3 ;
Float64 vq;
Float64 vqf1_old, vqf2_old, vqf3_old;
Float64 vmax, vmin;
Float64 sample = 0;
Float64 error_type = 0;
Float64 off = 1;
Float64 converter_on = 0;
Float64 fas = 0;
Float64 count = 0;
Float64 error = 0;
Float64 trigg1 = 0;
Float64 trigg2 = 0;
Float64 max, min, uz_ref, duty1_temp, duty2_temp, duty3_temp;
Float64 theta;
Float64 ud_I, uq_I, ud_I_temp, uq_I_temp, umax, umin;
Float64 Udc_test;
UInt16 scantable[4] = {1, 2, 3, 4};
Float64 u[4];
void PWM_sync_interrupt(void)
{
/*--------------------------------On/Off-------------------------------*/
if(Udc>250 && station==1 && off==1 && enable==1)
{
aut = 1;
on = 1;
}
else if(off==1 && enable==1)
{
aut = 2;
}
if(station==1)
{
vqf1_old = Eqn;
vqf2_old = Eqn;
vqf3_old = Eqn;
w_hat_old = 2*PI*50;
theta_hat_old = 0;
wf4_old = 2*PI*50;
}
ds1104_bit_io_set(DS1104_DIO11);
sample=0;
tid = 0;
error_type = 0;
off = 0;
converter_on = 1;
}
else if(on==0 && off==0) //Off
{
ds1104_bit_io_clear(DS1104_DIO11);
off = 1;
converter_on = 0;
}
if(converter_on ==1)
{
sample = sample+1;
}
/*---------------------------------Startup sequence-------------------*/
if(sample < 10000) //Change limits after one second
{
imax = 20;
vmax = 300;
vmin = 0;
K_adj = 0.20;
}
else if(sample == 10000)
{
imax = 20;
vmax = 250;
vmin = 130;
K_adj = 0.20;
}
/*---------------------------------------------------------------------*/
host_service(1, 0); /* Data Acquisition service */
RTLIB_TIC_START(); /* start time measurement */
/* write PWM Duty cycle to slave DSP and test for error */
ds1104_slave_dsp_pwm3_duty_write(task_id, index, duty1, duty2, duty3);
ia = ds1104_adc_read_conv(2);
ib = ds1104_adc_read_conv(3);
valfa = ds1104_adc_read_conv(4);
vbeta = ds1104_adc_read_conv(5);
//signalanpassning
ia = ia*25;
ib = ib*25;
valfa = valfa*v_adj;
vbeta = vbeta*v_adj;
Udc = Udc*408;
/*--------------------------------Calculation of vq--------------------*/
vq = sqrt((valfa*valfa)+(vbeta*vbeta)); //voltage over capacitor
/*---------------------------------Vectors to abc----------------------*/
va = sqrt(0.66666667)*valfa;
vb = -sqrt(0.16666667)*valfa + sqrt(0.5)*vbeta;
vc = -sqrt(0.16666667)*valfa - sqrt(0.5)*vbeta;
/*---------------------------------Calculation of i_alfa,beta----------*/
ic = -ia-ib;
sym = (ia+ib+ic)/3;
ia = ia-sym;
ib = ib-sym;
ic = ic-sym;
ialfa = sqrt(3/2)*ia;
ibeta = sqrt(0.5)*(ib-ic);
/*---------------------------------ab to dq----------------------------*/
id = ialfa*sin(theta_hat_old) - ibeta*cos(theta_hat_old);
iq = ialfa*cos(theta_hat_old) + ibeta*sin(theta_hat_old);
//id = ialfa*cos(theta_hat_old) + ibeta*sin(theta_hat_old);
//iq = ialfa*sin(theta_hat_old) - ibeta*cos(theta_hat_old);
/*---------------------------------Filtering---------------------------*/
//LP-filter1 4Hz
vqf1 = ((vq-vqf1_old)*w1*Ts)+vqf1_old;
//LP-filter2 1Hz
vqf2 = ((vq-vqf2_old)*w2*Ts)+vqf2_old;
//LP-filter3 0.5Hz
vqf3 = ((vq-vqf3_old)*w3*Ts)+vqf3_old;
/*---------------------------------Estimator---------------------------*/
w_hat = w_hat_old + ((ra_w*ra_w*Ts)*(-ud_ref_old+(R*id_ref_old)-
(w_hat_old*L*iq_ref_old)))/Eqn;
theta_hat = theta_hat_old + w_hat_old*Ts + ((2*ra_w*Ts)*
(-ud_ref_old+(R*id_ref_old)-(w_hat_old*L*iq_ref_old)))/Eqn;
if(w_hat<(2*PI*49))
w_hat = 2*PI*49;
if(w_hat>(2*PI*51))
w_hat = 2*PI*51;
if(theta_hat_old>(2*PI))
{
theta_hat = theta_hat - (2*PI);
theta_hat_old = theta_hat_old - (2*PI);
}
if(converter_on ==0)
{
w_hat = (2*PI*50)+w_adj;
}
//LP-filter4 5Hz
wf4 = ((w_hat-wf4_old)*w4*Ts)+wf4_old;
/*---------------------------------Droops------------------------------*/
if(aut==1)
{
//Slow droops
vq_ref = vqf2_old + (Kw/Kv)*(wn-wf4_old);
w_ref = wf4_old - (Kv/Kw)*(Eqn-vqf2_old);
//Fast droops
P_ref = Kv*(vq_ref-vqf1);
Q_ref = -Kw*(w_ref-w_hat_old);
}
//Idling
else if(aut==2)
{
P_ref = 0;
Q_ref = 0;
id_ref_old = 0;
iq_ref_old = 0;
ud_I = 0;
uq_I = 0;
}
P_ref = P_ref_man;
//Current limitation
if(id_ref > imax)
id_ref = imax;
/*---------------------------------Current controller------------------*/
ud_I_temp = K_adj*K*(Ts/Ti)*(id_ref-id) + ud_I;
uq_I_temp = K_adj*K*(Ts/Ti)*(iq_ref-iq) + uq_I;
//Anti-windup
if(ud_ref>umax)
{
ud_ref = umax;
ud_I = umax - (K_adj*K*(id_ref-id));
}
else if(ud_ref<umin)
{
ud_ref = umin;
ud_I = umin - (K_adj*K*(id_ref-id));
}
else
{
ud_I = ud_I_temp;
}
if(uq_ref>umax)
{
uq_ref = umax;
uq_I = umax - (K_adj*K*(iq_ref-iq));
}
else if(uq_ref<umin)
{
uq_ref = umin;
uq_I = umin - (K_adj*K*(iq_ref-iq));
}
else
{
uq_I = uq_I_temp;
}
/*---------------------------------dq to ab----------------------------*/
ualfa_ref = ud_ref*sin(theta_hat_old) + uq_ref*cos(theta_hat_old);
ubeta_ref = -ud_ref*cos(theta_hat_old) + uq_ref*sin(theta_hat_old);
//ualfa_ref = ud_ref*cos(theta_hat_old) - uq_ref*sin(theta_hat_old);
//ubeta_ref = ud_ref*sin(theta_hat_old) + uq_ref*cos(theta_hat_old);
/*---------------------------------Vectors to abc----------------------*/
ua_ref = sqrt(0.66666667)*ualfa_ref;
ub_ref = -sqrt(0.16666667)*ualfa_ref + sqrt(0.5)*ubeta_ref;
uc_ref = -sqrt(0.16666667)*ualfa_ref - sqrt(0.5)*ubeta_ref;
/*---------------------------------symmetry----------------------------*/
duty1_temp = (ua_ref/Udc)+0.5;
duty2_temp = (ub_ref/Udc)+0.5;
duty3_temp = (uc_ref/Udc)+0.5;
max=ua_ref;
if(ub_ref>max)
max=ub_ref;
if(uc_ref>max)
max=uc_ref;
min=ua_ref;
if(ub_ref<min)
min=ub_ref;
if(uc_ref<min)
min=uc_ref;
uz_ref=(max+min)/2;
ua_ref = ua_ref-uz_ref;
ub_ref = ub_ref-uz_ref;
uc_ref = uc_ref-uz_ref;
/*---------------------------------Power calculation-------------------*/
P = iq*vqf1;
Q = (id*vqf1);
/*---------------------------------DAC---------------------------------*/
ds1104_dac_write(1, (valfa/300));
ds1104_dac_write(2, (ualfa_ref/300));
/*---------------------------------Synchronization---------------------*/
if(fas==0 && station!=1)
{
if(va>20)
{
trigg1 = 1;
}
if(ua_ref>20 && trigg1==1)
{
trigg2 = 1;
}
/*---------------------------------Update variables--------------------*/
vqf1_old = vqf1;
vqf2_old = vqf2;
vqf3_old = vqf3;
w_hat_old = w_hat;
theta_hat_old = theta_hat;
wf4_old = wf4;
ud_ref_old = ud_ref;
id_ref_old = id_ref;
iq_ref_old = iq_ref;
exec_time = RTLIB_TIC_READ();
}
/*-----------------------------------Main-------------------------------*/
void main(void)
{
init(); /* DS1104 and RTLib1104 initialization */
/*initiering av DIO*/
ds1104_bit_io_init(DS1104_DIO11_OUT); //bit_IO kanal 11 out
//ds1104_slave_dsp_pwm3_start(task_id);
ds1104_enable_hardware_int(DS1104_INT_SLAVE_DSP_PWM);
RTLIB_INT_ENABLE();
/*---------------------------------------------------------------------*/
/* Background tasks */
while(1)
{
if(enable==0 && stopp==0) //stop
{
ds1104_bit_io_clear(DS1104_DIO11);
ds1104_slave_dsp_pwm3_stop(task_id);
stopp=1;
ds1104_dac_write(1, stopp);
ds1104_dac_strobe();
converter_on = 0;
fas=0;
count = 0;
error = 0;
w_adj = 0;
}
else if(enable==1 && stopp==1) //start
{
/*-------------Constants---------------*/
Kw = Sn/(wn*delta_w);
Kv = Sn/(Eqn*delta_v);
K = (L/Ts)+(R/2);
Ti = ((L/R) + (Ts/2));
//Ti=0;
Kc = wn*L;
/*-------------Initial values----------*/
duty1 = 0.5;
duty2 = 0.5;
duty3 = 0.5;
vqf1_old = Eqn;
vqf2_old = Eqn;
vqf3_old = Eqn;
w_hat_old = 2*PI*50;
theta_hat_old = 0;
wf4_old = 2*PI*50;
id_ref_old = 0;
iq_ref_old = 0;
ud_ref_old = 0;
ud_I = 0;
uq_I = 0;
umax = 0.7*Udc;
umin = -0.7*Udc;
on = 0;
stopp=0;
sample=0;
error_type = 0;
fas = 0;
count = 0;
error = 0;
w_adj = 0;
trigg1 = 0;
trigg2 = 0;
ds1104_slave_dsp_pwm3_start(task_id);
}