Calib_Step2_CalculateStoreParameters

Overview

The Calib_Step2_CalculateStoreParameters function block performs the second step of the AI module calibration procedure. This step calculates and stores calibration parameters for the selected channel, based on PLC AI module values at multiple input levels (0%, 25%, 50%, 75%, 100%).

Module_ID                       :=  (USINT)
Channel_Number                  :=  (USINT)
Channel_Mode                    :=  (BOOL)
Measured_0_percent              :=  (UINT)
Measured_25_percent             :=  (UINT)
Measured_50_percent             :=  (UINT)
Measured_75_percent             :=  (UINT)
Measured_100_percent            :=  (UINT)
CMD_Calculate_Store_Parameters  :=  (BOOL)
STS_Done                        =>  (BOOL)
STS_Failed                      =>  (BOOL)
STS_Fault_Code                  =>  (USINT)

Interface

Inputs

NameTypeRange / UnitsDescription
Module_IDUSINT1 - 15Unique identifier of the AI module.
Channel_NumberUSINT0 - 3Target AI channel for calibration.
Channel_ModeBOOL0 / 1Channel mode for which the calculation is done:
1 = 0-10 V 0 = 4-20 mA.
Measured_0_percentUINT0 - 999 mV
3001 - 4999 µA
Measured value at 0% input.
Measured_25_percentUINT1501 - 3499 mV
7001 - 8999 µA
Measured value at 25% input.
Measured_50_percentUINT4001 - 5999 mV
11001 - 12999 µA
Measured value at 50% input.
Measured_75_percentUINT6501 - 8499 mV
15001 - 16999 µA
Measured value at 75% input.
Measured_100_percentUINT9001 - 10999 mV
19001 - 20999 µA
Measured value at 100% input.
CMD_Calculate_Store_ParametersBOOLTRUE / FALSEExecute on a rising edge (input goes from FALSE to TRUE).
⚠️ Valid range

Measured values must be within ±999 of the nominal target for the selected channel mode.
If a Measured_xx_percent value is outside the valid range, the FB will set STS_Failed = TRUE and provide the corresponding STS_Fault_Code.

Outputs

NameTypeDescription
STS_DoneBOOLTRUE if the calculation and storage of calibration parameters is successfully completed.
STS_FailedBOOLTRUE if the operation failed.
STS_Fault_CodeUSINTDiagnostic code indicating the reason for failure.

Fault Codes

CodeMeaningDescription
92Step2 Calculate/Store FailedCalculation or storage of parameters failed.
97Module FaultedThe AI module reported an internal fault.
98Module MismatchThe detected module type does not match the expected AI module.
99Module Not FoundThe specified Module_ID is not part of the current hardware configuration.

Example

PROGRAM PROG_AI_Calib_Step2_CalculateStoreParameters
    VAR
        AI_Calib_Step2 : Calib_Step2_CalculateStoreParameters;
        Trigger_Tag    : BOOL := FALSE; (* Toggling trigger for repeated scans *)
        _Measured_0_percent : UINT;
        _Measured_25_percent : UINT;
        _Measured_50_percent : UINT;
        _Measured_75_percent : UINT;
        _Measured_100_percent : UINT;
    END_VAR

    (* Call FB with the toggling tag as the command *)
    AI_Calib_Step2(
        Module_ID := 4,
        Channel_Number := 0,           (* Channel 0 *)
        Channel_Mode := 0,             (* 4-20mA mode *)
        Measured_0_percent := _Measured_0_percent,
        Measured_25_percent := _Measured_25_percent,
        Measured_50_percent := _Measured_50_percent,
        Measured_75_percent := _Measured_75_percent,
        Measured_100_percent := _Measured_100_percent,
        CMD_Calculate_Store_Parameters := Trigger_Tag
    );
END_PROGRAM

CONFIGURATION Config0
    RESOURCE Res0 ON PLC
        TASK task1_20ms(INTERVAL := T#20ms, PRIORITY := 1);
        PROGRAM Prog_Instance WITH task1_20ms : PROG_AI_Calib_Step2_CalculateStoreParameters;
    END_RESOURCE
END_CONFIGURATION