
clarenced (Customer) asked a question.
P2CDS-622 Setting Real Time Clock. Can set back in time, but setting forward causes *EXCEPTION* [ProcessorLoadWatchdog]
Seems like the Processor load watchdog uses the real time clock. So when the time is set forward it thinks the system is crashed and triggers an exception. Any ideas how to set the real time clock from the HMI as a user. I see you can set the time from the PLC shell, but the user can not access that.
This example program can set the time back by 1 minute but crashes on setting it forward by 1 minute.
- PROGRAM PLC_PRG
- VAR
-
- setFwd: BOOL;
- setBack: BOOL;
- utc: DWORD;
- result: UDINT;
-
- END_VAR
-
- utc := SysTimeRtcGet(pResult := result);
-
- IF setFwd THEN
- SysTimeRtcSet(utc + 60);
- setFwd := FALSE;
- END_IF
-
- IF setBack THEN
- SysTimeRtcSet(utc - 60);
- setBack := FALSE;
- END_IF
There is an errata associated with the "SysTimeRtsSet" but should be only when the IDE is connected to the PLC.
https://docs.codesys-p2cds622.com/en/latest/Errata/rtcsetconnect.html
As long as the PLC is running in standalone mode (not connected to IDE) and the Visualization (utilized via an external WebVisu Browser) has an input button select for "setFwd", "setBack", this should be functional.
Reference:
Quick note- some feedback from a colleague is the possibility of an error with "SysTimeRtcSet" getting executed on every Scan. We will be able to dive into more on Monday if required.
Here's what I was able to duplicate:
Will need to dive in deeper with developers. Will advise on Monday.
Currently setting the RTC clock during application run is not possible without causing this error because it's tied to the Codesys runtime "schedule". So when you change the time ahead (or behind) the system will think that amount of time has passed. We'll update the website to reflect this.
Is this just in place so the user can update the date and time displayed on Webvisu or is there some other functionality you are seeking?
One thing can do is have another date and time variable, say like APP_TIME, that will track and offset the time from the RTC.
Or if you are wanting a constant accurate time, you could use the same technique, but using a NTP server time. You would read the NTP time into an application variable and offset from the APP_TIME.
We apologize for this issue and that we cannot resolve directly.
An "Unsupported Feature" has been generated on the website ( https://docs.codesys-p2cds622.com/en/latest/Unsupported/setrtc.html ).
If it's a viable option for you to utilize the "SNTP" function support, it is discussed here: https://docs.codesys-p2cds622.com/en/latest/Example%20Projects/iiot_sntp.html .
Thanks for looking into this.
I don't know what expected real time clock accuracy would be, but if you think that the life of a plc is 10 to 15 years, at some point the clock will need to be adjusted. Asking a customer to load up codesys on his computer and do "rtc-set" from the PLC shell is not realistic. If you want a timeclock to start something at 12:00, you want it to start at 12:00 not 12:05. This could be handled with calculating an actual time based on an offset from the real time clock and allowing the user or sntp to adjust that offset.
This does not solve the requirement for an accurate clock to to be able to do internet connectivity. Some internet connectivity especially with security needs accurate time to work. I assume this is why most of your plc's now have an easy way to set the clock with SNTP. Having an offset that calculates a actual time won't help with this. Here is what chat GPT thinks about PC clock accuracy requirements:
How much error can my pc clock have before I will start experiencing internet connectivity problems?
ChatGPT said:
Your PC clock can be off by a few seconds without major issues, but if the error grows too large, you might start experiencing connectivity problems. Here’s how different levels of clock drift can impact your internet usage:
1. Small Error (Under 5 Seconds)
2. Moderate Error (5 Seconds to 5 Minutes)
3. Significant Error (5 Minutes to 30 Minutes)
4. Large Error (Over 30 Minutes)
5. Extreme Error (Over a Few Hours or Days)
Fixing Time Drift
Bottom Line
I'm sure the P2-CDS622 is different, but I'll see a substantial drift in one months time with P1ks that are not syncing with an NTP server.
The P2-CDS622 does not offer a way to sync with NTP during runtime? That seems like a feature that should be added.