Hi
I am using the IQmath library within our DSP code and am finding it tricky to get the correct method for integer division of an _iq variable
I have:
- the numerator: a measured _iq value of around 60.0
- the denominator: a Uint16 counter running in interrupt with value between 100 and 10000
Global_Q is 24 for our application
I would like to divide the _iq value by the Uint16 but I am unsure of the correct way to do this.
It might be that I am inspecting the variables incorrectly in CCS but for two options in the test code below both give negative numbers once den equals 1000
- this makes me suspect that I am hitting the limits of the global iq24?
#define kNoTests 4
Uint16 den = 10;
_iq num;
_iq testIQOut;
_iq testIQOutTwo;
static inline void _testRoutine(void){
num = _IQ(61.2);
Uint16 i;
// testing 10, 100, 1000, 10000
for (i = 0; i < kNoTests; i++ ) {
testIQOut = _IQdiv(num, _IQ16toIQ((_iq)((Uint32)den << 16)));
testIQOutTwo = _IQdiv(num, _IQmpyI32(_IQ(1.0), (Uint32)den));
den *= 10;
}
}
Any suggestions for how to cleanly do this would be gratefully received
Best regards,
- Richard