change frequency at runtime for PWM in mcuexpresso for FRDM-KL25Z

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

change frequency at runtime for PWM in mcuexpresso for FRDM-KL25Z

Jump to solution
1,249 Views
tims123
Contributor I

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.

0 Kudos
1 Solution
1,239 Views
kerryzhou
NXP TechSupport
NXP TechSupport

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.

-----------------------------------------------------------------------------

View solution in original post

0 Kudos
5 Replies
1,210 Views
tims123
Contributor I

Used Timers in my application for now. 

 

Implementing Frequency change in fsl_tpm.h API would be great though.

 

Closing the issue.

0 Kudos
1,194 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi tims123

   Thanks for your updated information.

    Any new questions in the future, welcome to create the new question post!

 

Best Regards,

Kerry

0 Kudos
1,240 Views
kerryzhou
NXP TechSupport
NXP TechSupport

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.

-----------------------------------------------------------------------------

0 Kudos
1,235 Views
tims123
Contributor I

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.

0 Kudos
1,226 Views
kerryzhou
NXP TechSupport
NXP TechSupport

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

0 Kudos