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.

TMS320F28334: IQ Library in HVACI Sensor less 2833x (Control Suite) example :

Part Number: TMS320F28334
Other Parts Discussed in Thread: C2000WARE

Hi All,

What is the difference between below 2  functions  in IQ math lib.

1.)   _IQ(2.0);


2.)   _IQ2toIQ(2.0);

Also, Please elaborate when to use function 1 and function 2 with an individual example.

Also, please let me know that "Q24" means 24 Integer bit or fraction resolution in Q24 format?

Thanks & Regards,

  • Hello,

    What is the difference between below 2  functions  in IQ math lib.
    Also, Please elaborate when to use function 1 and function 2 with an individual example.

    The difference between the two functions is that the first is converting a floating point number into an IQ value with the GLOBAL_Q format (whatever you select this to be), but the second function is converting the number from an IQ2 format to the GLOBAL_Q format. The GLOBAL_Q format is the basically a default IQ value format that you use in your program, which by default is 24. Here is an example of how you can use each:

    // How to use _IQ(float F) function
    float floatVal = 2.0;
    _iq fixedValGlobal = _IQ(floatVal);
    
    // How to use _IQNtoIQ(_iqN A) function
    floatVal = 3.0;
    _iq2 fixedValAlt = _IQ2(floatVal);
    fixedValGlobal = _IQ2toIQ(fixedValAlt);

    The way you included the functions in your post is not the proper syntax; you can refer to the IQmath user guide for more details (C2000Ware_4_XX_XX_XX\libraries\math\IQmath\c28\docs in your file explorer).

    Also, please let me know that "Q24" means 24 Integer bit or fraction resolution in Q24 format?

    Within the user guide you can view the exact details, but essentially the "24" refers to the precision of the fixed-point datatype. All the IQ datatypes are long, meaning they are 32 bits in size.

    Best regards,

    Omer Amir

  • Hello Omen Amir,

    Here the range of Q24 is -128 to 127.999 just 7 bit integer , 1 bit is for sign and 24 bit will be fraction right?? 

    Q24 means 24 fixed integer or 24 bit resoltuion after radix point fraction?  The image is from ... c28x IQ Math Libary  section 3.2.

    Also Can you give an example for Q format representation in texas C283x?

    Also exlpain me one Q format arthematic math any addition, multiplication with taking Q16 or Q8 format.

    Thanks & Regards, 

    Meet Pandya

  • Hello,

    Here the range of Q24 is -128 to 127.999 just 7 bit integer , 1 bit is for sign and 24 bit will be fraction right?? 

    Yes, that's correct.

    Q24 means 24 fixed integer or 24 bit resoltuion after radix point fraction?  The image is from ... c28x IQ Math Libary  section 3.2.

    Q24 means that 24-bits are used to represent the fractional part of the number that's stored.

    Also Can you give an example for Q format representation in texas C283x?

    The Q format is a library in C2000Ware, it is solely based on software, not the device type. To use the Q24 format, it should essentially break down like this:

    Also exlpain me one Q format arthematic math any addition, multiplication with taking Q16 or Q8 format.

    Unfortunately I could not find the exact assembly file where the functions are actually implemented. If you want to know how these are done, you can run one of the IQmath examples and use the "Assembly Step Into" operation to see the assembly code that is used. This code shows exactly how the operations are done.

    Best regards,

    Omer Amir

  • Hello Omer Amir,

    I was checking HVACI_SENSORLESS_2833x example in CONTROL SUITE. In that Project, I have some doubts that I wanted to ask on which the previous question were also asked.

    Which are as follows:

    1) I have read IQ math Guide in Control Suite and from Internet about Q Notation but yet I am unable to understand IQ math method in the project. I understand that Q notation is means fixed point value. I also read its document in control suite. Can you please give me info about this in easy way with example.

    2) There is macro in IQ math header  #define   _IQ24(A)      (long) ((A) * 16777216.0L)  I don't understand what exactly this macro do. I understand that it will converts the  value to Q24 Value but what is exactly its purpose which I am not able to understand.(Why it multiply with 2^n. (N= Q format resolution, Q24 then it is multiply with 2^24, for Q20 it is multiply with 2^20). With this multiplication it will covert to Q24 format , is it right? If yes then , Will this macro not exceed that Q24 range. T


    As Q24 has integer range -128 to 127. Then, How this is Q24 conversion?

    3) I have MCU F28334. It has FPU. What changes I should make to use this code for F28334? I know there is Float MATH option in header file. Should I open only that macro or any other changes is need to be done?

    4) Why to use _IQmpy? why we can't use normal FPU multiplication, is there any result difference between those? Please explain. 



    Please help me through this IQ math loop as soon as possible. Thanks in advance. Waiting For your reply.

    Thanks & Regards,
    Meet Pandya 

  • Hello,

    1. Can you clarify what you're asking for? There are existing IQmath examples within the library directory (C2000Ware_4_XX_XX_XX\libraries\math\IQmath\c28\examples), and I've already given you an example of how the format works, so I'm not sure what kind of example you need.
    2. The macro you're looking at essentially is shifting the integer part of the number to the left so that the lower 24 bits (24 bits = 0xFF FFFF in hex) can be used for the precision or fractional part of the fixed-point representation. Please look at the user guide again; the IQ24 datatype allows 8 bits for the integer and 24 bits for the fractional part (using 2's complement, 1 bit is technically used for the sign). The 8 bits for the integer go from -127 to 128, which you can verify using 2's complement. I'm not sure what you mean when you ask if the macro will not exceed Q24 range; if a value is outside the integer range of -127 to 128, then the bits get discarded when it is shifted.
    3. If you have a device with the FPU and you are using IQmath there are no changes necessary since these two do not interact with each other, but be aware that unless your code needs to use fixed-point representation for legacy reasons (i.e. you have a huge program that uses IQmath and it would be unreasonable to replace all the datatypes), it's better to just use floating point values instead, as they are more accurate and the FPU will be used to speed up floating-point operations. The FPU is hardware that speeds up floating point operations, whereas IQmath is software that is used to do fixed-point operations if floating-point operations will be too slow (usually used when there is no FPU on a device).
    4. _IQmpy is used because you cannot do ordinary multiplication on fixed-point numbers; remember that part of the number is integer and the other part is fractional, and the IQmath library allows different sizes for these two parts of the number. Therefore, the multiplication needs to take into account whether two IQ24 datatypes are being multiplied or two IQ5 datatypes. FPU multiplication is used on floating-point numbers; you can look up the exact format of what a floating-point number is (IEEE-754 standard), but fixed-point numbers and floating-point numbers inherently have different structures to their datatype, so they cannot be multiplied the same way (if you look at the assembly output from the compiler, this should be clearer).

    I suggest looking up examples online of how fixed-point and floating-point numbers are used, because the TI math library follows the general format that's used in most other places.

    Best regards,

    Omer Amir