PIC24EP256GP204, MPLABX v6.00, XC16 v2.10, PICKIT3
In the code below DutyCycle is int8_t and OC2RS, OC2R are processor registers uint16t.
OC2RS is 0xFFFF
DutyCycle is 75
Gives OC2R = Temp = 0x028F - INCORRECT
With commented out code enabled and the 'Temp = OC2RS * DutyCycle / 100' line commented out gives Temp = 0xBFFF - CORRECT.
How should I perform this calculation?
Is there any disadvantage in splitting up the calculation?
In the code below DutyCycle is int8_t and OC2RS, OC2R are processor registers uint16t.
OC2RS is 0xFFFF
DutyCycle is 75
Gives OC2R = Temp = 0x028F - INCORRECT
With commented out code enabled and the 'Temp = OC2RS * DutyCycle / 100' line commented out gives Temp = 0xBFFF - CORRECT.
How should I perform this calculation?
Is there any disadvantage in splitting up the calculation?
Code:
uint32_t Temp;
#ifdef SWAP_DIRECTION_LEFT
#ifdef SWAP_PWM_LEFT
//Temp = OC2RS;
//Temp *= DutyCycle;
//Temp /= 100;
Temp = OC2RS * DutyCycle / 100;
OC2R = Temp;