Encoders using Interrupts

I am writing an application that involves two encoders measuring the position of two separate motors. The encoders are supposed to output 100 pulses per revolution so I set up a Mega to cause an interrupt when the rising edge of each of these pulses is detected. That is, one interrupt for the 'left' encoder and one interrupt for the 'right' encoder.

The motors lift a harness up and down and the encoders are used to make sure that the motors stay in a two revolution range. For instance, if the very top is set to the zero point, it needs to stay between this value and 200 (two full revolutions). The encoders seem to work fine when using only one and I'm able to stop the motor in code at 0 or at 200. But something different happens when I use both of the motors/encoders at the same time...

I'm not sure if the interrupts are interrupting each other before they have time to execute the code they contain, but they seem to miscount. For instance, if both of the motors are at the 0 location and I lower until it reaches 200, they seem to stop at the same spot meaning the code properly counted the 200 interrupts for each encoder. But when I raise them back up, one will stop at 25 or any value around there and think/know that its at the 0 location. This then repeats for the following raise/lower processes and they get further and further out of wack.

I'm not sure if other people experience a problem similar to this when using two encoders and two interrupts, but if anyone can help, I would greatly appreciate it.

By the way, the software I'm writing controls whether or not the motors spin CW or CCW so there is only the need for one line per encoder and not two to tell the direction.

You need to post all your sketch to really receive any help. The fact that one alone works but two not so well could be that you are spending too much time inside the ISR interrupt routines, causing missing interrupts. When you are inside a ISR, all other interrupts are disabled until the ISR routine completes and returns to the main sketch.

Lefty