What is connected to X1?
If there is an encoder connected to X0, X1 the counter will change counting direction on every change of X1, which will result in erratic counting back and forth.
Also, verify that nothing else in the program writes to the counter or resets it.