Object ‘Unit conversion’

Symbol

A Unit conversion object is used to define a conversion rule. The following table lists all defined conversion rules. You can edit a conversion rule in the input fields listed below the table.

Table of conversion rules

Name <name> : <name>_Impl is the name of the conversion rule. CODESYS automatically implements the entry as a function block <name>_Impl and instances it as <name>.
Type

Type of conversion rule

  • Single scaling (offset): adds an offset to the input variable. Result := Input + Offset
  • Single scaling (factor): multiplies the input variable by a factor. Result := Input * Factor
  • Linear scaling 1 (factor and offset): converts the input variable with a factor and offset. Result := Input * Factor + Offset
  • Linear scaling 2 (Base and target range): converts the input variable for the output value to be within a target range. CODESYS calculates the functional linear equation internally.
  • User defined conversion: configures a user-defined conversion rule with IEC operators. The input variable is rValue.
  • Switchable conversion: defines a conversion rule that CODESYS executes independent of any specified language or variable.
Setting Displays the configured conversion rule.
Condition
  • TRUE: CODESYS always executes the conversion.

  • Language If the language in the visualization is the language defined here, then CODESYS executes the conversion. The current visualization language is located in the VisuElems.CurrentLanguage variable.

  • Variable: If the comparison is TRUE, then CODESYS executes the conversion rule. CODESYS can pass the comparison for a constant, variable, or IEC expression.

    You can edit the comparison below the table in the Condition setting.

Condition setting

If you select TRUE as the Condition, then the field is hidden.

If you configure Language as the Condition, then the field shows the current configuration, for example en,de.

If you select Variable as the Condition, then the field shows the current configuration, for example PLC_PRG.bActual=PLC_PRG.bSet.

You can edit the current condition setting below the table in the input fields for Condition setting.

Input field ‘Single scaling (offset)’

The input variable is added with an offset.

Offset
  • as a number, including REAL
  • as an IEC variable

Input field ‘Single scaling (factor)’

The input variable is multiplied by the factor.

Factor
  • as a number, including REAL
  • as an IEC variable

Input field ‘Linear scaling 1 (factor and offset)’

The input variable is converted with the linear equation defined below.

Factor
  • as a number, including REAL
  • as an IEC variable
Offset
  • as a number, including REAL
  • as an IEC variable

Input field ‘Linear scaling 2 (Base and target range)’

The input variable is converted to be within a target range. CODESYS internally creates a linear equation from the following input values.

Base start value

Lowest possible value for the input variable.

  • as a number, including REAL
  • as an IEC variable
Base end value

Highest possible value for the input variable.

  • as a number, including REAL
  • as an IEC variable
Target start value

Lowest possible value for the output variable.

  • as a number, including REAL
  • as an IEC variable
Target end value

Highest possible value for the output variable.

  • as a number, including REAL
  • as an IEC variable

Example

Conversion of electric current from a 10-bit input signal to an amperage range of 4-20 mA

Base start value 0
Base end value 1024
Target start value 4.0
Target end value 20.0

Input field ‘User defined conversion’

Convert := Conversion rule as mathematical function of rValue The input variable is rValue.
Reverse := Reverse function of the function defined in Convert

Input field ‘Switchable conversion’

Use this conversion rule when you want to apply a conversion that is language-specific or variable-dependent.

Switchable conversion name Selected from a list of predefined conversion rules. Double-click directly into the field for editing.
Condition setting Configured condition. Click into the input fields in Condition setting to edit the condition.

Example

The Conv_A_LanguageDependent conversion rule that defines which conversion rule is executed for the English or German language.

Name Type Setting Condition Condition setting
Conv_A_LanguageDependent Switchable conversion Conv_AInInch, Conv_AInMM Language  
Switchable conversion name Condition setting
Conv_AInInch en
Conv_AInMM de

See also