Inbetriebnahme
// 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 for 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);
//Due to 'output = gain * input + offset', the offset have to be adapted:
nOffset := nOffset * nGain;
// Initiate writing to CoE:
nSubIndex := nSubIndScalGain;
nSTATE_WRITE_COE := 10;
nSTATE_SCALE_GAIN := nSTATE_SCALE_GAIN + 10;
END_IF
10:
IF(nSTATE_WRITE_COE = 0) THEN
IF NOT (nOffset = 0) THEN
// (bScalingOrder is TRUE)
ELM3xxx
Version: 2.11
689