Expression Tips and Tricks

Last updated:  February 13, 2002

This document describes some interesting ways to use expression instructions.

Convert a counting number in one variable to an array of relay control variables:
 
Result Expression
mod_data_out control==1
mod_data_out[1] control==2
mod_data_out[2] control==3
mod_data_out[3] control==4

Moving variable values from one variable to another:
 
Result Expression
temperature #mod_analog_in[3]
#mod_data_out[1] relay
Modules can be duplicated and only entries in expressions at the top and bottom of the module need to be modified. At the top, the required global variables are copied to local variables. Then again at the bottom, required local variables are copied to global variables. In this manner the body of the module stays the same thus allowing the associated HMI screen to be used unmodified.

Set a variable to a constant:
 
Result Expression
status 1
status 3 'if' (X>=1)
status X==2

PLC Ladder Logic:
It is very easy to convert ladder logic to ICON expressions: Below are a number of ladder logic examples with the ICON expressions following:
    X1   Y0
|--[ ]----(OUT)
 
Result ICON Expression
Y0 X1

    X1   Y0
|--[ ]----(SET)
 
Result ICON Expression
Y0 1 'if' X1

    X1   Y0
|--[ ]----(RST)
 
Result ICON Expression
Y0 0 'if' X1

    X1   Y0
|--[/]----(OUT)
 
Result ICON Expression
Y0 compl(X1)

    X1   Y0
|--[/]----(SET)
 
Result ICON Expression
Y0 1 'if' compl(X1)

    X1   Y0
|--[/]----(RST)
 
Result ICON Expression
Y0 0 'if' compl(X1)

   X0    X1  Y0
|---[ ]---[/]---(OUT)
 
Result Expression
Y0 X0 & compl(X1)

     X0   X1   Y0
|---[ ]--|-[/]---(SET)
|    X2 |
|---[ ]--|
 
Result Expression
Y0 1 'if' ((X0 : X2) & compl(X1))

A standard PLC timer can be done as follows:
   X0   X1  T0  K5
|--[ ]---[/]---[TMR]
 
Result Expression
T0_Value (X0 & compl(X1)) * (T0_Value+1)
T0_Contact T0_Value>=5

A standard PLC counter can be done as follows:
   X0   CT0   K10
|--[ ]---|Count     |
|  X1   |   CNT    |
|--[ ]---|Reset     |
 
Result Expression
CT0_Value CT0_Value+1 'if' (X0>CT0_Last)
CT0_Value 0 'if' X1
CT0_Contact CT0_Value>=10
CT0_Last X0