This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F5259: iqmathlib GLOBAL_IQ always defaults to 4

Part Number: MSP430F5259
Other Parts Discussed in Thread: MSP-IQMATHLIB


In my project I use iqmathlib fix point arithmetic library in various files.

In each file I use the following sequence:

#define GLOBAL_IQ    6  // e.g.
#include <IQmathLib.h>

After building and flashing I notice that when opening the declaration of 


it jumps to iqmatlib.h to the following section as if GLOBAL_IQ == 4 

same happens when opening the declaration of:

iqtemp = _IQmpy(ucnt, _IQ(-636.8443398));

it jumps to :

I even tried:

#undef GLOBAL_IQ
#define	GLOBAL_IQ    	6
#include "IQmathLib.h"

Same results :(

This happens with any #define value, on any file, always handle GLOBAL_IQ==4

I double checked GLOBAL_IQ in project properties>compiler>predefines and there is no such definitions

I've cleaned and rebuilt the project. Same results.

Any thoughts ?

  • Hi eyalasko,

    I will try to bring in the MSP430 MSP-IQMathlib author for his comments. I do not believe #define macros are global so attempting to change the value outside of IQmathLib.h will have no effect. Have you tried changing the GLOBAL_IQ definition inside of IQmathLib.h?


  • Hey Ryan,

    Thanks for your prompt response.
    I did not change the GLOBAL_IQ inside iqmathlib.h as I need different fixed point 'resolution' in each of my source files.
    That why I use local #define GLOBAL_IQ just before #include "iqmathlib.h" as noted in section 2.6 of the iqmathlib user's guide (first method)

    Thanks again
  • Hey eyalasko,

    Okay we are on the same page now. When I open a function declaration inside of CCS I notice that it does jump to the settings from the GLOBAL_IQ value defined in IQmathLib.h, however the disassembler shows that the actual function being referred is from the GLOBAL_IQ defined before IQmathLib.h is included. What IDE, compiler, and IQmathLib version are you using?

  • CCS
    Compiler 16.9.1LTS
    iqmathlib .a is taken from TI_PRODUCTS_DIR\MSP430Ware_3_50_00_04\iqmathlib\libraries\CCS\MPY32\5xx_6xx\IQmathLib.a  (I think its
    iqmathlib.h is included from "${TI_PRODUCTS_DIR}\MSP430Ware_3_50_00_04\iqmathlib\include"  (I think its

  • Hey Ryan,

    any update on this ?

  • eyalasko,

    I'm able to recreate this issue, I see that the incorrect definition of GLOBAL_Q is being used however when I compile and run I get the correct result. I created a test project with the following two files.


    #include "msp430.h"
    // Set global Q to 12, this shows correctly in header
    #define GLOBAL_Q                12
    #include "QmathLib.h"
    volatile _q result;
    extern _q testQ4(void);
    int main(void)
        /* Disable WDT. */
        // Result set to _Q12(1.0) = 4096 correctly
        result = _Q(1.0);
        // Call test function, result set to _Q4(1.0) = 16 correctly
        result = testQ4();
        return 0;


    // Set global Q to 4, the header still shows 12 from main.c
    #define GLOBAL_Q                4
    #include "QmathLib.h"
    _q testQ4(void)
    	_q result;
    	result = _Q(1.0);
    	return result;

    Opening the QmathLib header from main.c shows _Q(A) being defined to _Q12(A) as you would expect. Opening the header from test.c however incorrectly shows _Q(A) being defined to _Q12(A) when it should be _Q4(A). When I run the project the result is set correctly for both cases so the macros are working however I believe this is an issue with how CCS handles processor and syntax highlighting, header files are processed for one .c file but not reprocessed when opening from a different source.



**Attention** This is a public forum