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.
- Do not use retained variables as outputs of Function Blocks.
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)
In Figure 2:
- The
ReadActualPositionXis continually reading position feedback from an axis.- The copy block is saving a specific value to a retain variable.
ActualPositionXis the intermediate variable andSavedPositionXis the retain variable.







