MultiTrack (Advanced): Measuring elapsed time with a SuperTimer

There are times when you will want to measure how much time has elapsed since some event. Maybe you want to display an elapsed time on the fly or determine how long it took to get up to temperature. To achieve this you need to capture the start time using STStart (which means you need to declare a 3-byte timer variable using defTIME24), and subsequently get the amount of elapsed time using fSTTimeSince. What fSTTimeSince does is to calculate the amount of time that has elapsed since the moment captured by STStart and leave the result in floating point register W. The number in W will be in units of 10mS.

Example:

The following example is a stop watch written as a MultiTrack task to run in an MMi201 with LCD. The complete program file is located in the directory path Examples>MultTrk under SPLatPC in Program Files. The file name is MulTrk02.SPT.

There are a few interesting features in this program:

(Click here for some tips for working around problems with copy and paste out of Internet Explorer and HTML-help (.chm) files)

        LaunchTask      StopWatch
        RunTasksForever

;----- StopWatch task ---------
;I/O is set up for an MMi201
iSW_StartButton         iEQU    12
iSW_StopButton          iEQU    11
iSW_ResetButton         iEQU    10

SW_Timer        defTIME24       ;Reserve RAM for the stopwatch timer

StopWatch:
SW_Set0:
        OBLCD_SetCur    0,0
        OBLCD_Text      "  0.00"                ;Clear stopwatch display
SW_0:
        ResetK                                  ;Clear Key latches
        WaitOnK         iSW_StartButton         ;Wait for start command
SW_Set1:
        STStart         SW_Timer                ;Start timing
        ResetK                                  ;Clear Key latches

;Main timing..
;While the SuperTimer takes care of the actual timing, we monitor
;the stop button, breaking off every 100mS to update the display.
SW_1:   
        WaitOnKT        iSW_StopButton,10       ;100mS
        GoIfT           SW_Set2                 ;G/ button was pressed
        GoSub           SW_Display              ;Update the display
        GoTo            SW_1                    ;Keep watching the button

;Here when user hits the stop button
SW_Set2:
        ResetK                                  ;Clear Key latches
        GoSub           SW_Display              ;Display final time
SW_2:
        WaitOnK         iSW_ResetButton         ;Wait for reset
        GoTo            SW_Set0                 ;Repeat

;Subroutine to grab and display elapsed stopwatch time
SW_Display:
        fSTTimeSince    SW_Timer                ;Get time
        fLoadQ          0.01                    ;10mS increments
        fMul                                    ;Scale to seconds
        OBLCD_SetCur    0,0
        OBLCD_fDispW    6,2
        Return