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);
}
Solved! Go to Solution.
Hello,
You are triggering the SW synchronization too fast in the infinite while loop.
Because the FTM driver initializes SYNCONF_SWRSTCNT = 1, the FTM_CNT is reset to 0 every time the SW synchronization is triggered in the FTM_DRV_UpdatePwmChannel() function.
Please use a delay loop between the calls of this function.
Thanks,
BR, Daniel
Hello,
You are triggering the SW synchronization too fast in the infinite while loop.
Because the FTM driver initializes SYNCONF_SWRSTCNT = 1, the FTM_CNT is reset to 0 every time the SW synchronization is triggered in the FTM_DRV_UpdatePwmChannel() function.
Please use a delay loop between the calls of this function.
Thanks,
BR, Daniel