While loop in action block

Hello,

I have created a module that I am trying to use to store recipe parameters in arrays, and then mapping elements of the arrays into the tuning parameters and the min/max value into a different Equipment module.

Below is my code for an action block

I have 2 while loops that are writing to tuning parameters for a PCSD EM TP_VALUE, TP_MIN, and TP_MAX from an array that I have set up. However, what I’m noticing is that it is executing the whole code in 1 scan and only updating the value for the final TP055. The while loop is incrementing the index, but are not writing the TP_TARGET, TP_TARGET_MIN, and TP_TARGET_MAX for every iteration of i, only the final iterarion. Any idea how to make this work?

i := 1;
WHILE i < 10 DO
'^/TP_VALUE_INDEX.CV' := "/TP00" + i + "_VALUE.CV";
'^/TP_MIN_INDEX.CV' := "/TP00" + i + "_MIN.CV";
'^/TP_MAX_INDEX.CV' := "/TP00" + i + "_MAX.CV";

'^/TP_TARGET.$REF' := '^/FERMENTER_INDEX.CV' + '^/TP_VALUE_INDEX.CV';
'^/TP_TARGET_MIN.$REF' := '^/FERMENTER_INDEX.CV' + '^/TP_MIN_INDEX.CV';
'^/TP_TARGET_MAX.$REF' := '^/FERMENTER_INDEX.CV' + '^/TP_MAX_INDEX.CV';

IF '^/TP_TARGET.CST' = 0 AND '^/TP_TARGET.$REF' = '^/FERMENTER_INDEX.CV' + '^/TP_VALUE_INDEX.CV' THEN
'^/TP_TARGET.CV' := '^/DNA_T_PARAM'[i][1];
'^/TP_TARGET_MIN.CV' := '^/DNA_T_LIM'[i][1];
'^/TP_TARGET_MAX.CV' := '^/DNA_T_LIM'[i][2];
i := i + 1;
ENDIF;
END_WHILE;

WHILE i >= 10 AND i <= 55 DO
'^/TP_VALUE_INDEX.CV' := "/TP0" + i + "_VALUE.CV";
'^/TP_MIN_INDEX.CV' := "/TP0" + i + "_MIN.CV";
'^/TP_MAX_INDEX.CV' := "/TP0" + i + "_MAX.CV";

'^/TP_TARGET.$REF' := '^/FERMENTER_INDEX.CV' + '^/TP_VALUE_INDEX.CV';
'^/TP_TARGET_MIN.$REF' := '^/FERMENTER_INDEX.CV' + '^/TP_MIN_INDEX.CV';
'^/TP_TARGET_MAX.$REF' := '^/FERMENTER_INDEX.CV' + '^/TP_MAX_INDEX.CV';
IF '^/TP_TARGET.CST' = 0 AND '^/TP_TARGET.$REF' = '^/FERMENTER_INDEX.CV' + '^/TP_VALUE_INDEX.CV' THEN
'^/TP_TARGET.CV' := '^/DNA_T_PARAM'[i][1];
'^/TP_TARGET_MIN.CV' := '^/DNA_T_LIM'[i][1];
'^/TP_TARGET_MAX.CV' := '^/DNA_T_LIM'[i][2];
i := i + 1;
ENDIF;
END_WHILE;

'IN_D.CV' := 0;

  • Unfortunately, your code as written is not going to work as you have designed. Dynamic references require a scan or two to resolve, so this is why you are only seeing the last one take effect. Loops execute in 1 scan. I think your best options are to unroll the loop and have lots of repeated code and/or consider restructuring the loop to do 1 value per scan. Next scan the dyn ref should be resolved and you can then write the values. This has the downside of taking 120 scans or so of the module to push all the values out.