Tool/software: Code Composer Studio
Hello All,
I have having an issue with the IQFrac function for the MSP430. In a nutshell, it seems that trying to get the fractional portion of a negative IQ number removes all the sign extension, and gives a positive number.
(Note: all my values are IQ16)
In my case, I am calling the IQ16Frac function on a variable whose value is -0.0625 (in hex, this is 0xFFFFE000). When I call the IQfrac function, it returns only 0x0000F000 which is 0.9375, where my value should be -0.0625 (in hex 0xFFFFF000). In this case, it seems the IQFrac function is just masking off the top 16 bits regardless of sign of the IQ number...
When I step through the assembly, I can see combined registers R12 (value 0xF000) and R13(value 0xFFFF), after the call to _IQ16Frac, the registers are R12 (0xF000) and R13 (0x0000). Thus, the combination of this IQ16 number is now 0x0000F0000 (0.9375) which is not correct.
Dissassembly:
010118: 521C 1F04 ADD.W &0x1f04,R12
01011c: 621D 1F06 ADDC.W &0x1f06,R13
010120: 13B1 1950 CALLA #_IQ16frac
010124: 4C82 1F04 MOV.W R12,&0x1f04
010128: 4D82 1F06 MOV.W R13,&0x1f06
Registers before CALLA instruction:
R12 0x00F000 Core
R13 0x00FFFF Core
Registers after CALLA instruction:
R12 0x00F000 Core
R13 0x000000 Core
So I guess the question is, am I doing something wrong?? If not, any easy workarounds??
Thanks,
-mike