« Moving mountains | Main | Tech Support: Reading back a program »

Tech Support: Divide and Conquer

Here's an example of how a tricky problem can be solved by breaking it down into smaller pieces, in this case by using a separate MultiTrack task.

Rab has a MultiTrack program where any one of several independent tasks may generate an alarm The alarm results in a siren sounding. What Rab wants is for the alarm to have a Clear button, and when the button is pressed the siren will be muted for 20 minutes. How can this be programmed?


Providing it's OK for the siren to always remain on until manually cleared, the function can be implemented very simply with a separate task to control the siren. This siren task gets sent alarm requests by other tasks. Here's the code. It should be simple enough for anyone with FastTrack plus MultiTrack exposure to analyze.

;===== Siren manager ==========

;A GoSub SIR_Alarm will start the siren on output oSIR_en.
;The siren will run until the clear button iSIR_Clear is pressed.
;Thereafter it will ignore any further requests (GoSub SIR_Alarm)
;for 20 minutes.

;Uses a semaphore and one MultiTrack task.

;Do a GoSub SIR_Init at the start of your program to initialise.

oSIR_en oEQU 8 ;(say)
iSIR_Clear iEQU 9 ;(say)

sSIR_Request defSEM

SIR_Init:
ClrS sSIR_Request
LaunchTask SIR_Task
Return

SIR_Alarm:
SetS sSIR_Request
Return

SIR_Task:
WaitForST sSIR_Request
On oSIR_en
WaitForInK iSIR_Clear
Off oSIR_en
Pause 120000 ;20 minutes
ClrS sSIR_Request
GoTo SIR_Task


This example also illustrates using a semaphore to communicate between MultiTrack tasks, as well as using GoSubs (subroutines) to "hide" the internal workings of the siren function.

TrackBack

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

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 January 4, 2008 5:59 PM.

The previous post in this blog was Moving mountains.

The next post in this blog is Tech Support: Reading back a program.

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