IQmath
8 - 22 C2000 Microcontroller Workshop - Numerical Concepts
IQmath Approach
GLOBAL_Q simplification
#define GLOBAL_Q 18 // set in “IQmathLib.h” file
_iq Y, M, X, B;
Y = _IQmpy(M,X) + B; // all values are in Q = 18
GLOBAL_Q
User selects “Global Q” value for the whole application
based on the required dynamic range or resolution, for example:
The user can also explicitly specify the Q value to use:
_iq20 Y, M, X, B;
Y = _IQ20mpy(M,X) + B; // all values are in Q = 20
0.000 000 06-128.000 000 00127.999 999 9424
0.000 001-2048.000 0002047.999 99920
0.000 000 004-8.000 000 0007.999 999 99628
ResolutionMin ValMax ValGLOBAL_Q
The basic "IQmath" approach was adopted in the creation of a standard math library for the Texas
Instruments TMS320C28x DSP fixed-point processor. This processor contains efficient hardware
for performing 32x32 bit multiply, 64-bit shifts (logical and arithmetic) and 32-bit add/subtract
operations, which are ideally suited for 32 bit "IQmath".
Some enhancements were made to the basic "IQmath" approach to improve flexibility. They are:
Setting of GLOBAL_Q Parameter Value: Depending on the application, the amount of numerical
resolution or dynamic range required may vary. In the linear equation example, we used a Q val-
ue of 24 (Q24). There is no reason why any value of Q can't be used. In the "IQmath" library,
the user can set a GLOBAL_Q parameter, with a range of 1 to 30 (Q1 to Q30). All functions
used in the program will use this GLOBAL_Q value. For example:
#define GLOBAL_Q 18
Y = _IQmpy(M, X) + B; // all values use GLOBAL_Q = 18
If, for some reason a particular function or equation requires a different resolution, then the user
has the option to implicitly specify the Q value for the operation. For example:
Y = _IQ23mpy(M,X) + B; // all values use Q23, including B and Y
The Q value must be consistent for all expressions in the same line of code.