William "Chops" Westfield wrote: > I want to calculate: > > (ticks * ) / 1000 > > to return the number of milliseconds elapsed based on a count > maintained by a timer ISR. microsecondsPerTick is a nice constant > number like 1024 or 2048, so the multiplication becomes a shift, and > factoring out twos I get: > > (ticks * (microsecondsPerTick/8)) / 125 > > "ticks" is at least 40 bits, however, and the multiplication MUST NOT > OVERFLOW (been there, trying to fix that!), so I'm looking at at at > least a 48bit intermediate value. Do you have access to the ISR? I would be inclined to do the following, rather than (or in addition to) simply counting the raw ticks: /* microseconds can be a 16-bit integer */ microseconds += microsecondsPerTick; while (microseconds >= 1000) { microseconds -= 1000; ++milliseconds; } -- Dave Tweed -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist