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:
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
}
Regards,
Anton