Pages: [1]   Go Down
Author Topic: Reading RPM Playground code error  (Read 2759 times)
0 Members and 1 Guest are viewing this topic.
United States
Offline Offline
Full Member
***
Karma: 0
Posts: 148
Learning
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://www.arduino.cc/playground/Main/ReadingRPM
Code:
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:
rpm = 30*1000/(millis() - timeold)*rpmcount;
Should be  
Code:
rpm = 30*1000/((millis() - timeold)/rpmcount);
OR
Code:
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
Logged

Pages: [1]   Go Up
Jump to: