Hi,
I am using FTM2 in dual edge input capture mode.
FTM2 running on 187500Hz frequency clock.
The PPM signal i am trying to capture is attached.
I am getting some negative numbers sporadically, more frequent when running higher FTM2 clock frequency. But it has a pattern, in the middle of the "overflow" value (65535/2 = 32768) when running 187500Hz FTM clock.
I suspect it is related to an overflow interrupt(s) is/are skipped, have debugged in two days without figuring out the cause of this glitch.
The source code is based on SDK example frdmk64f_ftm_dual_edge_capture with modifications, and is attached.
I appreciate the help and the time consumed to answer this thread!
Best Regards,
已解决! 转到解答。
Hi,
Because you use only the rising edge as a capture signal, I suggest you use single edge capture mode(normal input capture mode) mode and the code will become simple.
void FTM_INPUT_CAPTURE_HANDLER(void)
{
if ((FTM_GetStatusFlags(DEMO_FTM_BASEADDR) & kFTM_TimeOverflowFlag) == kFTM_TimeOverflowFlag)
{
/* Clear overflow interrupt flag.*/
FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, kFTM_TimeOverflowFlag);
g_timerOverflowInterruptCount++;
}
else if (((FTM_GetStatusFlags(DEMO_FTM_BASEADDR) & FTM_FIRST_CHANNEL_FLAG) == FTM_FIRST_CHANNEL_FLAG))
{
/* Disable first channel interrupt.*/
FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, FTM_FIRST_CHANNEL_FLAG);
capture1Val = FTM_GetInputCaptureValue(DEMO_FTM_BASEADDR, (ftm_chnl_t)(BOARD_FTM_INPUT_CAPTURE_CHANNEL));
period=g_timerOverflowInterruptCount*(FTM_MOD&0xFFFF)+capture1Val-capture1Val_Prev;
capture1Val_Prev=capture1Val;
}
}
If you do want to use dual-capture mode, I suggest you disable the first channel interrupt, in this mode, only the second edge generate interrupt.
Hope it can help you
BR
XiangJun Rong
Hi,
Because you use only the rising edge as a capture signal, I suggest you use single edge capture mode(normal input capture mode) mode and the code will become simple.
void FTM_INPUT_CAPTURE_HANDLER(void)
{
if ((FTM_GetStatusFlags(DEMO_FTM_BASEADDR) & kFTM_TimeOverflowFlag) == kFTM_TimeOverflowFlag)
{
/* Clear overflow interrupt flag.*/
FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, kFTM_TimeOverflowFlag);
g_timerOverflowInterruptCount++;
}
else if (((FTM_GetStatusFlags(DEMO_FTM_BASEADDR) & FTM_FIRST_CHANNEL_FLAG) == FTM_FIRST_CHANNEL_FLAG))
{
/* Disable first channel interrupt.*/
FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, FTM_FIRST_CHANNEL_FLAG);
capture1Val = FTM_GetInputCaptureValue(DEMO_FTM_BASEADDR, (ftm_chnl_t)(BOARD_FTM_INPUT_CAPTURE_CHANNEL));
period=g_timerOverflowInterruptCount*(FTM_MOD&0xFFFF)+capture1Val-capture1Val_Prev;
capture1Val_Prev=capture1Val;
}
}
If you do want to use dual-capture mode, I suggest you disable the first channel interrupt, in this mode, only the second edge generate interrupt.
Hope it can help you
BR
XiangJun Rong