DC motor don't come back in same position

Do you know if your code is reliably counting revolutions?

I would greatly simplify the ISR code if that was my project - perhaps down to the point where it just increments (or decrements) the count variable and sets a flag to say there is a new value.

Then I would do the rest of the computation in the main code whenever the flag shows there is new data.

It would also allow you to print the count as it happens for debugging purposes.

How many sensor pulses do you get per revolution?

I am doing something a bit similar to read the speed and count revolutions of a small DC motor in a model train - but using a reflective optical sensor. I don't need to "measure" direction because I will know that from the code that drives the motor.

...R