FTM to generate PWM in Output compare mode in KEA128

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

FTM to generate PWM in Output compare mode in KEA128

跳至解决方案
1,541 次查看
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 解答
1,357 次查看
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!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

2 回复数
1,358 次查看
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!
-----------------------------------------------------------------------------------------------------------------------

1,357 次查看
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 项奖励
回复