Software Tools
Table 2. Some IQMath Functions Used Often in Motor Control Applications
C
_IQ(float)
+
-
_IQmpy
_IQdiv
_IQsqrt
_IQisqrt
_IQsin
_IQcos
_IQatan
_IQatan2
_IQsinPU
_IQcosPU
_IQatan2PU
_IQsat
_IQabs
2.1.4
Calling an IQMath Function in C
The IQ Math library is very user-friendly and comes with detailed documentation explaining the features
and usage of each library function, along with example code. The following sample code shows how to
write a Park transform function using IQ Math library trigonometric and multiplication functions:
#include
"math.h"
#include
"IQmathLib.h"
#define
TWO_PI 6.28318530717959
void
park_calc(PARK *v)
{
_iq cos_ang, sin_ang;
sin_ang = _IQsinPU (v->angle);
cos_ang = _IQcosPU (v->angle);
v->de = _IQmpy(v->ds ,cos_ang) + _IQmpy(v->qs ,sin_ang);
v->qe = _IQmpy(v->qs ,cos_ang) - _IQmpy(v->ds ,sin_ang);
}
Note that in the above example, the variables are declared not as fixed or float but as "iq." The iq type is
interpreted at compile time, and is substituted for a fixed- or floating-point variable type, depending on the
device type being used. Consequently, the code above can be run on a fixed-point or a floating-point
device without any changes, therefore enabling easy migration between floating- and fixed-point devices.
2.1.5
Advantages of the IQMath Library for Motor Control
IQmath uses the instructions present on the C28x™ devices in the most efficient way to compute the
various math functions. Briefly, the benefits and contributions of the IQMath Library in C2000™-based
digital motor control can be summarized as follows:
•
Selection of dynamic range and resolution on fixed point devices: For fixed-point devices, a
choice of Q can be made depending on dynamic range and resolution requirements of the system.
Q24 is used by default but can be changed easily to select another Q format if needed.
•
Float to fixed migration: All the functions available in the floating-point version of the library are
available on fixed-point version and vice versa; hence, migration from float to fixed becomes very easy.
The use of "iq" type while writing code enables the compiler to interpret the math type to be used for
the variables at compile time. Thus, no or little change is required to the source code when migrating
from floating- to fixed-point devices.
4
TMS320C2000 Motor Control Primer
C++
IQ(float)
+
-
*
/
sqrt
isqrt
sin
cos
atan
atan2
sinPU
cosPU
atan2PU
sat
abs
Copyright © 2010, Texas Instruments Incorporated
www.ti.com
Operation
Constant
Add
Subtract
Multiply
Divide
Square root
1/Square root
Sine
Cosine
Arc tangent
Arc tangent 2 opr.
Sine per unit
Cosine per unit
Arc tangent 2 opr. per unit
Saturation
Absolute value
SPRUGI6 – September 2010
Submit Documentation Feedback
Need help?
Do you have a question about the TMS320C2000 and is the answer not in the manual?
Questions and answers