|
|
| Line 5: |
Line 5: |
| | {| | | {| |
| | |- | | |- |
| − | |An internal 32-bit clock is maintained by the VEX firmware. It counts in units of 1-millisecond. Four timers (<span class="codeStringsNums">T1</span>, <span class="codeStringsNums">T2</span>, <span class="codeStringsNums">T3</span>, and <span class="codeStringsNums">T4</span>) 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. | + | |An internal 32-bit clock is maintained by the Arduino firmware. It counts in units of 1-millisecond. Four timers (<span class="codeStringsNums">T1</span>, <span class="codeStringsNums">T2</span>, <span class="codeStringsNums">T3</span>, and <span class="codeStringsNums">T4</span>) 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. | | 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. |
| 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.
|
| Parameter
|
Explanation
|
Data Type
|
| timer
|
A timer to use.
|
TTimers
|
Timers:
|
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
|
|
| 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.
|
| Parameter
|
Explanation
|
Data Type
|
| timer
|
A timer to use.
|
TTimers
|
Timers:
|
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
|
|
| 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.
|
| Parameter
|
Explanation
|
Data Type
|
| timer
|
A timer to use.
|
TTimers
|
Timers:
|
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
|
|