The RMC motion controllers support various levels of keeping track of time. The RMC75, RMC150, and RMC200 include system time registers that keep track of time since the RMC started up. The RMC200 also contains a real-time clock and supports real-time registers.
The system time registers can be used for functions such as delay timers, calculating time between events, and comparing the time occurrence of motion controller events with the times of other devices.
Register Name |
Data Type |
Access |
Time Base |
Rollover |
Tag Name |
RMC75 |
RMC150 |
RMC200 |
System Time - Time base starts when RMC powers up |
||||||||
Time Gear Master |
REAL |
Read Only |
1.0 s |
1 s |
_Time |
✓ |
✓ |
✓ |
Time, 16th Milliseconds |
DINT |
Read Only
|
0.000 062 5 s |
1.5 days |
_Controller.SysTime_16thmsec |
✓ |
✓ |
✓ |
Time, Seconds |
DINT |
Read Only
|
1.0 s |
68 years |
_Controller.SysTime_sec |
✓ |
✓ |
✓ |
Time, Milliseconds |
DINT |
Read Only
|
0.001 s |
24.8 days |
_Controller.SysTime_msec Or: _SysMS |
✓ |
✓ |
✓ |
Time, Microseconds |
DINT |
Read Only
|
0.000 001 s |
35.7 minutes |
_Controller.SysTime_usec |
✓ |
✓ |
✓ |
Time, Nanoseconds |
DINT |
Read Only
|
0.000 000 001 s |
1 second |
_Controller.SysTime_nsec |
✓ |
✓ |
✓ |
Time, Loop Ticks |
DINT |
Read Only
|
Same as the Loop Time (0.000 125 s to 0.008 s) |
3.1 - 198 days |
_Controller.SysTime_loops Or: _SysTicks |
✓ |
✓ |
✓ |
Real Time - Time base starts Jan. 1, 1970 |
||||||||
Real Time UTC, Seconds |
DINT |
Read/Write
|
1.0 s |
February 7, 2106 (232 s) |
_Controller.RealTimeUTC_sec |
|
|
✓ |
Real Time Local, Seconds |
DINT |
Read/Write
|
1.0 s |
February 7, 2106 (232 s) |
_Controller.RealTimeLocal_sec |
|
|
✓ |
Real Time, Nanoseconds |
DINT |
Read/Write
|
0.000 000 001 s |
1 second |
_Controller.RealTime_nsec |
|
|
✓ |
Using the Time registers
Time Gear Master
This register is intended only for use as a master register for gearing to time, such as running a curve based on time. It smoothly increments and wraps every second. It is the only time register that has a type of REAL.
Time, Seconds
Time, Milliseconds
Time, Microseconds
These DINT registers are used for general computing of time differences in units of seconds, milliseconds, or microseconds. The user can do a simple 32-bit subtraction to compare the elapsed time.
For example, to determine when 1 second has elapsed, the current time is first stored in a variable using an expression such as:
time0 := _Controller.SysTime_msec
then the following condition determines when 1 seconds has elapsed since the time was stored:
_Controller.SysTime_msec – time0 > 1000
Since each of these registers is a 32-bit DINT, each value will wrap from +2,147,483,647 to -2,147,483,648. However, because subtracting DINT values uses 32-bit modulo math, the subtraction will yield the intended result as long as no more than 231-1 (2,147,483,647) time units have elapsed between the two times.
The user must choose which time base provides adequate granularity and rollover times. For many applications in user programs, the Time, Milliseconds registers works well, as the default loop time is 1 ms, and times are typically in the range covered by this register (up to 231 ms).
For long times and fine granularity, use Time, Seconds together with Time, Nanoseconds, as described in Calculating Time with Seconds and Nanoseconds below.
Time, Loop Ticks
This DINT register has a time base that matches the current loop time. For example, if the loop time is 1 ms, its time base will be 1 ms. If the loop time is 500 µs, its time base will be 500 µs.
This register is not recommended for use because its time base can be difficult to convert to a normal time, and if a user program employing this register is ported to an RMC with a different loop time, the results may not be consistent. For calculating small time increments, use Time, 16th Milliseconds instead.
Time, 16th Milliseconds
This DINT register with a time base of 62.5 µs can be used in some applications where small time increments must be calculated, rather than the Time, Loop Ticks register. It is intended to be used for taking simple differences in timestamps, similar to the Time, Seconds, Time, Milliseconds, and Time, Microseconds registers.
Time, Nanoseconds
This DINT register is different from the ones above, since it wraps at 1 billion. Specifically, it cannot be used like this:
_Controller.SysTime_nsec – time0 > 1000 //Do not do this!
because rolling over at 1 billion breaks that difference.
This register is intended to be used in conjunction with Time, Seconds for computing accurate time differences, as described in Calculating Time with Seconds and Nanoseconds below.
Real Time UTC, Seconds (RMC200 Only)
Real Time Local, Seconds (RMC200 Only)
Real Time, Nanoseconds (RMC200 Only)
These DINT registers capture the real time, as determined by the real-time clock. When the RMC200 powers up, these registers take on the time stored from the onboard real-time clock. The time can also be adjusted via RMCTools, writing to these registers from a user program, or from an external device such as a PLC. The time is in Unix time, which is seconds and nanoseconds since midnight UTC/GMT January 1, 1970.
The Real Time UTC, Seconds register gives the Coordinated Universal Time (UTC), which corresponds to Greenwich Mean Time (GMT). The Real Time Local, Seconds register gives the local real time, which is adjusted for the selected time zone and daylight savings time, if applicable. The Real Time, Nanoseconds register applies to both.
These registers can be written to from a user program or from an external device such as a PLC. Writing to Real Time UTC, Seconds will automatically update Real Time Local, Seconds and vice versa. The local time zone offset is maintained when either Seconds register is written.
If both Real Time, Nanoseconds and one of the Real Time, Seconds registers is to be written to, then it is important that both registers are written to in the same User Program step or, if written to externally, then both registers should be written to in the same message. If the Seconds and Nanoseconds are written separately, then it is possible for the nanoseconds to roll over between the two writes and end up with an incorrect time.
It is not safe to compute basic mathematical differences based on these real time values because the real time can be adjusted while the controller is running. See Calculating Time with Seconds and Nanoseconds below.
Calculating Time with Seconds and Nanoseconds
The Time, Seconds register (_Controller.SysTime_sec) is used together with the Time, Nanoseconds register (_Controller.SysTime_nsec) to calculate the time between two events, with very fine granularity over long time spans. To calculate the time between two events, a time difference calculation must be performed between the two times, of which each time is represented by a seconds DINT and a nanoseconds DINT. This calculation is somewhat complicated, so Delta has provided user functions to capture times and compute differences, as described below.
User Functions
Delta has provided several user functions to perform the calculation between two times. These user functions are available for download from Delta's forum at https://forum.deltamotion.com/. Search for Time Functions, download the RMCTools User Function Library (.rmcflib) file, and import it into the User Functions in RMCTools.
Time Capture User Function
This function is for capturing the current system time and storing in two DINT variables.
TIME_CAPTURE(out DINT time_sec, out DINT time_nsec) : DINT
Captures the current system time, by capturing _Controller.SysTime_sec and _Controller.SysTime_nsec into the two output parameters time_sec and time_nsec. The return value is unused and will always be zero.
Elapsed Time User Functions
These functions determine the elapsed time between the current system time and a previously captured time.
TIME_ELAPSED_SEC(DINT t0_sec, DINT t0_nsec) : REAL
Returns time elapsed since the specified timestamp in seconds with fraction. This value is imprecise because of the limitations of 32-bit floating point math.
TIME_ELAPSED_MSEC(DINT t0_sec, DINT t0_nsec) : REAL
Returns time elapsed since the specified timestamp in milliseconds with fraction. Unlike TIME_ELAPSED_SEC, this value is precise up to certain limits. For a 1 msec loop time, this value is precise up to approximately 16,000,000 msec, and for a 0.125 msec loop time, is precise up to approximately 2,000,000 msec.
General Time Difference User Functions
The user functions listed above are relatively easy to use when determining how much time has elapsed since an event. Delta also provides more advanced user functions for determining the amount of time between two events, for which the times of each has been stored:
TIME_DIFF(DINT t0_sec, DINT t0_nsec, DINT t1_sec, DINT t1_nsec, out DINT dur_sec, out DINT dur_nsec) : DINT
Calculates the difference between two times by subtracting the time t0 (seconds and nanoseconds) from t1 (seconds and nanoseconds) and returning the resulting duration in seconds and nanoseconds as output parameters. The return value is unused and will always be zero.
TIME_DIFF_SEC(DINT t0_sec, DINT t0_nsec, DINT t1_sec, DINT t1_nsec) : REAL
Returns the difference between two times in seconds by subtracting the time t0 (seconds and nanoseconds) from t1 (seconds and nanoseconds) and returning the resulting duration in seconds with fraction as a REAL. This value is imprecise because of the limitations of 32-bit floating point math.
TIME_DIFF_MSEC(DINT t0_sec, DINT t0_nsec, DINT t1_sec, DINT t1_nsec) : REAL
Returns the difference between two times in milliseconds by subtracting the time t0 (seconds and nanoseconds) from t1 (seconds and nanoseconds) and returning the resulting duration in milliseconds with fraction as a REAL. Unlike TIME_DIFF_SEC, this value is precise up to certain limits. For a 1 msec loop time, this value is precise up to approximately 16,000,000 msec, and for a 0.125 msec loop time, is precise up to approximately 2,000,000 msec.
Converting to Seconds or Milliseconds
These user functions convert a time represented by two DINTs (seconds and nanoseconds) to a single REAL, in seconds or milliseconds. These functions are typically not necessary, since the TIME_ELAPSED and TIME_DIFF functions above can output the time to a single REAL.
DURATION_SEC(DINT dur_sec, DINT dur_nsec) : REAL
Converts from a duration in seconds and nanoseconds to seconds with fraction as a REAL.
DURATION_MSEC(DINT dur_sec, DINT dur_nsec) : REAL
Converts from a duration in seconds and nanoseconds to milliseconds with fraction as a REAL.
Example: Elapsed Time
To calculate the time that has elapsed since a certain event, first, capture the time of the event, and then use a TIME_ELAPSED function to determine the elapsed time.
The functions in this example can be obtained from Delta's forum at https://forum.deltamotion.com/. Search for Time Functions, download the RMCTools User Function Library (.rmcflib) file, and import it into the User Functions in RMCTools.
Example: Time Difference
To calculate the time difference between two times that each have been stored as seconds and nanoseconds, use a TIME_DIFF function.
The functions in this example can be obtained from Delta's forum at https://forum.deltamotion.com/. Search for Time Functions, download the RMCTools User Function Library (.rmcflib) file, and import it into the User Functions in RMCTools.
First, capturing the time that the first event occurred:
Next, capture the time that the second event occurred:
Finally, calculate the difference between the two times:
See Also
System Time Registers | RMC200 Real-Time Clock | Event Timers
Copyright © 2024 Delta Computer Systems, Inc. dba Delta Motion