FTM PWM Questions

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

FTM PWM Questions

1,014 Views
derekcook
Senior Contributor I

Hello, 

I have a couple of questions about the FTMs. 

1) Is it possible to set one FTM channel to be one frequency, and another FTM channel to be a different frequency? This does not work for me. I am trying to set channel 0 to run at 25kHz on FTM2, and channel 1 to run at 1kHz. When I do this, both channels run at 1kHz: 

Here is my init function:

/* Configure ftm params with frequency 25kHZ */
ftm_u_pwmParam.chnlNumber = FTM_U_PWM_CHANNEL;
ftm_u_pwmParam.level = u_pwmLevel;
ftm_u_pwmParam.dutyCyclePercent = u_pwm_dutyCycle;
ftm_u_pwmParam.firstEdgeDelayPercent = 0U;

ftm_brake_pwmParam.chnlNumber = FTM_BRAKE_PWM_CHANNEL;
ftm_brake_pwmParam.level = brake_pwmLevel;
ftm_brake_pwmParam.dutyCyclePercent = brake_pwm_dutyCycle;
ftm_brake_pwmParam.firstEdgeDelayPercent = 0U;

FTM_GetDefaultConfig(&ftm2_pwmInfo);

/* Initialize FTM module */
FTM_Init(FTM2_BASEADDR, &ftm2_pwmInfo);

FTM_SetupPwm(FTM2_BASEADDR, &ftm_u_pwmParam, 1U, kFTM_CenterAlignedPwm, 25000U, FTM_SOURCE_CLOCK);
FTM_SetupPwm(FTM2_BASEADDR, &ftm_brake_pwmParam, 1U, kFTM_CenterAlignedPwm, 1000U, FTM_SOURCE_CLOCK);

/* Enable channel interrupt flag.*/
FTM_EnableInterrupts(FTM2_BASEADDR, FTM_U_PWM_CHANNEL_INTERRUPT_ENABLE);
FTM_EnableInterrupts(FTM2_BASEADDR, FTM_BRAKE_PWM_CHANNEL_INTERRUPT_ENABLE);

/* Enable at the NVIC */
EnableIRQ(FTM2_INTERRUPT_NUMBER);

FTM_StartTimer(FTM2_BASEADDR, kFTM_SystemClock);

2) Can I get a frequency less that 1kHz out of an FTM Channel? Looking at the different clocks, this should be my minimum edge aligned PWM frequency, however anything I set less than 1kHz comes out as 1kHz: 

kCLOCK_CoreSysClk 120000000 – Min = 500Hz

kCLOCK_PlatClk 120000000 – Min = 500Hz

kCLOCK_BusClk 60000000 – Min = 250Hz

kCLOCK_FlexBusClk 30000000 – Min = 125Hz

kCLOCK_FlashClk 24000000 – Min = 100Hz

3) When I try to use a clock slower than the kCLOCK_BusClk, such as the kCLOCK_FlexBusClk and kCLOCK_FlashClk my output PWM is double of what I set? Why would this be? It is double for both the Edge and Center Aligned PWM.

4) I can't see any difference between a center and edge aligned PWM. Reading online it seems the center aligned PWM period should be double the edge aligned since the counter has to count up and then back down, but when I set center or edge aligned both of the periods are equal. 

Labels (1)
0 Kudos
3 Replies

690 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Derek,

1. I'm afraid it is impossible. All channels in a FTM share one counter, each counter has a MOD register which determine the frequency. You can't get 2 different frequency simultaneously.

2. You can get pwm lower than 1kHz. I take K64 for example. The Bus clock is 50Mhz max. Prescale factor selection is 128. If you want pwm to be 500Hz, set MOD=50,000,000/128/500-1=780. You can look into FTM_SetupPwm() for detail.

3. I don't know which mcu do you use. But to K series and KV series MCU, you can only use bus clock as the source of FTM. You can use Flexbus or flashbus.

4. Edge-Aligned PWM period is determined by (MOD-CNTIN+0x0001). Centre-Aligned PWM period is determined by 2x(MOD-CNTIN). But the driver has taken this into consideration.

Regards,

Jing

690 Views
derekcook
Senior Contributor I

Thanks for the response! This answered all of the questions I had

0 Kudos

690 Views
linestream-adam
Senior Contributor I

Derek,

1. I don't think you will be able to get two different channels on the same FTM to run at different frequencies. You should change to using two different FTMs.

I think the rest are probably better addressed by some of the MCU experts on this forum.