Set Realtime Clock from CODESYS

Is there a way to set the EPIC’s Realtime Clock from CODESYS?

I’m attempting to use the “SysTimeRtcSet” Function, but it’s returning an error code 25: “ERR_NO_ACCESS_RIGHTS”.

Currently Codesys does not have access rights to the realtime clock. May ask what you are trying to solve with this? You can point the EPIC at any NTP server, public or on premises to keep the time synched.

2 Likes

Thanks for the reply Garrick. I’m really just in a testing phase at this time - there is no specific use case at this point in time. That said, in some applications, I don’t have access to an NTP Server and I want to be able to send a time synch from the SCADA Server (via OPC UA).

I have tested the NTP Server connection - that’s nice. BTW, how often does the controller sync with the NTP Server?

If you don’t have access, you could always use a GPS NTP Server, or setup the SCADA Server to be a time server.

I don’t have a hard number for that. We use the default precision of ntpd. Anything that can be configured from /etc/ntp.conf is accessible via ssh (with a shell-access license).

Thanks again, I appreciate the quick response.

Opto has chosen to use a very basic NTP.conf file and let the algorithm do its thing, so this is hard to answer as we don’t explicitly set the minpoll or maxpoll.

1 Like

With NTP, to get as accurate times as possible it is best to have consistent round trip times with the server. Note, the NTP protocol adjusts the skew of the system clock with a feedback loop. It rarely does a bulk clock time change. As a simplification, you can think of it as a PID loop where the PV is your local time, the Setpoint is the time of the NTP server. There is definitely more to it because it is a statistics algorithm.

The main purpose of having the time be dead on is for synchronization purposes. It may be worth looking into ieee1588. An easy way and kinda old school to sync actions of two controllers is to wire a DO from one controller into the DI of the other to request an action. The time response will be within 20ms or so depending on the scan rate of the IO and jitter.

The default settings from opto for codesys is 20ms streaming interval and I typically see a max jitter of 5ms or so for the task.

As a side note. I know for deep sea logging, there is no gps and they want to correspond the readings with other deep sea loggers so having accurate time is crucial. They make the loggers with very accurate low drift rtc so the time readings will be roughly the same for all the loggers deep down.