Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

S_LinearSensor (FUN)

Description

This function is used to calibrate linearly the sensor value (mV, µA, mΩ) to other physical unit (, bar, km/h, kg, etc.).

To operate correctly it is required that sensor operates linearly or at least almost linearly.

The input value is calibrated from the input scale to the output scale according the input parameters. Both the negative and the positive slope are supported.

 

Sensor hardware errors are diagnosed with SafeConversion library's function blocks S_ADCToVoltageOrCurrent or S_VoltageToResistance.  

 

Sensor value alarms and warnings are diagnosed with SafeDataValidation library function block S_ValueDiagnostic.

 

Inputs

Input variable name

Data type

Unit

Range

Description

S_i_InputValue

SAFEDINT

mV, µA, mΩ

-

Sensor value.

S_i_InputMin

SAFEDINT

mV, µA, mΩ

-

Sensor minimum value

S_i_InputMax

SAFEDINT

mV, µA, mΩ

-

Sensor maximum value

S_i_OutputMin

SAFEDINT

-

-

Minimum output value, corresponds to S_i_InputMin

S_i_OutputMax

SAFEDINT

-

-

Maximum output value, corresponds to S_i_InputMax

Return value

Data type

Range

Description

SAFEDINT

-2140000000 –
(+) 2140000000

Calibrated value.

Note! Value is not limited between S_i_OutputMin and S_i_OutputMax

Errors

No errors.

Example code

This example contains the validation of 2 linear PT sensors voltage signals, conversion from voltage to temperature and the diagnostic of temperature value .

 

 

 

Safe definitions:

 

PROGRAM S_TemperaturePT

VAR_INPUT

S_i_SafetySystemEnable: SAFEBOOL := FALSE;

i_PT_A: SAFEDINT := DINT#0;         (*PT sensor A voltage signal mV*)

i_PT_A_Pullup: SAFEDINT := DINT#0;  (*Sensor reference voltage mV*)

i_PT_B: SAFEDINT := DINT#0;         (*PT sensor B voltage signal mV*)

i_PT_A_Status: EPEC_SC.Status;

i_PT_A_Pullup_Status: EPEC_SC.Status;

i_PT_B_Status: EPEC_SC.Status;

i_pEventCodePT_A: POINTER TO EPEC_DITF.EventCode := DWORD#0;

i_pEventCodePT_B: POINTER TO EPEC_DITF.EventCode := DWORD#0;

END_VAR

VAR_OUTPUT

o_S_Temperature: SAFEDINT;

o_TemperatureStatus: EPEC_SDV.Status;

END_VAR

VAR

initDone: BOOL;

validationEnable: BOOL;

S_ValidatedVoltage: SAFEDINT;

S_ValidatedResistance: SAFEDINT;

S_Temperature: SAFEDINT;

validation_status: EPEC_SDV.Status;

resistance_status: EPEC_SC.Status;

S_PTValidation: EPEC_SDV.S_ValidateAI;

S_PTResistance: EPEC_SC.S_VoltageToResistance;

S_PTDiagnostics: EPEC_SDV.S_ValueDiagnostic;

END_VAR

VAR CONSTANT

S_AI_TOLERANCE: SAFEDINT := DINT#100;

(*PT1000 res - celsius scaling parameters*)

S_PT_INPUT_MIN: SAFEDINT := DINT#882000;

S_PT_INPUT_MAX: SAFEDINT := DINT#1117000;

S_PT_OUTPUT_MIN: SAFEDINT := DINT#-30;

S_PT_OUTPUT_MAX: SAFEDINT := DINT#30;

 

END_VAR

 

 

Init at safe PRG:

 

IF NOT initDone THEN

initDone := TRUE;

 

S_PTValidation.Init(

S_i_InvertedCh2 := FALSE,

S_i_DiagnosticDelay := EPEC_HW.Constants.G_VOLTAGE_INPUT_DIAGNOSTIC_DELAY,

S_i_SafeOutputValue := EPEC_HW.Constants.G_VOLTAGE_INPUT_SAFE_VALUE,

S_i_Tolerance := S_AI_TOLERANCE,

S_i_SumValue := DINT#0,

i_pEventCode := i_pEventCodePT_A,

i_pEventCodeCh2 := i_pEventCodePT_B

);

 

S_PTResistance.Init(

S_i_InternalPullUpResistance := EPEC_HW.PULL_UP_RESISTANCE.R_2K2,

S_i_InternalPullDownResistance := EPEC_HW.PULL_DOWN_RESISTANCE.R_82K,

S_i_OutputResistanceHigh := DINT#1400,

S_i_OutputResistanceLow := DINT#843,

S_i_DiagnosticDelay := UINT#1000,

i_pEventCode := i_pEventCodePT_A

);

 

S_PTDiagnostics.Init(

S_i_HighErrorLimit := DINT#100,

S_i_LowErrorLimit := DINT#-40,

S_i_EnableHighError := TRUE,

S_i_EnableLowError := TRUE,

S_i_DiagnosticDelay := UINT#1000,

S_i_SafeOutputValue := DINT#0,

i_pEventCode := i_pEventCodePT_A

);

 

END_IF

 

 

Code at safe PRG:

 

 

See also

 

 

Source file topic100407.htm

Last updated 19-Dec-2024