FB_CTRL_MOVING_AVERAGE
The function block provides a moving mean value filter in the functional diagram.
The arithmetic mean of the last n values is calculated.
The programmer must create an array, ARRAY [ 1.. n ] of FLOAT, in which the function block can store the data that it requires internally.
VAR_INPUT
VAR_INPUT
fIn : FLOAT;
fManSyncValue : FLOAT;
bSync : BOOL;
eMode : E_CTRL_MODE;
bHold : BOOL;
END_VAR
fIn : Input variable for the moving average filter.
fManSyncValue : Input value to which the moving average filter can be set, or that is issued at the output in manual mode.
bSync : A rising edge at this input sets the moving average filter to the value fManSyncValue.
eMode : Input that specifies the block's operating mode.
bHold : A TRUE at this input will hold the internal state (and therefore also the output) constant at its current value, independently of the input value.
VAR_OUTPUT
VAR_OUTPUT
fOut : FLOAT;
eState : E_CTRL_STATE;
eErrorId : E_CTRL_ERRORCODES;
bError : BOOL;
END_VAR
fOut : Output of the moving average filter.
eState : State of the function block.
eErrorId : Supplies the error number when the bError output is set.
bError : Becomes TRUE, as soon as an error occurs.
VAR_IN_OUT
VAR_IN_OUT
stParams : ST_CTRL_MOVING_AVERAGE_PARAMS;
END_VAR
stParams : Parameter structure of the moving average filter. This consists of the following elements:
TYPE
ST_CTRL_MOVING_AVERAGE_PARAMS:
STRUCT
tCtrlCycleTime : TIME := T#0ms; (* controller
cycle time [TIME] *)
tTaskCycleTime : TIME := T#0ms; (* task cycle
time [TIME] *)
nSamplesToFilter : UINT;
pWorkArray_ADR : POINTER TO FLOAT := 0;
nWorkArray_SIZEOF : UINT := 0;
END_TYPE
tCtrlCycleTime : Cycle time with which the control loop is processed. This must be greater than or equal to the TaskCycleTime. The function block uses this input value to calculate internally whether the state and the output values have to be updated in the current cycle.
tTaskCycleTime : Cycle time with which the function block is called. If the function block is called in every cycle this corresponds to the task cycle time of the calling task.
nSamplesToFilter : The number of values, n, whose arithmetic average value is calculated.
pWorkArray_ADR : The address of the array where the input values are temporarily stored.
nWorkArray_SIZEOF: Size of the WorkArray.