S32k144-Problem about PWM output of FTM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32k144-Problem about PWM output of FTM

Jump to solution
2,098 Views
cqhcau
Contributor I

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);
}

Labels (1)
Tags (1)
0 Kudos
1 Solution
1,927 Views
danielmartynek
NXP TechSupport
NXP TechSupport

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

View solution in original post

0 Kudos
1 Reply
1,928 Views
danielmartynek
NXP TechSupport
NXP TechSupport

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

0 Kudos