Commissioning
END_IF
END_CASE
// ----- Offset scaling (program 1) -----
IF bScaleOffsetStart THEN
CASE nSTATE_SCALE_OFFSET OF
0:
bScaleOffsetDone := FALSE; // Initialization of confirmation flag
// Get min/max values within a period of the signal:
fb_get_min_max(nInputValue:=nScaledSampleVal);
IF fb_get_min_max.bRESULT THEN // Wait if Limit-Values are valid
// Min/Max Values valid, continue..
// calculate current offset deviation:
fOffsetDeviationVal :=
(fb_get_min_max.nMaxVal - ABS((fb_get_min_max.nMaxVal-fb_get_min_max.nMinVal)/2));
// Offset deviation check:
IF ABS(fOffsetDeviationVal) < nOFFSET_MIN_VAL_REF THEN
// Deviation in acceptable range - offset scaling done,
// now write correction value into CoE Object:
nDINT_Value := REAL_TO_DINT(nOffset);
// Initiate writing to CoE:
nSubIndex := nSubIndScalOffs;
nSTATE_WRITE_COE := 10;
nSTATE_SCALE_OFFSET := nSTATE_SCALE_OFFSET + 10;
ELSE
// Calculate new offset value (new by old with deviation)
nOffset := nOffset - fOffsetDeviationVal;
END_IF
END_IF
10:
IF(nSTATE_WRITE_COE = 0) THEN
// Scaling offset done within CoE of the device
bScaleOffsetDone := TRUE;
bScaleOffsetStart := FALSE;
nSTATE_SCALE_OFFSET := 0;
END_IF
END_CASE
END_IF
// ----- Gain scaling (program 2) -----
IF bScaleGainStart THEN
CASE nSTATE_SCALE_GAIN OF
0:
bScaleGainDone := FALSE; // Initialization of confirmation flag
// Get min/max values within a period of the signal:
fb_get_min_max(nInputValue:=DINT_TO_REAL(nPAI_Sample));
IF fb_get_min_max.bRESULT THEN // Wait if Limit-Values are valid
// Calculate Gain
nGain := nPRESET_MAX_VAL/ABS((fb_get_min_max.nMaxVal-fb_get_min_max.nMinVal)/2);
// ..shift gain value by 16 Bit left and convert to DINT:
nDINT_Value := REAL_TO_DINT(65536 * nGain);
88
Version: 1.2
EPP3504-0023