Not really sure if this is a bug or just C behaviour. This code gives the wrong result for a division, unless I use type casting.
int temp; uint16_t MOTOR_CURRENT_CAL; ... // temp is -1250 at this point // MOTOR_CURRENT_CAL is 485 // This should give -2 for the division //temp /= MOTOR_CURRENT_CAL; // This gives 132 //temp /= (int) MOTOR_CURRENT_CAL; // This gives -2
Anyone knows why? Perhaps I should declare MOTOR_CURRENT_CAL as unsigned int instead?