Download Reference Frame Conversions with the ADMC331

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Electric machine wikipedia , lookup

Pulse-width modulation wikipedia , lookup

Three-phase electric power wikipedia , lookup

Transcript
a Reference Frame Conversions with the ADMC331
AN331-11
a
Reference Frame Conversions with
the ADMC331
AN331-11
© Analog Devices Inc., January 2000
Page 1 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
Table of Contents
SUMMARY...................................................................................................................... 3
1
INTRODUCTION TO REFERENCE FRAME THEORY............................................ 3
1.1
Overview..........................................................................................................................................................3
1.2
Three-phase to two-phase transformation (Clarke transformation) .........................................................3
1.3
Vector rotation (Park transformation) .........................................................................................................5
1.4
Practical implementation of the transformations ........................................................................................7
2
THE REFERENCE FRAME CONVERSION ROUTINES ......................................... 8
2.1
Using the conversion routines........................................................................................................................8
2.2
Formats of inputs and outputs.......................................................................................................................9
2.3
Usage of the DSP registers .............................................................................................................................9
2.4
The program code.........................................................................................................................................10
2.5
Access to the library: the header file...........................................................................................................11
3
SOFTWARE EXAMPLE: TESTING THE CONVERSION ROUTINES................... 13
3.1
The main program: main.dsp......................................................................................................................13
3.2
The main include file: main.h ......................................................................................................................16
3.3
Example output.............................................................................................................................................16
4
DIFFERENCES BETWEEN LIBRARY AND ADMC331 “ROM-UTILITIES” ......... 18
© Analog Devices Inc., January 2000
Page 2 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
Summary
The introduction of reference frames in the analysis of electrical machines has turned out not only to be
useful in their analysis but also has provided a powerful tool for the implementation of sophisticated
control techniques. This application note gives an introduction to the theory of the most commonly used
reference frames and provides routines that allow for easy conversion amongst them. They are
implemented in a library-like module for immediate and intuitive application.
1 Introduction to reference frame theory
1.1
Overview
As the application of ac machines has continued to increase over this century, new techniques have been
developed to aid in their analysis. Much of the analysis has been carried out for the treatment of the wellknown induction machine. The significant breakthrough in the analysis of three-phase ac machines was
the development of reference frame theory. Using these techniques, it is possible to transform the phase
variable machine description to another reference frame. By judicious choice of the reference frame, it
proves possible to simplify considerably the complexity of the mathematical machine model. While these
techniques were initially developed for the analysis and simulation of ac machines, they are now
invaluable tools in the digital control of such machines. As digital control techniques are extended to the
control of the currents, torque and flux of such machines, the need for compact, accurate machine models
is obvious.
Fortunately, the developed theory of reference frames is equally applicable to the synchronous machines,
such as the Permanent Magnet Synchronous Machine (PMSM). This machine is sometimes known as the
sinusoidal brushless machines or the brushless ac machine and is very popular as a high-performance
servo drive due to its superior torque-to-weight ratio and its high dynamic capability. It is a three-phase
synchronous ac machine with permanent-magnet rotor excitation and is designed to have a sinusoidal
torque-position characteristic.
The aim of this section is to introduce the essential concepts of reference frame theory and to introduce
the space vector notation that is used to write compact mathematical descriptions of ac machines. Over
the years, many different reference frames have been proposed for the analysis of ac machines. The most
commonly used ones are the so-called stationary reference frame and the rotor reference frame.
1.2
Three-phase to two-phase transformation (Clarke transformation)
Three-phase ac machines are conventionally modeled using phase variable notation. However, for a threephase, star-connected machine, the phase quantities are not independent variables so that:
i sA (t ) + i sB (t ) + i sC (t ) = 0
v sA (t ) + v sB (t ) + v sC (t ) = 0
(1)
ϕ sA (t ) + ϕ sB (t ) + ϕ sC (t ) = 0
© Analog Devices Inc., January 2000
Page 3 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
where is , vs and ϕs denote stator phase currents, voltages and flux linkages, respectively.
As a result of this redundancy in the phase variable representation it is possible to transform the system to
an equivalent two-phase representation. The transformation from three-phase to two-phase quantities is
written in matrix form as:
i sA ( t ) 
i sα ( t )  2 1 cos(γ ) cos(2 γ ) 

  i sB ( t ) 
i ( t )  = 
 sβ  3 0 sin(γ ) sin(2 γ )  i ( t ) 
 sC 
(2)
where γ =2π/3. The transformation is equally valid for the voltages and flux linkages. The stator current
space vector is defined as the complex quantity:
i s ( t ) = i sα ( t ) + ji sβ ( t )
(3)
and it is possible to write (2) more compactly as:
is ( t) =
2
2
i sA ( t ) + a i sB ( t ) + a i sB ( t )
3
[
]
(4)
where a is a vector operator that produces a vector rotation of γ = 2π/3 and is defined as:
a = exp( jγ ) = cos(γ ) + j sin(γ )
(5)
The choice of the constant in the transformations of (2) and (4) is somewhat arbitrary. Here, the value of
2/3 is adopted. Its main advantage is that magnitudes are preserved across the transformation. Therefore,
sinusoidal phase currents with a peak magnitude of Im produce a current space vector with a peak
magnitude of Im. For this transformation, the inverse relationship is written:
0 
i sA (t )   1
i (t )  =  cos(γ ) sin (γ )  i sα (t )
 sB  
 i sβ (t ) 

