AnsweredAssumed Answered

Need help setting up PWM on FTM2_CH0 for output to PortB, bit 18.

Question asked by David Pfaltzgraff on Jul 10, 2015
Latest reply on Jul 13, 2015 by David Pfaltzgraff

I am trying to set up a FRDM-K22F board so that Port b, bit 18 is a PWM signal out. (This is connected to the header J1, pin 12.)


My code is as follows:


ftm_pwm_param_t PWM_Param = {



    20000,         // Frequency

    50,            // Duty cycle (0 - 100!!)






// Set up the PWM hardware for FTM2_CH0 on Port B, bit 18

    PORT_HAL_SetMuxMode(PORTB, 18u, kPortMuxAlt3);

    GPIO_HAL_SetPinDir(PTB, 18u, kGpioDigitalOutput);

    PORT_HAL_SetDriveStrengthMode(PORTB, 18u, kPortLowDriveStrength);

    PORT_HAL_SetSlewRateMode(PORTB, 18u, kPortSlowSlewRate);

    SIM_HAL_EnableClock(SIM, kSimClockGateFtm2);


    FTM_HAL_SetClockSource(FTM2, kClock_source_FTM_None);

    FTM_HAL_SetClockPs(FTM2, kFtmDividedBy2);

    FTM_HAL_SetMod(FTM2, 0xFFFE);

    FTM_HAL_EnablePwmMode(FTM2, &PWM_Param, CHAN0_IDX);

    FTM_HAL_SetBdmMode(FTM2, kFtmBdmMode_11);



What am I missing that prevents the PWM signal from appearing on the pin?


I Know that Port B, pin 18 is the right one as I was able to replace the kPortMuxAlt3 in the first line with a kPortMusAsGpio and before the SIM_HAL line insert an infinite loop toggling the bit and it shows up on the scope.


To answer the anticipated question of why I wouldn't use the FTM_DRV series of routines: These routines limit the output resolution to a range of 0 to 100. For my application I need much higher resolution and plan to use the full 16-bit capability.


Thanks for any pointers.