NXT Timing

An internal 32-bit clock is maintained by the NXT 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 an application programg. Theses timers are useful for measuring elapsed time of events.

16-bit integers are the default variable type for RobotC on the NXT. 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.

 

wait1Msec(nMSec);

wait10Msec(nTenMSec);   

Program execution will wait for the specified number of clock units. Units can be in either 1-millisecond or 10-millisecond counts.

 

The maximum interval that can be specified is either 32.767 seconds or 327.67 seconds depending on which function is used.

 

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 functions 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.

 

ClearTimer(theTimer);   

Resets the value of the specified timer to zero.

 

time100[]

time10[]

time1[]

These three four-element arrays hold 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 time1[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].

 

nSysTime

This variable contains the value of the 32-bits of the internal 1-msec clock. This clock is reset when system is initially powered on.

 

nPgmTime

This variable contains the value of the 32-bits of the internal 1-msec “user” clock. This clock is reset when user program 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.

 

setClockTime(hours, minutes);

This function can be used to set the time of day. The NXT maintains an internal system clock that counts minutes. Note that the system clock is reset to time 0:00 whenever the NXT is first powered on; the clock is not incremented when the NXT is powered off.

 

nClockMinutes

This read/write variable provides access to the NXT clock describer above. The value ranges from 0 to 1439 before it wraps around back to 0. [Note: there are 1440 minutes in 24 hours].