IQmath Library for C28x

From Texas Instruments Embedded Processors Wiki

Jump to: navigation, search

Contents

Introduction to IQmath for C28x MCUs

Texas Instruments TMS320C28x IQmath Library is collection of highly optimized and high precision mathematical Function Library for C/C++ programmers to seamlessly port the floating-point algorithm into fixed point code on TMS320C28x devices.

IQmath uses the internal hardware of the C28x in the most efficient way to operate with 32bit fixed-point numbers. Taking into account that all process data usually do not exceed a resolution of 16 bits, the library gives enough headroom for advanced numerical calculations.

These routines are typically used in computationally intensive real-time applications where optimal execution speed & high accuracy is critical. By using these routines you can achieve execution speeds considerable faster than equivalent code written in standard ANSI C language. In addition, by providing ready-to-use high precision functions, TI IQmath library can shorten significantly your DSP application development time.

The usage of the IQmath library can be understood with the help of this document.

Please refer to the link to download the IQmath library.

Frequently Asked Questions

Q: Digital Motor Control Library

The F28x Digital Motor control library contains the Digital Motor control software modules. These component modules, implemented in IQmath, are used to construct the systems such as Sensored/ Sensor less Control. Download this SPRC080 library to get the individual components and documents. Some examples of the component modules are PID controllers, Clarke, Park transforms, PWM drivers and much more.

Q: How do I change an IQmath project to a native floating-point project for the C28x+FPU?

To convert an IQmath application to floating point, follow these steps:
  • In the IQmath header file, select FLOAT_MATH. The header file will convert all IQmath function calls to their floating-point equivalent.
  • When writing a floating-point number into a device register, you need to convert the floating-point number to an integer. Likewise when reading a value from a register it will need to be converted to float. In both cases, this is done by multiplying the number by a conversion factor. For example to convert a floating-point number to IQ15, multiply by 32768.0. Likewise, to convert from an IQ15 value to a floating-point value, multiply by 1/32768.0 or 0.000030518.0. One thing to note: The integer range is restricted to 24-bits for a 32-bit floating-point value.
//
// Example:
// Convert from float to IQ15
 
//
// If MATH_TYPE == IQ_MATH
// Use the IQmath conversion function
//
 
#if MATH_TYPE == IQ_MATH
   PwmReg = (int16)_IQtoIQ15(Var1);
 
//
// If MATH_TYPE == FLOAT_MATH
// Scale by 2^15 = 32768.0
//
 
#else // MATH_TYPE is FLOAT_MATH
   PwmReg = (int16)(32768.0L*Var1);
#endif


  • If your device has the on-chip floating-point processing unit (C28x+FPU), then you can take advantage of the on-chip floating point unit by doing the following:
  • Use C28x codegen tools version 5.0.2 or later.
  • Tell the compiler it can generate native C28x floating-point code. To do this, use the –v28 --float_support=fpu32 compiler switches. In Code Composer Studio V3.3 the float_support switch is on the advanced tab of the compiler options.
  • Use the correct run-time support library for native 32-bit floating-point. For C code this is rts2800_fpu32.lib. For C++ code with exception handling, use rts2800_fpu32_eh.lib.
  • Use the C28x FPU Fast RTS library (SPRC664) to get a performance boost from math functions such as sin, cos, div, sqrt, and atan. The Fast RTS library should be linked in before the normal run-time support library.

Q: I want to mix IQmath and floating-point math on a C28x with floating-point unit (C28x+FPU) device. I get an error that the library is not compatible with the --float_support=fpu32 build option. What can I do?

The linker will not allow you to mix libraries built with float support with libraries that were not built with float support. Instead of using the IQmath.lib library instead use IQmath_f32.lib. This build of the library can be linked with code built with the --float_support=fpu32 switch. This can be useful for mixing IQmath with native floating-point code on devices with the C28x+FPU.
IQmath_f32.lib is available in the IQmath library V1.5 and later.

Q: If I use IQmath_f32.lib, does it do native floating point operations?

No - functions in this library still operate on _iq math types. Remember all fixed-point operations are 100% compatible on the C28x+FPU.

For technical support please post your questions at http://e2e.ti.com. Please post only comments about the article IQmath Library for C28x here.
Leave a Comment
Personal tools