FTM to generate PWM in Output compare mode in KEA128

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

FTM to generate PWM in Output compare mode in KEA128

Jump to solution
912 Views
vigneshbalaji
Senior Contributor I

Hi,

     I want to generate PWM in FTM 2 Channel 1 pin PTH1 using output compare mode. Please help me in setting the duty cycle, frequency etc.

I have made the code snippet below which generates a PWM from the pin but don't know how to control it.

    SIM_SCGC |= SIM_SCGC_FTM2_MASK; /* Enable Clock for FTM2 */
    FTM2_SC |= FTM_SC_PS(7);    /* Select Preescaler in this case 128. 20 Mhz /128 =156.25 Khz. */
                                /* Counter increase by one every 6.4 us */
    FTM2_SC |= FTM_SC_CLKS(1); /*FTM2 use system clock*/
    SIM_PINSEL1 |= 0x0004;
    FTM2_C1SC = 0x14;
1 Solution
728 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi VIGNESH bALAJI,

    If you want to change the duty cycle and the frequency, I suggest you use the EPWM mode instead of the the output compare mode.

   Because from your code, you are using the output compare mode with match toggles the channel output, then the duty will be fixed at the the 50%, but if you want to change the frequency , you can change the MOD register.

  But, if you use the EPWM, if you want to change the duty, you can change the CnV value; if you want to change the frequency, you can change the MOD register.

   You can try it on your side.

   About the code, you can refer to the KE FTM project, which can be downloaded from this link:

   https://www.nxp.com/webapp/Download?colCode=FRDM-KEXX-Driver-Library-Package&appType=license 

   If you still have question about it, please kindly let me know.


Have a great day,
Kerry

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

View solution in original post

2 Replies
729 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi VIGNESH bALAJI,

    If you want to change the duty cycle and the frequency, I suggest you use the EPWM mode instead of the the output compare mode.

   Because from your code, you are using the output compare mode with match toggles the channel output, then the duty will be fixed at the the 50%, but if you want to change the frequency , you can change the MOD register.

  But, if you use the EPWM, if you want to change the duty, you can change the CnV value; if you want to change the frequency, you can change the MOD register.

   You can try it on your side.

   About the code, you can refer to the KE FTM project, which can be downloaded from this link:

   https://www.nxp.com/webapp/Download?colCode=FRDM-KEXX-Driver-Library-Package&appType=license 

   If you still have question about it, please kindly let me know.


Have a great day,
Kerry

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

728 Views
vigneshbalaji
Senior Contributor I

Thank you Kerry Zhou,

                                      I figured out the same thing yesterday and it worked for me :smileyhappy:. Thanks for conforming it.

0 Kudos