Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

S_KTYSensor (FUN)

Description

This function converts resistance value to temperature (°C). POU’s operational range is from -50°C to 150°C.

This function can be used for KTY type temperature sensor such as KTY1000 and KTY2000.

 

The function has internal calibration curve with 9 calibration points which is used in calibration.

Between 2 consecutive calibration points the curve is assumed to be linear.

 

Figure 5-2. Calibration curve points.

 

The calibration curve is calculated from equation 1

 

 

, where R25 = resistance at 25°C, T = temperature, α = 7,88*10-3 and β = 1,937*10-5.

 

The equation is taken from Infineon Technologies KTY sensor specification. The calibration curve is not necessary exactly identical to some other manufacturer's KTY sensors. The input parameters S_i_ResistanceAt25degC and S_i_CalibrationOffset can be used to tune the curve so that it is accurate enough in most cases. S_i_ResistanceAt25degC defines the sensor resistance value at 25°C and S_i_CalibrationOffset shifts the calibration curve linearly up or down.

 

 

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_SensorResistance

SAFEDINT

> 0

KTY sensor resistance. If value < 0 then resistance value 0 is used internally.

S_i_ResistanceAt25degC

SAFEUDINT

> 0

Sensor’s typical resistance value at 25°C. If value is 0 then default value 1000000 (1000 Ω) is used internally.

S_i_CalibrationOffset

SAFEDINT

-

Resistance offset value for fine tuning calibration curve

Return value

Data type

Unit

Range

Description

SAFEDINT

°C

-50 – (+)150

Measured sensor temperature.

Errors

No errors.

Example code

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

 

 

Safe definitions:

 

PROGRAM S_TemperatureKTY

VAR_INPUT

S_i_SafetySystemEnable: SAFEBOOL := FALSE;

i_KTY_A: SAFEDINT := DINT#0;         (*KTY A sensor voltage signal mV*)

i_KTY_A_Pullup: SAFEDINT := DINT#0;  (*KTY sensor reference voltage mV  *)

i_KTY_B: SAFEDINT := DINT#0;         (*KTY B sensor voltage signal mV*)

i_KTY_A_Status: EPEC_SC.Status;      (*KTY A sensor voltage signal status*)

i_KTY_A_Pullup_Status: EPEC_SC.Status; (* Reference voltage status *)

i_KTY_B_Status: EPEC_SC.Status;      (*KTY B sensor voltage signal status*)

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

i_pEventCodeKTY_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_KTYValidation: EPEC_SDV.S_ValidateAI;

S_KTYResistance: EPEC_SC.S_VoltageToResistance;

S_KTYDiagnostics: EPEC_SDV.S_ValueDiagnostic;

END_VAR

VAR CONSTANT

S_AI_TOLERANCE: SAFEDINT := DINT#100;

S_KTY_RES_AT_25C: SAFEUDINT := UDINT#2000000;

S_KTY_NO_OFFSET: SAFEDINT := DINT#0;

END_VAR

 

Init at safe PRG:

 

IF NOT initDone THEN

initDone := TRUE;

 

S_KTYValidation.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_pEventCodeKTY_A,

i_pEventCodeCh2 := i_pEventCodeKTY_B

);

 

S_KTYResistance.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#4500,

S_i_OutputResistanceLow := DINT#1000,

S_i_DiagnosticDelay := UINT#1000,

i_pEventCode := i_pEventCodeKTY_A

);

S_KTYDiagnostics.Init(

S_i_HighErrorLimit := DINT#100,

S_i_LowErrorLimit := DINT#-5,

S_i_EnableHighError := TRUE,

S_i_EnableLowError := TRUE,

S_i_DiagnosticDelay := UINT#1000,

S_i_SafeOutputValue := DINT#0,

i_pEventCode := i_pEventCodeKTY_A

);

 

END_IF

 

 

Code at safe PRG:

 

 

 

See also

 

 

 

Source file topic100408.htm

Last updated 19-Dec-2024