Example: Creating a Timer

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.

  1. Define a Variable
    Define a variable, called
    Time0. Define it as a DINT:


     

  2. Write a User Program
    The User Program will consist of the following:

 

 

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

Programming Examples Overview


Send comments on this topic.

Copyright © 2024 Delta Computer Systems, Inc. dba Delta Motion