Go Down

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

#### Newman180

##### Nov 24, 2010, 01:07 am
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;     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