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.

CCS/MSP430F2619: QMath / IQMath, I have 16 bit Accel data, what the best implementation and format to calculate total acceleration from X,Y,Z and inclination.

Part Number: MSP430F2619
Other Parts Discussed in Thread: MSP-IQMATHLIB, MSP430WARE, MSP430G2553

Tool/software: Code Composer Studio

I'm looking for working solution or example codes based on QMath/IQMath where I have 16 bit Accel data (can be downsized to 12 bits Accel data if necessary), where total acceleration is calculated (square of each X,Y,Z and then sum it and finally sqrt of the sum). I also interested how to use atan2 for inclination calculation.

R. 

 

  • All MSP-IQMATHLIB information is provided in the User's Guide: software-dl.ti.com/.../MSP430-IQmathLib-UsersGuide.pdf

    A few examples are also provided as a part of MSP430Ware -> Libraries -> IQmath Library -> Example Projects -> MPY Software or in the library download but I am otherwise unaware of specific examples pertaining to the application in question.

    Regards,
    Ryan
  • Hi Richard,

    Have you taken a look at the MSP430 Orientation Tracker TI Design? The TI Design showcases how the IQmath libraries combined with an accelerometer can be used to calculate acceleration magnitude, detect when the device is in free fall, calculate inclination angles (pitch and roll) using atan2 and calibration of the accelerometer using gravity as a reference.

    The design uses MSP430G2553 and the software Qmath/IQmath libraries but that same routines can be used with any device and version of the libraries.

    Regards,

    Brent Peterson

  • Yes I has a look and it was helpful, thanks

    Now I have ADC readout which is transulated to 10,000 as mG/10, ie 1G = 10,000 readout. This was done by seperate code (non Iq method).The maximum is +/-8G which suite Accel nicely.

    I decided to use q12 math to represent +/-8.000G (devided has three full scale configuration +/-2,4,8G

    The question is how to convet int value of +/-10000mG/10 or +/-75000 mG/10 to Q12 variable, I had a read thro the QMath manual but could not figure out, I do not see int to Q12 solution from the manual or demo code.

    Example code would be helpful.

    Thanks.
  • You can convert measurement values to Q12 by dividing the integer measurement by the scale (10,000 in this case). Since measurements are 16-bit we'll use the IQmath divide function and then cast to Q12 to get the final result in Q12 format with a range of +/-8.0G. The Q12 result is converted to float to verify the result and is equal to 0.5 as expected (0.5G = 5000mG/10).

        _q12 result;
        int32_t measurement = 5000;
        result = (_q12)_IQ12div(measurement, 10000);
        volatile float resultFloat = _Q12toF(result);

    Regards,

    Brent Peterson

  • Is there QMath or IQMath calculator via website or Android app?
    What the best book or material to cover this topic?

    I found divider is 3.45454 number so I can do better with IQ12mpy with 1/3.45454 instead but I get
    q12(1.00024) via IQ12div(Data,3.45454)
    q12(0.999756) via IQ12mpy(Data,1/345454), it say pm section 6.1 manual, it is two time faster for QMath and 10 time faster on IQMath (wow!).

    The manual noted 14 bit precision while multiply has 16 bit precision, wondered if this has to do with this?

    A small error but curious what happened there.

**Attention** This is a public forum