Square wave output with variable frequency, FTM

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

Square wave output with variable frequency, FTM

1,234 Views
christofferjärl
Contributor II

Need some help to set up one FTM Ch to be able to output constant 50% DC PWM, with at run time variable frequency.

Target; 1Hz - 500Hz

Using SDK, S32K144.

Any suggestions?

Thank you!

/ Chris

0 Kudos
3 Replies

1,107 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Chris J

There is already an example that can do this in the SDK that comes with the S32DS, you can find it as ftm_pwm_s32k144. Please check it and don't hesitate to tell me if you have any question about it.


Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
-------------------------------------------------------------------------------

0 Kudos

1,107 Views
christofferjärl
Contributor II

Hi Jorge!

I have looked into this example and as far as i can see it is set up to

  • increment or decrement duty cycle
  • Update channel duty cycle
  • Wait for a number of cycles to make the change visible

I have tried to use the FTM_DRV_UpdatePwmPeriod() function to just change the period/frequency and keep the DC at 50%.

But I seeing some trouble to keep a clean 50%DC while changing period. I think I have some kind of timer sync problem..?

0 Kudos

1,107 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Chris J

You have to update the Duty cycle too, because it has to be recalculated with every change in the period, so you need something like:

FTM_DRV_UpdatePwmPeriod(INST_FLEXTIMER_PWM1, FTM_PWM_UPDATE_IN_TICKS, new_period, true);
FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 0U, FTM_PWM_UPDATE_IN_DUTY_CYCLE, 0x4000U, 0U, true);

Hope this helps

Regards

0 Kudos