如何计算RPM 12V直流电机100rpm w / Encoder

时间:2017-05-04 08:27:38

标签: c arduino-uno

我试图在arduino uno中以这种方式找到脉冲。您可以看到我尝试过的编码,这也是电机编码器的示例图像。

enter image description here

//The sample code for driving one way motor encoder
const byte encoder0pinA = 2;//A pin -> the interrupt pin 0

const byte encoder0pinB = 4;//B pin -> the digital pin 4

byte encoder0PinALast;

int duration;//the number of the pulses

boolean Direction;//the rotation direction 


void setup()

{  
  Serial.begin(57600);//Initialize the serial port

  EncoderInit();//Initialize the module
}

void loop()

{

  Serial.print("Pulse:");

  Serial.println(duration);

  duration = 0;

  delay(100);

}

void EncoderInit()

{

  Direction = true;//default -> Forward  

  pinMode(encoder0pinB,INPUT);  

  attachInterrupt(0, wheelSpeed, CHANGE);

}

void wheelSpeed()

{

  int Lstate = digitalRead(encoder0pinA);

  if((encoder0PinALast == LOW) && Lstate==HIGH)

  {

    int val = digitalRead(encoder0pinB);

    if(val == LOW && Direction)

    {

      Direction = false; //Reverse

    }

    else if(val == HIGH && !Direction)

    {

      Direction = true;  //Forward

    }

  }

  encoder0PinALast = Lstate;

  if(!Direction)  duration++;

  else  duration--;
}

我已经知道脉搏,但我不知道如何计算这种马达的转速。     如何计算rpm已知脉冲?     任何人都可以帮助我找到解决方法,如果有人想帮助我,我将非常感激。

0 个答案:

没有答案