FRDM-K22F gpio and ftm peripheral drivers

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

FRDM-K22F gpio and ftm peripheral drivers

跳至解决方案
758 次查看
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 解答
482 次查看
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 回复
483 次查看
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 项奖励