Hello,
There are a couple of possibilities that seem to give the desired results -
#define PWM_MODULUS 0x0400
#define V_PULLIN 100L
#define V_HOLDING 18L
const unsigned short PWM_HOLDING = (PWM_MODULUS * V_HOLDING) / 120;
const unsigned short PWM_PULLIN = (PWM_MODULUS * V_PULLIN) / 120;
GLOBALVAR = ANOUTHERVAR / (char)V_HOLDING;
The second possibility is as follows, where PWM_MODULUS is forced to be a 32-bit value, giving the result of the multiplication also 32-bit.
#define PWM_MODULUS 0x0400L
#define V_PULLIN 100
#define V_HOLDING 18
const unsigned short PWM_HOLDING = (PWM_MODULUS * V_HOLDING) / 120;
const unsigned short PWM_PULLIN = (PWM_MODULUS * V_PULLIN) / 120;
GLOBALVAR = ANOUTHERVAR / V_HOLDING;
The final statement for either method takes the same number of bus cycles to execute (115 cycles when simulating a HC908 device).
Regards,
Mac