I am building an instrument that is designed for a user to track an object optically. Every 15 seconds the instrument makes a measurement of the bearing of the object being tracked and elevation of the optical axis. After making the measurement the ZX-24 makes some calculations and displays the results. In the older instrument, the calculation/display was done during the waiting time for the next observation. This cycle occurs for as long as the observer wishes to collect data. The end of one 15 second tracking period is the beginning of the next. The user must get an audible warning (piezo-buzzer) for the last 5 seconds of the measurement period. I have a buzzer attached to the ZX-24.
I believe that this is possible to do with the ZX-24 but I just do not seem to be able to get my head around how to do it. I have read AN-209, "Task Management" and AN-210 "Sharing Data between Tasks". I confess I do not completely understand what I read, but I have a suspicion the answer is in them somewhere.
Any enlightenment will be appreciated.
Vic
Timing task
Timing task
Vic Fraenckel
KC2GUI
windswaytoo ATSIGN gmail DOT com
KC2GUI
windswaytoo ATSIGN gmail DOT com
Put the code that turns on the buzzer in its' own task. The trick is that, unlike most tasks, it shouldn't loop. It just runs through once and exits, turning on the buzzer output at the beginning, waiting 5 seconds, then turning the buzzer off again.
The next part is figuring out how to trigger that task at the right time. If the computations always take 15 seconds, it should be fairly easy. Right before your start computing the result, call the buzzer task. That task should wait for 10 seconds, then turn on the buzzer for 5, then turn off the buzzer and exit.
-Don
The next part is figuring out how to trigger that task at the right time. If the computations always take 15 seconds, it should be fairly easy. Right before your start computing the result, call the buzzer task. That task should wait for 10 seconds, then turn on the buzzer for 5, then turn off the buzzer and exit.
-Don
Don,
I suspect I did not make it clear how this puppy will function. The instrument is tracking a moving object. The end of one 15 second period IS the beginning of the next. The observer needs to be warned 5 seconds before the end of each period in order for him/her to be sure the optics's cross hairs are on the tracked object at the time of the measurement. During the "free" period (10 seconds in this case) the calculation/display for the last observation takes place.
Can such a thing be done? If so, how?
Any further enlightenment will be appreciated.
Vic
I suspect I did not make it clear how this puppy will function. The instrument is tracking a moving object. The end of one 15 second period IS the beginning of the next. The observer needs to be warned 5 seconds before the end of each period in order for him/her to be sure the optics's cross hairs are on the tracked object at the time of the measurement. During the "free" period (10 seconds in this case) the calculation/display for the last observation takes place.
Can such a thing be done? If so, how?
Any further enlightenment will be appreciated.
Vic
Vic Fraenckel
KC2GUI
windswaytoo ATSIGN gmail DOT com
KC2GUI
windswaytoo ATSIGN gmail DOT com
I think I'm understanding correctly. What you need is to have 2 concurrent tasks, one to keep track of the timing and buzzer thing, and another to do the math. Obviously, the math calculations don't take as much time as the you have available (15 seconds in this case).
The code below is an example of what I was describing in my previous post. All of the timing happens in the BuzzerTask. Sub Main() does nothing but call the other tasks. Bear in mind that this simply skeleton code to illustrate the example.
There should be error checking in case the MathTask takes longer than expected to complete, as well as a slew of other details that are particular to you specific application.
-Don
The code below is an example of what I was describing in my previous post. All of the timing happens in the BuzzerTask. Sub Main() does nothing but call the other tasks. Bear in mind that this simply skeleton code to illustrate the example.
Code: Select all
Private BuzzerTaskStack(1 to 30) as Byte
Private MathTaskStack(1 to 30) as Byte
Sub Main()
Do
'Check if the BuzzerTask is running
If NOT(TaskIsValid(BuzzerTaskStack)) Then
'If not, start both tasks at the same time
CallTask "BuzzerTask", BuzzerTaskStack
CallTask "MathTask", MathTaskStack
Else
'If the BuzzerTask is running, wait till it's done
Call Sleep(0)
End If
Loop
End Sub
Private Sub BuzzerTask()
'Define a pin for the output
Const BuzzerOutputPin as Byte = C.1
'Sleep for the first 10 seconds
Call Sleep(10.0)
'Turn on the buzzer
Call PutPin(BuzzerOutputPin, zxOutputHigh)
'Leave the buzzer on for 5 seconds
Call Sleep(5.0)
'Turn off the buzzer
Call PutPin(BuzzerOutputPin, zxOutputLow)
'End the task
End Sub
Private Sub MathTask()
'Do some math calculations here
Call Sleep(0)
End Sub
-Don