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.

TMS320F28069: IQdiv allways results in the integer 567497

Part Number: TMS320F28069

Hello,

I was trying to use the IQmath library, to calculate this division:

//(in the header file "Encoder.h" speediq is defined as:)
double speed;

//(...)


//And then in the Encoder.c file i did as follows:
//p->speed = 105468.75f/temp1;                          //the division i want to make
p->speed = _IQtoF(_IQdiv(_IQ(105468.75),_IQ(temp1))); //The division using IQ

I redefined GLOBAL_Q to 10 in the "Encoder.h" file. And tried to convert the result to float but the result is allways 567497

I think it may be the same issue as the related post, but couldn't find how was this solved... I have never used the IQ library so any comment is very much apreciated,

Thank you,

Joan Marc

  • Hi,

    Do you mean the float result is 567497 or the IQ result? Does this happen for all values of temp1? 

    -Shantanu

  • Hi Shanty,

    I apollogize, the float result is 567497.75 i get the integer 567497 only if i declare the variable "speed" as long. I also tried diferent values of "temp1" and i allways get the same result. I don't know if it helps, but i tried to declare the variable "speediq" as the following types, and stepping over the line:

    "p->speediq = _IQtoF(_IQdiv(_IQ(105468.75),_IQ(temp1)));"

    I got following results, independent of the value of temp1, i allways get the same...:

    speediq as int: => results in 32767

    speediq as long: => results in 567497

    speediq as float => results in 567497.75

    speediq as long double => results in 567497.75

    speediq as _iq => results in 567497 (the debugger represents this as "long")

    I also removed the _IQtoF() function, just to see what i get, so the line is:

    "p->speediq = _IQdiv(_IQ(105468.75),_IQ(temp1));" and i also tried diferent values for temp1, allways get the same result.

    speediq as int: => results in 10031

    speediq as long: => results in 581117743

    speediq as float => results in 581117696.0

    speediq as long double => results in 581117743.0

    speediq as _iq => results in 581117743 (the debugger represents this as "long")

    I also found that if i tried the "step into" function of the debugger, it just steps over, the same as the "step over function". Should i be able to "step into"? it is very strange... i really don't know what can i check or try, i apreciate any comments.

    Thank you in advance for your attention,

    -Joan Marc

  • Hi,

    What is the value of temp1? IQ10 has the following range: [-2097152, 2097152) and precision of ~0.001 (Refer section 3.2 in IQMath documentation). 

    Depending on the value of temp1, it may have underflowed or overflowed the range. Can you try by changing the Q value?

    -Shantanu