Changing FTM_PWM period and duty cycle

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Changing FTM_PWM period and duty cycle

2,384 次查看
bartezz32
Contributor I

I'm using S32K148 with FTM_PWM and OSIF modules in Processor Expert. I want to update PWM period from 1Hz to 4Hz.
When 1Hz 50% duty cycle signal using "FTM_DRV_UpdatePwmChannel()" is generated everything looks good:

FTM_DRV_UpdatePwmChannel.PNG

 

After delay for 2 seconds (from OSIF module - "OSIF_TimeDelay()") and PWM period update to 4Hz using "FTM_DRV_UpdatePwmPeriod()" period is not changed and signal is not generated anymore:

FTM_DRV_UpdatePwmPeriod_2sec_OSIF_Delay.PNG
Calling again "FTM_DRV_UpdatePwmChannel()" after "FTM_DRV_UpdatePwmPeriod()" not show any change.

My FTM_PWM configuration in Processor Expert:

flexTimer_pwm1_Configuration.PNGflexTimer_pwm1_Initialization.PNG
Example code in main.c:

bartezz32_1-1615981426353.png

What cause a problem? Do I need manually change value in registers, instead of PE configuration?

0 项奖励
回复
5 回复数

2,271 次查看
bartezz32
Contributor I

Hello, 

This code works, but I have another question.
Is it possible in "Next Loading Point" sync mode to find a reload opportunity after period update in faster way? In pictures below a red signal show the moment when Period and Duty Cycle update methods are called, but generating signal with new period value is done later. Red signal is generated using GPIO pin connected to another port in the board.  

FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 1U, FTM_PWM_UPDATE_IN_TICKS, 500, 0U, false);
FTM_DRV_UpdatePwmPeriod(INST_FLEXTIMER_PWM1, FTM_PWM_UPDATE_IN_TICKS, 1000, true);
PINS_DRV_WritePin(PTD, 17, 1);
OSIF_TimeDelay(980);
PINS_DRV_WritePin(PTD, 17, 0);
FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 1U, FTM_PWM_UPDATE_IN_TICKS, 125, 0U, false);
FTM_DRV_UpdatePwmPeriod(INST_FLEXTIMER_PWM1, FTM_PWM_UPDATE_IN_TICKS, 250, true);
PINS_DRV_WritePin(PTD, 17, 1);

 

1.PNG

 

2.PNG

Depending on value in OSIF_TimeDelay() the update is done different moments (red line goes from 1 to 0 and back to 1). But signal is changed later (at next reload opportunity). 
In immediate reload is done instantly. Like in this pictures bellow
immediate.PNG

 

immediate_2.PNG

I was trying to call a methods: 

FTM_DRV_SetHalfCycleCmd(FTM0, true);
FTM_DRV_SetHalfCycleReloadPoint(INST_FLEXTIMER_PWM1, 500, false);

Between FTM_DRV_Init() and FTM_DRV_InitPwm(), but nothing happens. Is it even possible to find a faster reload opportunity, because now reload opportunity is delayed?

 

 

0 项奖励
回复

2,239 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hello @bartezz32,

Please try this:

FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 1U, FTM_PWM_UPDATE_IN_TICKS, 500, 0U, false);
FTM_DRV_UpdatePwmPeriod(INST_FLEXTIMER_PWM1, FTM_PWM_UPDATE_IN_TICKS, 1000, true);

OSIF_TimeDelay(2000);

FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 1U, FTM_PWM_UPDATE_IN_TICKS, 125, 0U, false);
FTM_DRV_UpdatePwmPeriod(INST_FLEXTIMER_PWM1, FTM_PWM_UPDATE_IN_TICKS, 250, false);

FTM_DRV_SetHalfCycleReloadPoint(INST_FLEXTIMER_PWM1, 500, true);

OSIF_TimeDelay(2000);

 

The two functions UpdatePWMChannel() and UpdatePWMPeriod() do not trigger the synchronization but the SetHalfCycleReloadPoint() does. 

 

Regards,

Daniel

0 项奖励
回复

2,357 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Can you attach the project do that I can test it?

 

BR, Daniel

0 项奖励
回复

2,354 次查看
bartezz32
Contributor I

When sync point (in Processor Expert) is changed from "Next Loading Point" to "Immediate" signal is generated in proper way. If I'm using "Next Loading Point" I need to change something more in registers to work as it should?Sync_Point_Immediate.PNG

 

0 项奖励
回复

2,297 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Sorry for the delayed response.

I tested the code and it updates the C1V register to a higher number than the value in the MOD register.

Can you use something like this instead?

FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 1U, FTM_PWM_UPDATE_IN_TICKS, 500, 0U, false);
FTM_DRV_UpdatePwmPeriod(INST_FLEXTIMER_PWM1, FTM_PWM_UPDATE_IN_TICKS, 1000, true);

OSIF_TimeDelay(2000);

FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 1U, FTM_PWM_UPDATE_IN_TICKS, 125, 0U, false);
FTM_DRV_UpdatePwmPeriod(INST_FLEXTIMER_PWM1, FTM_PWM_UPDATE_IN_TICKS, 250, true);

 

Thanks,

Daniel

0 项奖励
回复