I have the RTC set up to give an interrupt every second, in the interrupt I reset the FTM counter and my software FTM overflow counter and then wait for an input capture. When I get the input capture I print (over USB-CDC) the time in hours, minutes, seconds and then the time to the input capture event in nano-seconds. The FTM is set up to be clocked at 50MHz so the tick is 20nS.
Thus the highest value I would expect to see in my "software" overflow counter before the "seconds" interrupt cleared it, would be 1/(65334 x 20nS) = 762
However I regularly see values over this, can anyone say why this would happen?
Here is the main code created with KSDK 1.3
//turns on seconds interrupt;
//Turn on the FTM counter in free running mode and enable overflow int
FTM_DRV_CounterStart(flexTimer1_IDX, kCounting_FTM_UP, 0x00, 0xFFFF, true);
//Turn on the FTM0 input capture
FTM_DRV_SetupChnInputCapture(flexTimer1_IDX, kFtmFallingEdge, FTM0_channel_1, input_filter_off);
if (FTM0_Ch1_ICflag == 1 )
FTM0_Ch1_ICflag = 0; // clears "input capture" flag set in FTM interrupt routine
cmd_get_datetime(); // prints the current date time
Ch1_nanoseconds_value =(((FTM0_Ch1_timer_overflow_count_store <<16) + FTM0_Ch1_capture_value)*20); // calculates the ns position of pulse this second
PRINTF("capture value%d\r\n", FTM0_Ch1_capture_value);
PRINTF("overflowcount %d\r\n", FTM0_Ch1_timer_overflow_count_store);
PRINTF("overflowcount x 65536 = %d\r\n", (FTM0_Ch1_timer_overflow_count_store<<16));
.....and here is the terminal view, with a couple of examples (second and last) with the overflow count significantly above 762, any thoughts?
Here are the two interrupt routines.
FTM0_timer_overflow_count= 0; //Resets my timer overflow counter back to zero
FTM_HAL_SetCounter(g_ftmBase[flexTimer1_IDX],0); //Resets the FTM counter back to zero
//checking the interrupt flag source and clearing
FTM0_Ch1_timer_overflow_count_store = FTM0_timer_overflow_count;
FTM0_Ch1_ICflag = true;