I'm having an issue with an RPM code, maybe you can help.
I'm using a hall effect sensor to pickup a keyway on a shaft to give me RPM.
Its triggering an interrupt once per revolution. The MAXIMUM hz for these interrupts is only 150hz.
The hall effect sensor is capable of 100x that at a minimum.
I'm using an Arduino Nano with a screw terminal shield.
The code is as follows:
volatile byte revolutions;
unsigned long rpm;
unsigned long timeold;
unsigned long rpmicros;
unsigned long revs;
void setup()
{
Serial.begin(115200);
attachInterrupt(0, rpms, FALLING);
revolutions = 0;
timeold = 0;
}
void loop()
{
if (revolutions >= 5) {
detachInterrupt(0);
rpmicros = micros() - timeold;
revs = (60000000 * revolutions);
rpm = revs / rpmicros;
timeold = micros();
Serial.println(rpm);
revolutions = 0;
attachInterrupt(0, rpms, FALLING);
}
}
void rpms()
{
revolutions++;
}
The issue I am having is that the maximum RPM it will read seems to be proportional to the number of revolutions in the first line of the loop. If I set it revolutions >= 1, I will get an RPM but will only be able to read pretty much at idle. If I rev it up, the RPM seems to hit a wall and I just get what looks like a Sine wave on the serial plotter.
If I increase it to revolutions >= 3, I can get up to about (don't quote me on the exact number) 1600-1800 RPM before it hits this apparent wall.
At revolutions >= 5, I can get much higher.
At revolutions >= 1, I hit the wall somewhere around 60,000 microseconds per revolution.
60,000 microseconds is only ~17 hz. Shouldn't the Nano be able to operate faster than that???
Is there something in the math that I am missing, or maybe in the programming?