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
| Name | Type | Range / Units | Description |
|---|---|---|---|
| Module_ID | USINT | 1 - 15 | Unique identifier of the AI module. |
| Channel_Number | USINT | 0 - 3 | Target AI channel for calibration. |
| Channel_Mode | BOOL | 0 / 1 | Channel mode for which the calculation is done:1 = 0-10 V 0 = 4-20 mA. |
| Measured_0_percent | UINT | 0 - 999 mV 3001 - 4999 µA | Measured value at 0% input. |
| Measured_25_percent | UINT | 1501 - 3499 mV 7001 - 8999 µA | Measured value at 25% input. |
| Measured_50_percent | UINT | 4001 - 5999 mV 11001 - 12999 µA | Measured value at 50% input. |
| Measured_75_percent | UINT | 6501 - 8499 mV 15001 - 16999 µA | Measured value at 75% input. |
| Measured_100_percent | UINT | 9001 - 10999 mV 19001 - 20999 µA | Measured value at 100% input. |
| CMD_Calculate_Store_Parameters | BOOL | TRUE / FALSE | Execute 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
| Name | Type | Description |
|---|---|---|
| STS_Done | BOOL | TRUE if the calculation and storage of calibration parameters is successfully completed. |
| STS_Failed | BOOL | TRUE if the operation failed. |
| STS_Fault_Code | USINT | Diagnostic code indicating the reason for failure. |
Fault Codes
| Code | Meaning | Description |
|---|---|---|
| 92 | Step2 Calculate/Store Failed | Calculation or storage of parameters failed. |
| 97 | Module Faulted | The AI module reported an internal fault. |
| 98 | Module Mismatch | The detected module type does not match the expected AI module. |
| 99 | Module Not Found | The 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