This topic provides an example of how to use the _SysMS tag to create timer functionality in the RMC. The _SysMS tags holds the number of milliseconds since the RMC powered up. It is a 32-bit DINT, and will wrap around to -2147483648 after it reaches its maximum value of 2147483647.
If you need a timer to track values less then one millisecond (e.g. the loop time is less then one millisecond), then you may wish to use the _Controller.SysTime_usec tag instead, which has units of microseconds.
Example
Consider an application that toggles a discrete output every 10 seconds. One method of achieving this is as follows. Notice that this is not necessarily the best way to achieve this application. However, the point here is to illustrate how to make a timer. This is intended to be a starting point for the reader to create more complicated timer applications.
Define a Variable
Define a variable, called Time0. Define it as a DINT:
Write a User Program
The User Program will consist of the following:
Toggle the output.
Assign Time0 = _SysMS.
Wait until _SysMS minus Time0 is equal to the time increment before repeating the step. In this case the time increment is 10 seconds, or 10000 milliseconds. One loop time will be lost in jumping to the next step. Assuming the loop time is 1 msec, the comparison will be to 10000 minus 1, which is 9999.
This program will loop forever until the task is stopped.
Handling _SysMS Wrapping
Notice that the _SysMS value in the above example will wrap its 32-bit limit eventually, but the math in the Link Condition will still be correct even through a wrap. However, if the inequality in the link condition is rearranged, it may not handle the wrapping correctly. For example, ”_SysMS >= Timer0 + 9999”, though mathematically identical, will not handle _SysMS wrapping.
See Also
Copyright © 2024 Delta Computer Systems, Inc. dba Delta Motion