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.

Compiler/MSP430FR5969: MSP430 MATHLIB/ IQMATH/ Trignometeric functions

Part Number: MSP430FR5969
Other Parts Discussed in Thread: MATHLIB, MSPMATHLIB, MSP-IQMATHLIB,

Tool/software: TI C/C++ Compiler

Hi! I am using math.h header file for my trignometeric and algorithmic functions. Then i saw the MSP Mathlib guide www.ti.com/.../slau499.pdf and now I want to implement that library in my CCSv8 Program.

I tried to go on this link  and clicked on get software then it takes forward to (Sorry, the page you’re looking for can’t be found.).

At this directory C:\ti\ccsv8\ccs_base\msp430\lib\5xx_6xx_FRxx. I found MSPMathlib files(that are .lib/ object file library). I tried to include them as guided in (slau499.pdf)

After getting file linked to my program. I include it as #include "msp430_math.h" then it gives me an error that could not find the file.

Also, IQmath and MSPMathlib are two different libraries or not??

As in this forum, MSP430 Library is actually named IQmath. 

Can anyone please guide me for this.

Thanks in advance!!

  • Hello Neeraj,

    As explained by Mike in this e2e post, the MSPMATHLIB and MSP-IQMATHLIB are two different libraries. The MSP-IQMATHLIB can be downloaded from the library's web-page and is compatible with all of the MSP430 flash and FRAM devices. It's purpose is to port a floating-point algorithm into fixed-point code on MSP430.

    The MSPMATHLIB is a math library compatible with the F5xx, F6xx, and FRAM devices and serves as a library to optimize floating-point scalar math functions. You are correct that this library is provided with the CCS download for MSP430 devices. I think that in order to fix the error you are receiving about the file not being found, you need to add the directory of the file to your include path in the project properties:

    You will likely end up adding the path: ${CCS_BASE_ROOT}/msp430/lib/5xx_6xx_FRxx

    Best regards,

    Matt

  • Hello Matt,

    Initially, I didn't include the directory as you posted above. Now I have done that but still my problem is not resolved.As in, I would like to use MSPMATHLIB(for trignometeric and algorithmic functions).

    I have given the path as C:\ti\ccsv8\ccs_base\msp430\lib\5xx_6xx_FRxx and it is on th top of #include search path.

    Now, I dont now how to include that file into program

    #include "MSPMATHLIB.h" or #include "msp430_math.h". Could you help me with it!!

  • Neeraj,

    After doing further digging into MSPMATHLIB, I learned that the MSPMATHLIB is now automatically used as the default math library functionality for the MSP430FRxx/F5xx/F6xx devices. There is no need to include msp430_math.h, as math.h will automatically reference the correct MSPMATHLIB library file. Please refer to this E2E post for more information: e2e.ti.com/.../390434

    I will reach out to the software team to fix the MSPMATHLIB webpage so that it is more clear in our documentation on how this math library is implemented.

    Best regards,

    Matt
  • Hi Matt,

    After adding the directory of MSPMATHLIB. Now in my code, I comment out the math.h header file. It says the trigonometric and algorithmic functions are not defined.

    And I don't see any MSPMATHLIB file and hence I can see the functions and definitions. In short, I am still unable to use it. It doesn't loads or works.

    Could you please help me!!

    Regards,

    Neeraj 

  • Neeraj,

    Please refer to my previous post where I linked an e2e thread that  explains the correct process of  incorporating MSPMATHLIB in a project. On that E2E thread, scroll down to the last comment which is surrounded by a green box , this is where the process is explained.

    Doing this will define all of the algorithmic and trigonometric functions provided in the library.

    Best regards,

    Matt

  • Hi Matt,

    I did go through the e2e thread as you have mentioned and also the green box that is the fix for MSPMATHLIB.

    The thing is when I comment out the #include<math.h> now there are no build errors for the sin/cos functions but there is always a warning function declared implicitly. Also, I do  normal operation like sqrt(25) it returns me some strange output(as int number 4055) instead of 5.

    But on the other hand when I use #include<math.h> it gives the correct result but the number of cycles is not less and I don't know whether it's MSPMATHLIB used or MATH.h??

    Regards,

    Neeraj

  • Neeraj,

    MSPMathlib is active, by default, in CCSv5.5+ for all new projects on all supported devices. In order to ensure that the project is using MSPMATHLIB, you need to make sure libmath.a is under Project → Properties → Build → MSP430 Linker → File Search Path in the "Include library file or command file as input (--library, -l)" field.

    As long as you put libmath.a before other libraries that are listed there, CCS takes care of properly including the proper math library functions you want to use.

    Here is another e2e post about the same issue in case you need further clarification: e2e.ti.com/.../345026

    Best regards,

    Matt
  • Hi Matt,

    I did read e2e thread e2e.ti.com/.../345026 fix for MSPMATHLIB.

    Now I place libmath.a before other libraries that are listed there in MSP430Linker->FIle Search Path

    when I comment out the #include<math.h> now there are no build errors for the sin/cos functions but there is always a warning function declared implicitly.

    i.e. #255-D thats regarding the usage of this function. Maybe it occurs due to wrong syntax of the func used.

    processors.wiki.ti.com/.../225

    As i don't know the correct syntax for using srt func in MSPMATHLIB(and it is a statically linked lib so I am not able to open the lib file and check for Syntax).

    Also, I do  normal operation like sqrt(25) it returns me some strange output(as int number 4055) instead of 5.

    Please help me regarding this issue

  • Hey Matt,

    The above warning #255-D states that the func is called implicitly. So I tried to search syntax for it in the .lib files provided by CCS. But, I was unable to get the syntax. Hence after going through statically linked and dynamically linked library.

    I got to know that for using the statically linked library placed at location C:\ti\ccsv8\ccs_base\msp430\lib\5xx_6xx_FRxx\
    we need the header file or the source code respective to the compiled .lib file.

    So, Could you provide me the source code(.h/.cpp) of the MSPMATHLIB library(mentioned in User's guide SLAU499).

    Regards,
    Neeraj
  • Neeraj,

    While I am unable to provide the source code for the MSPMATHLIB library, I can assist in helping with its implementation. I conducted a test using a very basic example on the MSP430FR5969 Launchpad to compare the compiler provided math library to the MSPMATHLIB library and was able to confirm that the MSPMATHLIB implementation of square-root was almost 10x better in terms of cycle counts:

    #include <msp430.h>
    #include "math.h"
    
    int main(void)
    {
      volatile float a,b = 25;
    
      WDTCTL = WDTPW | WDTHOLD;       // Stop WDT
    
      a = sqrtf(b);     //MSPMATHLIB floating point square-root
      a = sqrt(b);      //Compiler floating point square-root
      __no_operation();
    
      while(1);
    }

    Here are all of the functions supported by the library and the syntax associated with them:

    /* Mathlib function prototypes */
    extern float sinf(float input);
    extern float cosf(float input);
    extern float tanf(float input);
    extern float asinf(float input);
    extern float acosf(float input);
    extern float atanf(float input);
    extern float atan2f(float input1, float input2);
    extern float logf(float input);
    extern float expf(float input);
    extern float sqrtf(float input);
    extern float fmodf(float input1, float input2);
    extern float reciprocalf(float input);

    To use them in your project you just need to write the name of the operation with an 'f' at the end of it ( i.e. sqrtf(), sinf(), and cosf() )

    Hopefully this helps clear things up and you are able to start comparing the benefits of using the optimized floating-point library.

    Best regards,


    Matt

  • Hey Matt,

    To add Trignometric and Algorithmic functionality of MSPMATHLIB in CCSv8(or higher):
    1. Add libmath.a under Project → Properties → Build → MSP430 Linker → File Search Path in the "Include library file or command file as input (--library, -l)" field. Important: Put libmath.a before other libraries that may be listed here.
    2. Including <math.h> header file.

    The statically linked file i.e. libmath.a + math.h  and the use of correct definition of functions as in sqrtf instead of normal sqrt. It will work 100% and correct.

    I also tested the same thing with sqrt of math.h (3591 cycles) and with sqrtf of MSPMATHLIB(458 cycles) i.e 7.84 times better (approx 7.9 times mentioned in MSPMATHLIB Datasheet SLAU499)

  • Thanks Matt for your time.

    Regards,
    Neeraj
  • Thanks Matt

    Regards,
    Neeraj

**Attention** This is a public forum