i sC (t ) cos(2γ ) sin (2γ ) 
(6)
As the aim of any digital current control scheme is to control current amplitude, it is felt that this form is
more suitable for control purposes. Transformation (2) and its counterpart (6) are denoted hereafter as the
Forward Clarke Transformation and the Reverse Clarke Transformation, respectively.
The space vector may be viewed in the complex plane as shown in Figure 1. The conventional magnetic
axes of the three machine phases are separated by γ = 2π/3. The real or sα axis of the new two-axis coordinate system is arbitrarily chosen to coincide with the sA axis. Obviously, the imaginary or jsβ axis
lies in quadrature with the sα axis. The current space vector is shown at an arbitrary location in the
complex plane. The phase currents may be obtained by projecting the current space vector onto the
respective phase axis.
© Analog Devices Inc., January 2000
Page 4 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
jsβ
β
sB Axis
i sC
is
γ
isA
sα
α
sA Axis
i sB
sC Axis
Figure 1: Relationship of stator current space vector and stator phase currents.
Consider the case of a balanced set of three-phase stator currents:
i sA = I m sin(θ − ϕ )
i sB = I m sin(θ − γ − ϕ)
(7)
i sC = I m sin(θ − 2 γ − ϕ )
where Im is the magnitude of the phase currents, θ = ωt is the angular position in radians and ϕ is the
phase angle. Using (2) the currents of (7) may be transformed to the equivalent two-phase representation
to give:
i sα = I m sin(θ − ϕ)
i sβ = − I m cos(θ − ϕ )
(8)
so that the current space vector of such a system may be written as:
i s = I m sin(θ − ϕ) − jI m cos(θ − ϕ )
= − jI me (θ − ϕ )
j
(9)
which describes a circular trajectory in the space vector plane.
Therefore, a balanced three-phase system in phase variables transforms to a circular locus in the
equivalent two-axis representation. The radius of the circle is the peak magnitude of the phase
quantities. The circular locus is described at a rate equal to the angular frequency of the phase
quantities.
1.3
Vector rotation (Park transformation)
The stator current, voltage and flux linkage space vectors are complex quantities defined in a reference
frame whose real axis is fixed to the magnetic axis of stator winding sA. However, the corresponding
quantities defined for the rotor circuit of a three-phase ac machine are similarly stated in a reference
© Analog Devices Inc., January 2000
Page 5 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
frame fixed to the rotor. In the analysis of electrical machines, it is generally necessary to adopt a
common reference frame for both the rotor and the stator. For this reason, a second transformation,
known as a vector rotation, is formulated that rotates space vector quantities through a known angle.
In the space vector diagram of Figure 1, the axes of the space vector plane are stationary. Meanwhile the
space vectors of the current, voltage and flux linkages rotate about these axes at a rate equal to the angular
frequencies of the corresponding phase quantities. If instead a new reference frame is defined where the
axes are made to rotate at the same rate as angular frequency of the phase quantities, stationary current,
voltage and flux linkage space vector result.
Consider applying the vector rotation through an angle θ:
ν = e − jθ
(10)
to the current space vector of (3). The current space vector in this new reference frame is given by:
i dq = i sd + ji sq = i se − jθ
(11)
which may also be written in matrix form as:
i sd   cos (θ) sin (θ)  i sα 
 
i  = 
 sq  − sin (θ) cos (θ) i sβ 
(12)
The real component of the current space vector in this new reference frame is the direct axis component
while the imaginary component is called the quadrature axis component.
The relationship of the real and imaginary components of the current space vector in the original
stationary two-axis reference frame and the new rotating reference frame is shown in Figure 2. Clearly,
from the viewpoint of the stationary (αβ) frame, both the current space vector and the direct and
quadrature axes are rotating at a speed ω. However, when viewed from the rotating reference frame, the
current space vector is stationary. The real axis of the rotating reference frame is located at an angle θ
from the real axis of the stationary reference frame. The elimination of position dependency from the
machine electrical variables is the main advantage of a vector rotation. This transformation will be
referred to as the Reverse Park Transformation.
Stationary
Imaginary Axis
jsβ
Rotating
Imaginary Axis
ω
jsq
i sβ
is
Rotating Real
Axis
sd
isd
i sq
θ
isα
sα
Stationary Real
Axis
Figure 2: Relationship of current space vector components in stationary and rotating reference frames.
The inverse vector rotation, to transform from a rotating to a stationary reference frame, may be written:
© Analog Devices Inc., January 2000
Page 6 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
i s = i dq e jθ
(13)
i sα  cos (θ) − sin (θ) i sd 
 
