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: IQ format

Tool/software: Code Composer Studio

Hello, 

  My stupid question is about IQ format.  For example, can I present an integer 446 as _IQ(446)?  What means or number of _IQ(0.03)?  In addition, _IQ15(1.0) = 2 ^^ 15 = 32768? _IQ15(0.03) = 0.03 x a^^15 = 983?

  Thanks,

  Yong

  • You must be using one of the IQmath libraries from TI.  Exactly which one do you use?  Once I know that, I'll move this thread to where those experts are available.

    Thanks and regards,

    -George

  • I used the TI subroutine 2 poles 2 zero regulator CNTRL_2p2zInline().

  • Which TI device do you use?  For instance, is it a C2800 device, or a C6600 device?

    Thanks and regards,

    -George

  • Hello, 

    As you mentioned, to convert floating point to Q15, you must multiply the number by 2^^15 and round to the nearest integer.

    Hence the range is 0 to (1 + (2^15 - 1)/2^15 ) or 0 to 1.999

    However, if you want to store whole numbers as well, you need to keep in mind the register size. For example, if you are storing your numbers in a 16 bit register and you are using Q15 format, the maximum number you can store is 0xFFFF * 2^(-15) = 1.9999. If you are using a 32 bit register, the maximum number you can store is 0xFFFFFFFF * 2^(-15) = 131071.9999. 

     Since F28M53H52 uses 32 bit registers, _IQ15(446) will be stored as 446 * 2^15 = 14614528. Similarly, _IQ15(1.0) = 32768 and IQ15(0.03) = 983. 

    Hope this helps.

    -Shantanu

  • Hello, Shantanu,

      I returned with the que

  • Hello, Shantanu,

      Thank for your answer but asked one question but seemed you did not receive it. My question is

      If _IQ15(446) = 446 x 2^15 = 14514528, but based TI's Q format range and resolution table, it indicates that for _IQ15, its range is -65536 to 65535.999969482.  Does that mean my _IQ15(446) will be saturated as 65535 instead of 14514528?  In addition, if I still want to use _IQ15 to present 446, should I use _IQ15(446/2^15) instead?

     Thansk,

     Yong

  • Yong, 

    Apologies. I overlooked the fact that it was a signed data type. You are correct about the range. It works the same way as when you try to store a number larger than the size of the data type. It will overflow and you will get a junk value. 

    I would definitely recommend that you opt for a different Q format. If it is absolutely necessary for you to use Q15, I suggest you to break the number into two parts and use two registers/variables to store the number. 

    Your approach of _IQ(446/2^15) may work if you account for this conversion throughout the code and make sure there is no confusion between other numbers. Also, you need to keep in mind the resolution. The resolution for Q15 is 0.000030518. You cannot store a number x if x/2^15 is less than that resolution. Ultimately, using _IQ(446/2^15) is not a reliable and scalable approach. 

    Hope this helps. 

    -Shantanu