To rotate EC motor one revolution and stop it

Hello
I got a quick question about the coding I have.

First of all I am using a EC motor
https://downloads.maxonmotor.com/Katalog_neu/eshop/Downloads/Katalog_PDF/maxon_ec_motor/EC-max-programm/new/newpdf_11/EC-max-22-283837_11_EN_164.pdf

and a motor encoder
https://downloads.maxonmotor.com/Katalog_neu/eshop/Downloads/Katalog_PDF/maxon-tacho/Encoder-HEDS-5540/new/newpdf_11/ENC-HEDS-5540-500imp-110511_11_EN_266-267.pdf

Looking at the spec of motor encoder, I found out that for one revolution, the max pulse would be 500. So I have programmed it such a way that the motor would rotate 360 degrees at 500 th pulse. However the motor stopped approximately 270 degrees after the starting point. According to our output read out, it started from

Position: 0
to
Position: -32718

Can someone please tell me what mistakes I have made on my code?

Following code is what I tested out :

#define DIR_PIN 8
#define STEP_PIN 9
#define motorenable 10

int encoder0PinA = 2;
int encoder0PinB = 3;

volatile int encoder0Pos = 0;
volatile int encoder0PinALast = LOW;
volatile int n = LOW;
int valNew = 0;
int valOld = 0;
volatile int m = LOW;
int temp;

void setup()
{  
  pinMode(DIR_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode(motorenable, OUTPUT);
  
  pinMode (encoder0PinA,INPUT);
  pinMode (encoder0PinB,INPUT);  
  Serial.begin (9600);  
  attachInterrupt(1, CountA, CHANGE);  
  attachInterrupt(0, StateB, FALLING);
}

void loop()
{  
  int pulse = 500;
  digitalWrite(motorenable, HIGH);
  int dir = (pulse > 0)? HIGH:LOW;
  digitalWrite(DIR_PIN,dir); 
  
  if(temp >= pulse)
  {
    digitalWrite(motorenable, LOW);
    delay(100000);
  }
       Serial.print("Position: ");
       Serial.println(temp); 
  
  
}

void CountA()
{  
  n = digitalRead(encoder0PinA);   
  if ((encoder0PinALast == LOW) && (n == HIGH)) 
  {     
    if (m == LOW) 
    {       
       temp = encoder0Pos--;   
    }     
    else 
    {       
       temp = encoder0Pos++;   
    }   
  }
}
void StateB()
{  
  m = digitalRead(encoder0PinB);
}

I think you should be reading both pins in the same interrupt service routine.

A 7000 - 12000 RPM motor, with a 500 pulse per revolution encoder is going to result in a lot of pulses per minute. Using digitalRead twice is going to result in a lot of missed pulses. Direct port manipulation would be faster, but even than it may not be fast enough.

Shouldn't you be resetting encoder0PinALast someplace in your code? If not, what purpose does it serve?

Thank you for your reply but can you elaborate bit more on it? I think I am not understanding this correctly

if (m == LOW)
    {       
       temp = encoder0Pos--;   
    }     
    else
    {       
       temp = encoder0Pos++;   
    }

What is "temp" doing there?

Thank you for your reply but can you elaborate bit more on it? I think I am not understanding this correctly

First, you probably need to describe what you are doing. Trying to turn a 12000 RPM motor exactly one revolution just isn't possible.