What to do if the timer's time precision is insufficient when using the Codesys system controller?
I. Functions and Precautions
(1) Function Description: This document provides a trick for situations where the timer's precision is insufficient.
(2) Precautions: Our NIMC2000N-B series requires a task cycle of at least 2ms, so the timer generally needs to be set to at least 2ms. This document uses 1ms to demonstrate the effect under extreme conditions.
II. Operation Steps
(1) Open the Codesys project, select Tools, Library Storage.

Figure 2.1
(2) Click Find in the pop-up window.

Figure 2.2
(3) Enter "systimecore" at the top of the Find Library pop-up window, select SysTimeCore, 3.5.17.0, and click Open.

Figure 2.3
(4) When the red box shown below appears in the installed libraries, it indicates that the installation is complete.

Figure 2.4
(5) Double-click the Library Manager on the left to open the Library Manager interface.

Figure 2.5
(6) Click Add Library.

Figure 2.6
(7) Select Advanced.

Figure 2.7
(8) In the top text box of the Add Library pop-up window, enter systimecore, select the first library that appears below, and click OK to add the newly installed library to the project.

Figure 2.8
(9) After successful addition, the newly installed library will appear in the following figure.

Figure 2.9
(10) Then return to PLC_PRG and declare a timer TON1, two TIME type variables TimeStart and TimeEnd, and a DINT type variable TimeDelta.

Figure 2.10
(11) Instantiate the timer in the program writing box below.

Figure 2.11
(12) As shown in the figure below, use the SysTimeGetMs() function to get the system start time at the start of the timer, and use the SysTimeGetMs() function to get the system end time at the end of the timer. Calculate the difference between these two times, and you can use the TimeDelta variable to get a more accurate timer working time.

Figure 2.12
(13) As shown in the figure below, although our timer is set to 1ms, due to system hardware limitations, the actual working time of the timer is around 0-5ms. Using this more precise time to correct our sampled data can achieve better results.




















