My second point was that, even if the counter wraps around once during your race, your subtraction will still get the right answer, as long as you use unsigned arithmetic.
E.g., you take your first reading just 99 counts before the wraparound at 4294967196, then your engine runs for a while and you take another reading 300 counts later. You counter has wrapped after 100 counts and then counts 200 times more so its value is now 200. If you subtract 4294967196 from 200 you get -4294966996 in integer arithmetic, which I think is what you are worried about. But if you use 32 bit unsigned subtraction, which is available in may programming languages (and mysql, too, if I recall correctly) then the answer is 300, which is the answer that you want, the number of counts between samples. So you can ignore the wrap-around of the counter as long as you are sure that it didn't wrap around more than once between samples. On Sat, Jan 3, 2009 at 00:51, Jaap Struyk <[email protected]> wrote: > Doug Collinge schreef: > > > races before you wrap the counters. Just for fun-with-numbers sake, > > that's 93 years of daily races! > > In that case I will be 144 before I have to worry... ;-) > > > Forgive me if I am being pedantic here but it sounded like you didn't > > really understand that wrapping counters should not be a problem, even > > if it could happen. > > I didn't understand fully how they worked but I understand now. (I am a > technician, give me a lathe and I do wonders but with electronics and > source code I am a skippy-ball jumping around and having fun ;) > > In side my owfs2mysql script I start with reading the counter at top and > after that the loop is subtracting the previous reading from the current > so only the difference is calculated (and converted to rpm) and put into > mysql, if there would be one reading a bit odd it's not really a problem. > > Thanks all for helping out and learning me stuff! > > > > ------------------------------------------------------------------------------ > _______________________________________________ > Owfs-developers mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/owfs-developers >
------------------------------------------------------------------------------
_______________________________________________ Owfs-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/owfs-developers