i  = 
 sβ   sin (θ) cos (θ)  i sq 
(14)
or in matrix form as:
This rotation is commonly called the Forward Park Transformation.
Consider application of the vector rotation of (10) to the current space vector of (9) derived for the
balanced set of stator currents:
i dq = − jI me − jϕ
(15)
so that:
i sd = − I m cos(ϕ )
i sq = − I m sin(ϕ)
(16)
which are independent of the instantaneous angular position of the phase quantities.
Therefore, a balanced three-phase system in phase variables may be transformed to an equivalent
two-axis representation that is independent of the angular position by applying a three-phase to
two-phase transformation followed by a vector rotation by the angular position of the phase
quantities.
1.4
Practical implementation of the transformations
In this section, some considerations are made about the overall computational efficiency of the
transformations.
•
The Forward Clarke Transformation given by (2) may be reduced into a computationally more
efficient form by explicitly substituting the (constant) cosine and sine values and applying the first
equation of (1). It is easily seen that these actions lead to:
i sα (t ) 
i (t )  = 
 sβ  
•
i sA (t )

1
(i (t ) − i sC (t ))
3 sB
The Reverse Clarke Transformation given by (6) is implemented by explicitly substituting the
(constant) cosine and sine values and applying the first equation of (1):

i sα (t )
i sA (t )  
i (t )  = − 1 i (t ) + 3 i (t )
2 sβ

 sB   2 sα
1

i sC (t )  − 2 i sα (t ) − 23 i sβ (t ) 
•
(17)
(18)
Unlike the Clarke transformations, both Park transformations require the real-time computation of the
transforming matrix itself. This entails the evaluation of one sine and one cosine function for each.
However, the forward and reverse matrices are mutually transposed. A more efficient usage of these
transformation is therefore to calculate the sine and cosine function once and to build the two
matrices by reversing the sign of the sine where appropriate. This will be explained more in detail in
the next section.
© Analog Devices Inc., January 2000
Page 7 of 18
a Reference Frame Conversions with the ADMC331
•
AN331-11
At last, it may be noted that the two transformation steps of (2) and (12) can be combined into a
single transformation that may be written as:
i sA 
i sd  2  cos(θ) cos(θ − γ ) cos(θ − 2 γ )  
  i sB 
i  = 
 sq  3 − sin(θ) − sin(θ − γ ) − sin(θ − 2 γ ) i 
 sC 
