i'm trying to use an encoder to track motor position. i trigger an ISR on the rising edge of one of the encoder outputs.
the following plot shows the motor position vs time (msec). The circles on the plot show a point being plotted. It shows groups of points about ~0.3 msec apart separates by ~3 msec (time between groups).
this data, including the usec timestamp is captured in a buffer during each ISR event and dumped later. The isr is occurring with no other activity. A function is called from loop() and does not return until triggered by a button press.
the data shows that the motor position changes every ~0.3 msec. Tracking position will not be accurate if the isr cannot be processed for more than that time (~3msec).
is there some other interrupt enabled, perhaps for Serial processing?
the code executed while the isr is active. ButtonPress() monitors 2 inputs, returning true if either is LOW.
// ------------------------------------------------
void
simple (void)
{
do {
dist = target - pos;
if (Abs(dist) < 300)
SetSpeed(0);
} while (! buttonPress());
SetSpeed(0);
cond = C_STOP;
}
the delay appears fairly period, so i think it may be some other interrupt. Just having a better understanding of what else the environment is doing could save me some time. I can try disabling all other interrupts and restoring them after my operation is complete.
Change the motor speed and graph again. Does the gap in data still happen every 10 counts at the new speed? Is the gap still about 10 counts long? That would indicate a problem in the encoder.
If, however, the periods of data (3 ms) and no data (3 ms) remain at the new speed, that would indicate that the encoder is not the problem and something is interfering or the code is incorrect. The only interrupt that is not under your control is the millisecond timer which happens for a few microseconds and happens every 900-something microseconds. Those times don't match your data.
i removed the encoder and manually rotated ~1 turn and ~30 counts. The capture is plotted below. The initial jaggedness is probably me just getting it situated in my hand. It shows the ~ correct number of counts. It looks like there's nothing wrong with the encoder.
the following plot is nearer when the motor is started and running faster. Seems like there's more activity. It does appear that the gap widens, 25 msec, near when the motor stops turning. Could more freq ISR events exacerbate a problem