cattledog:
As others have indicated, you are not reading all the available quadrature transitions. Your code is reading only one of the four transitions available. With a 20 cpr encoder, you should be seeing 5 counts/rev with your code.There is a very similar encoder with 12 cpr, and that would give 3 counts with your code. Are you certain that you have the 20 cpr encoder?
Yes, I am using 12 CPR encoder. My apologies. I also modified the code but still confused since it seems to get the right output in one rotation but every time the numbers are different.
2
6
10
12