Need some simple math help...

I'm trying to calculate RPMs from a motor with an encoder. For some reason I can't seem to figure out the formula....

My encoder is 2000PPR

void updateSpeed(){
  
  newPosition = mBEnc.read();    // Gets current pulse count
  newTime = millis();
  
  if(newPosition != oldPosition) {
    float dTravel = abs(newPosition - oldPosition);
    float tTravel = newTime - oldTime;
    
    cRPM = 0;    // Magic Math here

    oldPosition = newPosition;
    oldTime = newTime;  
  }
  
}

thanks for any help or thoughts!

    float dTravel = abs(newPosition - oldPosition);
    float tTravel = newTime - oldTime;

Why are these two variables floats? The change in position is a number of clicks. Surely, you didn't turn the encoder 3.14159 clicks. The change in time is in milliseconds.

What have you tried? If the encoder outputs 2000 pulses per revolution, then dividing the number of pulses by 2000 should give the number of revolutions, right? The number of revolutions divided by the time taken the detect that number of pulses will give revolutions/xxx, where xxx is the unit of time. tTravel being in milliseconds, the rate of rotation will be revolutions per millisecond. It isn't rocket surgery to convert that to revolutions per second, revolutions per minute, or revolutions per fortnight.

Thanks for pointing out the floats... for some reason I had a really big brain fart today!

Here is a what I have now... It seems to be putting out he correct RPMs....

Thanks for the help Paul!

void updateSpeed(){
  
  newPosition = mBEnc.read();
  newTime = millis();
  
  if(newPosition != oldPosition) {
    int dTravel = abs(newPosition - oldPosition);
    int tTravel = newTime - oldTime;
    cRPM = dTravel * (60000.0 / tTravel / 2000);  // This is declared as a int
   
    Serial.print("PaulS travels at: ");
    Serial.print(cRPM);
    Serial.print("RPMs");
    Serial.println("");


    oldPosition = newPosition;
    oldTime = newTime;  
  }
  
}