control a stepper motor with rotary encodeer

It would help everybody help you, if you could minimize the code you have trouble with. Focus on what's going wrong, delete as much as possible from your code while keeping the part that makes it go wrong. The moment you delete something that will lead to the code working ok, you have found where the error is. Good chance is you find the bug yourself! If not, post the code here, inside the code tags, together with your circuit.