Universal Software Timer Main Page

Aus ProjectWiki

Wechseln zu: Navigation, Suche

This is an easy-to-use universal software timer library, for use with any hardware timer, featuring automatic determination of needed timer parameters on precompile, up to 256 independant software timers, each can be enabled/disabled and an interrupt queue if more than one sw interrupt occured at once.

Free for personal use, credits and a short mail with your project info and/or comments, improvements etc. to this library would be nice.


How to use this

the values are just for example

Initialisation:

$crystal = 16000000
'[...]                                                       ' your Code
Const False = 0: Const True = 1                             ' make it more readable

Const Ticker_hwtimer = 0                                    ' Choose which hardware timer to use
Const Ticker_frequency = 10000                              ' set the timer resolution
Const Tickers = 2                                           ' # of software timers to use
$include "tickers.bas"
Ticker_time(1) = 25                                         ' Interrupt Ticks to trigger SW-Timer 1
Ticker_time(2) = 500                                        ' SW-Timer 2 and so on...
Ticker_enabled(1) = True                                    ' Enable/Disable SW-Timer
Ticker_enabled(2) = False
'[...]
Enable Interrupts

Main Loop:

>Do
   '[...]
   Select Case Ticker_get_interrupt()                       ' make sure that this function is called at least once per
                                                                 ' hw timer overflow, so don't make the µC hanging around
      Case 1:                                                  ' Ticker 1 triggered an interrupt
         '[...]
      Case 2:                                                  ' Ticker 2 interrupt
         '[...]
   End Select

   '[...]
Loop

Download

Persönliche Werkzeuge