WAIT in a MultiTasking program

basically miscellaneous, if it doesn't fit another sub-forum enter it here, we might even promote it to its own sub-forum
Post Reply
olzeke51
Posts: 414
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

WAIT in a MultiTasking program

Post 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



basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: WAIT in a MultiTasking program

Post 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.

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: WAIT in a MultiTasking program

Post 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

basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: WAIT in a MultiTasking program

Post 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.

Post Reply