RPM_A = (60*(newpositionA - oldpositionA) * 1000) /((newtimeA-oldtimeA)*16*2);
RPM_A =(float) (60.0 * (newpositionA - oldpositionA) * 1000.0) /((newtimeA-oldtimeA)*32.0);
// multiply by 60 because ... ?// multiply by 1000 because ... ?long t1 = 60L * 1000L *(newpositionA - oldpositionA);// multiply by 16 because ... ?// multiply by 2 because ... ?long t2 =16L * 2L * (newtimeA-oldtimeA);// Calculate the rpmRPM_A = (float) t1 / (float) t2;
I do not understand what is different between the two approaches, mathematically they are the same but through arduino it is different.
the compiler sometimes make a bad guess on how to handle the overall calculation.
Quotethe compiler sometimes make a bad guess on how to handle the overall calculation.The compiler doesn't guess.Pete
guessed that the 5 was an integer and the next time it guessed that it was a float.
int RPM_A;..........RPM_A = (int) ( 60L * ((long) newpositionA - (long ) oldpositionA ) * 1000L ) / (((long) newtimeA - (long) oldtimeA ) * 16L * 2L );
Please enter a valid email to subscribe
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