I am using an FTM module on the K64F as a quadrature decoder to keep track of the position of an optical rotary encoder. I would also like to time-tag the edges of of the A/B quad channels using FTM Input Capture, so that I can more precisely calculate rotation speed. Is this possible with a single FTM module, or will I need to physically connect the quadrature signals to two separate physical pins, each one monitored by a separate FTM module? The first module would continue to act as the Quad Encoder (say FTM2), while the second module (say FTM3) would act as a free-running timer responsible for the periodic interrupt, and the input capture.
For example, say I am measuring angular speed w by running a periodic interrupt (with period dt, in seconds) in which I execute the code:
current = FTM_GetQuadDecoderCounterValue(FTM2);
omega = (revCount + (current - previous))/(PPR*dt); // in revolutions per second
previous = current;
(where PPR is the number of pulses per revolution that the encoder provides, and revCount is incremented anytime that overflows). The above calculation assumes time
dt between the
previous edges, which need not be exactly true. That is, it neglects the time that has passed between the quad decoder increment (i.e. edge received), and the
FTM_GetQuadDecoderCounterValue(FTM2) function call that happens in the above ISR. So what I really need is something like:
omega = (revCount + (current - previous))/(PPR*(t_current - t_previous));
t_previous are recorded using input capture of the quad channel pulses on FTM3.