I wanted to change frequency of PWM at runtime to ramp the stepper motor.
I looked at various options like PPG, but its not available on mcuxpresso or i didn't find it.
Please help.
Solved! Go to Solution.
Hi tims123
Do you use the TPM to output the PWM?
If yes, if you want to change the PWM frequency , you can change your TPMx_MOD,
More details, please check the KL25 reference manual:
https://www.nxp.com/docs/en/reference-manual/KL25P80M48SF0RM.pdf
chapter 31.4.8.1 MOD Register Update
31.4.8.1 MOD Register Update
If (CMOD[1:0] = 0:0) then MOD register is updated when MOD register is written.
If (CMOD[1:0] ≠ 0:0), then MOD register is updated according to the CPWMS bit, that
is:
• If the selected mode is not CPWM then MOD register is updated after MOD register
was written and the TPM counter changes from MOD to zero.
• If the selected mode is CPWM then MOD register is updated after MOD register was
written and the TPM counter changes from MOD to (MOD – 1).
Wish it helps you!
If you still have questions about it, please kindly let me know!
Best Regards,
Kerry
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-----------------------------------------------------------------------------
Used Timers in my application for now.
Implementing Frequency change in fsl_tpm.h API would be great though.
Closing the issue.
Hi tims123
Thanks for your updated information.
Any new questions in the future, welcome to create the new question post!
Best Regards,
Kerry
Hi tims123
Do you use the TPM to output the PWM?
If yes, if you want to change the PWM frequency , you can change your TPMx_MOD,
More details, please check the KL25 reference manual:
https://www.nxp.com/docs/en/reference-manual/KL25P80M48SF0RM.pdf
chapter 31.4.8.1 MOD Register Update
31.4.8.1 MOD Register Update
If (CMOD[1:0] = 0:0) then MOD register is updated when MOD register is written.
If (CMOD[1:0] ≠ 0:0), then MOD register is updated according to the CPWMS bit, that
is:
• If the selected mode is not CPWM then MOD register is updated after MOD register
was written and the TPM counter changes from MOD to zero.
• If the selected mode is CPWM then MOD register is updated after MOD register was
written and the TPM counter changes from MOD to (MOD – 1).
Wish it helps you!
If you still have questions about it, please kindly let me know!
Best Regards,
Kerry
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-----------------------------------------------------------------------------
I'm using the fsl_tpm.h API, it has a method to update PWM duty cycle , but not Frequency or Time Period. will try updating MOD register and will let you know.
HI tims123
Ok, you can try it at first.
Any updated information from your side, just feel free to let me know.
Best Regards,
Kerry