RTC
The function block "RTC" ( Real Time Clock ) can be used to realize an internal software clock in the 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 output of the function block the current date and time is available in the common DATE_AND_TIME (DT) format. Multiple instances of the RTC function block can be created within one PLC program.
The way the system works means that the RTC 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 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 : DATE_AND_TIME;
END_VAR
EN: The function block is re-initialized with a specified date and time by a rising edge at this input.
PDT: ( Preset Date and Time ) The initialization values for the function block's date and time. A rising edge at the EN input will cause the function block to adopt this value.
VAR_OUTPUT
VAR_OUTPUT
Q : BOOL;
CDT : DATE_AND_TIME;
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 and time at the PDT output are valid.
CDT: ( Current Date and Time ) The current date and time from the RTC instance. 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.
Requirements
Development environment | Target System | PLC libraries to include |
---|---|---|
TwinCAT v2.9.0 Build > 1030 and higher | PC or CX (x86) | TcUtilities.Lib |
TwinCAT v2.10.0 Build >= 1301 | CX (ARM) |