Hi, Snehal,
Regarding your question, I think this is the procedure of the dual capture code. From hardware perspective, you have to connect the captured signal to the even channel of FTM, for example FTM_CH0, FTM_CH2,..., the odd channel is ignored. When the first edge of captured signal is detected, the current FTM counter value is latched to the FTM_CnV reg, when the second edge of captured signal is detected, the current FTM counter value is latched to the FTM_Cn+1V reg, when the FTM_CHn+1 channel interrupt is enabled, an interrupt occurs, you can read the FTM_CnV/FTM_Cn+1V register to variables in ISR of odd channel, figure out the difference, it is okay.
so you can use the snippet for the ISR of FTM.
unsigned int c2v,c3v,diff_cycle;
void FTM0_IRQHandler()
{
//checking the interrupt flag source
//clear interrupt flag
if(FTM_HAL_HasChnEventOccurred(g_ftmBase[FTM_INSTANCE],CHAN2_IDX))
{
FTM_HAL_ClearChnEventFlag (g_ftmBase[FTM_INSTANCE],CHAN2_IDX);
c2v=FTM_HAL_GetChnCountVal(g_ftmBase[FTM_INSTANCE],CHAN2_IDX);
}
if(FTM_HAL_HasChnEventOccurred(g_ftmBase[FTM_INSTANCE],CHAN3_IDX))
{
FTM_HAL_ClearChnEventFlag (g_ftmBase[FTM_INSTANCE],CHAN3_IDX);
c3v=FTM_HAL_GetChnCountVal(g_ftmBase[FTM_INSTANCE],CHAN3_IDX);
}
//figuring out the difference of FTM0_C2V and FTM0_C3V
diff_cycle=c3v-c2v;
}
for the initialization code, I think this is the procedure:
FTM_DRV_Init(BOARD_FTM_INSTANCE, &user_info);
FTM_DRV_SetupChnDualEdgeCapture (BOARD_FTM_INSTANCE, ¶m,BOARD_FTM_X_CHANNEL,0);
TM_HAL_EnableChnInt(g_ftmBase[FTM_INSTANCE],CHAN3_IDX); //enable odd channel interrupt
FTM_DRV_SetClock(BOARD_FTM_INSTANCE,kClock_source_FTM_SystemClk, kFtmDividedBy1);
FTM_HAL_SetDualEdgeCaptureCmd(g_ftmBase[FTM_INSTANCE],CHAN2_IDX,true); //set the DECAPx in FTM_COMBINE register to launch the capturing
for(;;) {} //waiting interrupt
I think it is okay, but I do not test the code.
Hope it can help you
BR
XiangJun Rong