merged changes from Tom D., and checking for tick counter underflow. Functions ok, except that for a 10ms tick period without idle time interruption there are two unnecessary tick interrupts happening.