Page 1 of 1

CallTask - How to question

Posted: 15 March 2008, 18:24 PM
by super-d
I just got my ZX24A and I'm trying to work with an interrupt and multitasking.

My test code is below. First I'm a beginner but I'm trying to hook up a flow meter to the ZX. This little test runs (StatusTask=3) and then terminates fine (StatusTask=255). My question is how do I restart the task so it can start watching the interrupt again once it terminates?

For my project I need to see when the interrupt fires and count the pulses or transitions on that pin (code not in place yet). Once I have the pulse count I want to restart the task but I'm unsure how to do that. I've tried to CallTask again when the StatusTask=255 in the loop but it still remains terminated.

Thanks
David

Code: Select all

Dim SerTaskStack(1 to 40) As Byte
Sub Main()
	CallTask "TaskTest",SerTaskStack
	
	Do
	Debug.Print Cstr(StatusTask(SerTaskStack))
	Delay(2.0)
	Loop
	
End Sub


Sub TaskTest()
	Call WaitForInterrupt(&h1c, 0)
	'Later code will go here to count
	'pulses or transitions
	Debug.Print "Task ran"
End Sub

Re: CallTask - How to question

Posted: 15 March 2008, 19:05 PM
by dkinzer
super-d wrote:My question is how do I restart the task so it can start watching the interrupt again once it terminates?
A commonly used strategy is to not let it terminate by adding an infinite loop to the task.

Code: Select all

Sub TaskTest() 
  Do
    Call WaitForInterrupt(&h1c, 0) 
    'Later code will go here to count 
    'pulses or transitions 
    Debug.Print "Task ran" 
  Loop
End Sub