Help find motor RPM using Pololu Metal Gearmotor Encoder

I have 75:1 Metal Gearmotor 25Dx54L mm HP with 48 CPR Encoder.
I’d tried to find whether the RPM at motor shaft is 130 rpm by using arduino code. The code as below. However, the result I got is RPM = 2.58 (in average).
Can you help me to find out why is not as spec?

// Define pin locations and delay time between each query
#define EncoderPinA  2
#define EncoderPinB  3
#define DELAY_TIME 1000 // dealy 1 second
 
// Using 75:1 Metal Gearmotor 25Dx54L mm HP with 48 CPR Encoder
//Key specs at 6 V: 130 RPM and 450 mA free-run, 130 oz-in (9.4 kg-cm) and 6 A stall.
#define Encoder_CPR 48        
 
// Create a variable in memory that the interrupt code can access
// Also create the change value globally
volatile unsigned int EncoderPos = 0;
double dVal = 0;
 
// Initialize
void setup()
{
  // Set input pin state for the line sensors
  pinMode(EncoderPinA, INPUT);
  pinMode(EncoderPinB, INPUT);
 
  // Register a hardware interupt function for pin 2 (which is indexed by value 0)
  // This function sets the EncoderEvent() function to be called whenever a line detector detects a change
  attachInterrupt(0, EncoderEvent, CHANGE);
 
  // Start serial communication
  Serial.begin (9600);
}
 
// Program loop
void loop()
{
  // Find the before and after value between the delay times
  unsigned int OldPos = EncoderPos;
  delay(DELAY_TIME);
  unsigned int NewPos = EncoderPos;
 
  // If an integer overflow occures, throw out the new value
  if(abs(NewPos - OldPos) < 30000)
  // number of counts per second
    dVal = (double)(NewPos - OldPos) / (double)DELAY_TIME;
 
  // Convert  RPM of motor should be  130 RPM for 6V
  double RPM= (dVal * 60) / Encoder_CPR;
  
  // Print data
  Serial.print("RPM: ");
  Serial.println(RPM);

}
 
// Encoder event for the interrupt call
void EncoderEvent()
{
  // Read for data and bit changes
  // This is gray-code logic
  if (digitalRead(EncoderPinA) == HIGH)
  {
    if (digitalRead(EncoderPinB) == LOW)
      EncoderPos++;
    else
      EncoderPos--;
  }
  else
  {
    if (digitalRead(EncoderPinB) == LOW)
      EncoderPos--;
    else
      EncoderPos++;
  }
}

Hello.

I am sorry you are having trouble getting your encoder to work. It looks like you are not correctly incrementing encoder counts. As you have written it, your code increments and then decrements the encoder wheel counts continuously, so I do not expect to get any useful data that way. You might try looking at our Wheel Encoder library for an idea of how to keep track of shaft revolutions. The encoder library is described inside the Pololu AVR C/C++ Library User’s Guide and its functions are described inside the Pololu AVR Library Command Reference.

By the way, it looks like you are calculating the number of revolutions of the backshaft. You would still need to divide “RPM” by that gearmotor’s exact gear ratio (74.83) to get the rotations of its output shaft.

-Jon