External TwinCAT synchronization

Sample: EL6692 bridge terminal

External TwinCAT synchronization 1:

Using the sample programs

This document contains sample applications of our products for certain areas of application. The application notices provided here are based on typical features of our products and only serve as samples. The notices contained in this document explicitly do not refer to specific applications. The customer is therefore responsible for assessing and deciding whether the product is suitable for a particular application. We accept no responsibility for the completeness and correctness of the source code contained in this document. We reserve the right to modify the content of this document at any time and accept no responsibility for errors and missing information.

In this example, two Beckhoff IPCs with TwinCAT 2.11, b1539, will be synchronized with each other. One PC is the master clock, the second (slave clock) synchronizes its ‘time’ to the first. As the fieldbus, EtherCAT makes the necessary operating resources available, in particular EtherCAT’s own synchronization mechanism, distributed clocks.

The procedure is as explained in the previous chapter.

The following must be observed:

Note

Effect on devices when changing the shift times

Side effects relating to the function of the other slaves when the shift times are changed should be taken into account!

External TwinCAT synchronization 2: Sample program (Download), TwinCAT 2.11

Pay attention in the program to the use of ‘signed’ and ‘unsigned’ 64-bit variables as required.

demo_el6692_dc_synchronization_s.zip

Topology

External TwinCAT synchronization 3:
Topology of the example program

Station Master: EK1100, EL2202, EL6692

Station Slave: EK1100, EL2202

In this example, the EL6692 is synchronized in the direction PrimarySide --> SecondarySide (RJ45 connection). Synchronization in the other direction is also possible.

External TwinCAT synchronization 4:

EL6692 documentation

Please note the information in the EL6692 documentation regarding the system behavior of this terminal.

Demo program

In this demo program, the slave’s own local DC time from the ReferenceClock in the EtherCAT strand is offset by the time difference to the external synchronization device. This offset therefore only makes sense on a platform that is a synchronization slave to one master.

The synchronization route can be
- another EtherCAT system; means: Beckhoff EL6692 bridge terminal (this example)
- an IEEE1588 system; means: Beckhoff EL6688 PTP terminal
- an arbitrary timer with time information (GPS, radio clock); means: TwinCAT ‘External Synchronization’ supplement

The principle:
TwinCAT cyclically receives (e.g. every second) a pair (64-bit, unit 1 ns) made up of an internal (DC) and an external time stamp. These two time stamps are originally obtained simultaneously. The offset between the two timebases is calculated from the initial difference and made known in the System Manager | EtherCAT device | InfoData. Furthermore, the slave TwinCAT readjusts its own local DC time from the course of the two time stamps with respect to each other.

Calculations:

Setting up TwinCAT 2.11

In the following procedure the complete system is set up as follows:

The synchronization direction of the time can be set up the other way around; the instructions must then be followed analogously.

Sync Master side

External TwinCAT synchronization 5:
Device on the master side
External TwinCAT synchronization 6:
Set the EL6692 PrimarySide to DC
External TwinCAT synchronization 7:
Activate PDO 0x1A02 to display the time stamps
External TwinCAT synchronization 8:

Timestamp PDO

The activation of the timestamp PDO indicates to the TwinCAT software on the respective side that this side is to be synchronized, i.e. that it is the Sync Slave.
It is not necessary to activate the timestamp PDO on the Sync Master side (i.e. the side that represents the reference clock).

External TwinCAT synchronization 9:
Set the synchronization direction on the PrimarySide; in this case SyncSettings: Primary -> Secondary
External TwinCAT synchronization 10:
Activate the display of the DC offsets in the EtherCAT master; can be evaluated on the master side
External TwinCAT synchronization 11:
Master PC works with its own ReferenceClock as a basis

TwinCAT can now be activated and started on this side. All devices must be in OP, WorkingCounter = 0, no LostFrames. The EL6692 time stamps on the PrimarySide remain at 0, because the SecondarySide has not yet been configured.

Sync Slave side

The EL6692, SecondarySide is set to DC and 0x1A02 according to the fig. Set the EL6692 PrimarySide to DC and Activate PDO 0x1A02 to display the time stamp.

After reloading the configuration (or restarting in ConfigMode, FreeRun), the synchronization direction can be read out by means of GetConfiguration on the SecondarySide, see the fig. SecondarySide of the EL6692.

External TwinCAT synchronization 12:
SecondarySide of the EL6692
External TwinCAT synchronization 13:
EtherCAT master settings, slave side

After the restart, the DC function of the EL6692 is known to the EtherCAT master; therefore, it now offers this EL6692 as an ExternalSyncDevice in the DC dialogue.

The linking of the following variables is necessary for the evaluations; see the fig. Slave side.

External TwinCAT synchronization 14:
Slave side

Note

Demo program

The following screenshots and information refer exclusively to the PLC demo program discussed here and the example code it contains, and not to the analysis functions of the system manager. See also the note.

On the slave side, the start of the synchronization can be observed with the incorporated visualization.

External TwinCAT synchronization 15:
Start slave side

Only the local DC time is available on the slave side immediately after the start.

External TwinCAT synchronization 16:
Time stamp known

Following receipt of the first time stamps via the EL6692, the offset is known; in this case it is around 3 minutes different to the time of the IPC used. Synchronization has begun; in this sample a window of ± 10 µs is to be achieved.

External TwinCAT synchronization 17:
Synchronization successful