MultiTrack (Intermediate): SuperTimers
A companion feature to MultiTrack is the SuperTimer. The SuperTimer feature provides for timing and measuring intervals from 10mS to over 46 hours in a single, consistent mechanism. Features include:
- 10mS resolution with 46 hours range (24 bit timer)
- Available inside and outside of MultiTrack
- The number of timers that can be running is limited only by available RAM memory
- Every task in MultiTrack task has one re-usable SuperTimer which is accessed via simplified instructions, and can have more by using RAM.
- Simple interval generation as well as measurement
- A speed-up mechanism to simplify debugging
Note: When executed inside a MultiTrack task, the FastTrack instructions with built in timing (Pause, WaitOnT, WaitOffT and WaitOnKT) use the task's SuperTimer.
We have also converted the older timing instructions like Pause, WaitOnT etc so that in dialect 16 and later they too have a range of 10mS to 46 hours.
In this lesson I will show you how to use the SuperTimer that is available in every MultiTrack task. In later lessons you will see the more advanced features.
The basis of the SuperTimer feature is a 46hour/10mS system timer that is running continuously. A time interval is generated by capturing the value of the system timer at the start of the interval and then waiting for it to have advanced by the required amount from the captured value. It turns out that if the math is done carefully (the controller takes care of all that automatically, nothing for you to worry about), even if the system timer rolls over from max to 0 during the interval, providing the interval required is less than the capacity of the timer (46 hours), everything works out OK. The caveat is that you must make sure your program can never attempt to generate or measure a single interval in excess of 46 hours (actually 46h36m12.16s)
Example: The following code is a rewrite of the main sequencer from the example in the previous lesson. I have made two functional changes:
- The cook time has been increased from 3 minutes to 3 hours (1,080,000 times 10mS)
- There is a stop button to allow the cycle to be manually cut short.
The two instructions involved in the actual timing are MarkTime and LoopIfTiming.
MarkTime simply captures the current value of the System Timer and stores it in an special register associated with each MultiTrack task. LoopIfTiming has two arguments. The first is the required interval, in this case 1,080,000. The second is where to jump to if the interval has not expired since the last MarkTime in the current task.
(Click here for some tips for working around problems with copy and paste out of Internet Explorer and HTML-help (.chm) files)
;===== The main sequencer ============================================
MainSequence:
WaitOnK iStartButton ;Wait for start command
On oFillValve ;Start filling
WaitOn iFullProbe ;Wait for full
Off oFillValve ;Stop filling
SetS sHeaterEnable ;Signal the heater to start
SetS sAdditiveEnable ;Signal the additive pump to run
WaitForST sAtTempSetPoint ;Wait for vessel to get up to temperature
MarkTime ;Note the time
;In the CookLoop we sit endlessly testing for timeout and also testing the stop
;button. We do a YieldTask each time around to free up the processor for other things
CookLoop:
YieldTask
GoIfInK iStopButton,CookStop
LoopIfTiming 1080000,CookLoop
CookStop:
ClrS sHeaterEnable ;Stop the heater
On oDrainPump ;Start draining
WaitOff iEmptyProbe ;Wait for it to empty
Off oDrainPump ;Stop draining
GoTo MainSequence ;Go back and wait for the next cycle
Exercise 1:
Graft the above code into the previous example program. Save the result with a different file name and then test it. You may find it useful to set a breakpoint at the YieldTask instruction.
Exercise 2:
There are two hazards in the above functional changes. The first is the danger of a previously latched press of the stop button. The second is the danger of stopping the process while the additive pump is still running. It may not be a good idea to be running the additive pump while the vessel is draining. Fix the problems. Hint: You will need to change the additive task over to using a SuperTimer.
