Previous Topic

Next Topic

Book Contents

Book Index

fSTSinceMark [D>=22]

Calculates the time elapsed since the last MarkTime in the current task. The result is returned as a floating point number in W. This will be an integer value in the range 0 to 16,777,215 times 10mS. This instruction may only be used a MultiTrack task. It is based on the assumption that there was a prior MarkTime instruction in this task (failing which the result is unpredictable).

From dialect 20 some controllers allow you to program the 10mS basic "tick" interval over the range 1mS to 255mS via a setting in the CPU device. See the CPU device documentation for your controller.

Warning: You cannot use Pause, WaitOnT, WaitOffT or WaitOnKT between a MarkTime and its corresponding fSTSinceMark.

Explanation: In MultiTrack there is exactly one timer per task that is provided "free" by the system. It is used/shared by Pause, WaitOnT, WaitOffT, WaitOnKT and MarkTime.

See MultiTrack tutorial

Dialect exclusions: Not available in dialects before 22.

Example:

The following program has two tasks. Timer measures the duration of an "On press" of the push button on input 16 of an MS120 and displays it on the LCD. Blinker blinks the LED on output 11 once per second as long as the button is depressed.

        On              20              ;Backlight
        LaunchTask      Timer
        LaunchTask      Blinker
        RunTasksForever
 
;Measure and display button on-time        
Timer:
        WaitOn          16
        MarkTime                        ;Start timing
        WaitOff         16
        fSTSinceMark                    ;Get the elapsed time
        fLoadQ          10
        fMul
        OBLCD_SetCur    0,0
        OBLCD_fDispW    8,0
        OBLCD_Text      "mS"
        GoTo            Timer  
        
;Blink a LED while the button is on
Blinker:                       
        Off             11
        WaitOn          16
Blinker2:        
        On              11
        WaitOffT        16,5
        GoIfT           Blinker
        Off             11
        WaitOffT        16,95
        GoIfT           Blinker
        GoTo            Blinker2

Previous Topic

Next Topic