FTM to generate PWM in Output compare mode in KEA128

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

FTM to generate PWM in Output compare mode in KEA128

ソリューションへジャンプ
1,554件の閲覧回数
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,370件の閲覧回数
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,371件の閲覧回数
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,370件の閲覧回数
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 件の賞賛
返信