encoder driving me crazy, help

Instead of just copying new position to oldposition, only do it if the newpos is less than your upper limit.

Better still work on the difference between old and new, and add the difference in only when your are within bounds. Using the difference has the advantage that going down can happen immediately.

Treat the long counter as just an indication on what the encoder is doing and use the information to maintain your own user interface number. By splitting the two you have more control.