Go Down

Topic: Reading RPM Playground code error (Read 2946 times) previous topic - next topic

Newman180

I believe I found an error in the code for reading RPM on a cpu fan

http://www.arduino.cc/playground/Main/ReadingRPM
Code: [Select]
if (rpmcount >= 20) {
    //Update RPM every 20 counts, increase this for better RPM resolution,
    //decrease for faster update
    rpm = 30*1000/(millis() - timeold)*rpmcount;
    timeold = millis();
    rpmcount = 0;
    Serial.println(rpm,DEC);


The code
Code: [Select]
rpm = 30*1000/(millis() - timeold)*rpmcount;
Should be  
Code: [Select]
rpm = 30*1000/((millis() - timeold)/rpmcount);
OR
Code: [Select]
rpm = (30*1000/(millis() - timeold))*rpmcount;

The theory behind it...

The current code says that if it takes 100 millis between each pulse, and your counting 10 pulses :
30000/1000 = 30 RPM
Using the same code, if you double the counting pulses to 20 which would also double the time to 200 millis :
30000/4000 = 7.5 RPM  

These values should match

Using the corrected code:  100 millis  10 pulses
30000(10)/100 = 3000 RPM

Using corrected code: 200 millis 20 pulses
30000(20)/200 = 3000 RPM

Now they match.

I'm new to this, so if I'm wrong, speak up!

Thanks,
Austin

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy