Board Thread:Questions and Answers/@comment-24973829-20140801174251/@comment-5334617-20140801210721

Sorry, was just giving information. But you're right, I could be more helpful. This timer system should be robust...

It's more overhead, but it avoids some problems. Most importantly, if you're coming up to a  rollover, then calculating the new deadline value by adding the desired delay may cause an overflow. A nice feature is that turning off a timer, or pausing it for one or more  iterations, is easy; assign   to the appropriate variable. Other timer systems I have seen suffer from other flaws: a poorly-designed timer on the cusp of a rollover that uses  rather than   may never expire; referring to the system clock more than once per iteration could cause skipped 'ticks', or ticks that are double-counted; if the system clock ticked more than once in an iteration, the timer would run slow: this system has none of those flaws.

For a periodic timer, you should use the 'remainder' in the counter, rather than just resetting the value. For instance: