Insert Dead Time FTM0 FRDM-KE15Z

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

Insert Dead Time FTM0 FRDM-KE15Z

1,759 Views
pablo_cosgaya
Contributor II

Hello everyone,

I am finding trouble trying to insert dead time on a PWM signal in my FRDM-KE15Z Board. I have tried different configurations of FTM0 but none seem to work, the PWM signals on both channels pairs CH0/CH1 and CH2/CH3 work as expected except for the lack of dead time. I may be missing something I may not have figured out yet so I'd appreciate some help on this as I am quite new to both embedded systems and NXP microcontrollers.

Attached can be found my present configuration settings just in case my mistake is something that can be easily fixed that I may have not noticed.

pastedImage_1.png

pastedImage_2.png

pastedImage_3.png

Thanks in advance,

Pablo Cosgaya

5 Replies

1,444 Views
marek_neuzil
NXP Employee
NXP Employee

Hello Pablo Cosgaya,

I have checked the implementation of the deadtime insertion support in the fsl_ftm driver and there is missing support of the DTENn bit in the FTMx_COMBINE register that enables the deadtime insertion of the FTM channel pair (combined mode of channels n and n+1). I have reported the defect to the responsible development team (KPSDK-27729).

The initialization of the PWM channels is done in the FTM_SetupPWM() function. You can update the implementation of this function in the fsl_ftm.c file in your project by the following way:

/* Set the combine bit for the channel pair and enable dead time insertion. */
base->COMBINE |=
(1U << (FTM_COMBINE_COMBINE0_SHIFT + (FTM_COMBINE_COMBINE1_SHIFT * chnlParams->chnlNumber))) |
(1U << (FTM_COMBINE_DTEN0_SHIFT + (8 * chnlParams->chnlNumber)));

It is the line 515 in the fsl_ftm driver version 2.1.0.

This update of the source code always enable deadtime insertion for the PWM channel pair in the combined mode (kFTM_CombinedPwm).

 

You can also find detailed description of the FTM peripherals and examples of initialization in the application note AN5142 - Features of the FlexTimer Module, see the link https://www.nxp.com/docs/en/application-note/AN5142.pdf.

Best Regards,

Marek Neuzil

1,444 Views
pablo_cosgaya
Contributor II

Hello Marek,

Thanks for the help, but I have noticed that using your code to fix the deadtime issue causes the PWM outputs of an odd number (CH1, CH3) to deactivate and always outpute a false state while the even ones (CH0,CH2) keep working fine. I have also tried setting the deadtime enable on via the use of the  FTM_SetDeadTimeEnable() function without using your fix but the same error keeps appearing and I cannot quite figure out why. 

Any ideas why this may be?

Thanks in advance,

Pablo Cosgya

0 Kudos

1,444 Views
marek_neuzil
NXP Employee
NXP Employee

Hello Pablo Cosgaya,

Could you send me your project configuration file (*.mex file) or the generated peripherals.c and peripherals.h files, please? I will verify the functionality of the code on the target board.

Best Regards,

Marek Neuzil

0 Kudos

1,444 Views
pablo_cosgaya
Contributor II

Hello again,

I've added the .mex file and both peripheral files to this message.

Thanks for your support!

Pablo Cosgaya

0 Kudos

1,444 Views
marek_neuzil
NXP Employee
NXP Employee

Hello Pablo Cosgaya,

I have checked the functionality of the FTM outputs on the target board and I have found the problem with the PWM mode. The SetupPWM() function support just the Combine PWM mode but the Complementary PWM mode must be set for proper functionality of the deadtime insertion. Currently, the complementary mode and deadtime insertion is supported by the following inline functions in the ftm driver:

/*!
* @brief This function enables/disables complementary mode in a channel pair.
*
* @param base FTM peripheral base address
* @param chnlPairNumber The FTM channel pair number; options are 0, 1, 2, 3
* @param value true: enable complementary mode; false: disable complementary mode
*/
static inline void FTM_SetComplementaryEnable(FTM_Type *base, ftm_chnl_t chnlPairNumber, bool value)

/*!
* @brief This function enables/disables the dead time insertion in a channel pair.
*
* @param base FTM peripheral base address
* @param chnlPairNumber The FTM channel pair number; options are 0, 1, 2, 3
* @param value true: Insert dead time in this channel pair; false: No dead time inserted
*/
static inline void FTM_SetDeadTimeEnable(FTM_Type *base, ftm_chnl_t chnlPairNumber, bool value)

Therefore the same polarity of the FTM channels must be used (e.g. .chnlPolarity = 0), see the FTM configuration below: 

const ftm_config_t FTM_1_config = {
 .prescale = kFTM_Prescale_Divide_1,
 .bdmMode = kFTM_BdmMode_0,
 .pwmSyncMode = kFTM_SoftwareTrigger,
 .reloadPoints = 0,
 .faultMode = kFTM_Fault_Disable,
 .faultFilterValue = 0,
 .deadTimePrescale = kFTM_Deadtime_Prescale_16,
 .deadTimeValue = 20,
 .extTriggers = 0,
 .chnlInitState = 0,
 .chnlPolarity = 0,
 .useGlobalTimeBase = false
};‍‍‍‍‍‍‍‍‍‍‍‍‍‍

And the FTM initialization function must be updated by the following way:

void FTM_1_init(void) {
 FTM_Init(FTM_1_PERIPHERAL, &FTM_1_config);
 FTM_SetupPwm(FTM_1_PERIPHERAL, FTM_1_combinedPwmSignalParams, sizeof(FTM_1_combinedPwmSignalParams) / sizeof(ftm_chnl_pwm_signal_param_t), kFTM_CombinedPwm, 10000U, FTM_1_CLOCK_SOURCE);
 
 // Set the complementary mode and enable the deadtime insertion on the channel pairs
 FTM_SetComplementaryEnable(FTM_1_PERIPHERAL, kFTM_Chnl_0, true);
 FTM_SetDeadTimeEnable(FTM_1_PERIPHERAL, kFTM_Chnl_0, true);
 FTM_SetComplementaryEnable(FTM_1_PERIPHERAL, kFTM_Chnl_1, true);
 FTM_SetDeadTimeEnable(FTM_1_PERIPHERAL, kFTM_Chnl_1, true);
 
 FTM_StartTimer(FTM_1_PERIPHERAL, kFTM_SystemClock);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I have already proposed the updated of the ftm driver to support the complementary mode (including the deadtime insertion) in the FTM_SetupPWM(), FTM_SetupPwmMode() and FTM_UpdatePwmDutycycle() functions. Subsequently the FTM component shall be also updated to support the Complementary mode and deadtime insertion.

Best Regards,

Marek Neuzil

0 Kudos