- void CaptureHandle(void)
- {
- if( FTM_GetOverFlowFlag( FTM2 ))
- {
- FTM_ClrOverFlowFlag( FTM2 ); // Clear TOF Flag if it was set
- ++g_u32OverFlowCounts;
- }
- if( FTM_GetChannelFlag( FTM2, FTM_CHANNEL_CHANNEL0))
- {
- FTM_ClrChannelFlag( FTM2, FTM_CHANNEL_CHANNEL0 ); // Clear CH(n)F Flag
- g_u16CaptureValue = FTM2->CONTROLS[0].CnV; // capture value
- if( g_bFirstEdge )
- {
- g_bFirstEdge = FALSE;
- g_u16FirstEdgeCountValue = g_u16CaptureValue;
- }
- else
- {
- // Index of count buffer
- g_u32CurCntIndex++;
- if( g_u32CurCntIndex >= COUNT_NUM )
- {
- g_u32CurCntIndex = 0;
- }
-
- // Calc Count
- g_n32CountBuffer[g_u32CurCntIndex] = g_u16CaptureValue + (g_u32OverFlowCounts<<16) - g_u16FirstEdgeCountValue;
- g_u16FirstEdgeCountValue = g_u16CaptureValue; // Treak it as the first edge of the next pulse
- }
- }
- }
|