Hi, Roland,
It seems that the PE code has bug.
Pls refer to the following code. Firstly, you call the PWM1_SetDutyUS(2000); the LDD_TError PwmLdd1_SetDutyUS(LDD_TDeviceData *DeviceDataPtr, uint16_t Time) is called actually due to a macro. In the function, the float variable rtval = Time * 20.97152F; the rtval value is the tick number rather than a ratio to FTM_MOD register, because the system clock is 20.97125. In the case, the rtval value should be written the FTM_CnV register directly to change the duty cycle. But the PwmLdd1_SetDutyUS(LDD_TDeviceData *DeviceDataPtr, uint16_t Time) function treats the rtval as a ratio, the rtval is multiplied with the period, then write the FTM_CnV register, I think it is wrong. You can debug the code.
currently, it is okay to call the Setratio16() api function as you have done.
BR
XiangJun Rong
static void SetRatio(LDD_TDeviceData *DeviceDataPtr)
{
PwmLdd1_TDeviceData *DeviceDataPrv = (PwmLdd1_TDeviceData*)DeviceDataPtr;
uint16_t Period;
uint16_t Duty;
(void)TU1_GetPeriodTicks(DeviceDataPrv->LinkedDeviceDataPtr, &Period);
if (Period == 0U) {
Duty = DeviceDataPrv->RatioStore;
}
else {
Duty = (uint16_t)((((uint32_t)(Period) * DeviceDataPrv->RatioStore) + 0x8000) >> 0x10);
}
(void)TU1_SetOffsetTicks(DeviceDataPrv->LinkedDeviceDataPtr, CHANNEL, Duty);
}
LDD_TError PwmLdd1_SetDutyUS(LDD_TDeviceData *DeviceDataPtr, uint16_t Time)
{
PwmLdd1_TDeviceData *DeviceDataPrv = (PwmLdd1_TDeviceData *)DeviceDataPtr;
LDD_TimerUnit_Tfloat rtval; /* Result of multiplication */
/* Time test - this test can be disabled by setting the "Ignore range checking"
property to the "yes" value in the "Configuration inspector" */
if (Time > 0x0C35U) { /* Is the given value out of range? */
return ERR_PARAM_RANGE; /* If yes then error */
}
rtval = Time * 20.97152F; /* Multiply given value and actual clock configuration coefficient */
if (rtval > 0xFFFFUL) { /* Is the result greater than 65535 ? */
DeviceDataPrv->RatioStore = 0xFFFFU; /* If yes then use maximal possible value */
}
else {
DeviceDataPrv->RatioStore = (uint16_t)rtval;
}
SetRatio(DeviceDataPtr); /* Calculate and set up new appropriate values of the duty register */
return ERR_OK; /* OK */
}