CallTask - How to question

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
super-d
Posts: 3
Joined: 15 March 2008, 17:51 PM

CallTask - How to question

Post 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
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: CallTask - How to question

Post 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 
- Don Kinzer
Post Reply