Tuesday, July 19, 2011

Measuring Elapsed Time With Counters That Wrap

Timer Wrap: "The key to avoiding wrap problems is to perform the unsigned, don’t-care-about-overflow subtraction first, then do any additional operations needed. By using subtraction like this as the first operation, any wrap-around of the timer register that may have occurred just drops out. No special effort is needed to get rid of it!"
Ahh, learned this lesson the hard way. Instead of doing Now >= (A + 100), always do (Now - A) >= 100.


Post a Comment