By experimentation, that control bit does indeed seem to work! Not my 'favorite' way to prove chip functions, but in a pinch it will do...
This is CONTRARY to the AN4381 statement:
"The processing of the index signal together with the phase signals can only be done in an FTM with three or more channels."
That is, with the SOPT4 register contents set to use the CMP1 ‘output’ as the channel-0 input capture control (for the 2-channel FMT2 in this example):
//Hook FTM2 CH0 capture to run from this CMP1 comparator output!
SIM_SOPT4 |= SIM_SOPT4_FTM2CH0SRC(2);
I do INDEED get a capture value at the index edge! Now of course that still leaves one fundamental issue with this process – knowing ‘which direction’ we were going at the time! That is, for any ‘width’ of Index pulse more than ¼ of the quadrature-period, then the ‘rising’ (or falling) edge we encounter will be the ‘leading’ (or trailing) edge of the pulse, so the encoder counts will inherently differ by the number of PHA/B edges that occur during the width of the index pulse. There is a status bit that tells me the ‘last direction’ the counter was going when I read it, but any value of that assumes that the direction at the time I can get to read it is the same as the direction at the time of the Index-driven capture, which is ‘less than ideal’ in cases of shaft jitter, but I think this is going to work out ‘pretty well’. My next test is to try the 'dual edge capture' capabilities to give me both edges to work with, and that should help the counter-consistency decisions!
As an example, here is some output from my test:
Overflow UP -- output when overall counter goes from 0xFFFF back up thru 0
0031F -- output from comparator-interrupt routine
0031F UP -- output from FTM channel-zero input capture, also printing that ‘last direction’ as UP
00321 -- output from comparator-interrupt routine, going the other direction
00321 DN -- output from FTM channel-zero capture, going ‘down’ this time so the ‘leading edge’ comes 2 counts earlier!
0031F
0031F UP -- Back in the ‘up’ direction
0063F
0063F UP -- One ‘whole turn’ later!
Incidentally, this is a 200-slot encoder disk, so 800 (0x320) quad-edge counts per revolution. The above test was started right at the index pulse. At this ‘speed’ (a CRAWL) the comparator and capture interrupts agree on the encoder count. Certainly at higher speeds, and with some interrupt latency, this will NOT remain true.
Message was edited by: Earl Goodrich II