System Time

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
(231 ms/16)

_Controller.SysTime_16thmsec

Time, Seconds

DINT

Read Only

 

1.0 s

68 years
(231 s)

_Controller.SysTime_sec

Time, Milliseconds

DINT

Read Only

 

0.001 s

24.8 days
(231 ms)

_Controller.SysTime_msec

Or: _SysMS

Time, Microseconds

DINT

Read Only

 

0.000 001 s

35.7 minutes
(231 µs)

_Controller.SysTime_usec

Time, Nanoseconds

DINT

Read Only

 

0.000 000 001 s

1 second
(1 billion ns)

_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
(231 loop times)

_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
(1 billion ns)

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

Elapsed Time User Functions

These functions determine the elapsed time between the current system time and a previously captured time.

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:

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.

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


Send comments on this topic.

Copyright © 2024 Delta Computer Systems, Inc. dba Delta Motion