FUNCTION_BLOCK AVG_REAL

Hover on a highlighted element
to pop up its description (if any).

Simple ECC
Basic ECC

An instance of this Simple Function Block type computes an average of N samples. Its operation is defined by the Simple Execution Control Chart ( ECC ) shown above and the algorithms shown below.

For comparison, the ECC of an equivalent Basic FB type is shown above.

ALGORITHM RESET IN ST : (* Reset BUSY, COUNT, SUMX and AVG *)
  BUSY := TRUE;
  COUNT := 0;
  SUM := 0.0;
  AVG := 0.0;
END_ALGORITHM
ALGORITHM UPDATE IN Java : (* Update COUNT, SUM, AVG and BUSY *)
  if(BUSY.value){
    SUM.value += X.value;
    AVG.value = SUM.value/(++COUNT.value);
    BUSY.value = (COUNT.value < N.value);
  }
END_ALGORITHM