Rewrote handling of timer counts.

Timer count is now calculated by a macro in globals.h

The timer count MUST NOT exceed 2^16. This is NOT checked at
compile time, so use of the macro should be done with caution.