Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

How to read a single channel sensor (non-validated)

This section describes how to use a single channel sensor without validation. A pressure sensor is used as an example, but it can be applied to other sensor types.

 

This example uses the following libraries:

SafeConversion library

SafeSensorCalibration library

SafeDataValidation library

SafeSSeriesHardware library

 

, or alternatively non-safe library:

SensorsAndActuators library

 

 

S_ADCToVoltageOrCurrent and S_AIOverCurrentProtection POUs are included in the code template generated by MultiTool.

 

This architecture applies to any mA sensor measurement.

 

 

Single channel architecture for a voltage sensor is otherwise the same except for the over current protection is used only with a mA signal.

 

 

Architecture examples for sensor measurement:

 

SafeSSeriesHardware versions up to 1.3.2.7SafeSSeriesHardware versions up to 1.3.2.7

 

 

SafeSSeriesHardware version 1.4.0.0 or laterSafeSSeriesHardware version 1.4.0.0 or later

 

 

Example code (safety)

When the following example is used with non-safety I/O, the I/O variables are generated in Inputs program instead of S_Inputs.

 

For examples of the code template code, see also Reviewing I/O.

 

In the following example, the AI pin "PressureSensor" in mA mode is defined in MultiTool Creator.

First, the mA value is scaled to pressure value and then the pressure value is monitored.  

 

 

Safety PRG:

 

Init

 

IF NOT initDone THEN

   PressureValueDiagnostic.Init(

      S_i_HighErrorLimit:=380,   // 380 bar

      S_i_LowErrorLimit:=0,

      S_i_EnableHighError:=TRUE,

      S_i_EnableLowError:=FALSE,

      S_i_DiagnosticDelay:=100,  // 100ms

      S_i_SafeOutputValue:= 0,

      i_pEventCode:=ADR(S_Inputs.o_EventCode_PressureSensor)

   );

   

   initDone:=TRUE;

END_IF

 

 

 

 

Example code (non-safety)

In the following example, an AI pin named PressureSensor in voltage mode is defined in MultiTool Creator.

The read AD-value is first converted to voltage in Inputs PRG.

The voltage value is scaled to pressure value and then the pressure value is sent to CAN.  

 

The following example code uses alternative non-safe wrapper POU.

 

Code at non-safe PRG:

 

 

 

See also

 

 

 

Source file topic100382.htm

Last updated 13-Jun-2024