Real-time clock - example

The BX Controller features a real-time clock. The current time can be read via a function block. The following example will illustrate this.

Function block RTC

FUNCTION_BLOCK RTC

VAR_INPUT

EN         :BOOL;
PDT        :DT;

Legend

EN: Rising edge sets the time to the value available at the PDT input.

PDT: Date and time to be set.

VAR_OUTPUT

Q          :BOOL;
CDT        :BOOL;

Legend

CDT: Current time.

Required libraries:

Real-time clock - example 1: Download sample ST program (sample file)

PROGRAM MAIN
VAR
    fbTimer: TON;
    fbRTC: RTC;
END_VAR

 

fbTimer(PT:=t#60s,IN:=NOT fbTimer.Q);

IF fbTimer.Q THEN
    fbRTC;
END_IF
Real-time clock - example 2:

Do not call the RTC function block in every PLC cycle

Calling the RTC block increases the cycle time by approx. 5 ms, due to the data conversion into a TIME AND DATE variable. The function block should therefore not be called during each PLC cycle.
Alternatively, you can read the time via an ADS function block. The ADS function block returns the date and the time as WORD variables.
Example 19:30 hrs - hour: 19 / minute: 30

rtc example.prx