22 pulses difference doesn't sound like a binary error ( 8-16-32 pulses would be a hint ), but nevertheless did you try to store the stepcounts in an array instead of using the same register back and forth?
BTW: Is the microswitch debounced in hardware or software manners?
BTW: Is the microswitch debounced in hardware or software manners?