Here are some tips for writing expressions:
Minimize the number of CPU-intensive functions, such as EXPT, LOG2, and **.
Minimize the number of CPU-intensive parameter reads and writes by reducing the number of duplicate reads.
Use the Named Set command instead of the numerical equivalent to improve readability.
The following example shows the original expression and the same expression improved through a reduced number of reads:
Original
IF OUT1 = 1 AND IN2 = 1 AND 'A_UNIT/B_MODE.CV' = 3 THEN 'A_UNIT/STEP.CV' := 7; ENDIF; IF OUT1 = 1 AND IN2 = 0 AND 'A_UNIT/B_MODE.CV' = 2 THEN 'A_UNIT/STEP.CV' := 5; ENDIF;
Improved with Reduced Reads
IF OUT1 = 1 THEN IF IN2 = 1 AND 'A_UNIT/B_MODE.CV' = 3 THEN 'A_UNIT/STEP.CV' := 7; ENDIF; IF IN2 = 0 AND 'A_UNIT/B_MODE.CV' = 2 THEN 'A_UNIT/STEP.CV' :=5; ENDIF; ENDIF;
The following example shows the original expression and the same expression improved through the use of a temporary variable TEMPMODE:
Original
IF 'A_UNIT/B_MODE.CV' = 4 THEN 'A_UNIT/STEP.CV' :=9; ENDIF; IF 'A_UNIT/B_MODE.CV' = 5 THEN 'A_UNIT/STEP.CV' := 11; ENDIF;
Improved with Temporary Variable
TEMPMODE := 'A_UNIT/B_MODE.CV': IF TEMPMODE = 4 THEN 'A_UNIT/STEP.CV' := 9; ENDIF; IF TEMPMODE = 5 THEN 'A_UNIT/STEP.CV' :=11; ENDIF;
The following example shows the original expression and a more readable and informative version of the same expression that uses the Named Set Reference:
Original
IF 'UNIT/B_MODE.CV' = 3 THEN 'A_UNIT/STEP.CV' := 7; ENDIF;
Improved with Named Set Reference
IF 'A_UNIT/B_MODE.CV' = 'Bch_Mode: Auto' THEN 'A_UNIT/STEP.CV' := 'Step_Cmd: Step7'; ENDIF;