FRDM-K22F gpio and ftm peripheral drivers

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

FRDM-K22F gpio and ftm peripheral drivers

ソリューションへジャンプ
1,240件の閲覧回数
jimmynguyen
Contributor I

Hello all,

I am currently using KDS v3.0 and KSDK v1.3 to program the FRDM-K22F.  I am trying to output a PWM using the FTM driver into a GPIO pin on the board so that I am able to drive a the step frequency of a motor.  I took a look at the FTM driver and GPIO driver example, I am a little confused with how to set up the a GPIO pin for FTM usage.  

 

Thankyou,

Jimmy

ラベル(1)
0 件の賞賛
返信
1 解決策
964件の閲覧回数
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Jimmy Nguyen

You don't need look into GPIO example to implement an output of PWM using the FTM, FTM channel can be configured for edge-aligned PWM mode, and the signal will be in the pin associated. For example, the SDK 1.3 FTM example uses the FTM0_CH5 witch is in PTD5 (LED) as ATL4:

pastedImage_1.png

So inside the hardware_init() you can find the ftm pin configuration with:

 PORT_HAL_SetMuxMode(PORTD,5u,kPortMuxAlt4);‍‍

The example code set a PWM with a frequency of 24kHZ and a initial duty cycle of 0 that will be increasing and decreasing in the while(1), so you will see changes in the LED brightness:

    ftm_pwm_param_t ftmParam = {
        .mode                   = kFtmEdgeAlignedPWM,
        .edgeMode               = kFtmLowTrue,
        .uFrequencyHZ           = 24000u,
        .uDutyCyclePercent      = 0,
        .uFirstEdgeDelayPercent = 0,
    };‍‍‍‍‍‍‍
 if(brightnessUp)
        {
            // Increase duty cycle until it reach limited value
            if (++ftmParam.uDutyCyclePercent == 100u)
                brightnessUp = false;
        }
        else
        {
            // Decrease duty cycle until it reach limited value.
            if (--ftmParam.uDutyCyclePercent == 0)
                brightnessUp = true;
        }‍‍‍‍‍‍‍‍‍‍‍‍

Hope this information helps you
Have a great day,
Jorge Alcala

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

元の投稿で解決策を見る

0 件の賞賛
返信
1 返信
965件の閲覧回数
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Jimmy Nguyen

You don't need look into GPIO example to implement an output of PWM using the FTM, FTM channel can be configured for edge-aligned PWM mode, and the signal will be in the pin associated. For example, the SDK 1.3 FTM example uses the FTM0_CH5 witch is in PTD5 (LED) as ATL4:

pastedImage_1.png

So inside the hardware_init() you can find the ftm pin configuration with:

 PORT_HAL_SetMuxMode(PORTD,5u,kPortMuxAlt4);‍‍

The example code set a PWM with a frequency of 24kHZ and a initial duty cycle of 0 that will be increasing and decreasing in the while(1), so you will see changes in the LED brightness:

    ftm_pwm_param_t ftmParam = {
        .mode                   = kFtmEdgeAlignedPWM,
        .edgeMode               = kFtmLowTrue,
        .uFrequencyHZ           = 24000u,
        .uDutyCyclePercent      = 0,
        .uFirstEdgeDelayPercent = 0,
    };‍‍‍‍‍‍‍
 if(brightnessUp)
        {
            // Increase duty cycle until it reach limited value
            if (++ftmParam.uDutyCyclePercent == 100u)
                brightnessUp = false;
        }
        else
        {
            // Decrease duty cycle until it reach limited value.
            if (--ftmParam.uDutyCyclePercent == 0)
                brightnessUp = true;
        }‍‍‍‍‍‍‍‍‍‍‍‍

Hope this information helps you
Have a great day,
Jorge Alcala

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

0 件の賞賛
返信