FRDM-K22F gpio and ftm peripheral drivers

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

FRDM-K22F gpio and ftm peripheral drivers

Jump to solution
702 Views
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

Labels (1)
0 Kudos
1 Solution
426 Views
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!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
1 Reply
427 Views
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 Kudos