328 Timing Functions

An internal 32-bit clock is maintained by the VEX firmware. It counts in units of 1-millisecond. Four timers (T1, T2, T3, and T4) are built using this timing capability. These four timers can be individually reset to zero within a program. Theses timers are useful for measuring elapsed time of events.

16-bit integers are the default variable type for ROBOTC on the VEX. All of the timing functions operate with 16-bit signed variables. This does mean that caution should be exercised in programming to avoid overflow of timer values. A 16-bit signed variable has positive values in the range 0 to 32,767 and programs should periodically reset any timers that they use to prevent overflow.

32-bit integers are the default variable type for ROBOTC on the Cortex. All of the timing functions operate with 32-bit signed variables. A 32-bit signed variable has positive values in the range 0 to 2,147,483,648 and programs should periodically reset any timers that they use to prevent overflow.

ClearTimer(T1); // resets the value of Timer "T1" back to zero seconds

nClockMinutes

word nClockMinutes

(word) This read/write variable provides access to the CORTEX clock described above. The value ranges from 0 to 1439 before it wraps around back to 0. Note: there are 1440 minutes in 24 hours.

int varClock; // creates a variable
varClock = nClockMinutes; // stores the current value of the CORTEX Clock to a variable

nPgmTime

const long nPgmTime

(long) This variable contains the value of the lower 16-bits of the internal 1-msec clock. This variable is reset when user program first starts running. This clock does not increment when the program is in a debugger "suspended" state which is useful during single step debugging as the clock does not increment.

int varPgmTime; // creates a variable
varPgmTime = nPgmTime; // stores the current value of nPgmTime to a variable

nSysTime

const long nSysTime

(long) This variable contains the value of the lower 16-bits of the internal 1-msec clock. This variable is reset when CORTEX is first powered on.

int varSysTime; // creates a variable
varSysTime = nSysTime; // stores the current value of nSysTime to a variable

time1

long time1[TTimers timer]

(long) This array holds the current value of the respective timers. Each of the timer values can be retrieved in units of 1, 10 and 100 milliseconds depending on which array is used. For example, time1[T1] retrieves the value of timer T1 in units of 1-msec and time10[T1] retrieves the value using a 10-msec tick. And time100[T1] retrieves the value using 100-msec tick. Note that the arrays are “linked”. Setting time1[T1] = 0; will also reset the value of time10[T1] and time100[T1]. The value returned is a signed integer, so each array will meet its upper bounds at a value of 32,768 ticks.

int valTime1, valTime10, valTime100; // create three integers to read the value of the timer
valTime1 = time1[T1]; //Gets the value of Timer T1 in 1ms increments and stores it in a variable
valTime10 = time10[T1]; //Gets the value of Timer T1 in 10ms increments and stores it in a variable
valTime100 = time100[T1]; //Gets the value of Timer T1 in 100ms increments and stores it in a variable

time10

long time10[TTimers timer]

(long) This array holds the current value of the respective timers. Each of the timer values can be retrieved in units of 1, 10 and 100 milliseconds depending on which array is used. For example, time1[T1] retrieves the value of timer T1 in units of 1-msec and time10[T1] retrieves the value using a 10-msec tick. And time100[T1] retrieves the value using 100-msec tick. Note that the arrays are “linked”. Setting time1[T1] = 0; will also reset the value of time10[T1] and time100[T1]. The value returned is a signed integer, so each array will meet its upper bounds at a value of 32,768 ticks.

int valTime1, valTime10, valTime100; // create three integers to read the value of the timer
valTime1 = time1[T1]; //Gets the value of Timer T1 in 1ms increments and stores it in a variable
valTime10 = time10[T1]; //Gets the value of Timer T1 in 10ms increments and stores it in a variable
valTime100 = time100[T1]; //Gets the value of Timer T1 in 100ms increments and stores it in a variable

time100

long time100[TTimers timer]

(long) This array holds the current value of the respective timers. Each of the timer values can be retrieved in units of 1, 10 and 100 milliseconds depending on which array is used. For example, time1[T1] retrieves the value of timer T1 in units of 1-msec and time10[T1] retrieves the value using a 10-msec tick. And time100[T1] retrieves the value using 100-msec tick. Note that the arrays are “linked”. Setting time1[T1] = 0; will also reset the value of time10[T1] and time100[T1]. The value returned is a signed integer, so each array will meet its upper bounds at a value of 32,768 ticks.

int valTime1, valTime10, valTime100; // create three integers to read the value of the timer
valTime1 = time1[T1]; //Gets the value of Timer T1 in 1ms increments and stores it in a variable
valTime10 = time10[T1]; //Gets the value of Timer T1 in 10ms increments and stores it in a variable
valTime100 = time100[T1]; //Gets the value of Timer T1 in 100ms increments and stores it in a variable

wait1Msec

void wait1Msec(const long nMSec)

(void) Program execution will wait for the specified number of clock units. Units are in 1-millisecond counts. The maximum interval that can be specified is 32.767 seconds. An alternative, and far less efficient, method to perform a wait is to continually execute a tight code loop looking to see if a timer has reached the desired interval. It is best to use the wait function to insert a programmed delay in a program because tasks that are waiting do not consume any CPU cycles. This makes the most number of CPU cycles available for other tasks.

wait1Msec(1000); // the program will wait for 1 second before moving on (1ms * 1000)

wait10Msec

void wait10Msec(const int nTenMSec)

(void) Program execution will wait for the specified number of clock units. Units are in 10-millisecond counts. The maximum interval that can be specified is 327.67 seconds. An alternative, and far less efficient, method to perform a wait is to continually execute a tight code loop looking to see if a timer has reached the desired interval. It is best to use the wait function to insert a programmed delay in a program because tasks that are waiting do not consume any CPU cycles. This makes the most number of CPU cycles available for other tasks.

Parameter

Explanation

Data Type

nTenMSec

The amount of milliseconds to wait, measured in 10-millisecond counts.