please help trouble shoot code_S32DS for MPC5744P

Showing results for 
Search instead for 
Did you mean: 

please help trouble shoot code_S32DS for MPC5744P

Contributor III
NXP expert,
Please help trouble shoot code(a function and its call) below. why I got dutyU, V & W all equal to zero?
And would please provide a piece of suggested code to calculate: 4000*(19661/65535), the 3 numbers for in all integers(uint16), and the result should be integer(uint16) too, for MPC5744P motor control using S32DS.
FLEXPWM_set_duty(19661, 19661, 19661);
tBool FLEXPWM_set_duty(tU16 x, tU16 y, tU16 z){
 tU16 periodCarry, dutyU, dutyV, dutyW;
 dutyU = x;
 dutyV = y;
 dutyW = z;
 periodCarry = 4000;
 dutyU = (tU16)MLIB_Mul((tFloat)periodCarry, (MLIB_Div_FLT((tFloat)dutyU,(tFloat)65535)));
 dutyV = (tU16)MLIB_Mul((tFloat)periodCarry, (MLIB_Div_FLT((tFloat)dutyV,(tFloat)65535)));
 dutyW = (tU16)MLIB_Mul((tFloat)periodCarry, (MLIB_Div_FLT((tFloat)dutyW,(tFloat)65535)));
at this point, I got dutyU, dutyV, dutyW all equal to zero, but I am expecting them all 1200.
return (TRUE);
thank you very much.
Susan Li
Labels (1)
1 Reply

NXP Employee
NXP Employee

Hi liwuquan‌,

Just be careful that AMMCLIB functions need signed inputs. Most likely you so not get the correct answers due to the type casting - i presume the compiler informs you about that.

Why don't you try something simpler like this: multiplication followed by right shifting 16bits


Hope it helps!