(19)
This transformation converts the phase quantities to the rotating reference frame in a single step.
However, it is often more desirable and computationally more efficient to apply the transformation in
two steps as described previously. In this way it is necessary to compute only two sinusoidal
functions of position unlike the six required for (19).
2 The Reference Frame Conversion Routines
2.1
Using the conversion routines
The routines are developed as an easy-to-use library, which has to be linked to the user’s application. The
library consists of two files. The file “refframe.dsp” contains the assembly code for the subroutines. This
package has to be compiled and can then be linked to an application. The user simply has to include the
header file “refframe.h”, which provides function-like calls to the routines. By including this header file
the user automatically includes some trigonometric subroutines that are defined in a previous application
note1. The example file in the section 3 will demonstrate the usage of all the conversion routines.
The following table summarises the set of macros defined in this library.
Transformation
Clarke
Park – Method 1
Park – Method 2
Operation
Usage
Initialisation
refframe_Set_DAG_registers_for_transformations;
Forward Clarke
refframe_Forward_Clarke(Vabc, Vαβ);
Reverse Clarke
refframe_Reverse _Clarke(Vαβ, Vabc);
Calculate Sine & Cosine
refframe_Calc_SinCos(ϕ, Vsincos);
Reverse Park
refframe_Reverse_Park_SinCos(Vαβ, Vdq, Vsincos);
Forward Park
refframe_Forward_Park_SinCos (Vdq, Vαβ, Vsincos);
Reverse Park
refframe_Reverse_Park_angle(Vαβ, Vdq, ϕ);
Forward Park
refframe_Forward_Park_angle (Vdq, Vαβ, ϕ);
Table 1: Implemented routines
where Vabc is a three-element vector containing the three phase quantities, Vαβ consists of two elements
holding the components of the stator quantity vector, Vdq represents the two components of the rotor
quantities and ϕ is the angle of rotation. VSinCos holds the value for sin(ϕ) and cos(ϕ) for temporary
storage. The example will clarify its usage, while section 2.2 describes the format of the quantities.
1
AN331-10: Basic trigonometric subroutines for the ADMC331
© Analog Devices Inc., January 2000
Page 8 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
As already mentioned in section 1.4, there are two ways of implementation for the Park transformation.
The three routines listed for “Method 1” should be used whenever both the forward and reverse
transformation are required since the trigonometric functions are evaluated only once. This is
computationally more efficient at the expense of two additional memory locations for VSinCos. Method 2
calculates the sine and cosine functions every time the Park routine is called, but requires no memory
locations for them. This is recommended whenever only one transformation is required.
The routines do not require any configuration constants from the main include-file “main.h” that comes
with every application note. For more information about the general structure of the application notes and
including libraries into user applications refer to the Library Documentation File. Section 3 shows an
example of usage of this library. In the following sections each routine is explained in detail with the
relevant segments of code which is found in either “refframe.h” or “refframe.dsp”. For more information
see the comments in those files.
2.2
Formats of inputs and outputs
The implementation of the routines is such that values for angles are expected to be in the usual scaled
1.15 format. Therefore, +1 (0x7FFF) corresponds to +π radians or 180 degrees, and –1 (0x8000) to -π
radians or -180 degrees. This applies to the functions Calc_SinCos(…)2, Forward_Park_angle(…) and
Reverse_Park_angle(…). The other inputs are vectors. That means that the values passed to the routines
are addresses of contiguous memory locations. Typically, they are represented by labels, such as
Valphabeta in the example of section 3. The components of the vectors are numbers in the scaled 1.15
format. However, having the single components in this format does not necessarily entail that the input is
in this format. As a simple example, having Vα and Vβ both equal to 1 leads to a vector in the stationary
frame with magnitude 2 > 1 . Obviously, if this vector is the input to the inverse Clarke transformation,
it corresponds to demand a three-phase system of amplitude bigger than one. It is up to the user to ensure
that the inputs are meaningful and adequately scaled.
2.3
Usage of the DSP registers
The macros listed in Table 1 are based on three subroutines that are reported in the following table. Also,
an overview is given on the usage of the core DSP registers. It may be noted that the DAG registers M0,
M1, M2 must be set to 1 and L0, L1, L2 must be set 0 and that they are not modified by the conversion
routines. Furthermore, the trigonometric routines require that M5 and L5 be set to 1 and 0 respectively.
The call to Set_DAG_registers_for_transformations prepares these registers for the conversion
routines. It now becomes clear that this routine is necessary only once if none of the above-mentioned
registers are modified in another part of the user’s code. However, for the sake of efficiency, it may be
more appropriate to use single instructions to restore eventually modified registers rather than a call to
this macro that requires 8 instructions.
Subroutine
Input 3
Output 4
Modified registers
ax0, ay0, ar,
refframe_Forward_Clarke_
I1 = ^Input
I0 = ^Output
N/A
mx0, my0, mr,
I0, I1
Other registers
M0, M1 = 1,
L0, L1 = 0
2
The prefix “refframe_” of the functions is omitted for simplicity
3
^vector stands for ‘address of vector’
4
The output values are stored in the output vector in Data Memory. No DSP core register is used.
© Analog Devices Inc., January 2000
Page 9 of 18
a Reference Frame Conversions with the ADMC331
refframe_Reverse_Clarke_
refframe_Rotate_Vector_
I1 = ^Input
I2 = ^Output
I0 = ^Input
I1 = ^Output
my0 = cos(angle)
N/A
N/A
AN331-11
mx0, my0, mx1,
M1, M2 = 1,
my1, mr, I1, I2
L1, L2 = 0
mx0, mx1, mr,
M0, M1, M5 = 1,
I0, I1
L0, L1, L5 = 0
my1 = sin(angle)
Table 2 Usage of DSP core registers for the subroutines
When using the function like macros, the modified registers are those reported below. The major
difference to Table 2 is seen in the Park routines. This is because the routine Rotate_Vector only performs
a vector rotation with the transforming matrix as input, whereas the overall Park transformation requires
the computation of a sine and a cosine function.
Usage
Modified registers
refframe_Set_DAG_registers_for_transformations;
M0, M1, M2, M5 = 1, L0, L1, L2, L5 = 0
refframe_Forward_Clarke(Vabc, Vαβ);
ax0, ay0, ar, mx0, my0, mr, I0, I1
refframe_Reverse _Clarke(Vαβ, Vabc);
mx0, my0, mx1, my1, mr, I1, I2
refframe_Calc_SinCos(ϕ, Vsincos);
ax0, ay0, ay1, ar, af,mx1, my1, mr, mf, sr, I0, I5
refframe_Reverse_Park_SinCos(Vαβ, Vdq, Vsincos);
ax0, ar, mx0, mx1, my0, my1, mr, I0, I1, I2
refframe_Forward_Park_SinCos (Vdq, Vαβ, Vsincos);
mx0, mx1, my0, my1, mr, I0, I1, I2
refframe_Reverse_Park_angle(Vαβ, Vdq, ϕ);
ax0, ay0, ay1, ar, af, mx0, mx1, my0, my1, mr, mf,
sr, I0, I1, I5
refframe_Forward_Park_angle (Vdq, Vαβ, ϕ);
ax0, ay0, ay1, ar, af, mx0, mx1, my0, my1, mr, mf,
sr, I0, I1, I5
Table 3 Usage of DSP core registers for the Macros
2.4
The program code
The code contained in the file “refframe.dsp” defines the three routines that are listed in Table 2.
Some constants are defined which represent the hexadecimal equivalent of the constants in the
transformation equations.
{***************************************************************************************
* Constants Defined in this Module
*
***************************************************************************************}
.CONST
.CONST
.CONST
inverse_root3_ = 0x49e6;
root3_over_2_
= 0x6ed9;
minus_1_over_2_ = 0xc000;
The following code implements equation (17) of the forward Clarke transformation. Note that the order in
which the single operations are executed is changed. The reason for it is that the difference Vb-Vc in a three
phase system may assume values that are bigger than one ( Vb
© Analog Devices Inc., January 2000
− Vc ≤ 3 ) and therefore may not be
Page 10 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
represented in 1.15 format. This is avoided by pre-multiplying both components with the constant before
subtracting them.
refframe_Forward_Clarke_:
ar=dm(I1,M1);
{ ar : Va
}
dm(I0,M0) = ar;
{ Vx : ar
}
mx0 = inverse_root3_;
{ mx0 : 0.57735
}
my0 = dm(I1,M1);
{ ax0 : Vb
}
mr = mx0*my0 (ss), my0 = dm(I1,M1);
{ mr1 : 0.57735*Vb, my0 : Vc
mr = mr - mx0*my0 (ss);
{ mr : 0.57735*Vb - 0.57735*Vc }
if MV sat mr;
DM(I0,M0)=mr1;
{ Vy : mr1
}
rts;
}
The reverse Clarke transformation of equation (18) is shown here. Similarly to the case of the forward
transformation, overflows of the MAC need to be avoided, for input magnitudes equal to one. Again, the
corresponding if MV … instructions could be removed if this never occurs.
refframe_Reverse_Clarke_:
mx0=dm(I1,M1);
mx1=dm(I1,M1);
dm(I2,M2)=mx0;
my0=minus_1_over_2_;
my1=root3_over_2_;
mr=mx0*my0 (ss);
mr=mr+mx1*my1 (ss);
if MV SAT mr;
dm(I2,M2)=mr1, mr=mx0*my0 (ss);
mr=mr-mx1*my1 (ss);
if MV SAT mr;
dm(I2,M2)=mr1;
rts;
{
{
{
{
{
{
{
mx0:
mx1:
Va :
my0:
my1:
mr1:
mr1:
Vx
Vy
mx0
-0.5
0.866
-0.5*Vx
-0.5*Vx + 0.866*Vy
}
}
}
}
}
}
}
{ Vb: mr1 then mr1: -0.5*Vx
{ mr1: -0.5*Vx - 0.866*Vy }
{ Vc: mr1
}
}
As already mentioned the following routine is used by both the forward and reverse Park transformations. It
simply multiplies the input vector by the matrix of equation (14) whose elements are provided as inputs as
well. Refer to the description of the header file in the next section for more details on the evaluation of this
matrix. Once again, the same considerations as for the reverse Clarke transformation regarding saturation
apply.
refframe_Rotate_Vector_:
mx0=DM(I0,M0);
mr=mx0*my0 (ss), mx1=DM(I0,M0);
mr=mr-mx1*my1(ss);
if MV SAT mr;
DM(I1,M1)=mr1, mr=mx0*my1 (ss);
mr=mr+mx1*my0 (ss);
if MV SAT mr;
DM(I1,M1)=mr1;
rts;
2.5
{ mx0: Vi1
{ mr: Vi1*cos(q) then mx1: Vi2}
{ mr: Vi1*cos(q)-Vi2*sin(q)
}
{ Vo1: mr then mr: Vi1*sin(q) }
{ mr: Vi1*sin(q)+Vi2*cos(q)
}
{ Vy: mr
}
}
Access to the library: the header file
The library may be accessed by including the header file “refframe.h” in the application code, as was
already explained in the section 2.1.
The header file is intended to provide function-like calls to the routines presented in the previous section. It
defines the calls shown in Table 1. The file is mostly self-explaining. The following piece, after including the
trigonometric
library
and
the
core
routines,
defines
the
initialisation
routine
Set_DAG_registers_for_transformations and the macros for the forward and reverse Clarke
transformations. The only comment is that, since the input and output vectors are pointed to by index
registers of the DM-DAG, they must be defined in data memory.
.MACRO refframe_Set_DAG_registers_for_transformations;
M0 = 1;
L0 = 0;
M1 = 1;
L1 = 0;
M2 = 1;
L2 = 0;
Set_DAG_registers_for_trigonometric;
© Analog Devices Inc., January 2000
Page 11 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
.ENDMACRO;
.MACRO refframe_Forward_Clarke(%0, %1);
I1 = ^%0;
I0= ^%1;
call refframe_Forward_Clarke_;
.ENDMACRO;
.MACRO refframe_Reverse_Clarke(%0, %1);
I1 = ^%0;
I2 = ^%1;
call refframe_Reverse_Clarke_;
.ENDMACRO;
It is worth adding a few comments about the evaluation of the rotation matrix in the different forms of the
Park transformation. The first two macros calculate the sine and cosine values and directly call the vector
rotation routine. For the reverse transformation the only action that is required is to complement the value of
the angle. Note that, since the negate instruction ar = -%2; produces the complement except for an input of –
1 (0x8000). If this occurs, the twos-complement is 0x8000 with the overflow flag set to one. The conditional
instruction immediately after it detects this case and loads ar with the correct value for +1 (0x7FFF).
.MACRO refframe_Forward_Park_angle(%0, %1, %2);
ax0= %2;
CALL Cos_;
my0=ar;
{ my0: cos(q) }
CALL Sin_;
my1=ar;
{ my1: sin(q) }
I1 = ^%1;
I0 = ^%0;
call refframe_Rotate_Vector_;
.ENDMACRO;
.MACRO refframe_Reverse_Park_angle(%0, %1, %2);
ar = -%2;
if AV ar = pass 0x7fff;
ax0 = ar;
CALL Cos_;
my0=ar;
{ my0: cos(q) }
CALL Sin_;
my1=ar;
{ my1: sin(q) }
I1 = ^%1;
I0 = ^%0;
call refframe_Rotate_Vector_;
.ENDMACRO;
Method 1 of the Park transformation is implemented by the following three macros. The difference is that the
matrix for the reverse transformation is not obtained by recalculating the trigonometric functions with the
complemented angle, but by making use of the know symmetries of these functions. Since sin(-x)=-sin(x) and
cos(-x)=cos(x), the resulting matrix is obtained by inverting the sign of only the (previously stored) sine
value. Again, with a conditional instruction, the special case of –1 is correctly handled.
.MACRO refframe_Calc_SinCos(%0, %1);
ax0 = %0;
I0 = ^%1;
CALL Sin_;
DM(I0,M0)=ar;
CALL Cos_;
DM(I0,M0)=ar;
.ENDMACRO;
.MACRO refframe_Forward_Park_SinCos(%0, %1, %2);
I1 = ^%1;
I0 = ^%0;
I2 = ^%2;
my1= DM(I2,M2);
my0= DM(I2,M2);
call refframe_Rotate_Vector_;
.ENDMACRO;
© Analog Devices Inc., January 2000
Page 12 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
.MACRO refframe_Reverse_Park_SinCos(%0, %1, %2);
I1 = ^%1;
I0 = ^%0;
I2 = ^%2;
ax0= DM(I2,M2);
ar = -ax0;
if AV ar = pass 0x7fff;
my1 = ar;
my0= DM(I2,M2);
call refframe_Rotate_Vector_;
.ENDMACRO;
3 Software Example: Testing the Conversion Routines
3.1
The main program: main.dsp
The example demonstrates how to use the routines. All it does is to generate a three-phase sine wave
system. The phase components are then transformed into the stationary (αβ-) and rotor (dq) frame. After
that, the inverse transformations are executed. The different vectors are converted and may be displayed
on a scope by means of the digital to analog converter. The application has been adapted from two
previous notes5,6. This section will only explain the few and intuitive modifications to those applications.
The file “main.dsp” contains the initialisation and PWM Sync and Trip interrupt service routines. To
activate, build the executable file using the attached build.bat either within your DOS prompt or clicking
on it from Windows Explorer. This will create the object files and the main.exe example file. This file
may be run on the Motion Control Debugger.
In the following, a brief description of the additional code (put in evidence by bold characters) is given.
Start of code – declaring start location in program memory
.MODULE/RAM/SEG=USER_PM1/ABS=0x30
Main_Program;
Next, the general systems constants and PWM configuration constants (main.h – see the next section) are
included. Also included are the PWM library, the DAC interface library, trigonometric library and reference
conversion library.
{***************************************************************************************
* Include General System Parameters and Libraries
*
***************************************************************************************}
#include <main.h>;
#include <pwm331.h>;
#include <dac331.h>;
#include <trigono.h>;
#include <refframe.h>;
Variables definition: Here is where all the vectors for the transformation routines are declared.
{***************************************************************************************
* Local Variables Defined in this Module
*
***************************************************************************************}
.VAR/DM/RAM/CIRC/SEG=USER_DM
.VAR/DM/RAM/CIRC/SEG=USER_DM
.VAR/DM/RAM/CIRC/SEG=USER_DM
.VAR/DM/RAM/CIRC/SEG=USER_DM
.VAR/DM/RAM/CIRC/SEG=USER_DM
.VAR/DM/RAM/CIRC/SEG=USER_DM
SinCos[2];
Vabc[3];
Valphabeta[2];
Vdq[2];
Valphabeta_rev[2];
Vabc_rev[3];
{
{
{
{
{
{
sine cosine buffer
}
3 phase buffer
}
stat.ref.frame
}
rotor ref.frame
}
reverse from dq frame
reverse from alphabeta
}
}
5
AN331-03: Three-Phase Sine-Wave Generation using the PWM Unit of the ADMC331
6
AN331-06: Using the Serial Digital to Analog Converter of the ADMC Connector Board
© Analog Devices Inc., January 2000
Page 13 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
First, the PWM block is set up to generate interrupts every 100µs (see “main.h” in the next Section). The
main loop just waits for interrupts..
{********************************************************************************************}
{ Start of program code
}
{********************************************************************************************}
Startup:
PWM_Init(PWMSYNC_ISR, PWMTRIP_ISR);
DAC_Init;
IFC = 0x80;
ay0 = 0x200;
ar = IMASK;
ar = ar or ay0;
IMASK = ar;
{ Clear any pending IRQ2 inter.
{ unmask irq2 interrupts.
}
}
{ IRQ2 ints fully enabled here
}
Main:
jump Main;
{ Wait for interrupt to occur }
rts;
The interrupt service routine simply shows how to make use of the reference frame conversion routines. After
the usual call to the sine-wave generation (see the application note mentioned above for details) the three”
phase voltages” ( the duty-cycle values) are stored into a vector for use with the transformation routines. It
may be pointed out that the scope of this application note is only to demonstrate their usage. Clearly, from a
programmer’s point of view, it is more efficient and natural to generate the duty-cycle commands and store
them directly to this vector rather than passing through two separate variables wasting memory resources
and computation time. Since the conversion routines make use of the pointer register I1, the DAC operations
are to be stopped during their execution. Obviously, this may be removed when removing the DAC from the
final application (refer to the application note on the DAC for a description of its commands and to section
2.3 for details of register usage of the conversion routines). What follows (in bold characters) is the actual
conversion. Vabc is converted into the stationary reference frame (Valphabeta). Method 1 is then executed to
transform Valphabeta into the dq-frame (Vdq) and back into Valphabeta_rev by calculating the sine and
cosine of the angle once and invoking respectively the reverse and forward Park transformation. Method 2 is
also shown, although the related code is commented. The user may play with them by simply removing the
comment directive “!”. At last, the stationary vector is transformed back into the original 3-phase
description Vabc_rev. The following lines just update the DAC buffer for the digital-to-analog conversion.
Since only 8 DAC channels are available on the connector board, some of the 15 signals are commented.
Again, the user may play with this part of code to visualise all of them in separate times. The default is the
conversion of the angle ThetaA, the original 3-phase waveforms, the stationary reference frame and the rotor
reference frame. Section 3.3 will show the outputs that are produced by this example.
{********************************************************************************************}
{ PWM Interrupt Service Routine
}
{********************************************************************************************}
PWMSYNC_ISR:
my0 = DM(AD_IN);
mr = 0;
mr1 = dm(Theta);
mx0 = delta;
mr = mr + mx0*my0 (SS);
dm(Theta) = mr1;
Sin(mr1);
mr = ar*my0 (SS);
dm(VrefA) = mr1;
ax1 = dm(Theta);
ay1 = TwoPioverThree;
ar = ax1 - ay1;
Sin(ar);
mr = ar*my0 (SS);
© Analog Devices Inc., January 2000
{Clear mr
{Preload Theta
}
}
{Compute new angle & store
}
{ Result in ar register
{ Multiply by Scale for VrefA
}
}
{ Compute angle of phase B
}
{ Result in ar register
{ Multiply by Scale for VrefA
}
}
Page 14 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
dm(VrefB) = mr1;
ax1 = dm(Theta);
ay1 = TwoPioverThree;
ar = ax1 + ay1;
Sin(ar);
mr = ar*my0 (SS);
dm(VrefC) = mr1;
{ Compute angle of phase C
}
{ Result in ar register
{ Multiply by Scale for VrefA
}
}
ax0 = DM(VrefA); ax1 = DM(VrefB); ay0 = DM(VrefC); ay1= DM(Theta);
PWM_update_demanded_Voltage(ax0,ax1,ay0);
my0 = DM(VrefA);
}
DM(Vabc )=my0;
my0 = DM(VrefB);
DM(Vabc+1)=my0;
my0 = DM(VrefC);
DM(Vabc+2)=my0;
DAC_Pause;
{ store Vref A,B and C in vector Vabc
{ Required because I1, M1 and L1 are used by transformations}
refframe_Set_DAG_registers_for_transformations;
refframe_Forward_Clarke(Vabc,Valphabeta);
{method 1}
}
ax1= DM(Theta);
{ Sin and Cos calculated only once
refframe_Calc_SinCos(ax1, SinCos);
refframe_Reverse_Park_SinCos(Valphabeta,Vdq,SinCos);
refframe_Forward_Park_SinCos(Vdq,Valphabeta_rev,SinCos);
!{method 2}
}
!
!
!
ax1= DM(Theta);
{ Sin and Cos calculated twice
refframe_Reverse_Park_angle(Valphabeta,Vdq,ax1);
ax1= DM(Theta);
refframe_Forward_Park_angle(Vdq,Valphabeta_rev,ax1);
refframe_Reverse_Clarke(Valphabeta_rev,Vabc_rev);
DAC_Resume;
my0 = DM(Theta);
DAC_Put(1, my0);
{ Theta on channel 1
}
my0 = DM(Vabc );
DAC_Put(2, my0);
my0 = DM(Vabc+1);
DAC_Put(3, my0);
my0 = DM(Vabc+2);
DAC_Put(4, my0);
{ Original 3 phase system on 2,3,4
}
my0 = DM(Valphabeta );
DAC_Put(5, my0);
my0 = DM(Valphabeta+1);
DAC_Put(6, my0);
{ Stationary ref frame on 5,6
}
my0 = DM(Vdq );
DAC_Put(7, my0);
my0 = DM(Vdq+1);
DAC_Put(8, my0);
{ Rotor ref frame on 7,8
!
!
!
!
my0 = DM(Valphabeta_rev );
DAC_Put(5, my0);
my0 = DM(Valphabeta_rev+1);
DAC_Put(6, my0);
{ Back transformed stationary ref frame
!
!
!
!
my0 = DM(Vabc_rev );
DAC_Put(2, my0);
my0 = DM(Vabc_rev+1);
DAC_Put(3, my0);
{ Back transformed 3 phase system
© Analog Devices Inc., January 2000
}
}
}
Page 15 of 18
a Reference Frame Conversions with the ADMC331
!
!
AN331-11
my0 = DM(Vabc_rev+2);
DAC_Put(4, my0);
DAC_Update;
RTI;
3.2
The main include file: main.h
This file contains the definitions of ADMC331 constants, general-purpose macros and the configuration
parameters of the system and library routines. It should be included in every application. For more
information refer to the Library Documentation File.
This file is mostly self-explaining. As already mentioned, the reference frame library does not require any
configuration parameters. The following defines the parameters for the PWM ISR used in this example.
{********************************************************************************************}
{ Library: PWM block
}
{ file
: PWM331.dsp
}
{ Application Note: Usage of the ADMC331 Pulse Width Modulation Block
}
.CONST PWM_freq
= 10000;
{Desired PWM switching frequency [Hz]
}
.CONST PWM_deadtime
= 1000;
{Desired deadtime [nsec]
}
.CONST PWM_minpulse
= 1000;
{Desired minimal pulse time [nsec]
}
.CONST PWM_syncpulse
= 1540;
{Desired sync pulse time [nsec]
}
{********************************************************************************************}
3.3
Example output
The signals that are generated by this demonstration program are shown in the following figures. The
original three-phase system is described as follows:
 sin (ωt ) 
V A 
V  = V ⋅ sin (ωt − 2π )
3 

 B
4
sin (ωt − 3π )
VC 
( 20)
where ω and V denote the angular speed and the (scaled) amplitude. Note that it is in the form of equation
(7) with ϕ equal to zero. Figure 3 shows the produced waveforms versus the angle (-π to +π).
Vc
Vb
Va
ωt
π to
Figure 3 Three phase system (the saw-tooth is the representation of the angle ranging from -π
π)
+π
Applying the forward Clarke transformation (17) to this particular system leads to:
© Analog Devices Inc., January 2000
Page 16 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
Vα 
 sin (ωt ) 
V  = V ⋅ 

− cos(ωt )
 β
( 21)
describing a circular locus in the αβ-plane. This is shown in the next figure.
Vα
Vβ
Figure 4 Stationary reference frame versus theta (left) and in the αβ -plane (right)
The next step consists of applying the reverse Park transformation of (12) to ( 21). It is easily seen that the
resulting dq-vector is constant:
Vd 
0
V  = V ⋅  
− 1
 q
( 22)
Figure 5 represents this vector graphically in the time domain. Note that in the dq-plane the vector is
reduced to one point.
Vd
Vq
Figure 5 Rotor reference frame versus theta
© Analog Devices Inc., January 2000
Page 17 of 18
a Reference Frame Conversions with the ADMC331
AN331-11
The vectors Valphabeta_rev and Vabc_rev, which represent the back-transformed quantities, obviously
are, apart from eventual rounding errors, identical to Valphabeta and Vabc, respectively. As an example,
the following figure shows a comparison between Va and Va_rev both in the time domain and in xyrepresentation.
Va =Va_rev
ωt
Figure 6 Va and Va_rev versus theta (left) and in xy representation (right)
4 Differences between library and ADMC331 “ROM-Utilities”
The code presented in this application note is intended to substitute the one present in the ROM of the
ADMC331. The reason for this is that the Clarke transformation in the ROM does not correctly handle
the overflow problem mentioned in section 2.4. This bug has been fixed with a new routine shipped with
the installation tool. They must be linked into RAM memory. However, the routines do not behave
correctly when the inputs are of magnitude equal to one. Furthermore, the routines presented herein are
shorter and easier to use.
© Analog Devices Inc., January 2000
Page 18 of 18