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/TMS320F2812: Simple IQ conversion

Part Number: TMS320F2812


Tool/software: TI C/C++ Compiler

I have a 32bit signed integer. Example -

INT32 position_iq24;

I intend to convert it to a float using IQ_24 conversion. At the moment with my basic incorrect understanding, I am doing this. 

Result_PositionValue = _IQ24toF((_iq24)position_iq24);

It is ofcourse generating incorrect results. Please help me understand this IQ conversion a little better. I did try to read the manuals but did not grasp the content clearly (my bad). 

Thank you :) 



  • Raghu,

    It seems to be working ok.  Here is my test case:

    int32 a=0x01800000;    //a=1.5 in IQ24
    float32 x;
    x = _IQ24toF(a);

    I get x=1.5:

    Note that you don't need to typecast the argument as an _iq24.  All that is doing is typecasting a long as a long.  Does nothing.  Including the typecast doesn't change the result however.  It still works.

    Regards,

    David

  • Interesting :)
    Thank you David.

    One question. Does it also work with negative numbers?? Just curious!

    Kind Regards,
    Raghu
  • Also, while reading through the documentation again, another question pops in my head.
    The above mentioned line of code is in TMS320F2812. Because it's a fixed point DSP, is that a reason that I cannot do this conversion on the DSP itself? Which does not make complete sense (why will TI give a library function to convert if the hardware cannot convert at all) but I still ask to be a 100% sure.
  • Raghu,

    Raghu Rajappa said:
    Interesting :) 
     One question. Does it also work with negative numbers?? Just curious!

    It works on negative numbers, I guess depending on your definition of works.  I made a=0xFE800000, which is -1.5 in IQ24.  I get x=-1.49999988 in the CCS expressions window.  If I change to hex view, I see x=0xBFBFFFFF.

    The "Exact" answer is -1.5 = 0xBFC00000.  So, there is some numerical roundoff error in the last binary place when this number is converted from iq24 to float32.  The same thing could theoretically happen with positive numbers.  This is typical of floating point.  Results are not always exact.

    Is this roundoff error the reason you are saying the function is not working?

    Regards,

    David

  • Raghu Rajappa said:
    Also, while reading through the documentation again, another question pops in my head.
    The above mentioned line of code is in TMS320F2812. Because it's a fixed point DSP, is that a reason that I cannot do this conversion on the DSP itself? Which does not make complete sense (why will TI give a library function to convert if the hardware cannot convert at all) but I still ask to be a 100% sure.

    This has nothing to do with being a fixed point CPU.  Even a floating point CPU knows nothing about fractions.  A floating point CPU (such as F28335) could convert an int or a long to a float32 in hardware, but if the int or long is representing a fractional value (or IQ value) the CPU does not know anything about the binary point.  You'd still need to use the IQmath library to apply the proper scaling.
    - David