Page 1 of 1

WAIT in a MultiTasking program

Posted: Tue Oct 08, 2019 9:51 pm
by olzeke51
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

Re: WAIT in a MultiTasking program

Posted: Wed Oct 09, 2019 4:09 am
by basicchip
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.

Re: WAIT in a MultiTasking program

Posted: Tue Oct 22, 2019 4:42 pm
by basicchip
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

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

Posted: Fri Nov 01, 2019 3:54 am
by basicchip
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.