« Tech Support: Converting to MultiTrack | Main | Tech Support: RS485/ModBus on CC16 »

Tech Support: Converting to MultiTrack #2

Kelly wrote further:

In the example below with a star delta type setup, where there is Pause instruction in the subroutine which is illegal. I guess I would have to move the StarDeltaStart subroutine into the Task1 routine itself.
LaunchTask      Task1
LaunchTask Task2

Task1
yieldtask
gosub StarDeltaStart
goto Task1

StarDeltaStart
on StarRelay
pause 200
Off StarRelay
pause 50
on DeltaRelay
return

See example at http://splatco.com/skb/3439.htm The secondary function is relegated to a secondary task, with semaphores used to signal commands and completion. It is also possible to launch a task, have it do its job and then kill itself off, perhaps setting a semaphore before it dies. Remember that unlike say Visual Basic, the variables are static and global, and so exist for the life of the program, not just the life of the task. Using this idea, your program would become:

	LaunchTask	Main
RunTasksForever

Main: ClrS sStarted ;Make sure the 'all done' semaphore is clear.
LaunchTask StarDeltaStart
WaitForST sStarted
;continue ....

StarDeltaStart:
On oStarRelay
Pause 200
Off oStarRelay
Pause 50
On oDeltaRelay
SetS sStarted
KillTask ;Rather than return
I've omitted the equate and defSEM declarations.

StarDeltaStart can now be "called" from several places in the program. This may appear slightly inconvenient compared to a simply subroutine call. Think of StarDeltaStart however as a process rather than an action. There is no reason why Main cannot initiate the startup, go off and do a few other things and then later check if the motor is yet running.

Notice that I clear the sStarted semaphore before launching the StarDeltaStart task. I can't clear it in StarDeltaStart because the LaunchTask action only enters the task into a queue of tasks waiting to execute. It does not immediately execute any of the code in StarDeltaStart. StarDeltaStart code will only actually execute sometime after Main has yielded (depending on how many other tasks are also waiting to run).

Hazard alert!
If you have several tasks that can start the motor, you could risk having two copies of StarDeltaStart running at once. That may not be beneficial to the health of the motor or your fuses. In that case StarDeltaStart could have another semaphore to ensure only one copy can be running at once. It is not Best Practice to allow several tasks to control a single resource, for the very reason that those kinds of conflict can arise.

TrackBack

TrackBack URL for this entry:
http://www.splatco.com/cgi-sys/cgiwrap/microcon/managed-mt/mt-tb.cgi/44

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


About

This page contains a single entry from the blog posted on April 24, 2007 6:16 PM.

The previous post in this blog was Tech Support: Converting to MultiTrack.

The next post in this blog is Tech Support: RS485/ModBus on CC16.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.33