NTP provider
The NTP provider is an (S)NTP client that cyclically receives a time signal from an NTP server. This allows it to calculate an offset of the system time from the time signal of the NTP server and make it available accordingly.
Configuration
The NTP provider is implemented as TcCOM module TcNtpExternalTimeProvider. This module is commissioned as a TcCOM module as follows:
- TwinCAT project
- 1. Insert a TcCOM module under System->TcCOM Objects and select type TcNtpExternalTimeProvider in the category External Time Provider.
- 2. The module requires a task from which it is called. This is parameterized via the Context tab of the module:
- The TcCOM module can be parameterized:
The configuration takes place in the Parameter (Init) tab. The parameters have the following meanings:
- TimeType: The type of offset for which this module is to determine an offset.
Client Para:
- bEnable: The module can be disabled to prevent NTP communication.
- sServerName: The name of the NTP server to be used as the source.
- nServerAddress: IP address of an NTP server (used if sServerName is empty).
- nServerPort: The UDP port of the NTP server to be used (default: 123).
- tPollIntervall: The interval in which the NTP queries are to be started. The maximum specified by the server is taken into account, which may slow down requests.
This module passes a determined offset to TwinCAT via the ITcSetExternalTime interface. In addition, outputs are available for mapping.
NTP provider as NTP server
Optionally, the same module can also act as an NTP server. Thus, a time signal can be obtained from an external NTP server (as a client) and simultaneously provided to lower-level systems.
For the external server, the NTP protocol typically requires a minimum query time of 8 seconds or more. The NTP provider as NTP server, on the other hand, allows more frequent query intervals.
Server function
The server functionality is normally hidden. It can be displayed and configured via Show Hidden Parameters:
- bEnable: Enable NTP server functionality for this module. To do this, open the udp/123 port in the Windows firewall.
- nPort: The UDP port that is used to offer the server (default: 123).
The following parameters are used to adjust the NTP information provided. By default, the parameters are set as specified in the protocol; they can be overwritten here:
- nLeap: Manual configuration of the Leap Indicator.
- nStratum: Manual configuration of the stratum.
- nRoot: Manual configuration of the root server information, as defined depending on the stratum.
Filter function
If offsets are determined by the NTP server query, the module can independently perform a transition from the old offset to the new offset.
This functionality is normally hidden. It can be displayed and configured via Show Hidden Parameters:
- eMode: A selection of modes. Currently, either no adjustment or a linear adjustment is made (default).
The following parameters apply if "Linear" is selected as eMode:
- nFilter: Number of values for which the average is taken, i.e. number of NTP responses. With a poll interval of 1 s, nFilter = 60 would effect a filter for one minute. (Default: 60).
- nLimiter: The offset is changed by this value at the most per cycle. If the difference between the local and external clocks were to be 100 ms and the cycle time 1 ms, it would thus take 100,000 cycles or 1.6 minutes at nLimiter = 10 until the offset has settled. (Default: 1 µs).
- nModulo: Rounding of the offset. Usually this should be chosen depending on the cycle time. The offset is adjusted via this modulo so that no "un-round" times are created. The DC Time will return the modulo of the cycle time; corrected with the offset, the timestamp thus remains "round". The offset/timestamp changes as a result, but also with small jumps if an adjustment takes place. As described under nLimiter and with nModulo = 1000, the offset and thus the relative timestamp would increment every 100th cycle by 0.1 ms.
Diagnostics
Diagnostic information can be viewed under the Parameters (Online) tab.
For each line there is a corresponding description in the Comment column.
In addition, corresponding symbols are available for programmatic evaluation:
- bIsConnected: At least 8 successful responses were received from the server (TRUE) or at least 8 requests were not answered (FALSE).
- bIsSynchronized: The determined time of the client has been determined in the last 8 responses with a deviation smaller than the cycle time of the server.
- nLastUpdate: The time of the last evaluated response from the server.