AnsweredAssumed Answered

S32k144-Problem about PWM output of FTM

Question asked by qh c on Feb 16, 2020
Latest reply on Feb 17, 2020 by Daniel Martynek

I want to output one PWM signal with 4000hz,50% duty cycle.

I modify on the official  demo "ftm_pwm" ,the SDK is RTM3.0.0.

I change the PE  configuration of PWM to "Edge-Aligned PWM" .

 

 When I run  FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 0U, FTM_PWM_UPDATE_IN_DUTY_CYCLE, dutyCycle, 0U, true); only once like below, the PWM signal can output normally.

 

volatile uint16_t dutyCycle =0x4000;

/* Infinite loop
* - increment or decrement duty cycle
* - Update channel duty cycle
* - Wait for a number of cycles to make
* the change visible
*/
FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 0U, FTM_PWM_UPDATE_IN_DUTY_CYCLE, dutyCycle, 0U, true);
while (1)
{
// if (increaseDutyCycle == false)
// {
// dutyCycle--;
// if (dutyCycle < 1U)
// increaseDutyCycle = true;
// }
// else
// {
// dutyCycle++;
// if (dutyCycle > 0xFFFU)
// increaseDutyCycle = false;
// }
// FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 0U, FTM_PWM_UPDATE_IN_DUTY_CYCLE, dutyCycle, 0U, true);
// delayCycles(0x2FFU);
}

But when I run  FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 0U, FTM_PWM_UPDATE_IN_DUTY_CYCLE, dutyCycle, 0U, true);in the while loop like below, the PWM signal can not output.So what's the problem?How to use FTM_DRV_UpdatePwmChannel funtion  correctly?

 

/* Infinite loop
* - increment or decrement duty cycle
* - Update channel duty cycle
* - Wait for a number of cycles to make
* the change visible
*/
// FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 0U, FTM_PWM_UPDATE_IN_DUTY_CYCLE, dutyCycle, 0U, true);
while (1)
{
// if (increaseDutyCycle == false)
// {
// dutyCycle--;
// if (dutyCycle < 1U)
// increaseDutyCycle = true;
// }
// else
// {
// dutyCycle++;
// if (dutyCycle > 0xFFFU)
// increaseDutyCycle = false;
// }
FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 0U, FTM_PWM_UPDATE_IN_DUTY_CYCLE, dutyCycle, 0U, true);
// delayCycles(0x2FFU);
}

Attachments

Outcomes