Read rpm's of a Motor by interrupts

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tlerdrden
 
Posts: 80
Joined: Fri Nov 30, 2012 4:46 pm

Read rpm's of a Motor by interrupts

Post by tlerdrden »

Hi,
I have to read the rpm's of a motor that can run between 1000-2000 rpm, using, an inductive sensor. I'll use interrupts to read the rpm's of the motor with an Arduino Mega, but I don't know if will be able to detect all the interrupts (1000-2000 rpm = 1000 - 2000 interrupts /min = 17 -34 interrupts / second).
What do you think? If it's not going to work... Do you know any other way to sense the speed of the motor?
See the code:

Code: Select all

unsigned int rpm;
 unsigned long previTemps = 0;        // Variable per compare time
 long interval = 60000;           // 60000=minute
 
 void setup()
 {
   Serial.begin(9600);
   attachInterrupt(0, rpm_cinta, RISING);
   rpm = 0;
 }
 void loop()
 {
    unsigned long actualTemps = millis();
    if(actualTemps - previTemps > interval) {
    cli(); // Stop interrupts
    previTemps = actualTemps;   
    Serial.println(rpm); // Send rpm's by serial
    rpm=0;      // Reset rpm
    sei();// Disable interrupts
  }
 }
 void rpm_cinta()
 {
  rpm++; //Add rpm
  }
Thanks in advance,
Anton

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Read rpm's of a Motor by interrupts

Post by adafruit_support_bill »

You should have no trouble servicing interrupts at that rate. Your interrupt service routine is nice and concise as it should be. One other thing I would do is to declare your rpm variable as 'volatile'.

User avatar
tlerdrden
 
Posts: 80
Joined: Fri Nov 30, 2012 4:46 pm

Re: Read rpm's of a Motor by interrupts

Post by tlerdrden »

Adafruit Hello!
How is it going? I contact this time because I'm doing a program that uses some timers to turn digital outputs depending on time. My guess is that the variable associated with millis () will reset about 50 days after I have started my program (see http://arduino.cc/en/Reference/millis ), so I think it will affect all internal counters ... Do you know any way I can reset all counters when Millis () value goes back to zero?
See an attached code:

Code: Select all

void loop()
{
currentime = millis(); //Inicio control de temps
    if (counter1- currentime < 0)
    {
      counter1=currentime;
    }
    if (counter2- currentime < 0)
    {
      counter2=currentime;
    }
}
Thank you very much!

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Read rpm's of a Motor by interrupts

Post by adafruit_support_bill »

Rob Faludi has some code to handle the timer rollover: http://www.faludi.com/2007/12/18/arduin ... -handling/

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”