Different total encoder counts for same timing

Hi, I've written this code to control and read the total revolutions the motor is making within 10s. However, every time I restart it (unplug from battery or from pc), the total count i'm getting on the monitor differs. What can I be doing wrong? I'm using a quadrature encoder like this.

int PWM1 = 2;
int DIR1 = 51;
boolean go=true;
int counter = 0; 
int aState;
int aLastState; 
int outputA = 45;
int outputB= 47;
int start=millis();
void setup() 
{
  Serial.begin(9600);
  pinMode(PWM1, OUTPUT);
  pinMode(DIR1, OUTPUT);

  pinMode(outputA, INPUT);
  pinMode(outputB, INPUT); 
  
  analogWrite(PWM1, 200);

  aLastState = digitalRead(outputA);
  digitalWrite(DIR1, HIGH); 
}

void loop() 
{
  while(go==true){
  aState = digitalRead(outputA);
  if (aState != aLastState){
    if (digitalRead(outputB) != aState){
      counter ++;
    } else {
      counter --; 
    }
    Serial.print("Position: ");
    Serial.println(counter);
aLastState = aState; 
  if (millis()-start >=10000){
    go=false;
  }
  }
  }
  

}

every time I restart it (unplug from battery or from pc), the total count i'm getting on the monitor differs.

What range of different readings are you getting ?

UKHeliBob:
What range of different readings are you getting ?

Between 262 and 371, this is just based on the lowest and highest readings I’ve seen so far.

You should expect to get different values every time. Motor speed varies with time, voltage, load, friction, etc.

For a more detailed explanation, provide the required details, like links to the motor, motor driver, motor power supply, a wiring diagram, describe the motor load, etc.