SPLat Logo

Making time flow faster or slower

NOTICE: SPLat Controls has moved. We are now at 1/85 Brunel Rd, Seaford, 3198. map

This EasyStep will show you how to get timebase intervals other than the default 10mS, so you can easily generate very short or very long intervals.

Published, fittingly, on the 50th anniversary of the first episode of Doctor Who, the Time Lord.

The "SuperTimer" timing instructions all count time in intervals of 10mS. This allows you to generate delays from 10mS up to about 46 hours. There may however be occassions when you need intervals shorter than 10mS or longer than 46 hours. You can achieve this by changing the timebase to something other than the default 10mS. You can make the timers run up to 10 times faster or about 25 times slower than the default. In the EC1 the settability is individual per task, so you could have one task timing down to the millisecond and another generating an interval of 48 days in a single Pause instruction.

Here is a code snippet that will set the timebase of the current task only to 3mS

        SetU            0,3     ;Set my timebase to 3mS  (3.3333x normal speed)
        SPxCmd1         1,!CPU

 

Here is a slightly different version that could easily be used to create a subroutine

        LoadX           3
        PopU            0
        SPxCmd1         1,!CPU

 

Here is a complete program for the EC1. It simply flashes the two LEDs on the EC1 board, using two separate MultiTrack tasks. For the green LED it speeds up the timebase of the task by 10x (sets a 1mS timebase), but compensates by pausing for 1000 "units". For the red LED it uses the default timebase of 10mS, and it pauses for 100 units of time. The end result is that the two LEDs flash at the same rate.

The fact the two LEDs flash at the same rate proves that the timebase settings are independent per task.

;Testing setting of timebase per task 
;This example simply flashes both EC1 LEDs at 1Hz with 2 tasks.
;One task uses the default 10mS timebase. The other uses a 1mS timebase.

oGrn    EQU     0       ;Define the LED outputs
oRed    EQU     1

        LaunchTask      tskFast
        LaunchTask      tskSlow
        RunTasksForever

;---------------------------------------------------------------------        
;Task with fast timebase (1mS)      
tskFast:
        SetU            0,1     ;Set my timebase to 1mS  (10x normal speed)
        SPxCmd1         1,!CPU
FastLoop:
        On              oGrn
        Pause           1000
        Off             oGrn
        Pause           1000
        GoTo            FastLoop

;---------------------------------------------------------------------        
;Task with default timebase (10mS)
tskSlow:
        On              oRed
        Pause           100
        Off             oRed
        Pause           100
        GoTo            tskSlow
                

 

The following program illustrates a subtle point. It has two tasks, as before, flashing two LEDs. This time, however, I generate the delays in a subroutine that is shared by the two tasks. Both tasks call the same subroutine, but get delays related to their individual timebase settings.

;Testing setting of timebase per task 
;This example flashes both EC1 LEDs. It uses a shared subroutine to generate the delays.
;However, the two tasks have different timebases, so for each task the delays is different
;One task uses the default 10mS timebase. The other uses a 1mS timebase.

oGrn    EQU     0       ;Define the LED outputs
oRed    EQU     1

        LaunchTask      tskFast
        LaunchTask      tskSlow
        RunTasksForever

;---------------------------------------------------------------------        
;Task with fast timebase (1mS)      
tskFast:
        SetU            0,3     ;Set my timebase to 3mS  (3.3333x normal speed)
        SPxCmd1         1,!CPU
FastLoop:
        On              oGrn
        GoSub           Delay   ;This will give a 0.3s delay
        Off             oGrn
        GoSub           Delay
        GoTo            FastLoop

;---------------------------------------------------------------------        
;Task with default timebase (10mS)
tskSlow:
        On              oRed
        GoSub           Delay   ;This will give a 1s delay
        Off             oRed
        GoSub           Delay
        GoTo            tskSlow

;-----------------------------------------------------------------------
;Shared delay subroutine.
;This delays for 100 times the timebase of the calling task.
Delay:
        Pause           100
        Return 

 

Notes

  1. The timers can generate intervals down to 1mS. However, it can take your program some time before it actually tests the timer for expiration. This is called latency, and is a function of how much other work the program is doing.