cancel
Showing results for
Did you mean:

265 Views
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)
• ### Tips and Tricks

92 Views
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!

Daniel