Go Down

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


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

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;

The code
Code: [Select]
rpm = 30*1000/(millis() - timeold)*rpmcount;
Should be  
Code: [Select]
rpm = 30*1000/((millis() - timeold)/rpmcount);
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!


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!

via Egeo 16
Torino, 10131