Sunday 1 April 2012

Timer and settimer

There's a lot of detail on settimer in the manual, but I still struggled how to reset the timer. In fact it is blindlingly obvious:

timer=0

timer is just a word variable, which gets incremented when a second (hidden) "minor tick" variable overflows. The preload value in settimer specifies what value the "minor tick" counter moves to once it has hit 65535: the higher the preload value, the fewer increments needed, and so the sooner the "minor tick" overflows and increments timer.

The pitfall is that wheras the first settimer command will set the timer to zero, any subsequent settimer commands will change the rate at which the timer increments, but will NOT reset the timer

No comments:

Post a Comment