| Author | Joep Suijs, Copyright © 2008 Joep Suijs |
| Adapted-by | Rob Hamerling, William Welch |
| Compiler | >=2.4m |
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
No dependency found
var word timer0_interval_counter
No documentation found
var word timer0_countdown[DELAY_SLOTS]
No documentation found
var word timer0_load
preload value for timer0
timer0_poll_init()
initialize the timer and related variables. automatically detects and makes use of 16-bit timer0 if present.
set_delay(byte in slot, word in ticks)
setup the delay for the specified slot.
_timer0_poll()
for internal use only. roughly equivalent to timer0 ISR
_timer0_poll_init_rate(dword in overflow_rate)
for internal use only
check_delay(byte in slot) return bit
returns "true" when the delay has been achieved. be sure to call this routine fairly often if you care about fairly accurate delays.
interval_counter'get() return word
returns the current value of the interval timer
| 18f14k50 | 18f14k50_tmr0_poll_interval.jal |
| 18f2450 | 18f2450_tmr0_poll_interval.jal |
| 18f2520 | 18f2520_tmr0_poll_interval.jal |
| 18f2550 | 18f2550_tmr0_poll_interval.jal |
| 18f2620 | 18f2620_tmr0_poll_interval.jal |
| 18f452 | 18f452_tmr0_poll_interval.jal |
| 18f4550 | 18f4550_tmr0_poll_interval.jal |
| 18f4585 | 18f4585_canopen_blink.jal |
| 18f4620 | 18f4620_tmr0_poll_interval.jal |
| 18f67j50 | 18f67j50_tmr0_poll_interval.jal |