Need some simple math help...


i'm trying calculate rpms motor encoder. reason can't seem figure out formula....

my encoder 2000ppr



code: [select]

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 or thoughts!

code: [select]
    float dtravel = abs(newposition - oldposition);
    float ttravel = newtime - oldtime;

why these 2 variables floats? change in position number of clicks. surely, didn't turn encoder 3.14159 clicks. change in time in milliseconds.

what have tried? if encoder outputs 2000 pulses per revolution, dividing number of pulses 2000 should give number of revolutions, right? number of revolutions divided time taken detect number of pulses give revolutions/xxx, xxx unit of time. ttravel being in milliseconds, rate of rotation revolutions per millisecond. isn't rocket surgery convert revolutions per second, revolutions per minute, or revolutions per fortnight.


Arduino Forum > Using Arduino > Programming Questions > Need some simple math help...


arduino

Comments