Distributed Clocks & TwinCAT PLC

Distributed Clocks & TwinCAT PLC 1:

Validity of the following settings

The following information is based on TwinCAT 2.11 build 1539. More recent editions can have a different user interface design; however, usage remains analogously the same. Subfunctions may already have been included in the predecessor versions, but it should be noted that the same TwinCAT version (e.g. 2.11) must be present on both the target system and the programming system in order for the latest functions to be supported.

From the point of view of the PLC, TwinCAT 2.11 is a continuous development of TwinCAT 2.10. The PLC libraries have been expanded to include more features. The following libraries are of particular interest for use with Distributed Clocks functions:

These libraries are included in every TwinCAT installation.

Distributed Clocks & TwinCAT PLC 2:
PLC Libraries

Working with DC times in the controller

From the perspective of the controller the distributed clock time has the following characteristics:

The following 3 data types are recommended for handling DC times

Distributed Clocks & TwinCAT PLC 3:

64- vs. 32-bit representation

Some EtherCAT slaves can only handle 32 bit values for representing the DC time or handle it as a process data. In order to prevent problems caused by overflow (every 4.2 seconds), we strongly recommend using 64-bit times in the controller.

    • 32-bit times supplied to the PLC must be complemented with the current High part
    • In this case only the Low part (lower 32 bit) should be transferred to the hardware

    This sample project
    Distributed Clocks & TwinCAT PLC 4: (Download) contains a function block that cyclically adds the high part to a 32-bit DC time to make 64 bits.

    example_32bitdcextension.zip

    Reading the DC time

    As described, there are several time sources on a TwinCAT PC; of these, the Distributed Clock time is crucial for the EtherCAT system. Usually, the first DC-capable slave is the EtherCAT master clock; the controller, with its software form of the DC clock, is synchronized to this master clock. Hence, the current DC time is available in the controller.

    In the PLC there are 4 possibilities to access the current DC time, the "now" time, during task runtime.

    Distributed Clocks & TwinCAT PLC 5:

    Compatibility

    The functions F_GetActualDcTime and F_GetCurDcTaskTime can only be used with TwinCAT version 2.11 or higher (on programming and target system).

    Sample:

    A PLC task is configured in the System Manager with a cycle time of 500 µs and 100 µs base time.

    Distributed Clocks & TwinCAT PLC 6:
    Sample configuration with 500 µs cycle time
    Distributed Clocks & TwinCAT PLC 7:
    Sample configuration with 500 µs cycle time

    The evaluation of the above-mentioned procurement methods is enabled by Fig. Methods of reading the DC time:

    Distributed Clocks & TwinCAT PLC 8:
    Methods of reading the DC time

    At runtime of the PLC program the three F_Get... functions are now called at any desired point. Then, with TwinCAT 2.11 or higher, they return:

    The contents of DcSysTime come from the field side master clock - this copying procedure is subject to fluctuations over time and therefore does not advance precisely with cycle time. This also applies to other local DcSystem times transferred as process data from the hardware.