Search   
Home  Print View  

 

P112

Branch Content

Virtual Timers

The framework initializes the microcontroller's real timer Tmr0 to interrupt every one millisecond. Based on this "tick", various "virtual timers" are updated (decremented) by the interrupt service routine.

Unlike real timers, virtual timers are implemented in firmware. Each virtual timer consists of:

   COUNT variable
   VALUE literal
   BUSY flag

The BUSY flag resides in variable FLAGS; it is set while the virtual timer is counting, cleared after timeout. The VALUE literal expresses the count in milliseconds. The COUNT variable is decremented by the Tmr0 interrupt service routine until it reaches zero.

To start the virtual timer, the COUNT variable is loaded with the VALUE constant and the BUSY flag is set. This is done by macro START_VTIMER defined in macros.h. The BUSY flag is automatically cleared by the framework on timeout.

Using virtual timers in user code is as simple as running the START_TIMER macro to start it, then keep watching the BUSY flag for time out.

The framework implements one virtual timer (VT0) used for GPI debouncing. As a user, you can create and manage your own virtual timers. More on this in section "Writing your code".

Online Manuals -- this software is based on Help Books running at melissa