This function accelerates or slows down the frequency of the RTC to give control to the application for RTC compensation, depending on the operating environment (temperature, …). The compensation value is given in seconds per week. It can be positive (accelerate) or negative (slow down).
To see the general representation in IL or ST language, refer to the chapter Function and Function Block Representation.
This table describes the input parameters:
Inputs |
Type |
Comment |
---|---|---|
RtcDrift |
SINT (-29..29) |
Correction in seconds per week (-29...+29). |
This table describes the output variable:
Output |
Type |
Comment |
---|---|---|
SetRTCDrift |
Returns RTC_OK (00 hex) if command is correct otherwise returns the ID code of the detected error. |
In this example, the function is called only once during the first MAST task cycle. It accelerates the RTC by 4 seconds a week (18 seconds a month).
VAR
MyRTCDrift : SINT (-29..+29) := 0;
MyDay : sec.DAY_OF_WEEK;
MyHour : sec.HOUR;
MyMinute : sec.MINUTE;
END_VAR
IF IsFirstMastCycle() THEN
MyRTCDrift := 4;
MyDay := 0;
MyHour := 0;
MyMinute := 0;
SetRTCDrift(MyRTCDrift, MyDay, MyHour, MyMinute);
END_IF