Mike Brewster

KSDK2.0 FTM PWM setup bug

Discussion created by Mike Brewster on Feb 3, 2016
Latest reply on Jul 18, 2016 by manfredschnell

It appears there is a bug in the KSDK2.0 driver for the FTM in the FTM_SetupPwm function. It has to do with specifying the output type, the ELSnB:ELSnA settings in the CnSC register. The input parameter is ftm_chnl_pwm_signal_param_t *chnlParams. The level field in that struct is an enum of type ftm_pwm_level_select_t which has possible values of:


typedef enum _ftm_pwm_level_select


    kFTM_NoPwmSignal = 0U, /*!< No PWM output on pin */

    kFTM_LowTrue,          /*!< Low true pulses */

    kFTM_HighTrue          /*!< High true pulses */

} ftm_pwm_level_select_t;


The error is in the following line of code (which is used in both branches of if/else):


/* Setup the active level */

reg |= (FTM_CnSC_ELSA(chnlParams->level) | FTM_CnSC_ELSB(chnlParams->level));


this shifts level by 2 and masks it with 4 and ORs that with level shifted by 3 anded with 8.


This does not give the appropriate ELSnB:ELSnA settings.