Hi,
Sorry for the very late reply, but I was able to test the code again only today!
Thank you very much for your support! In the end, I probably found out what was going wrong.
I checked the NUMTOF bits inside the FTM0_CONF register, and they were correctly set.
However, thanks to a collegue of mine, I discovered that in this way I was computing the overflows for all the period of the signal, while in dual edge I was measuring only half period to get the signal frequency.
So, modifying the central part of the FTM0 interrupt handler in this way, I was able to get (finally) correct results:
// Do not check the TOF bit at the beginning
FTM0_SC &= 0x7F; // Then, after the TOF bit has been read, we clear them to be ready for the next handler call
if(FTM0_STATUS & 0x8) {
FTM0_STATUS &= 0x0;
if(FTM0_C2V > FTM0_C3V)
ftm0_pulse=0xFFFF+FTM0_C3V-FTM0_C2V+(ftm0_overflow_count-1)*65536;
else
ftm0_pulse=FTM0_C3V-FTM0_C2V+(ftm0_overflow_count)*65536;
OSSemPost(&ftm0sem, OS_OPT_POST_1 | OS_OPT_POST_NO_SCHED, &err);
ftm0_overflow_count=0; // FTM0 overflow count is set again to 0 for the next measurement.
} else if(FTM0_STATUS & 0x4) { // Count overflow only if nothing has happened on CH03, but something has happened on CH2 (half period is considered)
FTM0_overflow_count++;
}
This solutions seems to work correctly even for very low frequencies.
Thanks again!