Best Practices Retained Variables


    • Do not use retained variables as outputs of Function Blocks.
      • Doing so may cause problems with retaining the value if the FB is executed with the Enable input off.
      • The output structure can cause it to be conditionally updated to zero or the old value.

A work-around solution is to use a copy (1 gain) function to selectively enable updating the retain variable from an intermediate variable, which is the output of a function block. (Figure 1)

Figure 1: Example: copy (1 gain)