How to reset values cyclically

It is possible to reset some calculated values every 10 seconds by combining a few arithmetic functions

Some calculated values can be reset just like counters to get a new timeframe for the next calculated value. You can either do this manually with the "on Host" function or "on variable result". This How to is for an automated "on variable result" version.

To create an arithmetic virtual variable

  1. Under Configuration tab, click Read to add online controller (or add controller for offline configuration)
  2. Under the controller, right-click Virtual variables > Add > Append Variables
  3. Double-click the newly created variable to open the Variable settings window
  4. In the General section, change the type to Arithmetic
  5. Navigate to the Formula section to add the formula based on requirements below

Including the value you want to reset you will need six variables for this to work:

  1. TimeOLE2: Found under system variables as Time in OLE2 format, this shows the time in the OLE2 time format
  2. ConvertTimeOLE2ToDateTime: Breaks down the TimeOLE2 to seconds. Enter setpoint variables for each component
  3. % Modulo operation on the seconds to get a counter that resets e.g. every 5 seconds
  4. Lower: Function to get a variable switching between 1 and 0. Compares Arg1 and Arg2.
  5. ValueChanged: to get a single pulse when the Lower Variable switches from 0 to 1
    Monitors if there is a change in value
  6. Your actual calculated value.

The first 5 variables are needed to generate a single pulse after a set time. Depending on the conversion from OLE2 to Time you can either do this once every day, hour, half hour, minute, half minute, down to once a second.

The resulting ValueChanged variable will be put into the reset condition.

This can even be varied by using Setpoints instead of fixed parameters for the arithmetic functions.


Author: Marc-Oliver Hess