RTC_EX2

RTC_EX2 1:

The "RTC_EX2" (Extended Real Time Clock) function block allows an internal Software clock to be implemented in TwinCAT PLC. The clock must be initialized with a starting date and time. After the initialization the time and date are updated with each call of the function block. A CPU system clock is used to calculate the current time and date. The function block should be called in every PLC cycle, so that the current time can be calculated. At the function block output the current date and time is available in the Windows system time format. In contrast to the RTC function block, RTC_EX2 offers microsecond accuracy. Multiple instances of the RTC_EX2 function block can be created within one PLC program.

RTC_EX2 2:

RTC_EX2 time can differ from the reference time

The way the system works means that the RTC_EX2 time can differ from the reference time. The difference depends on the PLC's cycle time, the value of the basic system ticks, and on the hardware being used.

In order to avoid larger deviations the RTC_EX2 instance should be synchronized cyclically (e.g. with a radio clock or with the local Windows system time). The local Windows system time you can be synchronized with a reference time via the SNTP protocol.

VAR_INPUT

VAR_INPUT
   EN      : BOOL;
   PDT     : TIMESTRUCT;
   PMICRO  : DWORD;
END_VAR

EN: The RTC_EX2 function block is re-initialized with a specified date, time and millisecond by a rising edge at this input.

PDT: (Preset Date and Time ) The initialisation values for the function block's date and time (type: TIMESTRUCT). A rising edge at the EN input will cause the function block to adopt this value.

PMICRO: (Preset Milliseconds) The initialisation value for the milliseconds. A rising edge at the EN input will cause the function block to adopt this value.

VAR_OUTPUT

VAR_OUTPUT
   Q      : BOOL;
   CDT    : TIMESTRUCT;
   CMICRO : DWORD;
END_VAR

Q: This output is set if the function block has been initialized at least once. If the output is set, the values for the date, time and milliseconds at the PDT and CMICRO outputs are valid.

CDT: Current date and time of the RTC_EX2 instance (type: TIMESTRUCT). The CDT output is only updated when the function block is called. For this reason, instances of the function block should be called once in each PLC cycle.

CMICRO: (Current Microseconds) The microseconds output.

Example:

See: Example: Software clocks (RTC, RTC_EX, RTC_EX2).

Requirements

Development environment

Target platform

PLC libraries to be integrated (category group)

TwinCAT v3.1.0

PC or CX (x86, x64, ARM)

Tc2_Utilities (System)