I use _IQmpy() to multiply two IQ(15) numbers. When apply it to a negative number, it failed to give the correct answer. Here is a example:
#define GLOBAL_Q 15
_iq a = 50;
_iq b = -92;
_iq c;
c=_IQmpy(a, b); // c=-1, error
c= a*b /32768; // c=0, correct
I guess there is a truncation error. 50x(-92) = -4600 = 0xFFFFEE08. After a right shift 15 bit, it is 0xFFFFFFFF = -1. Even the error is only one bit, I used it in my PID controller with 10KHz control loop time, and it saturates my PID output quickly. Any suggestion?
Regards,
Yaoxin