# Handle correctly the RTC in PFC200, UTC time and cycle time

**URL:** <https://www.wago.community/t/handle-correctly-the-rtc-in-pfc200-utc-time-and-cycle-time/1957>\
**Category:** CODESYS\
**Tags:** how-to\
**Created:** [June 14, 2025, 8:55pm UTC](https://www.wago.community/t/handle-correctly-the-rtc-in-pfc200-utc-time-and-cycle-time/1957 "2025-06-14T20:55:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gjiorg](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/gjiorg/32/1575_2.png) [@gjiorg](https://www.wago.community/u/gjiorg)\
**Post date:** [June 14, 2025, 8:55pm UTC](https://www.wago.community/t/handle-correctly-the-rtc-in-pfc200-utc-time-and-cycle-time/1957/1 "2025-06-14T20:55:07Z")

</div>

Hi there,

I am new here, hopefully this post will have some meaning for others too.  
I am trying to work with WAGO RTC time.  
I am using the library SysTime.SysTimeRtc 3.5.17  
I would like to use it in two ways.  
First, use it to measure the cycle time of the Function “LogStatusErrors”. My “first” try  
was to use mS and it worked, but the result is 0  
VAR: tsNowStart, tsNowEnd, tsRun : UDINT;  
BODY Start: tsNowStart:= SysTimeRtc.SysTimeGetMs();  
// Strange code with Arrays I want to test/log!!!  
BODY End:  
tsNowEnd := SysTimeRtc.SysTimeGetMs();  
tsRun:= (tsNowEnd-tsNowStart);  
GVL\_IEM3150a.udiLastRunTime:=tsRun; //  
Since I am getting 0 in GVL, and I see that the Function is working from time to time, I need to use nS or something else?  
I am trying the Library Function FUNCTION **SysTimeRtcHighResGet** , but I get syntax errors with everything I tried.  
And secondly, in the arrays I mentioned before, I want to store the UTC time in some logs. So I have to use pTimestamp.  
Again, I tried “every” way with “every” variable declaration, but it never worked.  
Anybody to throw some help?  
Thank you in advance for your time!

George  
(my first post was on Saturday night!)

---

<div class="post-metadata">

**Author:** ![gjiorg](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/gjiorg/32/1575_2.png) [@gjiorg](https://www.wago.community/u/gjiorg)\
**Post date:** [June 15, 2025, 10:50am UTC](https://www.wago.community/t/handle-correctly-the-rtc-in-pfc200-utc-time-and-cycle-time/1957/2 "2025-06-15T10:50:29Z")

</div>

Saturday was hot, and I came up with some answers,  
2 ways to measure the cycle time of an FB:  
VAR:

| | //---- Time count 1st way ------- |
| --- | --- |
| tsNowStart, tsNowEnd, tsRun : ULINT; | |
| | |
| //---- Time cound 2nd way ------ | |
| tsHighStart, tsHighEnd : LTIME; | |
| runTime\_ns: LINT; | |
| BODY Begin | |
| //---- Time count 1st way ------- | |
| WagoAppTime.SysTimeRtc.SysTimeGetUs(pUsTime:=tsNowStart); | |
| //---- Time cound 2nd way ------ | |
| tsHighStart := FuGetLongSystemTime(); | |

BODY Begin  
//---- Time count 1st way -------  
WagoAppTime.SysTimeRtc.SysTimeGetUs(pUsTime:=tsNowStart);  
//---- Time cound 2nd way ------  
tsHighStart := FuGetLongSystemTime();

// Strange code with Arrays I want to test/log!!!

/---- Time count 1st way -------  
WagoAppTime.SysTimeRtc.SysTimeGetUs(pUsTime:=tsNowEnd);  
GVL\_IEM3150a.udiLastRunTime:=(tsNowEnd-tsNowStart);

//---- Time cound 2nd way ------  
tsHighEnd := FuGetLongSystemTime();  
GVL\_IEM3150a.udiLastRunTimeNs := FuGetLTimeDifferenceNanoseconds(tsHighEnd,tsHighStart);

The values I get (before start shifting the array) are something like  
10 for udiLastRunTime and  
7450 for udiLastRunTimeNs  
Any feedback?  
thank you

---

<div class="post-metadata">

**Author:** ![gjiorg](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/gjiorg/32/1575_2.png) [@gjiorg](https://www.wago.community/u/gjiorg)\
**Post date:** [June 15, 2025, 11:00am UTC](https://www.wago.community/t/handle-correctly-the-rtc-in-pfc200-utc-time-and-cycle-time/1957/3 "2025-06-15T11:00:01Z")

</div>

as far as the UTC time store to the array I tried this:  
VAR  
timeStamp : LTIME;

BODY  
IF error AND store THEN  
GVL\_IEM3150a.aErrorHistory[GVL\_IEM3150a.udiErrorCount].timeStamp := WagoAppTime.FuGetLongTime();  
END IF

GVL\_IEM3150a.udiErrorCount is the pointer of the array.

the logic works but the time I see on the logs is something like  
LTIME#20254d10h45m44s417ms  
I checked the RTC of the PLC and it is correct,  
Can somebody see my mistake? this code is written in a FUN that I call from a FB.  
Thank you in advance,

---

<div class="post-metadata">

**Author:** ![WagoIcard](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/wagoicard/32/1508_2.png) [@WagoIcard](https://www.wago.community/u/WagoIcard)\
**Post date:** [June 16, 2025, 12:27am UTC](https://www.wago.community/t/handle-correctly-the-rtc-in-pfc200-utc-time-and-cycle-time/1957/4 "2025-06-16T00:27:45Z")

</div>

```TEXT
FuGetLongTime 
Retrieves the global time (in UT, i.e. GMT+0000) since 1.1.1970 in LTIME format
he time format LTIME combines the representation of absolute time 
(in millisecond resolution) and large value range (584 years). 
It is uniformly applicable without having to worry about overflow or reference 
points.

```

The LTIME you have seem correct since it is the time difference between 1970/01/01 00:00:00.00 and now.  
What format you want the timestamp to be ?  
A Linux timestamp ?  
A text one like “2025/06/16 9:18:46.874” ?

You have the function: `FuConvertLStampToTimeComponents` which transform the LTIME to a human readable datatype (UTC) or `FuConvertLStampToLocalTimeComponents` for the LOCAL time / date.

---

<div class="post-metadata">

**Author:** ![WagoDamRud](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/wagodamrud/32/258_2.png) [@WagoDamRud](https://www.wago.community/u/WagoDamRud)\
**Post date:** [June 16, 2025, 8:37am UTC](https://www.wago.community/t/handle-correctly-the-rtc-in-pfc200-utc-time-and-cycle-time/1957/5 "2025-06-16T08:37:14Z")

</div>

If you want to show timestamp in text log, try to use function “Format1()” from WagoAppString library

---

<div class="post-metadata">

**Author:** ![gjiorg](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/gjiorg/32/1575_2.png) [@gjiorg](https://www.wago.community/u/gjiorg)\
**Post date:** [June 22, 2025, 7:55am UTC](https://www.wago.community/t/handle-correctly-the-rtc-in-pfc200-utc-time-and-cycle-time/1957/6 "2025-06-22T07:55:55Z")

</div>

Dear Damian,  
thank you for the suggestion on Strings…  
Nice!
