I am recording the RPM of a motor as start to a bigger project, the below code seems to have a limit of around 7000 to 8000 RPM. I am trying find out if this is a limitation of my hardware, the design of the hardware, code or Arduino.
The hardware consists of a IR LED and IR photosensor (SFH229 and SFH4350) spaced about 7mm apart at a radius of 23mm, a propeller (blade 12mm wide) pass's the IR's twice every revolution.
Any help or suggestions would be appreciated
Regards Simon
// RPM output to Serial Monitor using Interupt
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
void setup()
{
Serial.begin(9600);
//Interrupt 0 is digital pin 2, so that is where the IR detector is connected
//Triggers on FALLING (change from HIGH to LOW)
attachInterrupt(0, rpm_fun, FALLING);
rpmcount = 0;
rpm = 0;
timeold = 0;
}
void loop()
{
//Don't process interrupts during calculations
detachInterrupt(0);
//Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
//happened once per revolution instead of twice. Other multiples could be used
//for multi-bladed propellers or fans
rpm = 30*1000/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
//Print out result to Serial
Serial.println(rpm);
//Restart the interrupt processing
attachInterrupt(0, rpm_fun, FALLING);
}
void rpm_fun()
{
//Each rotation, this interrupt function is run twice, so take that into consideration for
//calculating RPM
//Update count
rpmcount++;
}