RTC

RTC 1:

The "RTC" (Real Time Clock) function block allows an internal clock to be implemented within a PLC controller (BCxxxx). The clock must be initialized with a starting date and time. After initialization, the time and date are updated cyclically each time the function block is called. A controller system clock is used to calculate the current time and date. The system clock has a resolution of one millisecond. The function block should be called in every PLC cycle, so that the current time can be calculated. The RTC has a potential error of about 1 minute in each 24 hours. In order to avoid large errors, the RTC can be cyclically synchronized (e.g. with a radio clock or with a TwinCAT PC via the fieldbus). The current date and time are available in the usual DATE_AND_TIME (DT) format at the function block's output. Multiple instances of the RTC function block can be created within one PLC program.

 

VAR_INPUT

VAR_INPUT

    EN  :  BOOL;

    PDT : DATE_AND_TIME; 

END_VAR

EN: on a rising edge at this input, the function block is reinitialized with a preset time and date.
PDT: ( Preset Date and Time ) the initialization values for the date and time of the function block. 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 this output is set, then the values for the date and time at the PDT output are valid.
CDT: ( Current Date and Time ) current date and time from RTC. 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.

 

Sample of a call in FBD:

PROGRAM MAIN
VAR
    RTC1           : RTC;
    Init_RTC       : BOOL;
    RTC_DataValid  : BOOL;
    RTC_DateAndTime: DT;
END_VAR

RTC 2:

Requirements

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v2.7.0 and above

BCxxxx (165)

Standard.Lb6, PlcSystemBC.Lb6, TcPlcUtilitiesBC.Lb6