FTM2 MK64 dual edge input capture glitch

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

FTM2 MK64 dual edge input capture glitch

跳至解决方案
416 次查看
RawiUA
Contributor I

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,

 

Screenshot 2023-12-25 005644.png

0 项奖励
回复
1 解答
379 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

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

 

在原帖中查看解决方案

0 项奖励
回复
1 回复
380 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

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

 

0 项奖励
回复