timer0_poll_interval

timer0 poll interval

Author Joep Suijs, Copyright © 2008 Joep Suijs
Adapted-by Rob Hamerling, William Welch
Compiler >=2.4m

Description

Fixed interval support for non-blocking delays, but without using
             an interrupt.
.
Note: In many (possibly most) cases, you would be wise to choose the ISR
      version of this library-- it will be much more accurate.
.
The setup of this library is straight-forward. First you define the overflow
rate for the timer. You'll have to make some trade-offs as to accuracy, frequency
of polling, etc.
.
>>> const timer0_overflow_rate = 1000 -- 1 kHz overflow rate
.
Optional usage, for finer control, you may specify:
.
        >>> const timer0_preload_value = nnn ( 0-0xff (8-bit), or 0-0xffff (16-bit) )
        >>> const timer0_prescale_value = nnn (0-7)
.
Next, you need to specify the number of slots. A slot is used to store the
end-time of a delay-period so you need one slot for each concurrent delay.
.
>>> const DELAY_SLOTS = 2 -- support 2 delays at the same time
.
Now, include the library and call it's init function:
.
>>> include timer0_poll_interval
>>> timer0_poll_init() -- init timer0
.
Now we are ready to use the delay functions. To demonstrate it's use, we take
two LEDs and let them blink at their own interval:
.
>> forever loop
>> if (check_delay(0)) then
>> set_delay(0, 409) -- 409 ticks on delay-slot 0
>> led = !led
>> end if
>> if (check_delay(1)) then
>> set_delay(1, 619) -- 619 ticks on delay-slot 1
>> led2 = !led2
>> end if
>> end loop


Dependencies

No dependency found



Summary

Global variables/contants

Procedures

Private

Functions


API details

Global variables/contants

Procedures

Private

Functions


Related samples

Here are the list of samples which use this library:

18f14k5018f14k50_tmr0_poll_interval.jal
18f245018f2450_tmr0_poll_interval.jal
18f252018f2520_tmr0_poll_interval.jal
18f255018f2550_tmr0_poll_interval.jal
18f262018f2620_tmr0_poll_interval.jal
18f45218f452_tmr0_poll_interval.jal
18f455018f4550_tmr0_poll_interval.jal
18f458518f4585_canopen_blink.jal
18f462018f4620_tmr0_poll_interval.jal
18f67j5018f67j50_tmr0_poll_interval.jal