Curious if WAIT(x) has any adverse affects on the timing in your MultiTasking.bas program??
my WAIT(x) is less than the assigned TaskTime, currently...
what if it is longer??
'
Olzeke51
WAIT in a MultiTasking program
Re: WAIT in a MultiTasking program
I would advise against using WAIT in a multitasking program. It would be better to relinquish your task to the next one. If you were waiting at the end of the task, on the next entry to it, check the TIMER to see if the minimum WAIT time had passed.
Much better to read the TIMER yourself and do the calculation.
Much better to read the TIMER yourself and do the calculation.
Re: WAIT in a MultiTasking program
The TIMER function is driven by the SysTick timer for most of our versions of BASIC.
While SysTick is a 24 bit counter, we use it and a SysTick interrupt that occurs every 65 msec. At that interrupt the upper bits of TIMER are incremented. So TIMER is a 32 bit twos compliment number derived from SysTick incrementing every microsecond that rolls over every 71.58 seconds.
So you can safely measure up to 35.8 seconds. Use this type of code to take advantage of the twos compliment number inside a multitasking task. So here is a task toggling an LED every second. Note that rather than WAIT it checks the TIMER and ends the task after the test
While SysTick is a 24 bit counter, we use it and a SysTick interrupt that occurs every 65 msec. At that interrupt the upper bits of TIMER are incremented. So TIMER is a 32 bit twos compliment number derived from SysTick incrementing every microsecond that rolls over every 71.58 seconds.
So you can safely measure up to 35.8 seconds. Use this type of code to take advantage of the twos compliment number inside a multitasking task. So here is a task toggling an LED every second. Note that rather than WAIT it checks the TIMER and ends the task after the test
Code: Select all
sub task3
dim startTime
dim toggle
toggle = 0
startTime = TIMER
while 1
if TIMER - startTime > 1000000 then
toggle = not toggle
startTime = TIMER
endif
IO(1)=toggle
VICIntSetPend0 = (1<<TIMER1_IRQn) ' force Timer 1. Interrupt -- ending this task slot
loop ' when this task is executed again it starts here inside the while 1 loop
end sub
Re: WAIT in a MultiTasking program
Also in the multitask setup, the task switch can occur in the middle of the WAIT or WAITMICRO. So unless you disable the task switch interrupt, all you can guarantee is that the WAIT will be at least the time requested.