Cycle time monitoring triggering "cycle time met" too soon

I have an expression tag that uses the following expression to count elapsed time (named RunTime):


Am using another expression tag called “CycleTimeMet” to compare the value from “RunTime” to a memory tag called “Recipe”, that code is:

try(if({[.]RunTime}.value = {[.]…/Recipe}.value,1,0),0)

Issue I’m seeing is that more often that not, “CycleTimeMet” goes true one second before “Runtime” equals “Recipe”. I’m assuming that this is due to the rounding of milliseconds from the call to “now()”, but am at a loss for how to correct it. Tried adding the “toint(round(floor(” functions above , but none of them seemed to affect it.
Is there a better way to approach this?


Would something like this do the trick (untested)?:

if({[.]…/InCycle} = 1,
   // Round down.
      // Get difference in ms and convert to decimal seconds.
      dateDiff({[.]…/InCycle.LastChange}, now(), 'ms') / 1000.0

I wouldn’t recommend using .LastChange, as that can update with quality changes, not just value changes. I recommend using a memory tag (of type Date) to hold the explicitly set start timestamp of your cycle.

1 Like