Skip to main content

Object: Unit Conversion

Symbol: _visu_icon_trend_recording.png

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

Table

Name

<name> : <name>_Impl is the name of the conversion rule.

The entry is automatically implemented as a <name>_Impl function block and instantiated with <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 internally calculates the functional linear equation.

  • User defined conversion: configures a user-defined conversion rule with IEC operators. The input variable is rValue.

  • Switchable Conversion: Defines a conversion rule which CODESYS executes independently 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. Example: en,de.

If you select Variable as the Condition, then the field shows the current configuration. 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 44. 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 45. 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