TwinCAT time sources

The Beckhoff TwinCAT automation suite can analyze several independent time sources. See also the sample program.

Information regarding the architecture:

Name

BIOS motherboard

CPU time

Windows/NT time

TwinCAT/TC time

Distributed clocks/DC time

Description

RTC (RealTimeClock), battery-operated on the motherboard

CPU counter from the controller hardware, not regulated

Initialized by RTC

Local system time of the Windows operating system (NT)

Initialized by RTC

Running TwinCAT clock

Initialized by Windows

The system returns the start time of the current task cycle.

Initialized by TwinCAT.

Data

 

64 bit
resolution: 100 nsPC Base

from 1.1.1601 00:00
resolution: 1 ms
Scope: structure with year, month, day, hour etc.

from 1.1.1601 00:00
resolution: 100 ns
Scope: 64 bit

from 1.1.2000 00:00
resolution: 1 ns
Scope: 64 bit

Reference

 

 

Local

Local time taking into account the set time zone, i.e. usually UTC

Local time taking into account the set time zone, i.e. usually UTC

PLC format

 

T_ULARGE_INTEGER

TIMESTRUCT

T_FILETIME

T_DcTime

Call

 

GetCpuCounter

NT_GetTime()

GetSystemTime()

F_GetActualDcTime()
(ab TwinCAT 2.11)

F_GetCurDcTickTime()
(= GetSystemTime)

F_GetCurDcTaskTime()
(from TwinCAT 2.11)

Update

 

With each call, possibly several times within a PLC cycle

 

with each base tick (System Manager | BaseTime)

ActualDcTime
with each call, possibly several times within a PLC cycle


TickTime
with each base tick
(System Manager | BaseTime)


TaskTime
At the start of the Sync task cycle

Sample application

can be used by the PLC block Nt_SetTimeToRtcTime for correcting the NT time

relative time measurements

Logging, time stamping at operating system level

High-precision, relative time-based tasks within one or across several task cycles

- High-precision, relative time-based tasks within the EtherCAT system
- Definitive reference to the global time through external synchronization possible

Manipulation options

 

 

- It can be changed to the current RTC time by the PLC function block Nt_SetTimeToRtcTime; this also triggers a correction of the RTC time

ATTENTION
Use of this function in conjunction with EtherCAT distributed clocks systems is not recommended.

- Synchronization at network level (SNTP, NTP)


 

Synchronization with external reference time from TwinCAT 2.11
 

Table 1: time architecture, required libraries: TcEtherCAT.lib, TcUtilities.lib, TcSystem.lib

Application scenario 1: Local control system without forced synchronization via the network

The local Windows clock is free-running and can be coupled to the RTC via Nt_SetTimeToRtcTime. This option is not recommended when using distributed clocks components!

We recommend using the TC or DC clock if absolute time references are required.

Ideally, the DC time should be coupled to an external reference time via suitable EtherCAT components.

Application scenario 2: Local control system with forced synchronization via the network

The local Windows clock is cyclically synchronized with the world time through a network clock/server/Internet time server.

Coupling of the Windows clock to the RTC through Nt_SetTimeToRtcTime is not recommended.

We recommend using the TC or DC clock. The reference to the absolute time can be established via the application through offset calculation at the NT time.

Ideally, the DC time should be coupled to an external reference time via suitable EtherCAT components.

Application scenario 3: Local control system with external reference time via EtherCAT

A frequency- and phase-synchronized analog time is available through coupling of the DC time to an external time source (GPS, radio clock, PTP/IEEE1588, EtherCAT). The NT and TC time are not required in the application.

TwinCAT time sources 1:

Common time synchronization

The usual time synchronization at operating system level works in discrete intervals ranging from several seconds to days. In the synchronization case this leads to an erratic/unsteady change of the subordinate time! The usual network synchronizations (SNTP, NTP and similar) or even Nt_SetTimeToRtcTime are affected by this. The application must be able to anticipate these sudden changes in the "absolute" time.
Beckhoff only integrates continuous synchronization techniques in EtherCAT.