Language Elements h1306 PDF
Language Elements h1306 PDF
Sucosoft S 40
Programming Software
                            Contents                          1
                            About This Manual                 3
                         1 Sucosoft Program Structure         5
                         2 Variable Declaration               7
                           Data types                         7
                           Variables                         15
                           Instancing of function blocks     27
                         3 Instruction Section of a POU      29
                           Instruction set                   29
                           Constants                         59
                           Program                           64
                           Function                          65
                           Function block                    67
                         4 Graphical Programming Languages   73
                           Introduction                      73
                           Programming in LD                 77
                           Programming in FBD                90
                         5 Functions                         109
                         6 Function Blocks                   203
                         7 Language Extension                555
                            Appendix                         561
                            Sucosoft agreements              561
                            Limit values of Sucosoft         563
                            Program examples LD/FBD          564
                            Index                            583
02/00 AWB 2700-1306 GB
                                                               1
                                    List of revisions for AWB 2700-1306 GB
                                    The following modifications have been made since
                                    the 06/99 edition:
2
                         About This Manual
                                                                               3
4
02/00 AWB 2700-1306 GB
                         1   Sucosoft Program Structure
                                                                                 5
    Sucosoft Program
    Structure
6
                                      2   Variable Declaration
                                                                                                7
      Variable Declaration
8
                                                   Data types
                                                                                 9
     Variable Declaration
                            VAR
                              Value1: analog_value;
                            END_VAR
10
                                                       Data types
                             VAR
                               MeasValue1 : analog_VALUE_1;
                               MeasValue2 : Voltage;
                               BoilerTemperature : Temperature;
                             END_VAR
                                                                                 11
     Variable Declaration
                            VAR
                              Main_street1 : Traffic_lights;
                              Side_street1 : Traffic_lights;
                              Side_street2 : Traffic_lights;
                              Car_stop : BOOL;
                            END_VAR
ST Car_stop
12
                                                   Data types
                         VAR
                          Array1 : Array_5_INT;
                          Array2 : Array_24_INT;
                         END_VAR
                          .
                          .
                          LD 5
                          ST Array2 [1,3,4]
02/00 AWB 2700-1306 GB
                          .
                          END_PROGRAM
                                                                             13
     Variable Declaration
                            TYPE
                              Plant_data :
                                  STRUCT
                                       MeasValue1 : BOOL := 1;
                                       MeasValue2 : INT := -15;
                                       MeasValue3 : UINT := 100;
                                   MeasValue4 : REAL := 10.2;
                                  END_STRUCT;
                            END_TYPE
                            VAR
                              Station1 : Plant_data;
                              Station2 : Plant_data;
                            END_VAR
                              LD Station1.MeasValue3
                              .
                              .
                            END_PROGRAM
                                                                                      02/00 AWB 2700-1306 GB
14
                                                                    Variables
                                         VAR
                                           Station1 : Plant_data;
                                           Station2 : Plant_data;
                                         END_VAR
                                                                                               15
     Variable Declaration
                              LD Input_1
                                                                                   02/00 AWB 2700-1306 GB
                              AND %I0.0.0.0.0
                              ST Result
                            END_PROGRAM
16
                                                       Variables
                                                                                 17
     Variable Declaration
VAR
   Marker            AT     %MW0.0.0.4:       ARRAY[1..10] of int;
   CounterFlags      AT     %MB0.0.0.50:      ARRAY[1..5, 1..3] of usint;
   Flags             AT     %MX0.0.0.7.0:     ARRAY[1..16] of bool;
   Status            AT     %ISX1.2.0.0.0:    ARRAY[0..7] of bool;
   Array             AT     %MD0.0.0.400:     ARRAY[1..2] of REAL;
END_VAR
18
                                                     Variables
                                                                                   19
     Variable Declaration
                            VAR
                              Byte_Var AT %I0.0.0.1:BYTE;
                              Word_Var AT %IW0.0.0.0:WORD;
                            END_VAR
                            Variable types
                            The types of all variables are defined in the
                            declaration section of a program organisation unit.
                            All variables that you use in the instruction section of
                            a POU must be declared in the declaration section.
                            The individual variable types are identified with
                            keywords. Variables of the same type are stored in
                            the declaration block. A declaration block starts with
                            a keyword, e. g. VAR or VAR_GLOBAL – depending
                                                                                       02/00 AWB 2700-1306 GB
20
                                                     Variables
Keyword Use
                                                                                          21
     Variable Declaration
22
                                                   Variables
PROGRAM user
                         VAR_GLOBAL
                           word_array : array[0..200] of word;
                         END_VAR
                         VAR
                           my_function_block : demo;
                         END_VAR
FUNCTION_BLOCK demo
                         VAR_IN_OUT
                           w_array : array[0..200] of word;
                         END_VAR
                         VAR
                           Help1 : word ;
                           Help2 : word ;
                         END_VAR
                           ld   w_array[100]
                           st   Help1
                           ld   Help2
                           st   w_array[200]
                         END_FUNCTION_BLOCK
02/00 AWB 2700-1306 GB
                                                                          23
     Variable Declaration
24
                                                   Variables
                         VAR RETAIN
                           Counter : CTU;
                         END_VAR
                         VAR_GLOBAL CONSTANT
                           ZeroKelvin : INT := -273;
                         END_VAR
                                                                               25
     Variable Declaration
Var_Input ✓ ✓
Var_Output ✓
Var_In_Out ✓
Var_Global ✓
Var_External ✓
Var ✓ ✓ ✓
Type ✓ ✓ ✓ ✓
26
                                                                            Instancing of function
                                                                            blocks
                                                                                                      27
28
02/00 AWB 2700-1306 GB
                                           3   Instruction Section of a POU
                                                                                                                  29
     Instruction Section of a
     POU
                                1)
                                      Instruction can be used in conjunction with a “(”
                                      parenthesis if required (deferring the operation).
                                      The instruction then refers to the result of the parenthesis
                                      expression, i. e. operand sequence. The deferred
                                      operation is continued after the “)“.
30
                                                   Instruction set
                         Structure of an instruction
                         Label   Operator   Operand       Comment
                                                                                        31
     Instruction Section of a
     POU
                                      Programming rules
                                      An IL sequence starts with a load instruction (LD or
                                      LDN) and is valid until a new load instruction is used.
                                      This does not apply to unconditional function block
                                      calls and jump / return operations).
                                      IL sequences (overview)
                                      The following syntax chart shows an overview of all
                                      IL sequences for all instruction groups. The use of
                                      the individual instruction groups is explained with
                                      detailed diagrams for each respective group.
End of line
Load instruct.
                      Label definit
                                                                                                 Assignment
                                                                                               Conditional jump
                                                                 Instruct. without parenth.
FB invocation
                                                                      FU invocation
                                                                                              Conditional return
Uncond. FB invocation
Unconditional jump
                                            Unconditional return
                                                                                                                   02/00 AWB 2700-1306 GB
32
                                                                          Instruction set
Comparison operators
FU invocation
Allocation
Set/reset
                                                Label definition
                                                Labels are used as jump targets. They are entered at
                                                the beginning of an instruction and may only be
                                                positioned at the beginning of a sequence.
02/00 AWB 2700-1306 GB
                                                                                                          33
     Instruction Section of a
     POU
34
                                                                    Instruction set
                                                                                                     35
     Instruction Section of a
     POU
                                   Assignments
ST                              Permitted data types: all
Store instruction
                                Description
                                The content of the working register is assigned to the
                                entered operand. The original value of the operand is
                                overwritten. The data type of the entered operand
                                must be the same as the data type of the data
                                element in the working register. The data type of the
                                working register content is defined by the data type
                                of the variables that is assigned a value first. Further
                                assignments can only be carried out with variables of
                                the same data type. It is possible for one assignment
                                to follow another one (see syntax chart on Page 32).
                                Examples
                                Operation        Status working     Comment
                                                 register
36
                                                                      Instruction set
                                                                                                      37
     Instruction Section of a
     POU
38
                                                             Instruction set
                                                                                              39
     Instruction Section of a
     POU
Logic operators
40
                                                     Instruction set
                         Examples
                         Operation        Operand        Comment
                                          status
                                                                                      41
     Instruction Section of a
     POU
42
                                                            Instruction set
                                                                                             43
     Instruction Section of a
     POU
44
                                                                    Instruction set
                                                                                                    45
     Instruction Section of a
     POU
46
                                                                    Instruction set
Arithmetic operators
                                        Example
                                        Operation      Comment
                                                                                                       47
     Instruction Section of a
     POU
                                Example
                                Operation        Comment
48
                                                                        Instruction set
                                        Example
                                        Operation         Comment
                                        Example
                                        Operation         Comment
                                                                                                            49
     Instruction Section of a
     POU
Comparison operators
changed.
50
                                                   Instruction set
                         M1:     .
                                 .
02/00 AWB 2700-1306 GB
                                                                                       51
     Instruction Section of a
     POU
                                         LD 1
                                         ADD Number1
                                         ST Number1    The unconditional jump to label M1 is
                                         JMP M1        carried out after each incrementation.
                                M2:       .
                                          .
                                                                                                  02/00 AWB 2700-1306 GB
JMPC / JMPCN                    Permitted data type: not relevant. The jump target
Conditional jumps               (label) is entered as the operand in the jump.
52
                                                   Instruction set
                         Description
                         Conditional jump in conjunction with the Boolean
                         content of the working register.
                         JMPC: Jump when 1
                         If the working register has the value 1, the jump will
                         be executed and the program will continue from the
                         specified jump target. If the working register has the
                         value 0, the jump will not be executed. The program
                         continues with the next instruction after the jump
                         instruction.
                         JMPCN: Jump when 0
                         If the working register has the value 0, the jump will
                         be executed and the program will continue from the
                         specified jump target. If the working register has the
                         value 1, the jump will not be executed. The program
                         continues with the next instruction after the jump
                         instruction.
                         The jump target must always be a sequence start
                         which is marked with a label. A jump is only possible
                         within a POU.
                         Example
                         Label   Operation     Comment
                                 JMP M1
                         M2:       .
                                   .
                                                                                        53
     Instruction Section of a
     POU
54
                                                                           Instruction set
                                                                                                             55
     Instruction Section of a
     POU
CAL                             Description
Unconditional                   The program is continued in the function block
invocation of function          entered as operand. The unconditional invocation
blocks                          may only be programmed after a sequence is
                                completed and is not permitted inside parenthesized
                                operations.
                                Example
                                Operation                              Comment
                                .
                                .
                                ST Output2                            After the allocation (end of
                                CAL Pulse generator_2_Hz (Set:=start, sequence) the invocation of the
                                               period:=time value) function block
                                                                      pulse_generator_2_Hz is
                                                                      carried out.
                                                                                                        02/00 AWB 2700-1306 GB
56
                                                                               Instruction set
                                                   .
                                                   .
                                                  ST Output2
                                                  LD Result3                  If the Boolean variable Result3 = 1, the
                                                  CALC Pulse generator_2_Hz   invocation of the function block
                                                  (Set:=Start,                Pulse_generator_2_Hz will be carried
                                                  Period:=Time value)         out.
                                                   .
                                                   .
02/00 AWB 2700-1306 GB
                                                                                                                   57
     Instruction Section of a
     POU
Invocation of functions
58
                                                                     Constants
number
                                                                                                59
     Instruction Section of a
     POU
                                                 T#12h34m or            Duration of
                                                 T#12h_34m              12 hours
                                                                        and 34 minutes
60
                                                    Constants
                         .Pre-defined   Meaning
                         Constants
                         Examples
                         Constants      Meaning, length of the
                                        character string
                                                                                  61
     Instruction Section of a
     POU
62
                                                 Constants
                                                                             63
     Instruction Section of a
     POU
VAR
   Counter1 : CTU;                        (* Declaration of the FB CTU as counter1 *)
   ShiftNumber AT %IW0.0.0.2: WORD;       (* Declaration of variables *)
   ShiftPlaces : INT := 2;                (* which are used by
                                          function SHL *)
   ShiftResult : WORD;
   Start AT %I0.0.0.0.0 : BOOL;           (* Declaration of further variables *)
   AT %I0.0.0.0.1 : BOOL;
   Impulse AT %I0.0.0.0.2 : BOOL;
   AT %I0.0.0.0.3 : BOOL;
   Belt AT %Q0.0.0.0.1 : BOOL;
   State : INT;
END_VAR
                                          (* Instruction section *)
   LD %I0.0.0.0.1
   AND Start
   ST Belt
   LD ShiftNumber                         (* FU invocation with parameter setting *)
   SHL ShiftPlaces
   ST ShiftResult
   CAL Counter1(CU := Impulse,            (* FB invocation with parameter setting*)
              ReSet := %I0.0.0.0.3)
  LD Counter1.CV
  ST State
                                                                                        02/00 AWB 2700-1306 GB
64
                                                               Function
                                                                                          65
     Instruction Section of a
     POU
66
                                                                        Function block
                                                                                                  67
     Instruction Section of a
     POU
                                Write         LD 1000
                                output        ST OUT1                 Not permitted
VAR_INPUT VAR_INPUT
68
                                                  Function block
                         VAR_INPUT
                           Reset : BOOL;
                           Value1 : USINT;
                           Value2 : USINT;
                         END_VAR
                         VAR_OUTPUT
                           Mean_value : USINT;
                         END_VAR
                           LD Value1
                           ADD Value2
                           DIV 2
                           ST Mean_value
                         END_FUNCTION_BLOCK
02/00 AWB 2700-1306 GB
                                                                             69
     Instruction Section of a
     POU
                                VAR
                                  Instance1_Name : meanval;
                                  Instance2_Name : meanval;
                                  MeasValue1 AT %IB0.0.0.0 : USINT;
                                  MeasValue2 AT %IB0.0.0.1 : USINT;
                                  Result1 AT %QB0.0.0.0 : USINT;
                                  Result2 AT %QB0.0.0.1 : USINT;
                                  Reset AT % I0.0.0.2.0 : BOOL;
                                END_VAR
END_PROGRAM
70
                                                   Function block
                                                                            71
72
02/00 AWB 2700-1306 GB
                                        4   Graphical Programming Languages
                                                                                                73
     Graphical Programming
     Languages
74
                                                                               Introduction
                                                       Ladder diagram
                         VAR
                            START       AT %I0.0.0.0.0: BOOL;   (*Motor ON (make contact)*)
                            OFF         AT %I0.0.0.0.1: BOOL;   (*Motor OFF (break contact)*)
                            EMER_STOP   AT %I0.0.0.0.2: BOOL;   (*Emergency-stop switch (break
                                                                 contact)*)
                            Motor      AT %Q0.0.0.0.0: BOOL;    (*Motor drive*)
                            Impulse    AT %I0.0.0.0.3: BOOL;    (*Impulse encoder*)
                            FinalValue       : INT:=20;         (*Comparison value for the counter*)
                            Halt             : BOOL;            (*Stop signal if counter=20*)
                            RevolutionsCounter: CTU;            (*Impulse counter*)
                         END_VAR
02/00 AWB 2700-1306 GB
                                                                                                       75
     Graphical Programming
     Languages
76
                                                                       Programming in LD
                                                                                                  77
     Graphical Programming
     Languages
78
                                                      Programming in LD
                         AND sequence
                         An AND sequence is created in LD by connecting
                         contacts in series. In order to fulfil the AND condition,
                         the individual input variables must simultaneously
                         have the states required by the contact type.
                                                                               79
     Graphical Programming
     Languages
                             OR sequence
                             An OR condition is created in LD by connecting
                             contacts in parallel. The OR condition is fulfilled if at
                             least one input variable has the status required for
                             contacting.
                             Mixed sequences
                             Mixed sequences are combinations of AND and OR
                             sequences. The sequence is fulfilled if the current
                             path between the left current rail and the output
                             symbol is closed via at least one path.
                                                                                         02/00 AWB 2700-1306 GB
80
                                                    Programming in LD
                                                                               81
     Graphical Programming
     Languages
                             Negated assignment
                             An output variable can also be assigned a negated
                             current result. This status is indicated by an oblique
                             stroke in the middle of the output symbol.
82
                                                    Programming in LD
                         Retentive assignment
                         The current result can be assigned to the output
                         variable retentively. The output will then retain its set
                         or reset status.
                              Set
                         If the current result is 1, the output variable is set,
                         i. e. is set to 1. The 0 status of the current result has
                         no effect on the value of the output variable. Setting
                         is represented by an output symbol with an S in the
                         middle.
                                                                               83
     Graphical Programming
     Languages
                             Jumps
                             The use of jump commands is a way of structuring
                             programs. They enable networks to be skipped
                             which are only processed occasionally. Jumps can
                             be executed depending on or irrespective of a
                             particular binary current result. The jump destination
                             is always the start of the network, i. e. the beginning
                             of a program sequence. A jump label must be
                             specified in addition to the jump symbol. The same
                             jump label name must be entered in the destination
                             network next to the network number.
84
                                                  Programming in LD
                             Unconditional jump
                         The unconditional jump JMP is executed irrespective
                         of the current result and is only useful in a program
                         section that is processed occasionally. An uncondi-
                         tional jump creates an independent network.
                         Network 0006 of the program shown contains the
02/00 AWB 2700-1306 GB
                                                                           85
     Graphical Programming
     Languages
                                Conditional jump
                             JMPC: The conditional jump JMPC is executed if the
                             current result is 1. The current result 0 causes the
                             program directly behind the jump operation to be
                             processed.
                             JMPCN: The conditional jump JMPCN is executed if
                             the current result is 0. If the current result is 1, the
                             program is processed directly after the jump
                             operation. Network 0003 of the program shown on
                             page 84 executes a jump to network 0007 if the value
                             of the variable Aggregate in network 0003 is 0.
                             Returns
                             Returns enable the program execution in the current
                             POU to be interrupted and returned to the program
                             level from which the POU was invoked. Returns can
                             be executed dependent on or irrespective of the
                             current result.
                                 Unconditional return
                             The unconditional return RET is executed irrespec-
                             tive of the current result. It is only useful in a program
                             section that is only processed occasionally and
                             which is not the last network. An unconditional return
                             starts a separate network.
                                Conditional return
                             RETC: The conditional return RETC is executed if the
                             current result is 1. If the current result is 0, the
                             program will be processed directly after the return
                             operation.
                                                                                          02/00 AWB 2700-1306 GB
86
                                                   Programming in LD
                         Invocation of functions
                         Functions in LD and in FBD are represented by a
                         rectangular graphical symbol. The input variables are
                         shown on the left-hand connection lines and the
                         output variables on the right. The name of the
                         function and the names of the input operands are
                         shown inside the block.
                                                                              87
     Graphical Programming
     Languages
88
                                                   Programming in LD
                                                                             89
     Graphical Programming
     Languages
                             Jump to a label if CR = 0
                                                                                    02/00 AWB 2700-1306 GB
90
                                                 Programming in FBD
                                                                         91
     Graphical Programming
     Languages
                             Logic sequences
                             The logic sequences AND, OR and XOR are shown
                             as graphical symbols with several input operands
                             and one output operand.
                             The value of an input operand can also be negated.
                             In this case the operand value is negated first of all,
                             after which the sequence is formed. These sequenc-
                             es too are shown with the three basic graphical
                             symbols for AND, OR and XOR. The operand to be
                             negated is marked by a negation symbol on the
                             connection line.
                             The result of a logic sequence of binary input
                             variables is a condition for one of the following
                             operations:
                                a store operation
                                a jump to a point in the program which is marked
                                by a jump label
                                a return to the invoking program
                             Logic sequences can refer to variables of the
                             ANY_BIT data type.
                                AND sequence
                             The input operands are ANDed. The current result is
                             assigned to the output operand.
                             The individual bits of the first operand of an AND
                             sequence of byte or word operands are sequenced
                             with the corresponding bits of the second operand.
                                                                                       02/00 AWB 2700-1306 GB
92
                                                  Programming in FBD
                                                                            93
     Graphical Programming
     Languages
operand Input_2.
94
                                                 Programming in FBD
                            Exclusive OR sequence
                         The input operands are XORed. The current result is
                         assigned to the output operand.
                         In an XOR sequence of byte or word operands, the
                         individual bits of the first operand are sequenced
                         with the corresponding bits of the second operand.
                         Mixed sequences
                         Mixed sequences consist of combinations of several
                         different graphical symbols in the same network.
02/00 AWB 2700-1306 GB
                                                                          95
     Graphical Programming
     Languages
96
                                                   Programming in FBD
                         Assignment
                         The current result or a constant can be assigned
                         directly to an output variable or after it has been
                         negated. There are two output symbols for both
                         options:
                         Direct assignment of a current result or a constant to
                         the output variable.
                                                                               97
     Graphical Programming
     Languages
                             Retentive assignment
                             The binary current result can be assigned retentively
                             to the output variable, which can also be set or reset
                             retentively.
                                  Set
                             If the current result is 1, the output variable is set,
                             i. e. is set to 1. The 0 status of the current result has
                             no effect on the value of the output variable. Setting
                             is represented by an output symbol with an S in the
                             middle.
98
                                                     Programming in FBD
                              Reset
                         If the current is 1, the output variable is reset, i. e. is
                         reset to 0. The current result 0 has no effect on the
                         value of the output variable. Resetting is represented
                         by an output symbol with an R in the middle.
                         Arithmetic operations
                         The arithmetic operations addition, subtraction,
                         multiplication and division can be used on numeric
                         data types.
                            Addition
02/00 AWB 2700-1306 GB
                                                                                 99
  Graphical Programming
  Languages
Subtraction
100
                                                  Programming in FBD
                             Compare operations
                         A compare operation involves the comparison
                         between the value of the first operand and the value
                         of the second operand. The completion of the
                         comparison is indicated by the status 1 on the output
                         operand.
                         All elementary data types can be used.
                         The graphical symbols are marked with the
                         appropriate operation name:
                         GT       greater than
                         GE       greater than or equal to
                         EQ       equal
                         NE       not equal to
                         LE       less than or equal to
                         LT       less than
                         Example: Greater than comparison
                                                                           101
  Graphical Programming
  Languages
                          Jumps
                          The use of jump commands is a way of structuring
                          programs. They enable networks to be skipped
                          which are only processed occasionally. Jumps can
                          be executed depending on or irrespective of a
                          particular binary current result. The jump destination
                          is always the start of the network, i. e. the beginning
                          of a program sequence. A jump label must be
                          specified in addition to the jump symbol. The same
                          jump label name must be entered in the destination
                          network next to the network number.
102
                                                  Programming in FBD
                             Unconditional jump
                         The unconditional jump JMP is executed irrespective
                         of the current result and is only useful in a program
                         section that is processed occasionally. An uncondi-
                         tional jump creates an independent network.
                         Network 0006 of the program shown contains the
02/00 AWB 2700-1306 GB
                                                                          103
  Graphical Programming
  Languages
                             Conditional jump
                          JMPC: The conditional jump JMPC is executed if
                          the current result is 1. If the current result is 0, the
                          program will be processed directly after the jump
                          operation.
                          JMPCN: The conditional jump JMPCN is executed if
                          the current result is 0. If the current result is 1, the
                          program is processed directly after the jump
                          operation.
                          Network 0003 of the program shown on page 102
                          executes a jump to network 0007 if the current result
                          in network 0003 is 0.
                          Returns
                          Returns enable the program execution in the current
                          POU to be interrupted and returned to the program
                          level from which the POU was invoked. Returns can
                          be executed dependent on or irrespective of the
                          current result.
                              Unconditional return
                          The unconditional return RET is executed
                          irrespective of the current result. It is only useful in a
                          program section that is only processed occasionally
                          and which is not the last network. An unconditional
                          return starts a separate network.
                                                                                       02/00 AWB 2700-1306 GB
104
                                                    Programming in FBD
                            Conditional return
                         RETC: The conditional return RETC is executed if
                         the current result is 1. If the current result is 0, the
                         program will be processed directly after the return
                         operation.
                         RETCN: The conditional return RETCN is executed if
                         the current result is 0. If the current result is 1, the
                         program will be processed directly after the return
                         operation.
                         Invocation of functions
                         Functions in LD and in FBD are represented by a
                         rectangular graphical symbol. The input variables are
                         shown on the left-hand connection lines and the
                         output variables on the right. The name of the
                         function and the names of the input operands are
                         shown inside the block.
02/00 AWB 2700-1306 GB
                                                                               105
  Graphical Programming
  Languages
106
                                                  Programming in FBD
                                                                          107
  Graphical Programming
  Languages
108
                         5   Functions
                                                                                 109
      Functions
PS 4-200
PS 4-300
                                                                                     PS 416
                                                                                              Stand- See
Function          Meaning                                                                     ard    page
Converter functions
*_TO_**           Type conversion of elementary data types     ✓          ✓          ✓        IEC, M 116
                  Type conversion of time and date             –          ✓          ✓               128
TRUNC             INT part of a REAL number                    –          ✓          ✓        IEC   202
Numeric functions
ABS               Formation of amount                          ✓          ✓          ✓        IEC   136
NEG               Two’s complement                             ✓          ✓          ✓        M     182
Arithmetic functions
ADD               Addition of numeric data types               ✓          ✓          ✓        IEC   137
                  Addition of duration to time and date        ✓          ✓          ✓        IEC   139
                  Addition of addresses                        ✓, #       ✓, #       –        M     141
MUL               Multiplication of numeric data types         ✓          ✓          ✓        IEC   176
                  Multiplication of duration                   –          ✓          ✓        IEC   179
                  Multiplication of addresses                  ✓, #       ✓, #       –        M     179
SUB               Subtraction of numeric data types            ✓          ✓          ✓        IEC   198
                  Subtraction of duration and time and date    ✓          ✓          ✓        IEC   199
                  Subtraction of addresses                     ✓, #       ✓, #       –        M     201
DIV               Division of numeric data types               ✓          ✓          ✓        IEC   150
                  Division of duration                         –          ✓          ✓        IEC   151
                  Division of addresses                        ✓, #       ✓, #       –        M     152
MOD               Remainder Division                           –          ✓          ✓        IEC   175
Edge detection
IsCarry           Test of carry bit                            ✓          ✓          ✓        M     162
IsZero            Test of zero bit                             ✓          ✓          ✓        M     165
IsOverflow        Test of overflow bit                         ✓          ✓          ✓        M     163
IsPositive        Test whether result is positive              ✓          ✓          ✓        M     164
IsBitTrue         Test of a bit in the result                  ✓          ✓          ✓        M     161
GetCarry          Get carry with multiplication or remainder
                                                                                                            02/00 AWB 2700-1306 GB
110
                                                                                               PS 4-200
PS 4-300
                                                                                                                     PS 416
                                                                                                                              Stand- See
                         Function         Meaning                                                                             ard    page
                         ShiftLeft        Shift left with carry
                         Carry                                                                 ✓          ✓          ✓        M     194
                         ShiftRight       Shift right with carry
                         Carry                                                                 ✓          ✓          ✓        M     195
                         ROL              Rotate left                                          ✓          ✓          ✓        IEC   190
                         ROR              Rotate right                                         ✓          ✓          ✓        IEC   191
                         Logic (Boolean) functions
                         AND, &           Logic AND function *)                                ✓          ✓          ✓        IEC   40
                                                              *)
                         OR               Logic OR function                                    ✓          ✓          ✓        IEC   43
                                                                        *)
                         XOR              Logic Exclusive OR function                          ✓          ✓          ✓        IEC   44
                         NOT              Bit complement formation                             ✓          ✓          ✓        IEC   183
                         Comparison functions
                         GT               Comparison function: ’larger than’ *)                ✓          ✓          ✓        IEC   50
                         GE               Comparison function: larger than or equal to *)      ✓          ✓          ✓        IEC   50
                                                                             *)
                         EQ               Comparison function: equal to                        ✓          ✓          ✓        IEC   50
                                                                                          *)
                         LE               Comparison function: smaller than or equal to        ✓          ✓          ✓        IEC   50
                                                                                  *)
                         LT               Comparison function: smaller than                    ✓          ✓          ✓        IEC   50
                         NE               Comparison function: not equal to *)                 ✓          ✓          ✓        IEC   50
                         OS system functions
                         PLC_Message      System diagnostics, reading message word             ✓          ✓          ✓        M     184
                         PLC_ReadClock Reading single element from real-time clock             ✓          ✓          ✓        M     186
                         Interrupt functions
                         Disable_Interrupt Disable alarm                                       ✓          ✓          ✓        M     147
                         Enable_Interrupt Enable alarm                                         ✓          ✓          ✓        M     153
                         Character string functions
                         LEN              Determine length of a character string               ✓          ✓          ✓        IEC   167
02/00 AWB 2700-1306 GB
                                                                                                                                      111
   Functions
PS 4-200
PS 4-300
                                                                                       PS 416
                                                                                                Stand- See
Function        Meaning                                                                         ard    page
DELETE          Delete n characters from a string                –          ✓          ✓        IEC   145
FIND            Find a string within a string                    –          ✓          ✓        IEC   156
INSERT          Insert a string in a string                      –          ✓          ✓        IEC   159
LEFT            Select n characters left of a string             –          ✓          ✓        IEC   166
MID             Sections of a string                             –          ✓          ✓        IEC   172
REPLACE         Replace characters in a string                   –          ✓          ✓        IEC   187
RIGHT           Select n characters right of string              –          ✓          ✓        IEC   189
Selection functions
LIMIT           Limitation                                       –          ✓          ✓        IEC   168
MAX             Maximum selection                                –          ✓          ✓        IEC   170
MIN             Minimum selection                                –          ✓          ✓        IEC   174
MUX             Multiplexer                                      –          ✓          ✓        IEC   180
SEL             Conditional operand selection                    –          ✓          ✓        IEC   192
112
                             operands appear on the left side. The data types of
                             the operands are shown outside the graphical
                             symbol.
                             Example: prototype representation
                             Comparison between instruction list and graphical
                             representations of a prototype function using the
                             SHR function as an example.
                             FUNCTION SHR : ANY_BIT
                             VAR_INPUT
                               IN : ANY_BIT;
                               N : ANY_INT;
                             END_VAR
                             END_FUNCTION
                                                                                113
  Functions
114
                                                                        Sucosoft provides several type-converting functions
                                                                        for type conversion between the elementary data
                                                                        types. The type conversion functions can be used for
                                                                        the following combinations of data types:
Output
                                                                                                                                            TIME_OF_DAY
                                                                                                                                  DWORD1)
                                                                                                                                                                 STRING1)
                                                                                          UDINT1)
                                                                                                    REAL1)
                                                                  DINT1)
                                                                                                                           WORD
                                                                           USINT
BOOL
                                                                                                                                                          DATE
                                                                                                                    BYTE
                                                                                   UINT
                                                     SINT
                                                                                                                                                                            BCD
                                                            INT
Input
SINT x x x x x x x x x x x
INT x x x x x x x x x x x
DINT1) x x x x x x x x x x x
USINT x x x x x x x x x x x
UINT x x x x x x x x x x x x
UDINT1) x x x x x x x x x x x
REAL1) x x x x x x
BOOL x x x x x x x x x
BYTE x x x x x x x x x
WORD x x x x x x x x x
DWORD1) x x x x x x x x x
DATE_AND_TIME x x
TIME x x
                              BCD                    x      x       x       x      x        x
                                       1)
                              STRING                                               x
                              ADDRESS2)                                            x
02/00 AWB 2700-1306 GB
                                                                                                                                                                            115
  Functions
Function prototype
              Description
              In a real case the character * would be replaced by
              the function name. The following type conversions
              are possible:
              Function name        Comment
116
                         Function name      Comment
                         SINT_TO_BOOL       The result has the value 0 with the value 0 of the
                         UINT_TO_BOOL       input operand, otherwise the result is 1.
                         UDINT_TO_BOOL1)
                         USINT_TO_BOOL
                         INT_TO_BOOL
                         DINT_TO_BOOL1)
                         1)   PS 416, PS 4-300 only
                                                                  High    Low
                         Conversion from   10100101     to     00000000 10100101
                                             USINT                   WORD
02/00 AWB 2700-1306 GB
                                                                                         117
  Functions
                                                   High    Low
              Conversion from   00100101   to   00000000 00100101
                                  SINT                 WORD
                                                   High    Low
              Conversion from   10100101   to   11111111 10100101
                                  SINT                WORD
              VAR
                Number1 : SINT := -1;
                Byte1 : BYTE;
              END_VAR
                LD Number1
                SINT_TO_BYTE
                ST Byte1 (* Byte1: 11111111 *)
              END_PROGRAM
                                                                           02/00 AWB 2700-1306 GB
118
                            Type conversion of ANY_INT to ANY_INT
Function prototype
                         Description
                         In a real case the character * would be replaced by
                         the function name. The following type conversions
                         are possible:
                         Function name      Comment
                                                                                          119
  Functions
120
                            Type conversion of ANY_BIT to ANY_INT
Function prototype
                         Description
                         In a real case the character * would be replaced by
                         the function name. The following type conversions
                         are possible:
                         Function name      Comment
                                                                                         121
  Functions
                                                       High     Low
              Conversion from   10100101     to     00000000 10100101
                                  BYTE                     UINT
                                                       High     Low
              Conversion from   10100101     to     00000000 10100101
                                  BYTE                      INT
                                                                                      02/00 AWB 2700-1306 GB
122
                         Example: invocation of the function
                         BYTE_TO_SINT
                         PROGRAM conv2
                         VAR
                           Byte1 : BYTE := 2#0111;
                           Number1 : SINT;
                         END_VAR
                           LD Byte1
                           BYTE_TO_SINT
                           ST Number1         (* Number1: 123 *)
                         END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                   123
  Functions
Function prototype
              Description
              In a real case the character * would be replaced by
              the function name. The following type conversions
              are possible:
              Function name        Comment
              BYTE_TO_BOOL    The result has the value 0 with the value 0 of the
              WORD_TO_BOOL    input operand, otherwise the result is 1.
              DWORD_TO_BOOL1)
124
                                       Type conversion ANY_INT to REAL
                         PS 4-300
                         PS 416
Function prototype
                                    Description
                                    In a real case the character * would be replaced by
                                    the function name. The following type conversions
                                    are possible:
                                    SINT_TO_REAL
                                    INT_TO_REAL
                                    DINT_TO_REAL
                                    USINT_TO_REAL
                                    UINT_TO_REAL
                                    UDINT_TO_REAL
02/00 AWB 2700-1306 GB
                                                                                    125
  Functions
Function prototype
                 Description
                  a real case the character * would be replaced by the
                 function name. The following type conversions are
                 possible:
                 REAL_TO_SINT
                 REAL_TO_INT
                 REAL_TO_DINT
                 REAL_TO_USINT
                 REAL_TO_UINT
                 REAL_TO_UDINT
126
                         Example: type conversion REAL_TO_INT
                         Input value :   Output value:
                         –1.4            –1
                         –1.4            –1
                         –1.6            –2
                         –1.6            –2
                         –1.5            –2
                         –2.5            –2
                         –0.5            –0
                         –3.5            –4
                         2049.0          –121
                         2178.0          –126
02/00 AWB 2700-1306 GB
                                                                        127
  Functions
Function prototype
                  Description
                  In a real case the character * would be replaced by
                  the function name. The following type conversions
                  are possible:
                  Function name                   Comment
* Alternative notation
128
                         Example: invocation of the function
                         DATE_AND_TIME_TO_TIME_OF_DAY
                         PROGRAM time
                         VAR
                           Date1 : DATE_AND_TIME := DT#1980-01-12-
                                                    18:15:00.00;
                           only_time : TIME_OF_DAY;
                         END_VAR
                           LD date1
                           DATE_AND_TIME_TO_TIME_OF_DAY
                           ST only_time (*only_time: 18:15:00.00 *)
END_PROGRAM
                         VAR
                           Date1 : DATE_AND_TIME := DT#1980-01-12-
                                                    18:15:00.00;
                           only_date: DATE;
                         END_VAR
                           LD date1
                           DATE_AND_TIME_TO_DATE
                           ST only_date          (*only_date: 1980-01-12 *)
                         END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                              129
  Functions
Function prototype
                 Description
                 The two bytes of the input operand of data type UINT
                 are in each case interpreted as an encoded graphic
                 character and output as a two-character string. This
                 type conversion is not useful unless the value of the
                 input variable actually corresponds to two encoded
                 characters.
                 Example: invocation of the function
                 UNIT_TO_STRING
                 PROGRAM main
                 VAR
                   str1 : STRING(5);
                 END_VAR
                         (* The constant 16#4F4B is shown as
                            the string ’OK’ *)
                   LD 16#4F4B
                   UNIT_TO_STRING
                   ST str1
                   LD   str1
                 END_PROGRAM
                                                                         02/00 AWB 2700-1306 GB
130
                                       Type conversion of STRING to UINT
                         PS 4-300
                         PS 416
Function prototype
                                    Description
                                    The two-character string specified in the input
                                    operand of the data type STRING is converted into
                                    the data type UINT. The left-hand character of the
                                    string is supplied in the high byte and the right-hand
                                    character in the low byte. The bit pattern of the input
                                    and output operands remains unchanged.
                                    If the character string consists of more than two
                                    characters only the two left-hand characters are
                                    evaluated. A single character is supplied in the low
                                    byte.
02/00 AWB 2700-1306 GB
                                                                                       131
  Functions
Function prototype
              Description
              In a real case the character * would be replaced by
              the function name.
              The input value is first converted into a BCD value
              which is then output as bit pattern data type
              (ANY_BIT). The length of the output variable need not
              be the same as the size of the BCD value. The most
              significant bits will be lost if the bit pattern data type
              assigned for the representation of the BCD result is
              too small. The following type conversions are
              possible:
              Function name      Comment
132
                              Type conversion of BCD to ANY_INT
Function prototype
                         Description
                         In a real case the character * would be replaced by
                         the function name.
                         The input value coded in a bit pattern of data type
                         BCD is converted to a binary-coded decimal value.
                         The input variable can be assigned any bit pattern
                         data type, irrespective the length of the output
                         variable.
                         The following type conversions are possible:
                         Function name      Comment
                                                                                      133
  Functions
134
                                    Type conversion of ADDRESS to UINT
                         PS 4-300
                         PS 416
Function prototype
                                    Description
                                    The data type of a variable or a function block
                                    parameter is converted from ADDRESS to UINT.
                                    With this, addresses of block copy functions, for
                                    example, can be saved for further evaluation in
                                    variables of type UINT since variables of type
                                    ADDRESS cannot be declared.
                                    Example: invocation of the function
                                    ADDRESS_TO_UINT
                                    PROGRAM addr_conv
                                    VAR
                                      Start_data_field AT %MB0.0.0.0 : BYTE ;
                                      Address1 : UINT ;
                                      Copy : BlockTransfer ;
                                    END_VAR
                                      LD &Start_data_field
                                      ST Copy.SourceAddress
                                      ADDRESS_TO_UINT
                                      ST Address1
                                    END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                                        135
  Functions
                 ABS
                 Summation
Function prototype
              Description
              The function ABS converts the numeric variable to
              a summation number; the data type remains
              unchanged.
              The smallest SINT value (-128) and the smallest INT
              value (-32768) are not modified by the ABS function
              since the binary values for -128 / +128 and -32768 /
              +32768 are identical. If such values occur in the
              ABS function, an error message will not be
              generated.
136
                                                  ADD
                            ADD
                            Multiple addition of numeric data types
Function prototype
                         Meaning of operands
                         IN1 The first addend must be provided via the
                              working register.
                         IN2    Further addends which are included in the
                                addition.
                                .
                                .
                         INn
                         Description
                         The value in the working register is added to the
                         values of the operands IN2 to INn. All input operands
                         are of the same numeric data type. The result is
                         made available in the working register for further
                         processing. If the result exceeds the range of values
                         permitted for the data type used an overflow will be
                         formed.
                         The data type of the result corresponds to the
                         selected data type of the input operand.
02/00 AWB 2700-1306 GB
                                                                          137
  Functions
              VAR
                A : INT := 7;
                B : INT := 2;
                Sum : INT;
              END_VAR
                LD 3
                ADD A
                ADD B
                ST Sum             (* Sum: 12 *)
              END_PROGRAM
ST Result
138
                                                      ADD
                              ADD
                              Addition of duration to time and date
Function prototype
                         Description
                         The input variable is increased by a time value and
                         the result is loaded into the working
                         register.Example: addition of time values
                              Only for PS 4-200:
                              An ADD operation with the data type TIME only
                              supplies correct results in the positive range.
                              Do not run this operation with negative values.
02/00 AWB 2700-1306 GB
                                                                                  139
  Functions
              VAR
                Time1 : TIME_OF_DAY := TOD#15:25:00.00;
                Time_value : TIME := T#10h6m15s;
                New_time : TIME_OF_DAY;
              END_VAR
                LD Time1
                ADD Time_value
                ST New_time
                   (* New_time: TOD#01:31:15.00 *)
              END_PROGRAM
140
                                                        ADD
                            ADD
                            Addition of addresses
Function prototype
                         Description
                         The input variable is increased and the result is
                         loaded into the working register.
                         Loops or conditions for function blocks can be
                         calculated with ADDRESS parameters, e. g. for
                         SDAT or BlockCopy. The address of a variable is
                         loaded by writing the address operand & in front of
                         the variable name.
                         Example: addition of addresses
                         PROGRAM adr_add
                         VAR
                           Start_data_field AT %MB0.0.0.0 : BYTE ;
                           Shift: UINT := 10 ;
                           Copy : BlockCopy ;
                         END_VAR
02/00 AWB 2700-1306 GB
                           LD &Start_data_field
                           ADD Shift
                           ST Copy.SourceAddress
                         END_PROGRAM
                                                                                   141
  Functions
      PS 4-300      CONCAT
      PS 416        Concatenation of strings
Function prototype
                 Meaning of operands
                 IN1 Single strings to be concatenated into one
                      string.
                        .
                        .
                 INn
                 Description
                 String “IN1” in the working register and string “IN2”
                 to “INn” are concatenated. The resulting string is
                 loaded into the working register. Strings “IN1” to
                 “INn” are written from left to right in ascending order.
                                                                            02/00 AWB 2700-1306 GB
142
                                                     CONCAT
                         VAR
                           Text1 : STRING := ’ab’;
                           Text2 : STRING := ’cd’;
                           Text3 : STRING := ’ef’;
                           Texts_1_2_3 : STRING;
                         END_VAR
                           LD      Text1
                           CONCAT Text2, Text3
                           ST      Texts_1_2_3 (* Texts_1_2_3:
                                               ’abcdef’ *)
                         END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                 143
  Functions
      PS 4-300      CONCAT
      PS 416        Concatenation of time and date
Function prototype
                 Meaning of operands
                 IN1 Date
                 IN2    Time1
                 Description
                 Date “IN1” and time “IN2” are combined to form a
                 data element of type DATE_AND_TIME and the result
                 is loaded into the working register.
                 Example “Deadline from time and date“
                 PROGRAM deadline
                 VAR
                   Date1 : DATE := D#1997-05-10;
                   Time : TIME_OF_DAY := T0D#6:35:00.00;
                   Date_and_Time1 : DATE_AND_TIME;
                 END_VAR
                   LD      Date1
                   CONCAT Time1
                   ST      Date_and_Time1
                                    (* Date_And_Time1:
                                    DT#1997-05-10-6:35 *)
                 END_PROGRAM
                                                                     02/00 AWB 2700-1306 GB
144
                                                              DELETE
                         PS 4-300       DELETE
                         PS 416         Delete n characters from string
Function prototype
                                    Meaning of operands
                                    IN   String containing the series characters to be
                                         deleted, made available via the working
                                         register.
                                    L      Number of characters to be deleted.
                                    P      Position of the character to be deleted from.
                                           1 corresponds to 1st character.
                                    Description
                                    “L” characters from position “P” are to be deleted
                                    from string “IN”. The resulting string is loaded into
                                    the working register.
                                    If L = 0 or P > than the current length of “IN”, IN is
                                    returned unchanged.
02/00 AWB 2700-1306 GB
                                                                                        145
  Functions
              VAR
                Text1 : STRING := ’abABCDcd’;
                Length : UINT := 3;
                Position : UINT := 5;
                Text2 : STRING;
              END_VAR
                LD      Text1
                DELETE Length, Position
                ST      Text2       (* Text2: ’abABd’ *)
              END_PROGRAM
146
                                                   Disable_Interrupt
                            Disable_Interrupt
                            Disable alarm
Function prototype
                         Description
                         An interrupt is disabled to prevent it interrupting the
                         read or write process of a main program. Interrupt
                         sources are the functions blocks: CounterAlarm,
                         EdgeAlarm and TimerAlarm for PS 4-300, PS 4-200;
                         CAlarm, FAlarm and TAlarm for PS 416.
                         The invocation of the function Disable_Interrupt
                         disables the Interrupt source which one of the
                         function blocks mentioned above has previously
                         started. This synchronises the access of the main
                         program and the Interrupt routine to common
                         data. Write accesses are affected (ST, S, R).
                         The instruction is programmed as an independent
                         sequence.
                         An element of the ALARM_CHANNEL enumeration
                         data type is transferred as argument for the function
                         Disable_Interrupt:
                         For PS 4-200
                         TYPE ALARM_CHANNEL
                           (CounterAlarm_Channel,
                           TimerAlarm_Channel,
                           EdgeAlarm_Channel):= CounterAlarm_Channel;
                         END_TYPE
02/00 AWB 2700-1306 GB
                                                                            147
  Functions
              For PS 4-300
              TYPE ALARM_CHANNEL
               (CounterAlarm_Channel, (*0*)
                TimerAlarm_Channel,   (*1*)
                EdgeAlarm_Channel_1, (*2*)
                EdgeAlarm_Channel_2):= CounterAlarm_Channel;
              END_TYPE
              For PS 416
              TYPE ALARM_CHANNEL
                (CounterAlarm_Channel, (*0*)
                 TimerAlarm_Channel,   (*1*)
                 EdgeAlarm_Channel_1, (*2*)
                 EdgeAlarm_Channel_2, (*3*)
                 EdgeAlarm_Channel_3, (*4*)
                 EdgeAlarm_Channel_4, (*5*)
                 EdgeAlarm_Channel_5, (*6*)
                 EdgeAlarm_Channel_6, (*7*)
                 EdgeAlarm_Channel_7, (*8*) (*.._8: 9*)
                 EdgeAlarm_Channel_8):= CounterAlarm_Channel;
              END_TYPE
148
                                                      Disable_Interrupt
                         VAR_GLOBAL
                           Buffer : INT ;
                           Edge_alarm : EdgeAlarm ;
                           I_Routine : AlarmFB ;
                         END_VAR
                         FUNCTION_BLOCK AlarmFB
                         VAR_EXTERNAL
                           Buffer : INT ;
                         END_VAR
                           LD 30000
                           ST Buffer
                         END_FUNCTION_BLOCK
02/00 AWB 2700-1306 GB
                                                                           149
  Functions
                 DIV
                 Division of numeric data types
Function prototype
              Meaning of operands
              IN1 The dividend is provided via the working
                   register.
              IN2    Divisor
              For this function all of the input operands must be of
              the same data type.
              Description
              The value in the working register is divided by the
              value of the operand IN2. The two input operands are
              of the same data type. The result is made available
              in the working register for further processing. If a
              division operation results in a remainder this will be
              added as a carry to the carry register.
              Example: division of numeric data types
              PROGRAM divide
              VAR
                A : INT := 15;
                B : INT := 3;
                Quotient : INT;
              END_VAR
                LD  A
                                                                       02/00 AWB 2700-1306 GB
                DIV B
                ST  Quotient         (* Quotient: 5 *)
END_PROGRAM
150
                                                              DIV
                         PS 4-300      DIV
                         PS 416        Division of duration
Function prototype
                                    Meaning of operands
                                    IN1 Time value of time duration data type
                                    IN2    Value by which the address operand IN1 is
                                           divided.
                                    Example: division of a time value
                                    PROGRAM Divide_time
                                    VAR
                                      Time_old : TIME := T#2h34m;
                                      Number : SINT := 2;
                                      Time_new : TIME;
                                    END_VAR
                                      LD  Time_old
                                      DIV Number
                                      ST  Time_new   (* Time_new :T#1h17m *)
                                    END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                                   151
  Functions
      PS 4-200      DIV
      PS 4-300      Division of addresses
Function prototype
                 Description
                 The input variable is divided by a divisor and the
                 result is loaded into the working register.
                 Loops or conditions for function blocks can be
                 calculated with ADDRESS parameters, e. g. for
                 SaveData or BlockCopy. The address of a variable is
                 loaded by writing the address operand & in front of
                 the variable name.
                 Example: division of addresses
                 PROGRAM addr_div
                 VAR
                   Start_Data_Field AT %MB0.0.0.30 : BYTE ;
                   Offset : UINT := 10 ;
                   Copy : BlockCopy ;
                 END_VAR
                                                                           02/00 AWB 2700-1306 GB
                   LD &Start_Data_Field
                   DIV Offset
                   ST Copy.SourceAddress
                 END_PROGRAM
152
                                                   Enable_Interrupt
                            Enable_Interrupt
                            Enable alarm
Function prototype
                         Description
                         An interrupt which has previously been disabled via
                         the function Disable_Interrupt is enabled via the
                         Enable_Interrupt function. Interrupt sources are the
                         CounterAlarm, EdgeAlarm and TimerAlarm function
                         blocks for PS 4-200 and PS 4-300; CAlarm, EAlarm
                         and TAlarm for PS 416. The instruction is
                         programmed as an independent sequence.
                         An element of enumerated data type
                         ALARM_CHANNEL is transferred as argument for
                         the function Enable_Interrupt.
                         For PS 4-200
                         TYPE ALARM_CHANNEL
                           (CounterAlarm_Channel,
                            TimerAlarm_Channel,
                            EdgeAlarm_Channel):= CounterAlarm_Channel;
                         END_TYPE
                         For PS 4-300
                         TYPE ALARM_CHANNEL
                           (CounterAlarm_Channel, (*0*)
                            TimerAlarm_Channel,   (*1*)
                            EdgeAlarm_Channel_1, (*2*)
                            EdgeAlarm_Channel_2):= CounterAlarm_Channel;
                         END_TYPE
02/00 AWB 2700-1306 GB
                                                                           153
  Functions
              For PS 416
              TYPE ALARM_CHANNEL
                (CounterAlarm_Channel,(*0*)
                 TimerAlarm_Channel, (*1*)
                 EdgeAlarm_Channel_1, (*2*)
                 EdgeAlarm_Channel_2, (*3*)
                 EdgeAlarm_Channel_3, (*4*)
                 EdgeAlarm_Channel_4, (*5*)
                 EdgeAlarm_Channel_5, (*6*)
                 EdgeAlarm_Channel_6, (*7*)
                 EdgeAlarm_Channel_7, (*8*) (*.._8: 9*)
                 EdgeAlarm_Channel_8):= CounterAlarm_Channel;
              END_TYPE
              VAR_GLOBAL
                Buffer : INT ;
                Edge_Alarm : EdgeAlarm ;
                I_Routine : AlarmFB ;
              END_VAR
END_PROGRAM
154
                                                  Enable_Interrupt
FUNCTION_BLOCK AlarmFB
                         VAR_EXTERNAL
                           Buffer : INT ;
                         END_VAR
                           LD 30000
                           ST Buffer
                         END_FUNCTION_BLOCK
02/00 AWB 2700-1306 GB
                                                                     155
  Functions
      PS 4-300      FIND
      PS 416        Find Character Sequence within a String: FIND
Function prototype
                 Meaning of operands
                 IN1 Basic string containing a specific sequence
                      of characters that is to be found. It is made
                      available via the working register.
                 IN2    Sequence of characters for which the basic
                        string “IN1” is searched.
                 Description
                 A specific sequence of characters is searched for in
                 the basic string “IN1”. If the characters searched for
                 are found, the position of the first character is
                 entered in the working register. Otherwise the value
                 “0” is output.
                 If the succession of characters is present several
                 times in the basic string, the first string found is
                 taken. A 0 is returned if one of the parameters is an
                 empty string.
                                                                          02/00 AWB 2700-1306 GB
156
                                                   FIND
                         VAR
                           Basic_Text : STRING := ’On_condition’;
                           Find_Text : STRING := ’On’;
                           Position : INT;
                         END_VAR
                           LD    Basic_Text
                           FIND Find_Text
                           ST    Position        (* Position: 4 *)
                         END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                       157
  Functions
                 GetCarryRegister
                 Carry after multiplication or remainder after
                 division
Function prototype
              Description
              The function GetCarryRegister refers to the result
              of a multiplication or division that has just been
              executed. If a multiplication has produced a carry,
              this is stored in the carry register. If a division has
              produced a remainder, this is also stored in the carry
              register. The function GetCarryRegister therefore
              accesses the carry register and loads its contents
              into the working register.
              No carry or remainder is formed after multiplication
              of USINT, SINT and real data types (PS 416,
              PS 4-300). The compiler supplies the corresponding
              error message.
              Example: get remainder of a division
              PROGRAM remainder
              VAR
                Number : INT := 127;
                Result_integer : INT;
                Result_remainder : INT;
              END_VAR
                LD Number
                DIV 4
                ST Result_integer   (* Result_integer : 31 *)
                                                                        02/00 AWB 2700-1306 GB
                GetCarryRegister
                ST Result_remainder (* Result_remainder : 3*)
                                     .
                                     .
END_PROGRAM
158
                                                              INSERT
                         PS 4-300       INSERT
                         PS 416         Insert String in String
Function prototype
                                    Meaning of operands
                                    IN1 Basic string in which another string (IN2) is to
                                         be inserted. The basic string is provided via
                                         the working register.
                                    IN2    String to be inserted in the basic string.
                                    P      Position of the character in the basic string
                                           from which the string is inserted. 1 means the
                                           1st character.
                                    Description
                                    String “IN2” is inserted into the basic string “IN1”
                                    after the character with the number specified by the
                                    P input operand. The resulting string is loaded into
                                    the working register. If P is greater than the current
                                    length of IN1, IN1 is returned unchanged.
02/00 AWB 2700-1306 GB
                                                                                        159
  Functions
              VAR
                Text1 : STRING := ’abcd’;
                Text2 : STRING := ’ABCD’;
                Position : INT := 2;
                newText : STRING;
              END_VAR
                LD      Text1
                INSERT Text2, Position
                ST      newText  (* newText:
                                   ’abABCDcd’ *)
              END_PROGRAM
160
                                                       IsBitTrue
                             IsBitTrue
                             Test of a single bit in the result
Function prototype
                         Meaning of operands
                         IN   Bit pattern in which a specified bit is tested
                         N         Bit position
                         Input operand        Input operand        Output operand
                         ANY_BIT              USINT                Bool
                         ANY_BIT              UINT                 Bool
                         Description
                         The status of the bit specified by operand N in bit
                         pattern IN is tested. The resulting value is sent to the
                         working register as the result.
                         This function is best used when followed by
                         conditional operations such as JMPC, JMPCN,
                         CALC, CALCN, RETC or RETCN.
                         Example: Testing a single bit in the result
                         PROGRAM bit_test
                         VAR
                           BitPattern : BYTE := 2#11010011;
                           Position :UINT := 4;
                           BitValue : BOOL;
                         END_VAR
02/00 AWB 2700-1306 GB
                           LD BitPattern
                           IsBitTrue Position
                           ST BitValue (* BitValue : 1 *)
                         END_PROGRAM
                                                                                    161
  Functions
                 IsCarry
                 Test of the carry bit
Function prototype
              Description
              The function IsCarry refers to the result of the previ-
              ously executed arithmetic function which checks the
              Boolean value of the carry bit and transfers the result
              to the working register.
              The IsCarry function should only be used with shift
              operations (SHL,SHR etc.) since it is the carry bit
              which is evaluated here. IsCarry should not be used
              for arithmetical operations. To evaluate the
              overshoot of the value range in arithmetical
              operations, you must use the IsOverflow function.
              This function is best used when followed by
              conditional operations such as JMPCN, CALCN, or
              RETCN.
              Example: Testing the carry bit
              PROGRAM carrybit
              VAR
                Edge : R_TRIG;
                Signal : AT %I0.0.0.0.0 : BOOL;
                Impulse : BOOL;
                Byte1 : BYTE := 2#11110000;
              END_VAR
                LD Byte1
                SHL 3
                                                                        02/00 AWB 2700-1306 GB
                BYTE_TO_USINT
                IsCarry            (* Carry register = 1 *)
                CALC Edge (CLK := Signal)
                LD Edge.Q
                ST Impulse
              END_PROGRAM
162
                                                   IsOverflow
                            IsOverflow
                            Test of the overflow bit
Function prototype
                         Description
                         The function refers to the result of the previously
                         executed arithmetic function which transfers the
                         Boolean value of the overflow bit to the working
                         register. The overflow bit has the Boolean value 1 if
                         the result of the previous operation exceeds the
                         entered value range of the data type. If the result is
                         within the value range, the overflow bit is 0.
                         This function is best used when followed by
                         conditional operations such as JMPC, JMPCN,
                         CALC, CALCN, RETC or RETCN.
                         Example: Testing the overflow bit
                         PROGRAM overflow
                         VAR
                           Edge : R_TRIG;
                           Signal : AT %I0.0.0.0.0 : BOOL;
                           Impulse : BOOL;
                           Number1 : SINT := 127;
                         END_VAR
                           LD Number1
                           ADD 12
                           IsOverflow
                           CALC Edge (CLK := Signal)
                           LD Edge.Q
02/00 AWB 2700-1306 GB
                           ST Impulse
                         END_PROGRAM
                                                                            163
  Functions
                 IsPositive
                 Test whether result is positive
Function prototype
              Description
              The function IsPositive refers to the result of the
              previously executed arithmetic function If the result is
              greater than or equal zero, 1 is loaded into the
              working register.
              The IsPostive function is compatible with Sucosoft
              S 30. In the case of unsigned variables (UINT,USINT
              etc.) which are greater than the maximum range / 2,
              IsPositive will deliver a 0 but in all other cases a 1.
              This function is best used when followed by
              conditional operations such as JMPCN, CALCN,
              RETCN.
              Example: Testing whether the result is positive
              PROGRAM res_pos
              VAR
                Edge : R_TRIG;
                Signal : AT %I0.0.0.0.0 : BOOL;
                Impulse : BOOL;
                Number1 : INT := 12;
              END_VAR
                LD Number1
                SUB 10
                IsPositive
                                                                         02/00 AWB 2700-1306 GB
END_PROGRAM
164
                                                   IsZero
                            IsZero
                            Test of the zero bit
Function prototype
                         Description
                         The function IsZero refers to the result of the
                         previously executed arithmetic function which
                         transfers the Boolean value of the zero bit to the
                         working register. The zero bit has the value 0 if the
                         previous operation supplies the value 0. If the result
                         is not equal 0, the zero bit is 1.
                         This function is best used when followed by
                         conditional operations such as JMPC, JMPCN,
                         CALC, CALCN, RETC or RETCN.
                         Example: Testing the zero bit
                         PROGRAM zero_bit
                         VAR
                           Edge : R_TRIG;
                           Signal : AT %I0.0.0.0.0 : BOOL;
                           Impulse : BOOL;
                           Number1 : INT := 12;
                         END_VAR
                           LD Number1
                           SUB 12
                           IsZero
                           CALC Edge (CLK := Signal)
                           LD Edge.Q
                           ST Impulse
02/00 AWB 2700-1306 GB
END_PROGRAM
                                                                           165
  Functions
      PS 4-300       LEFT
      PS 416         Select n Characters Left Of String
Function prototype
                 Meaning of operands
                 IN   String containing the left section of length L to
                      be taken. It is loaded into the working register.
                 L      Number of characters left of the STRING
                        operand IN to be loaded into the working
                        register.
                 Description
                 The function LEFT takes the left section of the
                 string present in the working register and enters this
                 section in the working register. The number of
                 characters to be taken is specified by input
                 operand L.
                 Example “Take the first four characters”
                 PROGRAM le_text
                 VAR
                   String1 : STRING := ’Teststring’;
                   CharNo : INT := 4;
                   n_left_chars : STRING;
                 END_VAR
                    LD    String1
                    LEFT CharNo
                 ST     n_left_chars   (* n_left_characters:
                                                                          02/00 AWB 2700-1306 GB
                                          ’Test’ *)
                 END_PROGRAM
166
                                                      LEN
                            LEN
                            Determination of the character string length
Function prototype
                         Description
                         The function LEN determines the length of the
                         character string in the working register (input
                         operand of data type STRING) and enters the
                         determined value as INT number into the working
                         register.
                         Example: determining the character string length
                         PROGRAM how_long
                         VAR
                           Text : STRING := ’Term’;
                           TextLength : INT;
                         END_VAR
                           LD Text
                           LEN
                           ST TextLength      (* TextLength: 4 *)
                         END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                       167
  Functions
                   LIMIT
                   Value limitation
Function prototype
              Meaning of operands
              MN Lower limit value
              IN      Test value
              MX      Upper limit value
              Description
              The values “MN” and “MX” specify the upper and
              lower limit value. The function compares the test
              value “IN” with “MN” and “MX”. If the “IN” value is
              between the two limit values, it is loaded into the
              working register. If “IN” is less than “MN”, the “MN”
              value is output. The “MX” value is output if “IN” is
              greater than “MX”.
                                                                      02/00 AWB 2700-1306 GB
168
                                                   LIMIT
                         VAR
                           max_val : INT := 124;
                           min_val : INT := 17;
                         Measval AT %IW0.0.0.10:INT; (*IW0.0.0.10 *)
                                               (* with value 135 *)
                           Result : INT;
                         END_VAR
                           LD     min_val
                           LIMIT Measval, max_val
                           ST     Result      (* Result: 124 *)
                         END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                       169
  Functions
      PS 4-300      MAX
      PS 416        Maximum Selection
Function prototype
170
                                                   MAX
                         VAR
                           Value1 : SINT := 155;
                           Value2 : SINT := -24;
                           Value3 : SINT := -3;
                           Value4 : SINT := 5;
                           Maximumval : SINT;
                         END_VAR
                           LD   Value1
                           MAX Value2, Value3, Value4
                           ST   Maximumval (* Maximumval: 155 *)
                         END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                   171
  Functions
      PS 4-300       MID
      PS 416         Section of a String
Function prototype
                 Meaning of operands
                 IN   String from which a sequence of characters is
                      to be removed. It is made available via the
                      working register.
                 L      number of “IN” string characters to be cut.
                 P      Position of the first character in the string to
                        be cut.
                        1 corresponds to the 1st character.
                 Description
                 “L” characters are to be cut from string “IN” starting
                 from position “P”. The cut string is loaded into the
                 working register. If “P” > current length of “IN”, “IN”
                 is returned unchanged.                                    02/00 AWB 2700-1306 GB
172
                                                   MID
                         VAR
                           String : STRING := ’Test_string’;
                           CharNo : INT := 7;
                           Start : INT := 5;
                           Text_Section : STRING;
                         END_VAR
                           LD   String
                           MID CharNo, Start
                           ST   Text_Section
                                          (*Text_section ’Characters’*)
                         END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                          173
  Functions
      PS 4-300      MIN
      PS 416        Minimum Selection
                 Function prototype
                 *) Supported data types: ANY_BIT, ANY_NUM,
                    ANY_DATE, TIME, STRING.
                   All parameters must be the same data type.
                 Meaning of operands
                 IN1 – INn Input operand for which the lowest value
                           is searched.
                 Description
                 The MIN function determines which of the input
                 operands has the lowest value. The specified
                 operand is loaded into the working register.
                 With STRING operands the current length is first
                 compared and the shorter operand is loaded into the
                 working register. If both operands are the same
                 length, the operand is loaded which has a less
                 significant character.
                 Example “Find minimum”
                 PROGRAM minimum
                 VAR
                   Value1 : SINT := 155;
                   Value2 : SINT := -24;
                   Value3 : SINT := -3;
                   Value4 : SINT := 5;
                                                                       02/00 AWB 2700-1306 GB
                   Minimumval : SINT;
                 END_VAR
                   LD    Value1
                   MIN Value2, Value3, Value4
                   ST    Minimumval  (* Minimumval: -24 *)
                 END_PROGRAM
174
                                                                MOD
                         PS 4-300      MOD
                         PS 416        Remainder Division
MOD
Function prototype
                                    Description:
                                    The input variable is divided by a divisor and the
                                    remainder is loaded into the working register. The
                                    MOD function is permissible for all ANY_INT types
                                    and is only supported by the PS 416 and PS 416 and
                                    PS 4-300.
                                    On the PS 4-200 the remainder of a division is
                                    processed using the GetCarryRegister function.
                                    Example “MOD function” in the program
                                    “mod_div”
                                    PROGRAM mod_div
                                    VAR
                                      Dividend : UINT := 256;
                                      Divisor   : UINT := 50;
                                      Remainder : UINT ;
                                    END_VAR
                                      LD  Dividend
                                      MOD Divisor
                                      ST  Remainder
                                    END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                                     175
  Functions
                 MUL
                 Multiplication of numeric data types
Function prototype
              Meaning of operands
              IN1 The first operand is supplied via the working
                   register.
              IN2    Further operands involved in the multiplica-
                     tion.
                     .
                     .
              INn
              With a function invocation all of the input operands
              must be of the same data type.
              Description
              The value in the working register is multiplied by the
              values of the operands “IN2” to “INn”. All input
              operands are of the same numeric data type. The
              result is made available in the working register for
              further processing. If the result exceeds the range of
              values permitted for the data type used an overflow
              will be formed.
                                                                       02/00 AWB 2700-1306 GB
176
                                                    MUL
                         VAR
                           A : SINT := 5;
                           B : SINT := 2;
                           C : SINT := 3;
                           Product_3times : SINT;
                         END_VAR
                           LD A
                           MUL B
                           MUL C
                           ST Product_3times      (* Product_3times: 30 *)
                         END_PROGRAM
ST Result
                                                                             177
  Functions
      PS 4-300      MUL
      PS 416        Multiplication of time
Function prototype
                 Meaning of operands
                 IN1 Time value of time duration data type
                 IN2    Value by which operand “IN1” is to be
                        multiplied.
                 Description
                 The time duration operand “IN1” is multiplied by the
                 value “IN2” and the result is loaded into the working
                 register.
                 Example: multiplication of a time value
                 PROGRAM time_mul
                 VAR
                   Time_old : TIME := T#2h34m;
                   Number : USINT:= 2;
                   Time_new : TIME;
                 END_VAR
                   LD  Time_old
                   MUL Number
                   ST Time_new      (* Time_new: T#5h8m *)
                 END_PROGRAM
                                                                         02/00 AWB 2700-1306 GB
178
                                                                   MUL
                         PS 4-200      MUL
                         PS 4-300      Multiplication of addresses
Function prototype
                                    Description
                                    The input variable is increased by a factor and the
                                    result is loaded into the working register.
                                    Loops or conditions for function blocks can be
                                    calculated with ADDRESS parameters, e. g. for
                                    SDAT or BlockCopy. The address of a variable is
                                    loaded by writing the address operand & in front of
                                    the variable name.
                                    Example: multiplication of addresses
                                    PROGRAM adr_mul
                                    VAR
                                      Start_ Datafield AT %MB0.0.0.2 : BYTE ;
                                      Offset : UINT := 10 ;
                                      Copy : BlockCopy ;
                                    END_VAR
02/00 AWB 2700-1306 GB
                                      LD &Start_ Datafield
                                      MUL Offset
                                      ST Copy.SourceAddress
                                    END_PROGRAM
                                                                                              179
  Functions
      PS 4-300      MUX
      PS 416        Multiplexer
Function prototype
                 Meaning of operands
                 K    Selection operand. Its numeric value depends
                      on the selected input operand IN0 to INn. It is
                      made available via the working register.
                      The permissible range of values for “K” is 0 – 6.
                      If the value is outside of the permissible range,
                      the highest permissible value will be taken.
                 IN0    Up to seven input operands between which
                        the selection is made. The input operand with
                        the number is selected that matches the value
                        “K”.
                        .
                        .
                 IN6
                 Description
                 The MUX function selects an input operand between
                                                                          02/00 AWB 2700-1306 GB
180
                                                      MUX
                         VAR
                           IN_Nr : USINT := 2;
                           Numb0 : INT := 15;
                           Numb1 : INT := -123;
                           Numb2 : INT := 1;
                           SelectedNo : INT;
                           a, b, c, d, e, f, g, h, i, j, K : BYTE;
                           result : BYTE;
                         END_VAR
                           LD IN_Nr
                           MUX Numb0, Numb1, Numb2
                           ST SelectedNo    (* SelectedNo: 1 *)
                         END_PROGRAM
                           LD  K
                           MUX a, b, c, d, e, f, g, h, i, j
                           ST  result
                           LD  K
                           MUX a, b, c, d, e, f, g
                           ST  result
                           JMP go_on
                           LD     K
                           SUB    7
                           MUX    h, i, j
                           ST     result
                         go_on:
                                                                        181
  Functions
                 NEG
                 Two’s complement
Function prototype
              Description
              The two's complement is formed for the numeric
              value of data type ANY_INT. The result is made
              available in the working register for further
              processing. The two's complement of signed
              numbers corresponds to the negation of a numeric
              value. For example, 100 is converted to -100. With
              unsigned values the two's complement formed is a
              different value.
              Example: two's complement
                LD Signed_Number
                NEG
              VAR
                Number : INT := 230;
                Complement_Number : INT;
              END_VAR
                LD Number
                NEG
                ST Complement_Number (* Now contains the
                                      value -230 *)
              END_PROGRAM
                                                                   02/00 AWB 2700-1306 GB
182
                                                   NOT
                            NOT
                            Bitwise complement formation
Function prototype
                         Description
                         If the input operand is of data type BOOL, the bit in
                         the working register is negated. If the input operand
                         is of data type BYTE, WORD or DWORD1) the indivi-
                         dual bits are negated, i. e. the one’s complement is
                         formed.
                         The result is made available in the working register
                         for further processing.
                         The NOT function is set if it is necessary to load or
                         assign a negated value of data type BOOL, BYTE,
                         WORD or DWORD1).
                         Example: function NOT
                           LD BitPattern
                           NOT
                           LD BitString
                           NOT
                           ST Negation_Result (* Negation_Result
                                                 2#11001010 *)
02/00 AWB 2700-1306 GB
END_PROGRAM
                                                                            183
  Functions
                 PLC_Message
                 System diagnostics evaluate message
Function prototype
              Description
              An element of the enumerated data type
              Message_Type is sent to the input of type
              Message_Type via the working register. The return
              value is a BOOL value and indicates the status of the
              bit in the message word selected via the enumerated
              data element.
              The enumeration type Message_Type which should
              be used contains the following elements:
              For PS 4-200
              TYPE
                MESSAGE_TYPE:
                (ISA, (*First cycle after start*)
                 IRE, (*RESET button has been pressed*)
                 IFO, (*Forcing in RUN active *)
                 REC, (*Remaining cycle processed after
                        restart*)
                 ICS, (*PLC cold started *)
                 NKD_1, (*New data to SBI 1*)
                 NKD_2, (*New data to SBI 2*)
                 NKD_3 (*New data to SBI 3*)
                ) := ISA;
              END_TYPE
                                                                      02/00 AWB 2700-1306 GB
184
                                                   PLC_Message
                         For PS 4-300
                         TYPE
                         MESSAGE_TYPE:
                           (ISA, (* =0:First cycle after start *)
                           IRE,   (* =1:RESET button actuated *)
                           IFO,   (* =2:Forcing in RUN active *)
                           REC,   (* =3:Remaining cycle run
                                                after restart
                            ICS,   (* =4:PLC cold started*)
                            NKD_1, (* =5:New data to SBI 1*)
                            NKD_2, (* =6:New data to SBI 2*)
                            NKD_3, (* =7:NeW data to SBI 3*)
                            ICT,   (* =8:ECT in first cycle *)
                            IAH,   (* =9:EAH in first cycle *)
                            IRT,   (* =10:ERT in first cycle *)
                           ) := ISA;
                         END_TYPE
                         PS 416
                         TYPE
                           MESSAGE_TYPE:
                           (ICS, (* =0:Initial Cold Start cycle*)
                            ISA, (* =1:Initial Start Again*)
                            RTW, (* =2:Run Time Warning*)
                            REC, (* =3:Rest Cycle*)
                            DAKE,(* =AK Error; card not addressable or
                                     not fitted*)
                            KOM, (* =5:Communication partner failed*)
                           ) := ISA;
                         END_TYPE
JMPCN No_new_start
                                                                         185
  Functions
                 PLC_ReadClock
                 Read a single element of the real-time clock
Function prototype
              Description
              An element of the enumerated data type
              PLC_CLOCK is sent to the input of type
              CLOCK_ELEMENT via the working register. The
              return value is of type USINT and indicates the value
              of the specified element of the real-time clock.
              The enumerated data type PLC_CLOCK to be used
              contains the following elements:
              TYPE
                PLC_CLOCK:
                (CK_YEAR, (*Year*)
                     CK_MONTH,    (*Month*)
                     CK_DAY,      (*Day*)
                     CK_WEEKDAY, (*Weekday; 0 = Sunday*)
                     CK_HOURS,    (*Hours*)
                     CK_MINUTES, (*Minutes*)
                     CK_SECONDS   (*Seconds*)
                ) := CK_YEAR;
              END_TYPE
              END_VAR
                LD CK_HOURS
                PLC_ReadClock
                ST Hours
              END_PROGRAM
186
                                                                 REPLACE
                         PS 4-300         REPLACE
                         PS 416           Replace Characters in a String
Function prototype
                                    Meaning of operands
                                    IN1               String containing characters to be overwritten. It
                                                      is made available via the working register.
                                    Description
                                    A number of characters in string “IN1” as specified
                                    by the input operand “L” is overwritten from position
                                    P with string “IN2”. The number of deleted and
                                    inserted characters can vary. The resulting string is
                                    loaded into the working register.
                                    L = 0 corresponds to the INSERT function. If P >
                                    current length of IN1, IN1 is returned unchanged.
02/00 AWB 2700-1306 GB
                                                                                                   187
  Functions
              VAR
                Old_Text : STRING := ’abbCDEe’;
                New_Chars : STRING := ’cd’;
                New_Text : STRING;
              END_VAR
                LD          Old_Text
                REPLACE     New_Chars, 4, 3   (*L=4, P=3*)
                ST          New_Text          (* New_Text:
                                                 ’abcde *)
              END_PROGRAM
188
                                                              RIGHT
                         PS 4-300       RIGHT
                         PS 416         Selection of n Characters Right of String
Function prototype
                                    Meaning of operands
                                    IN   String containing right section of length “L” to
                                         be taken. It is made available via the working
                                         register
                                    L      Number of characters from right of STRING
                                           operand “IN” to be loaded in the working
                                           register.
                                    Description
                                    The function “RIGHT” takes the right section of the
                                    string in the working register and transfers it to the
                                    working register. The number of characters to be
                                    taken is specified by input operand “L”.
                                    Example “Take right section of a string”
                                    PROGRAM re_text
                                    VAR
                                      String1 : STRING := ’Teststring’;
                                      CharNo : INT := 5;
                                      n_right_chars : STRING;
                                    END_VAR
                                      LD     String1
                                      RIGHT CharNo
                                      ST     n_right_chars (* n_right_chars:
02/00 AWB 2700-1306 GB
                                                              ’String’ *)
                                    END_PROGRAM
                                                                                       189
  Functions
                    ROL
                    Rotation left
Function prototype
              Meaning of operands
              IN   The number (bit pattern) to be rotated of the
                   data type “BYTE”, “WORD” or “DWORD“1).
              N          Number of places by which the operand “IN”
                         is rotated to the left.
              Description
              The bit pattern entered as the operand “IN” is shifted
              to the left by the number of places specified in the
              operand “N”. The free places are filled with the
              shifted bits. This shifted bit pattern is provided in the
              working register. The result has the same data type
              as the input operand “IN”.
              Example: bit pattern rotation to the left
              PROGRAM rot_le
              VAR
                Bit_pattern : BYTE := 2#01110001;
                Places : INT := 3;
                NewBitPattern: BYTE;
              END_VAR
                   LD    Bit_pattern
                   ROL   Places
                   ST    NewBitPattern   (* NewBitPattern:
                                            2#10001011 *)
                                                                          02/00 AWB 2700-1306 GB
END_PROGRAM
190
                                                    ROR
                               ROR
                               Rotation right
Function prototype
                         Meaning of operands
                         IN   The number (bit pattern) to be rotated. Of data
                              type BYTE, WORD or DWORD1).
                         N        Number of places by which the operand “IN”
                                  is rotated to the right.
                         Description
                         The bit pattern entered as the operand “IN” is shifted
                         to the right by the number of places specified in the
                         operand “N”. The free places are filled with the
                         shifted bits. This shifted bit pattern is provided in the
                         working register. The result has the same data type
                         as the input operand “IN”.
                         Example: bit pattern rotation to the right
                         PROGRAM rot_ri
                         VAR
                           Bit_pattern : BYTE := 2#01110001;
                           Places : INT := 2;
                           NewBitPattern : BYTE;
                         END_VAR
                              LD  Bit_pattern
                              ROR Places
                              ST  NewBitPattern   (* NewBitPattern:
                                                     2#01011100 *)
02/00 AWB 2700-1306 GB
END_PROGRAM
                                                                              191
  Functions
      PS 4-300      SEL
      PS 416        Conditional Operand Selection
Function prototype
192
                                                   SEL
                         VAR
                           Text1 : STRING := ’ABC’;
                           Text2 : STRING := ’abc’;
                           SelectorSwitch AT %I0.0.0.0.3 : BOOL;
                           Selected : STRING;
                         END_VAR
                           LD   SelectorSwitch
                           SEL Text1, Text2
                           ST   Selected   (* The contents of the
                                              variable selected
                                              depends on the status
                                              of I0.0.0.0.3 *)
                         END_PROGRAM
02/00 AWB 2700-1306 GB
                                                                      193
  Functions
                 ShiftLeftCarry
                 Shift left with carry
Function prototype
              Description
              The bit pattern specified as the input operand is
              shifted one bit to the left in the working register.
              The bit position which becomes free is assigned the
              original carry bit and the bit removed becomes the
              new carry bit.
              Data element of type BYTE:
                LD Bit_pattern
                ShiftLeftCarry
                ST NewBitPattern        (* NewBitPattern:
                  .        1100110x, x at the bit position 0 is
                  .        the old value of the carry bit *)
              END_PROGRAM
                                                                     02/00 AWB 2700-1306 GB
194
                                                   ShiftRightCarry
                            ShiftRightCarry
                            Shift right with carry
Function prototype
                         Description
                         The bit pattern specified as the input operand is
                         shifted one bit to the right in the working register.
                         The bit position which becomes free is assigned the
                         original carry bit and the bit removed becomes the
                         new carry bit.
                         Data element of type BYTE:
                                                                           bit
                         VAR
                           Bit_pattern : BYTE := 2#01011100;
                           NewBitPattern : BYTE;
                         END_VAR
                           LD Bit_pattern
                           ShiftRightCarry
                           ST NewBitPattern
                             .
                             .
02/00 AWB 2700-1306 GB
END_PROGRAM
                                                                          195
  Functions
                    SHL
                    Shift left
Function prototype
              Meaning of operands
              IN   The number (bit pattern) to be shifted of the
                   data type BYTE, WORD or DWORD1).
              N          Number of places by which the operand “IN”
                         is shifted to the left.
              Description
              The bit pattern entered as the operand “IN” is shifted
              to the left by the number of places specified in the
              operand “N”. The free places are filled with the
              zeroes. This shifted bit pattern is provided in the
              working register. The result has the same data type
              as the input operand “IN”.
              Example: shift bit pattern left
              PROGRAM shi_le
              VAR
                Bit_pattern : BYTE := 2#00111011;
                Places : INT := 3;
                NewBitPattern : BYTE;
              END_VAR
                   LD    Bit_pattern
                   SHL   Places
                   ST    NewBitPattern   (* NewBitPattern
                                                                       02/00 AWB 2700-1306 GB
                                             2#11011000 *)
              END_PROGRAM
196
                                                     SHR
                               SHR
                               Shift right
Function prototype
                         Meaning of operands
                         IN   The number (bit pattern) to be shifted of the
                              data type “BYTE”, “WORD” or “DWORD”1).
                         N          Number of places by which the operand “IN”
                                    is shifted to the right.
                         Description
                         The bit pattern entered as the operand “IN” is shifted
                         to the right by the number of places specified in the
                         operand “N”. The free places are filled with the zeros.
                         This shifted bit pattern is provided in the working
                         register. The result has the same data type as the
                         input operand “IN”.
                         Example: shift bit pattern right
                         PROGRAM shi_ri
                         VAR
                           Bit_pattern : BYTE := 2#00111011;
                           Places: INT:= 2;
                           NewBitPattern : BYTE;
                         END_VAR
                              LD    Bit_pattern
                              SHR   Places
                              ST    NewBitPattern   (* NewBitPattern:
02/00 AWB 2700-1306 GB
2#00001110 *)
END_PROGRAM
                                                                            197
  Functions
                 SUB
                 Subtraction of numeric data types
Function prototype
              Meaning of operands
              IN1 Minuend from which the operand “IN2”
                   is subtracted. The minuend is supplied
                   via the working register.
              IN2    Subtrahend which is subtracted from “IN1”.
              Description
              Operand “IN2” is subtracted from the value in the
              working register (operand “IN1”). The result is made
              available in the working register for further process-
              ing. When negative numbers are subtracted, an
              overflow will be sent to the overflow register if the
              result exceeds the value range of the data type used.
              With a function invocation all of the input operands
              must be of the same data type.
              Example: subtraction of numeric data types
              PROGRAM aminusb
              VAR
                A : INT:= 123;
                B : INT:= 12;
                Difference : INT;
              END_VAR
                LD A
                                                                       02/00 AWB 2700-1306 GB
                SUB B
                ST Difference        (* Difference: 111 *)
              END_PROGRAM
198
                                                          SUB
                                  SUB
                                  Subtraction of time and date
Function prototype
                             Description
                             The input variable “IN1” is reduced by the value of
                             “IN2” and the result is loaded into the working
                             register.
                                 Only PS 4-200:
                                  SUB operation with the data type TIME supplies
                                  only correct values in the positive value range.
                                  Never carry out operations with negative values.
02/00 AWB 2700-1306 GB
                                                                                        199
  Functions
              VAR
                Time1 : TIME_OF_DAY := TOD#15:25:00.00;
                Time_value : TME := T#3h6m15s;
                New_time : TIME_OF_DAY;
              END_VAR
                LD Time1
                SUB Time_value
                ST New_time
                      (* New_time: TOD#12:18:45 *)
END_PROGRAM
200
                                                                   SUB
                         PS 4-200      SUB
                         PS 4-300      Subtraction of addresses
Function prototype
                                    Description
                                    The input variable is decreased and the result is
                                    loaded into the working register.
                                    Loops or conditions for function blocks can be
                                    calculated with ADDRESS parameters, e. g. for
                                    SDAT or BlockCopy. The address of a variable is
                                    loaded by writing the address operand & in front of
                                    the variable name.
                                    Example: subtraction of addresses
                                    PROGRAM adr_sub
                                    VAR
                                      Start_Data_Field AT %MB0.0.0.20 : BYTE ;
                                      Offset : UINT := 10 ;
                                      Copy : BlockCopy ;
                                    END_VAR
02/00 AWB 2700-1306 GB
                                      LD &Start_Data_Field
                                      SUB Offset
                                      ST Copy.SourceAddress
                                    END_PROGRAM
                                                                                          201
  Functions
                    TRUNC
      PS 4-300
                    Integer part of a floating point number
      PS 416
Function prototype
                 Description
                 The TRUNC function transfers the integer part of a
                 floating-point number (REAL variable) to a signed
                 integer variable.
                 The choice of data type for the result is dependent on
                 the value of the integer part of the input operand.
                 Example “Transfer integer part of number”
                 The program “integ_part” transfers the integer part
                 (up to 16 positions) of the variable “Fl_Pt_Number” to
                 the variable “Int_Value”.
                 PROGRAM integ_part
                 VAR
                   Fl_Pt_Number : REAL := 123.5;
                   Int_Value : INT;
                 END_VAR
                   LD Fl_Pt_Number
                   TRUNC
                   ST Int_Value          (* Int_Value: 123 *)
                 END_PROGRAM
                                                                          02/00 AWB 2700-1306 GB
202
                        6   Function Blocks
                                                                             203
     Function Blocks
                                       SSI
PS 4-200
PS 4-300
                                                                                  PS 416
                                                                                           Stand- See
Function block          Meaning                                                            ard page
Edge detection
F_TRIG                  Edge evaluation, falling edge       ✓          ✓          ✓        IEC   315
R_TRIG                  Edge evaluation, rising edge        ✓          ✓          ✓        IEC   394
Bistable function blocks
RS                      RS-Flip-Flop                        ✓          ✓          ✓        IEC   417
SR                      SR-Flip-Flop                        ✓          ✓          ✓        IEC   490
Date and time
DATconcat               Concatenate the data type DT        ✓          ✓          ✓        M     277
DATsplit                Split the data type DT              ✓          ✓          ✓        M     281
DateConcat              Concatenate the data type DATE      ✓          ✓          ✓        M     277
DateSplit               Split the data type DATE            ✓          ✓          ✓        M     279
204
                                                                                           PS 4-200
PS 4-300
                                                                                                                 PS 416
                                                                                                                          Stand- See
                         Function block          Meaning                                                                  ard page
                         Alarm function blocks
                         CounterAlarm            Counter alarm                             ✓          ✓          ✓        M     256
                         EdgeAlarm               Edge-controlled alarm                     ✓          ✓          ✓        M     310
                         TimerAlarm              Timer alarm                               ✓          ✓          ✓        M     523
                         Counter and comparison function blocks
                         _16BitCounter           16-bit up/down counter                    ✓          ✓          ✓        M     214
                         _32BitCounter           32-bit up/down counter                    –          ✓          ✓        M     220
                         CounterLE               Block for addressing the counter LE       ✓          ✓          –        M     261
                         CTD                     Down counter                              ✓          ✓          ✓        IEC   267
                         CTU                     Up counter                                ✓          ✓          ✓        IEC   268
                         CTUD                    Up/down counter                           ✓          ✓          ✓        IEC   269
                         _16Bit_Compare          16-bit compare                            ✓          ✓          ✓        M     210
                         _32Bit_Compare          32-bit compare                            –          ✓          ✓        M     216
                         SSIEncoder              Absolute encoder                          –          ✓          –        M     504
                         IncEncoder              Incremental encoder                       –          ✓          –        M     327
                         Register function blocks
                         SR_x                    1-bit shift register                      ✓          ✓          ✓        M     492
                         SRB_x                   8-bit shift register                      ✓          ✓          ✓        M     496
                         SRW_x                   16-bit shift register                     ✓          ✓          ✓        M     500
                         LifoBx                  8-bit-LIFO register                       ✓          ✓          ✓        M     331
                         LifoWx                  16-bit-LIFO register                      ✓          ✓          ✓        M     335
                         FifoBx                  8-Bit-FIFO-Register                       ✓          ✓          ✓        M     317
                         FifoWx                  16-Bit-LIFO-Register                      ✓          ✓          ✓        M     321
                         Code converter
                         _16BitBinaryToBCD       16-bit binary/decimal code converter      ✓          ✓          ✓        M     212
                         _32BitBinaryToBCD       32-bit binary/decimal code converter      –          ✓          ✓        M     218
                         BCDTo16BitBinary        16-bit decimal/binary code converter      ✓          ✓          ✓        M     227
                         BCDTo32BitBinary        32-bit decimal/binary code converter208   -          ✓          ✓        M     229
06/99 AWB 2700-1306 GB
                                                                                                                                 205
   Function Blocks
PS 4-200
PS 4-300
                                                                                     PS 416
                                                                                              Stand- See
Function block        Meaning                                                                 ard page
Array operations
BlockCompare *)       Data-block comparison or searching for
                      values                                   ✓, #       ✓, #       –        M    231
BlockTransfer *)      Copy or initialise data blocks
                      Comparison of arrays                     ✓, #       ✓, #       –        M    236
CompareArray          Transfer of arrays                       ✓          ✓          ✓        M    250
TransferArray         Transfer data structures to an array     ✓          ✓          ✓        M    541
Serialize             Transfer array to data structures        ✓          ✓          ✓        M    453
Deserialize                                                    ✓          ✓          ✓        M    298
Character string processing
ADRtoSTR              Copy marker area to string               ✓, #       ✓, #       –        M    222
STRtoADR              Copy string to a marker area             ✓, #       ✓, #       –        M    507
COMtoSTR              Copy received characters to string       ✓          ✓          ✓        M    254
STRtoCOM              Copy string to marker area               ✓          ✓          ✓        M    509
Sequential control function block
SFC_x                 Sequence control function block          ✓          ✓          –        M    462
Communication function blocks
COM                   Serial communication                     –          –          ✓        M    249
SCO *)                Block for serial communication           ✓          ✓          –        M    430
PSCO                  Communication block Profibus             ✓          ✓          –        M    387
DialOrHangup          Establish or clear a connection to a                                         301
                      DTE via modem                            –          ✓          ✓        M    301
SendATCommand         Send AT commands to a modem              –          ✓          ✓        M    446
MOD200                MODBUS communication                     –          –          ✓        M    343
SUCOM_A               Emulation of programming protocol        –          ✓          ✓        M    511
SuconetP              PROFIBUS-FMS communication               –          –          ✓        M    515
SuconetS_BGKS         INTERBUS communication                   –          –          ✓        M    516
DE4netK               Frequency inverter DF 4                  ✓          ✓          ✓        M
MI4K                  Touchpanel MI 4                          ✓, #       ✓, #       –        M    339
MI4netK               Touchpanel MI 4                          ✓          ✓          ✓        M    341
PdpStationDiag        PROFIBUS-DP communication                –          ✓          ✓        M    369
ASi_PARAM             ASI slave parameter function block       ✓          ✓          –        M    224
                                                                                                           06/99 AWB 2700-1306 GB
206
                                                                                                 PS 4-200
PS 4-300
                                                                                                                       PS 416
                                                                                                                                Stand- See
                         Function block         Meaning                                                                         ard page
                         Read/write from/to memory card
                         SetMCFileLength        Create and initialise data file on memory card   –          –          3        M    456
                         ReloadData *)          Load data from memory card                       ✓, #       3          –        M    414
                         SaveData *)            Save data on memory card                         ✓, #       3          –        M    427
                                                                                                            3          3
                         ReadMC                 Read data from memory card                       ✓          3
                                                                                                                                M    404
                         WriteMC                Write data to memory card                        ✓                     3        M    550
                         OS system function blocks
                         PS_Diagnostic          PS diagnostics words                             –          –          ✓        M    377
                         PS_Message             PS message words                                 –          –          ✓        M    381
                         PS_SwitchPosition      PS switch positions                              –          ✓          ✓        M    385
                         PS_GetDateAndTime      Access to the real-time clock                    –          ✓          ✓        M    379
                         PS_ApplicationHalt     Pause the user program                           –          ✓          ✓        M    373
                         PS_ReadOSInfo          Check the operating system version               ✓          ✓          ✓        M    383
                         PS_ClearKOMBit         Acknowledge communication error                  –          –          ✓        M    375
                         CPUDataExchange        Data exchange between CPUs                       –          –          ✓        M    263
                         ColdstartRetention     Definition of a marker area which retains data
                                                even after cold start                          –            –          ✓        M    245
                         Peripheral access
                         ReadDirect             Direct reading from digital inputs               –          –          ✓, # M        401
                         WriteDirect            Direct writing to digital outputs                –          –          ✓, # M        546
                         ReadAnalogDirect       Direct reading from analog inputs                –          –          ✓        M    395
                         WriteAnalogDirect      Direct writing to analog outputs                 –          –          ✓        M    543
                         ReadCounterDirect      Direct reading of counter inputs                 –          –          ✓        M    398
                         Conversion functions
                         DataScale              Scaling of data                                  ✓          ✓          ✓        M    271
                         PTtoCelsius            Linearisation of PT1000 values                   ✓ 1)       –          –        M    390
                         PTtoFahrenheit         Linearisation of PT1000 values                   ✓ 1)       –          –        M    392
                         NItoCelsius            Linearisation of NI1000 values                   ✓ 1)       –          –        M    350
                         NItoFahrenheit         Linearisation of NI1000 values                   ✓ 1)       –          –        M    352
                         IEEE to Real           Number conversion                                –          ✓          ✓        M    326
                         Real to IEEE           Number conversion                                –          ✓          ✓        M    408
06/99 AWB 2700-1306 GB
                         1) PS 4-271 only
                         *) These function blocks operate in a marker area which must be defined under
                            ‹ Generate ➞ Program Parameters› when generating the code.
                                                                                                                                       207
  Function Blocks
208
                         Example: prototype representation
                         Comparison of an instruction list and graphical
                         representations of a prototype function block using
                         the R_TRIG function as an example.
                         FUNCTION_BLOCK R_TRIG
                         VAR_INPUT
                           CLK : BOOL;
                         END_VAR
                         VAR_OUTPUT
                           Q : BOOL;
                         END_VAR
END_FUNCTION_BLOCK
                                                                         209
  Function Blocks
                        _16Bit_Compare
                        16-Bit Comparator
                    Meaning of operands
                    InputValue1      First comparison value
                    Description
                    The _16Bit_Compare function block compares
                    InputValue1 to InputValue2 to see whether the value
                    of the number InputValue1 is greater, equal or less
                    compared with the value of the number InputValue2.
                    The result of the comparison is indicated by the three
                    output operands as follows:
                                                 Less              Equal   Greater
                    InputValue1 = InputValue2    0                 1       0
                                                                                     06/99 AWB 2700-1306 GB
210
                                                   _16Bit_Compare
                         VAR
                           Length_Compare : _16Bit_Compare;
                           Length1 : INT := 10;
                           Length2 : INT := 10;
                           L1_equal_L2 : BOOL;
                         END_VAR
                           CAL Length_Compare(InputValue1:=Length1,
                                              InputValue2:=Length2)
                           LD Length_Compare.Equal
                           ST L1_equal_L2
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                      211
  Function Blocks
                        _16BitBinaryToBCD
                        16-Bit Binary/Decimal Code Converter
                    Meaning of operands
                    BinaryValue    Binary-coded number
                    Description
                    A 16-bit binary number between -32768... +32767
                    at the BinaryValue operand is converted into a
                    BCD value. The four least significant digits of the
                    BCD value (1st – 4th decade) are written to the four
                    nibbles of the 16-bit DecimalLow operand in the
                    range. The most significant digit of the BCD value
                    (5th decade) is written to the least significant
                    nibble of the DecimalHigh operand. The sign of the
                    BCD value is shown in the Boolean Signed operand.
                                                                           06/99 AWB 2700-1306 GB
212
                                                       _16BitBinaryToBCD
                         VAR
                           Converter1 : _16BitBinaryToBCD;
                           BinaryNumber : INT;
                           Sign : BOOL;
                           HighNumber : UINT;
                           LowNumber : UINT;
                         END_VAR
                             .
                             .
                           CAL Converter1 (BinaryValue := BinaryNumber)
                           LD Converter1.Signed
                           ST Sign
                           LD Converter1.DecimalHigh
                           ST HighNumber
                           LD Converter1.DecimalLow
                           ST LowNumber
                           .
                           .
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                               213
  Function Blocks
                          _16BitCounter
                          16-Bit up/down counter
                    Meaning of operands
                    Forward        Up counter pulse, rising edge
                    Description
                    The _16BitCounter function block is used for the up-
                    ward and downward counting of signals. Each rising
                    edge on the Forward input operand increments the
                    counter by one. A rising edge on the Backward input
                    operand decrements the counter by one. The current
                                                                            06/99 AWB 2700-1306 GB
214
                                                   _16BitCounter
                         VAR RETAIN
                           Count_parts : _16BitCounter;
                         END_VAR
                         VAR
                           Light_barrier AT %I0.0.0.0.0 : BOOL;
                           Quantity : UINT;
                           Clear AT %I0.0.0.0.1 : BOOL;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                            215
  Function Blocks
      PS 4-300          _32Bit_Compare
      PS 416            32-bit comparator
                    Meaning of operands
                    InputValue1      First comparison value
                    Description
                    The _32Bit_Compare function block compares
                    InputValue1 to InputValue2 to see whether the value
                    of the number InputValue1 is greater, equal or less
                    compared with the value of the number InputValue2.
                    The result of the comparison is indicated by the three
                    output operands as follows:
                                                 Less              Equal   Greater
InputValue1< InputValue2 1 0 0
                    InputValue1 = InputValue2    0                 1       0
                                                                                     06/99 AWB 2700-1306 GB
216
                                                   _32Bit_Compare
                         VAR
                           Length_Compare : _32Bit_Compare;
                           Length1 : DINT := 10;
                           Length2 : DINT := 10;
                           L1_equal_L2 : BOOL;
                         END_VAR
                           CAL Length_Compare(InputValue1:=Length1,
                                              InputValue2:=Length2)
                           LD Length_Compare.Equal
                           ST L1_equal_L2
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                      217
  Function Blocks
      PS 4-300          _32BitBinaryToBCD
      PS 416            32-bit binary/decimal code converter
                    Meaning of operands
                    BinaryValue        Binary-coded number
                    Description
                    A 32-bit binary number between -2147483648...
                    +2147483647 at the BinaryValue operand is
                    converted to a BCD value. The individual digits of
                    the BCD number are output in the nibbles of the
                    operands OutputDecade1_4, OutputDecade 5_8 and
                    OutputDecade 9_10. The sign of the BCD value is
                    shown in the Boolean Signed operand.
                                                                             06/99 AWB 2700-1306 GB
218
                                                                                      _32BitBinaryToBCD
                                                           VAR
                                                             Converter2 : _32BitBinaryToBCD;
                                                             BinaryNumber : DINT;
                                                             Sign : BOOL;
                                                             Decade1_4 : UINT;
                                                             Decade5_8 : UINT;
                                                             Decade9_10 : UINT;
                                                           END_VAR
                                                              .
                                                              .
                                                             CAL Converter2(BinaryValue := BinaryNumber)
                                                             LD Converter2.Signed
                                                             ST Sign
                                                             LD Converter2.OutputDecade1_4
                                                             ST Decade1_4
                                                             LD Converter2.OutputDecade5_8
                                                             ST Decade5_8
                                                             LD Converter2.OutputDecade9_10
06/99 AWB 2700-1306 GB
                                                             ST Decade9_10
                                                              .
                                                              .
                                                           END_PROGRAM
                                                                                                            219
  Function Blocks
      PS 4-300            _32BitCounter
      PS 416              32-bit up/down counter
                    Meaning of operands
                    Forward       Up counter pulse, rising edge
                    Description
                    The _32BitCounter function block is used for the
                    upward and downward counting of signals. Each
                    rising edge on the Forward input operand increments
                    the counter by one. A rising edge on the Backward
                    input operand decrements the counter by one. The
                                                                            06/99 AWB 2700-1306 GB
220
                                                   _32BitCounter
                         VAR RETAIN
                         Count_parts : _32BitCounter;
                         END_VAR
                         VAR
                           Light_barrier : AT %I0.0.0.0.6 : BOOL;
                           Quantity : UDINT;
                           Clear : AT %I0.0.0.0.7 : BOOL;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                            221
  Function Blocks
                        ADRtoSTR
                        Convert Received Characters to STRING
                    Meaning of operands
                    Enable           Enable the conversion
                    Description
                    The function block is used to convert text data
                    received via an interface and stored in a marker area
                    to a variable of data type ANY_STRING.
                    A static “1” or TRUE at the Enable input starts the
                    conversion. The input parameter “StrLen” defines
                    the number of characters to be converted and thus
                    the length of the resulting string.
                    If the declared length of TextString is insufficient to
                    hold all the converted data, characters are only
                    copied into it until it is full.
                                                                                            06/99 AWB 2700-1306 GB
222
                                                                                ADRtoSTR
                         VAR
                            Marker_to_String : ADRtoSTR;
                            ReceiveText : STRING(4) := ’HALT’;
                            StartAddress AT %MB0.0.0.100 :
                                                    ARRAY[1..20] of BYTE;
                           ReceiveLength : UINT := 4;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                                  223
  Function Blocks
      PS 4-200          ASi_PARAM
      PS 4-300          Change Slave Parameters During Operation
                    Meaning of operands
                    Strobe            Initiate an acyclic job (rising edge)
                    CardAddress       Module number of the LE4-505-BS1 (1 or 2)
                    Command           Command type
                    StationNo         Address of slave (1 – 31) to be assigned
                                      parameters
                    Parameter        Parameters for the slave
                    Active            Function block status
                    RetParam          Send or read parameters
                    Error             Result of job or detected errors
                    Description
                    The ASi-PARAM function block is used for changing
                    slave parameters during operation. Only one function
                    block needs to be active for each ASi LE.
                    A rising edge at the Strobe input causes the input
                    parameters to be transferred. At the same time the
                    Active output is set to 1 and keeps this state until the
                    job is completed. If the Active output is 0, the values
                                                                                  06/99 AWB 2700-1306 GB
224
                                                                                        ASi_PARAM
                         Error code   Meaning when write command incorrectly Meaning when read command
                         (dec.)       executed                               incorrectly executed
                         00           Everything OK
                         02           Invalid station number (cause: number less than 1 or greater than 31)
06/99 AWB 2700-1306 GB
                                                                                                                      225
  Function Blocks
  Error code   Meaning when write command incorrectly Meaning when read command
  (dec.)       executed                               incorrectly executed
  Error code   Meaning when write command incorrectly       Meaning when read command incorrectly
  (dec.)       executed                                     executed
  17           ASi master not present, not configured, incorrect module type or module type or
               CardAddress less than 1 or greater than 2
  35           Invalid command
  38           Command still active (the message only appears if a command has been started on a
               second function block for the same ASi-LE)
  39           “Parameter” is greater than 15               –
                                  LD   ASIPAbau.RetParam
                                  ST   Response
                                  LD   ASIPAbau.Error
                                  ST   Diagnostics
                               END_PROGRAM
226
                                                            BCDTo16BitBinary
                             BCDTo16BitBinary
                             16-bit decimal/binary code converter
                         Meaning of operands
                         Signed             Sign of the BCD number
                         Description
                         A BCD number between -9999 .... +9999 in the
                         4 nibbles of the DecimalValue operand, specified as
                         positive or negative by the Signed operand is
                         converted to a binary number and output via the
                         BinaryValue operand.
                         Signed         Decimal Value       Binary Value   Binary Value
                                                            (decimal)      (hexadecimal)
                         0                0011                  11              B
                         0                9999                9999           270F
                         1               –1 3 1 1            –1311           FAE1
                         1               –9 9 9 9            –9999           D8F1
06/99 AWB 2700-1306 GB
                                                                                       227
  Function Blocks
                    VAR
                      Converter3 : BCDTo16BitBinary;
                      DecimalNumber : UINT := 16#13;
                      Sign : BOOL := 0;
                      BinaryNumber : INT;
                    END_VAR
                       .
                       .
                      CAL Converter3(Signed := Sign,
                                     DecimalValue := DecimalNumber)
                      LD             Converter3.BinaryValue
                      ST             BinaryNumber
                       .
                       .
END_PROGRAM
228
                                                                   BCDTo32BitBinary
                         PS 4-300       BCDTo32BitBinary
                         PS 416         3232-bit decimal/binary code converter
                                    Meaning of operands
                                    Signed         Sign of the BCD number
                                    Description
                                    A BCD number between -99999999.... +99999999 in
                                    the 8 digits of the DecimalValue operand, specified
                                    as positive or negative by the Signed operand is
                                    converted to a binary number and output via the
                                    BinaryValue operand.
06/99 AWB 2700-1306 GB
                                                                                      229
  Function Blocks
                    VAR
                      Converter4 : BCDTo32BitBinary;
                      DecimalNumber : UDINT := 13;
                      Sign : BOOL := 0;
                      BinaryNumber : DINT;
                    END_VAR
                       .
                       .
                      CAL Converter4(Signed := Sign,
                                     DecimalValue := DecimalNumberl)
                      LD Converter4.BinaryValue
                      ST BinaryNumber
                       .
                       .
END_PROGRAM
230
                                                                         BlockCompare
                         PS 4-200               BlockCompare
                         PS 4-300               Data Block Comparison or Value Search
                                        Meaning of operands
                                        Mode                Operating mode (0 = search, 1 = block
                                                            comparison)
                                        Description
                                        The BlockCompare function block has two operating
                                        modes: Value Search or Block Comparison.
06/99 AWB 2700-1306 GB
                                                                                                        231
  Function Blocks
232
                                                   BlockCompare
                         PROGRAM search
                         VAR
                           search_fb: BlockCompare;
                           SourceAddress AT %MB0.0.0.23 : BYTE := 16#7D;
                             (* Marker byte 23 initialised with the
                                search value 7D hex *)
                           DestinationAddress AT %MB0.0.0.27 : BYTE;
                           Start AT %I0.0.0.0.0 : BOOL;
                             (* Start search *)
                           Found : USINT;
                           Result_greater : BOOL;
                           Result_equal   : BOOL;
                           Result_less    : BOOL;
                         END_VAR
                           LD Start
                           CALC search_fb(Mode := 0,(*Data search mode*)
                                          SourceAddress := &SourceAddress,
                                          DestinationAddress :=
06/99 AWB 2700-1306 GB
                                                    &DestinationAddress,
                                          ElementNumber := 6)
                                         (*Search range of 6 bytes*)
                           LD search_fb.Output
                           ST Found
                                                                             233
  Function Blocks
234
                                                                                BlockCompare
                         PROGRAM compare
                         VAR
                            compare_fb : BlockCompare;
                            Source_Address AT %MB0.0.0.23 : BYTE;
                            Destination_Address AT %MB0.0.0.30 : BYTE;
                            Start AT %I0.0.0.0.0 : BOOL;
                              (*Start the comparison*)
                            Discrepancy : USINT;
                            Result_greater : BOOL;
                            Result_equal : BOOL;
                            Result_less : BOOL;
                         END_VAR
                           LD Start
                           CALC compare_fb (Mode := 1,(*Block comparison mode*)
                                             SourceAddress := &SourceAddress,
                                             DestinationAddress := &DestinationAddress,
                                             ElementNumber := 4)
                                             (*Compare range of 4 bytes *)
                           LD compare_fb.Output
                           ST Discrepancy
                           (*Location where the blocks are different:*)
                           (*   „DestinationAddress“ plus „Output“ *)
                           LD compare_fb.Greater
                           ST Result_greater
                           LD compare_fb.Equal
                           ST Result_equal
                           LD compare_fb.Less
                           ST Result_less
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                               235
  Function Blocks
      PS 4-200          BlockTransfer
      PS 4-300          Copy or Initialise Data Blocks
                    Meaning of operands
                    Mode                Operating mode (0 = Initialise, 1 = Copy)
                    Description
                    The BlockTransfer function block allows system
                    support for transferring data blocks. Data is trans-
                    ferred from the source address defined at the
                    SourceAddress input to the destination in the PLC
                    memory defined at the DestinationAddress input.
                    The Mode input defines the operating mode to be
                    used: Copy mode or Initialise mode.
                    The size of the data block is defined in byte at the
                    ElementNumber input.
                    The Error output indicates the following error code:
                    0 Data limits permissible
                                                                                    06/99 AWB 2700-1306 GB
236
                                                       BlockTransfer
                             Copy mode
                             In Copy mode the function block copies a complete
                             data range from a source address to a destination
                             address.
                             Example of Copy Mode
                             The contents of the data block marker bytes 23 to 26
                             are copied to marker area 30 to 33.
                             PROGRAM copy
                             VAR
                               copy_fb : BlockTransfer;
                               SourceAddress AT %MB0.0.0.23 : BYTE;
                               DestinationAddress AT %MB0.0.0.30 : BYTE;
                               Start AT %I0.0.0.0.0 : BOOL;
06/99 AWB 2700-1306 GB
                                 (*Start copying*)
                             END_VAR
                                                                             237
  Function Blocks
                      LD Start
                      CALC copy_fb (Mode := 1, (* Copy Mode ! *)
                                    SourceAddress := &SourceAddress,
                                    DestinationAddress
                                       := &DestinationAddress,
                                    ElementNumber := 4)
                                    (*Constant number of 4 bytes *)
END_PROGRAM
                    Initialise mode
                    In Initialise mode the function block copies a
                    specified value from the source address to a data
                    block starting with the destination address.
                    Example of Initialise Mode
                    The value of the marker byte specified in
                    SourceAddress is transferred into the number of
                    marker bytes specified in ElementNumber. The copy
                    operation starts from DestinationAddress. The
                    marker field %MB0.0.0.27 to %MB0.0.0.32 is
                    initialised with the data value 7D stored in
                    %MB0.0.0.23.
238
                                                                                 BlockTransfer
PROGRAM init
                         VAR
                            init_fb : BlockTransfer;
                            SourceAddress AT %MB0.0.0.23 : BYTE := 16#7D;
                             (* MarkerByte 23 initialised with the data value 7D hex *)
                            DestinationAddress AT %MB0.0.0.27 : BYTE;
                            Start AT %I0.0.0.0.0 : BOOL;
                             (*Start initialising*)
                         END_VAR
                           LD Start
                           CALC init_fb(Mode := 0, (* Initialise Mode *)
                                        SourceAddress := &SourceAddress,
                                        DestinationAddress := &DestinationAddress,
                                        ElementNumber := 6)
                                         (*Constant number of 6 bytes *)
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                                 239
  Function Blocks
      PS 416            CAlarm
                        Counter Alarm Function Block
                    Meaning of operands
                    Handle            Reference to an external alarm routine function
                                      block
240
                                                  CAlarm
                         Description
                         The CAlarm function block is used to count or detect
                         high-speed external signals. If an alarm is detected,
                         there are two possible responses to the alarm:
                            Interrogate the CallUpNumber output
                            The CallUpNumber output is incremented each
                            time an alarm event occurs. The user program
                            can interrogate this output to see whether and / or
                            how often an alarm has been triggered.
                            Execute an alarm routine
                            The alarm routine specified with Handle is called
                            each time an alarm event occurs. This allows an
                            event-controlled reaction to the alarm.
                         In the basic rack of the PS 416 CPU, the CAlarm
                         function block is permanently assigned to alarm
                         input %I0.0.0.0.0.
                         The edge-triggered EnableDisable input controls
                         the counter. The input is evaluated on an edge-
                         controlled basis. On detecting a rising edge at this
                         input (0->1, enable), the parameters of the input
                         operands are checked and the counter is started.
                         The alarm block has been successfully activated
                         when the Error output has 0 after the block is called.
                         A falling edge (1->0) stops the counter and the
                         outputs CountValue and CallUpNumber are reset.
                         The Predivide input specifies how many signals are
                         required on the hardware input to increment the
                         alarm counter by one.
                         The SetpointValue input specifies how many alarm
                         events are required to increment CallUpNumber by
                         one. If an alarm routine function block has been
06/99 AWB 2700-1306 GB
                                                                           241
  Function Blocks
242
                                                                                   CAlarm
PROGRAM CntAlarm
                         VAR CONSTANT
                            No_alarm_routine   : UINT := 16#55aa;
END_VAR
                         VAR
                           EnableCAlarm AT %I0.0.0.0.7 :BOOL;
                           ErrorCAlarm : USINT;
                           CountValueCAlarm : UINT;
                           CallUpNumberCAlarm : UINT;
                           CAlarmFB : CAlarm;
                           Output AT %Q0.0.0.0.0 : BOOL;
                           Error AT %Q0.0.0.0.7 : BOOL;
END_VAR
                           LD      EnableCAlarm
                           JMPCN   CONTINUE
                           LD      ErrorCAlarm
                           EQ      0
06/99 AWB 2700-1306 GB
                           JMPCN   ERROR_CALARM
                           LD      CAlarmFB.CallUpNumber
                           ST      CallUpNumberCAlarm
                           JMP     CONTINUE
                                                                                                             243
  Function Blocks
ERROR_CALARM:
  (* Error handling   *)
  LD    1
  ST    Error
  LD     CallUpNumberCAlarm
  GT     3
  JMPC   SET_1
  LD     0
  ST     Output
  JMP    END
SET_1:
  LD     1
  ST     Output
END:
END_PROGRAM
244
                                                                  ColdstartRetention
                         PS 416       ColdstartRetention
                                      Definition of a Marker Area with Cold Start
                                      Retention
                                  Meaning of operands
                                  Enable               A rising edge enables the definition of the cold
                                                       start retentive marker area
                                  Description
                                  The ColdstartRetention function block is used to
                                  define a block of marker bytes within the PS 416-
                                  CPU marker area (MB 0 – MB 4345) which is cold
06/99 AWB 2700-1306 GB
                                                                                                     245
  Function Blocks
246
                                                                                     ColdstartRetention
VAR RETAIN
END_VAR
                         VAR
                           SetValues AT%i0.0.0.0.0 : BOOL ;
                           RetentiveError AT%q0.0.0.0.0 : BOOL ;
                           Retentive : ColdstartRetention ;
                           FirstCycle : PS_Message ;
END_VAR
                                                                                                          247
  Function Blocks
  LD      RetentiveError
  EQ      0
  JMPCN   ERROR
  JMP     NORMAL_CYCLE
ERROR:
  (* Execute error routines   *)
  LD    1
  ST    RetentiveError
NORMAL_CYCLE:
  (* This part of the program only serves to illustrate
     the different retention behaviour of the declared variables.
     The following markers are retentive
     with a user-program warm start *)
  LD    M10
  LD    M12
  LD    M14
  ST    M20
  ST    M22
  ST    M24
ENDE:
END_PROGRAM
248
                                                             COM
                         PS 416      COM
                                     Function block for serial communication
                                  Description
                                  The COM function block is used for serial com-
                                  munication with the PS 416-COM-200 card.
                                  Please refer to the manual “Hardware and
                                  Engineering PS 416-COM-200 – Communication
                                  Module” (AWB 27-1237-GB) for a description of this
                                  function block and some application notes.
06/99 AWB 2700-1306 GB
                                                                                   249
  Function Blocks
                        CompareArray
                        Data Block Comparison or Value Search
                    Meaning of operands
                    Mode               Operating mode (0 = search, 1 = block
                                       comparison)
250
                                                   CompareArray
                         Description
                         The CompareArray function block has two operating
                         modes: Value Search or Block Comparison.
                         The mode is set with the Mode input.
                         The source and the destination can be of any
                         required size. All types of type ANY_INT and
                         ANY_BIT are permissible as array element types
                         apart from BOOL.
                         Error codes at the Error output:
                         0 No errors
                         1 Number of elements (ElementNumber) is 0
                         2 Source offset is outside the source area.
                         3 Number of elements exceeds the source area.
                         4 Destination offset is outside the destination area
                         5 Number of elements exceeds the destination
                            area.
                         Value Search mode
                         The Value Search mode is used to search for a
                         specified value in an array.The value to search for is
                         contained in the array specified with Source and
                         SourceOffset.
                         The start of the array to be searched for is specified
                         with Destination and DestinationOffset.
                         The length of the data block to be searched is
                         specified with ElementNumber. The Equal output will
                         be set if the search criterion is found within the data
                         block defined by the destination address and
                         ElementNumber.
                         Output indicates the position of this value within the
                         array:
06/99 AWB 2700-1306 GB
                                                                            251
  Function Blocks
  LD Start
  CALC search_fb (Mode := 0, (* Data search mode *)
                  Source := SourceAddress,
                  Destination := DestinationAddress,
                  ElementNumber := 6)   (* Search range of 6 bytes   *)
  LD search_fb.Output
  ST Found                 (* Location of the search value   *)
                           (* "Destination" plus "Output" *)
  LD   search_fb.Greater
  ST   Result_greater
  LD   search_fb.Equal
  ST   Result_equal
  LD   search_fb.Less
  ST   Result_less
END_PROGRAM
252
                                                                                 CompareArray
                           LD Start
                           CALC compare_fb(Mode := 1,             (* Block comparison *)
                                         Source := SourceAddress,
                                         Destination := DestinationAddress,
                                         ElementNumber := 4)   (* Comparison range: 4 bytes *)
                           LD compare_fb.Output
                           ST Deviation         (* Location where blocks *)
                                                (* differ: "Destination" plus "Output" *)
                           LD compare_fb.Greater
                           ST Result_greater
                           LD compare_fb.Equal
                           ST Result_equal
                           LD compare_fb.Less
                           ST Result_less
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                                       253
  Function Blocks
                        COMtoSTR
                        Convert Received Characters to String
                    Meaning of operands
                    ReceiveVariable Start address of the marker range where the data to
                                    be converted is located
                    Description
                    The function block is used to convert text data
                    received via an interface and stored in an array to a
                    variable of data type ANY_STRING.
                    A static “1” or TRUE at the Enable input starts the
                    conversion. The input parameter “StrLen” defines
                    the number of characters to be converted and thus
                    the length of the resulting string.
                    If the declared length of TextString is insufficient to
                    hold all the converted data, characters are only
                    copied into it until it is full. The data is copied to the
                    string 1:1 without ASCII conversion.
                                                                                           06/99 AWB 2700-1306 GB
254
                                                                                 COMtoSTR
                         VAR
                           EnableReceive AT%I0.0.0.0.0 : BOOL;
                           Array_to_String : COMtoSTR;
                           ReceiveText : STRING(20):
                           ReceiveArray : ARRAY[1..20] of byte;
                           ReceiveLength : UINT;
                           ReceiveFromSerial : COM ;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                                 255
  Function Blocks
      PS 4-200 1)           CounterAlarm
      PS 4-300              Counter Alarm Function Block
      PS 416
                    Meaning of operands
                    EnableDisable     Enabling and disabling of alarm execution
                                      Start condition positive edge (0 = Disable,
                                      1 = Enable)
                    Description
                    The CounterAlarm function block is assigned in the
                    PS 4-341-MM1, PS 4-201-MM1 PS 4-141-MM1 and
                                                                                          06/99 AWB 2700-1306 GB
256
                                                   CounterAlarm
                                                                             257
  Function Blocks
258
                                                  CounterAlarm
                                                                           259
  Function Blocks
                      LD   CountAlarm.Error
                      ST   Error
                                                                               06/99 AWB 2700-1306 GB
                      LD   CountAlarm.CountValue
                      ST   CountValue
                           (*This shows the current counter value *)
END_PROGRAM
260
                                                                         CounterLE
                         PS 4-200           CounterLE
                         PS 4-300           Control of the Counter LE Module
Counter-LE
                                        Meaning of operands
                                        LENumber            Module address of LE
                                                            (can only be 1 or 2)
                                                                                                          261
  Function Blocks
                    Description
                    The CounterLE function block controls the
                    LE 4-622-CX1. The following functions can be
                    executed:
262
                                                                   CPUDataExchange
                         PS 416       CPUDataExchange
                                      Exchange Data Between PLCs
                                  Meaning of operands
                                  SlotNumber          Slot number of the CPU which exchanges data
                                  Description
                                  If several CPUs of types PS 416-CPU-200/300/400
                                  are installed in the same rack, the
                                  CPUDataExchange function block can be used to
                                  exchange data between them. The same function
                                  block is used for both master and slave CPUs.
06/99 AWB 2700-1306 GB
                                                                                                       263
  Function Blocks
264
                                                  CPUDataExchange
                                                                           265
  Function Blocks
                    VAR
                      DataExchange : CPUDataExchange ;
                      EnableRead AT%i0.0.0.0.0 : Bool ;
                      ReadData : Array[1..20] of Byte;
                      ReadError : Uint ;
                    END_VAR
                      LD   EnableRead
                      CALC DataExchange (SlotNumber := 4,
                                         Direction := CD_READ,
                                         SourceOffset := 0,
                                         DestinationOffset := 0,
                                         Length := 20,
                                         DataBuffer := ReadData
                                         |
                                         ReadError := Errorcode )
END_PROGRAM
266
                                                         CTD
                              CTD
                              Down Counter
                         Meaning of operands
                         CD              Counter pulses, rising edge
PV Initial value
CV Counter status
                         Description
                         The function block CTD is used for the down
                         counting of impulses provided at the input operand
                         “CD”. The counter is set to “0” when initialised.
                         The value defined by the operand “PV” is loaded into
                         the counter as the initial value if the value of the
                         operand “Load” is “1”.
                         Each rising edge on the input “CD” is decremented,
                         i. e. reduced by one.
                         The output operand “CV” outputs the current
                         counter value. If the counter value is above the value
                         “0”, the output operand “Q” has the Boolean value
06/99 AWB 2700-1306 GB
                                                                           267
  Function Blocks
                         CTU
                         Up Counter
                    Meaning of operands
                    CU              Counter pulses, rising edge
PV Counter limit
CV Counter status
                    Description
                    The function block CTU is used for the up counting
                    of impulses provided by the input operand “CU”.
                    The counter is set to “0” when initialised. Each rising
                    edge on input “CU” increments the counter, i. e.
                    increases its value by one.
                    The counter value can be cleared with the value “1”
                    at the operand “ReSet”.
                    The output operand “CV” outputs the current
                    counter value. If the counter value is below the limit
                    value “PV”, the output operand “Q” has the Boolean
                    value “0”. The output “Q” is set to “1” when reaching
                                                                              06/99 AWB 2700-1306 GB
268
                                                      CTUD
                              CTUD
                              Up And Down Counter
                         Meaning of operands
                         CU              Counter pulses for up counting, rising edge
PV Load value
CV Counter status
                         Description
                         The function block CTUD is used for the counting up
                         and down of impulses. The counter is set to “0” when
06/99 AWB 2700-1306 GB
                                                                                       269
  Function Blocks
                    VAR
                      PersonCounter : CTUD;
                      Lightbarrier1 AT %I0.0.0.0.2 : BOOL;
                      Lightbarrier2 AT %I0.0.0.0.3 : BOOL;
                      Reset AT %I0.0.0.0.1 : BOOL;
                      PersonNumber AT %QW0.0.0.0 : INT;
                    END_VAR
                    END_PROGRAM
                                                                             06/99 AWB 2700-1306 GB
270
                                                          DataScale
                               DataScale
                               Scaling of data
DataScale
                         Meaning of operands
                         Set                Activates the function block
                         InputValue         Input value (IV) which can vary within the input
                                            range; IRB IV ≤ IRE
                                                                                          271
  Function Blocks
                    Description
                    The input range within which the value to be proc-
                    essed (IV) can vary is defined with the values IRE
                    (greatest input value) and IRB (smallest input value).
                    You can assign any output range you wish (ORE and
                    ORB) to this input range. The input value is converted
                    using the ratio of input range to output range. 2 limit
                    values (OLL and OLH) must be defined within this
                    output range.
                    If the converted value exceeds or undershoots a
                    limit, a message is output.
272
                                                  DataScale
                                                                           273
  Function Blocks
                    Example “Scaling”
                    PROGRAM analog_processing
                    VAR
                      Converter:           DataScale;
                      Start                AT %I0.0.0.0.0: BOOL;
                      Analog_Input         AT %IAW0.0.0.4: INT;
                      Analog_Output:       INT;
                      Continuation:        INT;
                      Range_Error:         USINT;
                      Parameter_Error:     USINT;
                    END_VAR
END_PROGRAM
274
                                                        DATconcat
                                DATconcat
                                Concatenate Date and Time
                         Meaning of operands
                         MilliSecond    Milliseconds part of date and time
                                                                             275
  Function Blocks
                               Description
                               The values specified as input operands of data type
                               UINT are combined to a value for date and time in the
                               output operand “OutputDAT”.
                               The function block converts the individual values of
                               the input operands to the appropriate sections for
                               date and time. The input operands must not exceed
                               the value ranges specified for a date and a time.
                               The year number must be between 1993 – 2092. If
                               the specified value ranges are exceeded, the status
                               “1” will show at the Error output.
                               Example: Concatenating date and time
PROGRAM dtgen
VAR
  DateTimeConcatenation : DATconcat;
  MilliSec : UINT := 0;
  Sec : UINT := 30;
  Min : UINT := 10;
  Hr : UINT := 3;
  Dy : UINT := 12;
  Mnth : UINT := 12;
  Yr : UINT := 1997;
  Err : BOOL;
  Date_1 : DATE_AND_TIME;
END_VAR
END_PROGRAM
                                                                                       06/99 AWB 2700-1306 GB
276
                                                        DateConcat
                                DateConcat
                                Concatenate Date
                         Meaning of operands
                         Day            Day part of a date
                         Description
                         The values entered as input operands of data type
                         UINT are combined to a date value in the output
                         operand “OutputDate”. The input operands must be
                         outside of the permissible value range for dates.
                         The year value must be between 1993 – 2092.
                         The Error output will be set to “1” if an impermissible
                         value is entered.
06/99 AWB 2700-1306 GB
                                                                                         277
  Function Blocks
                    VAR
                      Dateconcaten : DateConcat;
                      Date1 : Date;
                      Dy : UINT := 24;
                      Mnth : UINT := 12;
                      Yr : UINT := 1996;
                      Err : BOOL;
                    END_VAR
END_PROGRAM
278
                                                        DateSplit
                                DateSplit
                                Split DATE Data Type
                         Meaning of operands
                         InputDate      Date
                         Description
                         The date value specified via the input operand
                         “InputDate” is divided into elements that are each
                         output as UINT data types.
                         The year value must be between 1993 – 2092.
                         The output operand Error will be set to “1” if an
                         impermissible year value is entered.
06/99 AWB 2700-1306 GB
                                                                             279
  Function Blocks
                    VAR
                      DateElements : DateSplit;
                      Date1 : Date := D#1999-12-24;
                      Dy : UINT;
                      Mnth : UINT;
                      Yr : UINT;
                      Err : BOOL;
                    END_VAR
END_PROGRAM
280
                                                        DATsplit
                                DATsplit
                                Split DATE_AND_TIME Data Type
                         Meaning of operands
                         InputDAT       Date and time
                                                                             281
  Function Blocks
                    Description
                    The date and time value specified via input operand
                    “InputDAT” is divided into elements that are each
                    output as UINT data types.
                    The year number must be between 1993 – 2092.
                    The output operand Error will be set to “1” if an
                    impermissible year value is entered.
                    Example: Splitting date and time values
                    PROGRAM dtsplit
                    VAR
                      DT_Elements : DATsplit;
                      Date_1 : DT := DT#1999-11-20-22:13:12;
                      Millisec : UINT;
                      Sec : UINT;
                      Min : UINT;
                      Hr : UINT;
                      Dy : UINT;
                      Mnth : UINT;
                      Yr : UINT;
                      Err : BOOL;
                    END_VAR
                    END_PROGRAM
                                                                          06/99 AWB 2700-1306 GB
282
                                                                                         DE4netDP
                           PS 4-300                          DE4netDP
                           PS 416                            PROFIBUS-DP connection for frequency
                                                             inverters of series DF 4-120 and DF 4-34x
DE4netDP
                                                          Meaning of operands
                                                 Enable                   “1” signal activates frequency inverter. “0” signal
                                                                          disables any further control commands. With drive
                                                                          running, change of signal from “1” to “0” causes
                                                                          motor to coast.
                                                 Start                    A “1” state enables the motor drive, the output
                                                                          frequency is integrated to the specified setpoint
                                                                          according to the defined acceleration ramp. A
                                                                          change from “1” to “0” stops the motor with the
                                                                          defined deceleration ramp.
                                                 Quickstop                At “1” state, motor brakes to standstill using the
                                                                          quick-stop ramp. The ramp time is adjustable with
                                                                          the parameter 105 (PNU 105) (only DF 4-34x).
06/99 AWB 2700-1306 GB
                                                                                                                         283
  Function Blocks
284
                                                               DE4netDP
                                                                                                 285
  Function Blocks
286
                                                      DE4netDP
                             Description
                             The “DE4netDP” function block is used to transfer
                             process and parameter data. The identifier of the
                             user data length in the PROFIBUS configurator must
                             be “B7hex 71hex”. This means, 8 bytes are trans-
                             mitted via the DP parameter channel plus 2 words of
                             process data.
                             The mode of the frequency inverter must first be set
                             to 3 “Fieldbus mode”. This can be done with the
                             keyboard, operating software or even via the field
                             bus.
                             As soon as communication is established between
                             PLC and the DF 4, the process data is transferred
                             automatically and continuously with no explicit
                             programming required. If other parameters of the
                             DF 4 are to be changed via PROFIBUS-DP, this is
                             done via the parameter channel.
                             Process input data:
                             Enable, Start, Quickstop, DCBrake, TripReset,
                             ParameterSet, ReferenceFrequency:
                             Process output data:
                             StatusWord, ActualFrequency
                                “Parameternumber“
                             왘 Specify subindex “Subindex“ (always equals zero
                                for the DF 4)
                                                                              287
  Function Blocks
288
                                                      DE4netDP
                         
                             Response when bus interrupted (PNU 4000)
                               This parameter is only available for communi-
                               cation via PROFIBUS and is therefore not
                               described in the manual for the frequency
                               converter.
                               This parameter, and thus the response, is not
                               stored voltage failure safe in the DF 4 frequency
                               inverter but in the optional DE 4-NET-DP module.
                                                                                 289
  Function Blocks
                    Example
                    The following example shows the declaration in the
                    variable editor:
                    VAR
                      Drive_1                    : DE4netDP;
                      IN_PDP_S1T3at%IB1.3.0.0    : Array [0..11] of BYTE;
                      OUT_PDP_S1T3at%QB1.3.0.0   : Array [0..11] of BYTE;
                    END_VAR
290
                                                       DE4netK
                            DE4netK
                            Frequency inverter DF 4
                         Meaning of operands
                         SendData         Operator list for the send register
                                                                                   291
  Function Blocks
292
                                                            DE4netK
                             Description
                             The DE4netK function block forms the interface
                             between a PLC program and the DE 4-NET-K
                             Fieldbus module.
                             As soon as communication is established between
                             the PLC and the DF 4, process data is exchanged
                             automatically and continuously without requiring
                             explicit programming. Other DF 4 parameters are
                             changed via Suconet using the parameter channel.
                                                                                           293
  Function Blocks
294
                                                  DE4netK
                                                                           295
  Function Blocks
                    Write parameters:
                    왘 Specify parameter number in Parameternumber
296
                                                   DE4netK
                           CAL Drive_1(Enable := ,
                                       Start := ,
                                       Quickstop := ,
                                       DCBrake := ,
                                       TripReset := ,
                                       ParameterSet := ,
                                       MotorPotUp := ,
                                       MotorPotDown := ,
                                       FixedFrequency1 := ,
                                       FixedFrequency2 := ,
                                       FixedFrequency3 := ,
                                       Reversal := ,
                                       FreezeRamp := ,
                                       ReferenceFrequency := ,
                                       Command := ,
                                       Parameternumber := ,
                                       TransmitValue := ,
                                       TransmitValueOffset := ,
                                       SendData := SD_S1T1,
                                       ReadData := RD_S1T1
                                       |
                                       :=StatusWord,
                                       :=ActualFrequency,
                                       :=EchoCommand,
                                       :=EchoParameternumber,
                                       :=Busy,
                                       :=ReceiveValue,
                                       :=ReceiveValueOffset,
                                       :=ErrorCode)
06/99 AWB 2700-1306 GB
                                                                           297
  Function Blocks
                        Deserialize
                        Extract Data from Arrays
                    Meaning of operands
                    Destination         Destination variable
                    Description
                    The Deserialize function block extracts any required
                    data type from a source area at a starting position
                    specified by “Buffer + BufferOffset”.
                    The DestinationLength output specifies the length of
                    the destination data type in bytes.
                    Buffer is an array of any size. All ANY_BIT and
                    ANY_INT types apart from BOOL are permissible as
                    array elements.
                                                                                06/99 AWB 2700-1306 GB
298
                                                                                Deserialize
                                           DeserializedLength := DestinationLength)
                           LD deserie_fb.Error
                           USINT_TO_BOOL                (* Any Error ? *)
                           JMPC _Fail                   (* Error handling *)
                                                                                                        299
  Function Blocks
  LD deserie_fb.Error
  USINT_TO_BOOL               (* Any Error ? *)
  JMPC _Fail                  (* Error handling *)
300
                                                                  DialOrHangup
                         PS 4-300       DialOrHangup
                         PS 416         Establish or Clear a Connection to a DTE via
                                        Modem
                                    Meaning of operands
                                    Prefix           Dialling prefix before telephone number (for
                                                     example, “0W“)
                                                      If no prefix is required, the associated string
                                                     variable must at least contain an empty string
                                                     (String(0):=”;).
                                                     0: PS 416-CPU 400/300-SBI or
                                                        PS 4-341-MM1 SBI (transparent mode),
                                                     4...20: Slot for appropriate COM card
                                                                                                   301
  Function Blocks
                    Description
                    The DialOrHangup function block has two modes:
                    Dial and Hangup. This is specified with the FBMode
                    input:
                    TYPE tFBMODE:
                      ( Dial,
                        Hangup ):=Dial;
                    END_TYPE
302
                                                   DialOrHangup
                                                                            303
  Function Blocks
304
                                                       DialOrHangup
                                                                                305
  Function Blocks
VAR
  FB_DAH : DialOrHangup;
  FB_SEND : COM;
  StringToArray : STRtoCOM;
  DAH_FallingEdge : F_TRIG;
  SEND_FallingEdge : F_TRIG;
  Make_Dial : BOOL;
  DAHFlag : BOOL;
  SENDFlag : BOOL;
  PhoneString : String(30);
  FB_Strobe AT %I0.0.0.0.0 : BOOL;
  Display_DAH_Active AT %Q0.0.0.0.0 : BOOL;
  Display_ConnectOK AT %Q0.0.0.0.1 : BOOL;
  Display_HangupOK AT %Q0.0.0.0.2 : BOOL;
  Display_DAH_Error AT %QW0.0.0.2 : UINT;
  Prefix : STRING(3):=‘00W‘;
  PhoneNumber : STRING(13):=‘0228,602,1414‘;
  Response : STRING(254);
  message : String(54):=‘Hello, this is the PS 416    $R$L‘;
  sendString : String(80);
  sendData : ARRAY [1..256] OF BYTE;
  receiveData : ARRAY [1..256] OF BYTE;
  ...
END_VAR
Disconnect:
  LD    Hangup
  ST    FB_DAH.FBMode
  JMP   Start
                                                                    06/99 AWB 2700-1306 GB
Phone:
  LD      PhoneNumber
  St      PhoneString
  JMP     Start
306
                                                                                 DialOrHangup
                         Call:
                           CAL   FB_DAH( Strobe :=FB_Strobe,    (* Button *)
                                         SlotNumber :=10,
                                         FBMode :=,
                                         DialMode :=Tone,
                                         Prefix :=Prefix,
                                         PhoneNumber :=PhoneString,
                                         ResponseString :=Response,
                                         TimeOut := 60
                                         |
                                         Display_DAH_Active :=Active,
                                         Display_ConnectOK :=ConnectOK,
                                         Display_HangupOK :=HangupOK,
                                         :=ResponseStrLen,
                                         Display_DAH_Error :=Error)
                           LD    Response
                           LD    DAHFlag          (* Detect falling edge on FB_Active   *)
                           JMPC CheckAnswer
                           CAL   DAH_FallingEdge(
                                        CLK :=FB_DAH.Active
                                         |
                                        :=Q)
                           LD    DAH_FallingEdge.Q
                           JMPCN End
                           LD    1
                           ST    DAHFlag
                         CheckAnswer:
                           ...
                           LD    FB_DAH.Error
                           GT    0
                           JMPC Error
                           LD    FB_DAH.ConnectOK
                           JMPC Connect
                           LD    FB_DAH.HangupOK
                           JMPC Disconnected
                           JMP   End
06/99 AWB 2700-1306 GB
                                                                                                307
  Function Blocks
Disconnected:
  ...
  LD    0
  ST    Make_Dial    (* Redial is now allowed *)
  LD    0
  ST    SENDFlag
  ST    DAHFlag
  LD    0            (* Send text, reset strobe *)
  ST    FB_SEND.TransmitStrobe
  JMP   Send
:=Q )
  LD      SEND_FallingEdge.Q
  JMPCN   End
  LD      1
  ST      SENDFlag
308
                                                                              DialOrHangup
                         CheckSendAnswer:
                           ...
                           LD    0
                           ST    DAHFlag
                           LD    0
                           ST    Make_Dial    (* Data sent, hang up *)
                           JMP   End
                         Error:
                           ...
                           LD     1
                           ST     Make_Dial   (* Dialling error, hang up *)
                           LD     0
                           ST     SENDFlag
                           ST     DAHFlag
                         End:
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                             309
  Function Blocks
      PS 4-200 1)       EdgeAlarm
      PS 4-300          Edge-Controlled Alarm Function Block
      PS 416
                    Meaning of operands
                    EnableDisable   Enable and disable alarm execution
                                    Start condition rising edge (0 = Disable, 1 =
                                    Enable)
310
                                                  EdgeAlarm
                         Description
                         The EdgeAlarm function block is permanently
                         assigned in the PS 4-201-MM1 to the hardware input
                         %I0.0.0.0.0; on the PS 4-141-MM1 and PS 4-151-
                         MM1 this permanently assigned input is %I0.0.0.1.0.
                         The PS 4-341-MM1 controller is provided with two
                         EdgeAlarm inputs: %I0.0.0.0.1.0 and %I0.0.0.1.1.
                         The input EnableDisable starts and stops the
                         counter. With a rising edge (0–1 transition) the
                         counter is started. The counter is stopped and reset
                         if the input status changes from “1” or TRUE to “0” or
                         FALSE.
                         The RisingEdge input is used to define which signal
                         edge is to be evaluated.
                         The SetPointValue input defines the number of
                         signals to be counted before the alarm and the
                         function block are activated.
                         The maximum system capacity depends on the
                         following three factors: “Predivide”, “SetPointValue”
                         and the frequency set. These factors must be
                         selected so that no more than two interrupts occur
                         per millisecond.
                         The Error output indicates the following error code:
                         0 No errors
                         1 Setpoint is 0
                         3 Invalid alarm channel number
                                                                           311
  Function Blocks
312
                                                   EdgeAlarm
disable is to be implemented.
                                                                             313
  Function Blocks
                    VAR
                      Edgealarm : EdgeAlarm;
                      Error : USINT;
                      CountValue : UINT;
                      Pump : react_fb;
                      (*Declaration of function block
                        that is activated in the event of an alarm *)
                    END_VAR
                      CAL EdgeAlarm(EnableDisable := 1,
                                    Number := 0,
                                    RisingEdge := 0,
                                    SetPointValue := 1,
                                    Subroutine := Pump)
                      LD EdgeAlarm.Error
                      ST Error
                      LD EdgeAlarm.CallUpNumber
                      ST CountValue
                       (*This indicates the number of alarms *)
                                                                             06/99 AWB 2700-1306 GB
END_PROGRAM
314
                                                       F_TRIG
                               F_TRIG
                               Edge Detection of the Falling Edge
                         Meaning of operands
                         CLK             Input operand whose falling edge is detected.
                         Description
                         The function block “F_TRIG” evaluates the status of
                         the input operand “CLK”. It detects the status
                         change from “1” in a processing cycle to “0” in the
                         subsequent cycle and indicates this on the output
                         “Q” with the Boolean value “1”. The output is only set
                         to “1” during the processing cycle in which the
                         change of the status of “CLK” and a falling edge was
                         detected.
06/99 AWB 2700-1306 GB
                                                                                         315
  Function Blocks
                    VAR
                      Signal1_incoming : R_TRIG;
                      Signal1_outgoing : F_TRIG;
                      Signal1 AT %I0.0.0.0.2 : BOOL;
                      Pulse_0_1 : BOOL;
                      Pulse_1_0 : BOOL;
                    END_VAR
END_PROGRAM
316
                                                          FifoBx
                                FifoBx
                                8-Bit FirstIn-FirstOut Register (Queue)
                         Meaning of operands
                         FillPulse       Fill pulse
ReSet Reset
                         Description
                         There are 128 function block prototypes. The follow-
                         ing names can be used for *:
                         FifoB1
                         FifoB2
                           .
                           .
                         FifoB128
06/99 AWB 2700-1306 GB
                                                                          317
  Function Blocks
Contents of the FifoB8 register before and after a fill pulse 06/99 AWB 2700-1306 GB
318
                                                    FifoBx
                                                                               319
  Function Blocks
VAR
  Queue_32_byte : FifoB32;
  Pulse1 : BOOL;
  Pulse2 : BOOL;
  Reset : BOOL;
  QueueData : USINT;
  Full : BOOL;
  Empty : BOOL;
  Outputdata : USINT;
END_VAR
   .
   .
  CAL Queue_32_byte(FillPulse := Pulse1,
                    ReadOutPulse := Pulse2,
                    ReSet := Reset,
                    DataInput := QueueData)
  LD   Queue_32_byte.Full
  ST   Full
  LD   Queue_32_byte.Empty
  ST   Empty
  LD   Queue_32_byte.DataOutput
  ST   Outputdata
   .
   .
END_PROGRAM
320
                                                          FifoWx
                                FifoWx
                                16-Bit FirstIn-FirstOut Register
                                (Queue)
                         Meaning of operands
                         FillPulse       Fill pulse
ReSet Reset
                         Description
                         There are 128 function block prototypes. The follow-
                         ing names can be used for *:
                         FifoW1
                         FifoW2
                           .
06/99 AWB 2700-1306 GB
                           .
                         FifoW128
                                                                         321
  Function Blocks
322
                                                    FifoWx
                                                                               323
  Function Blocks
                    VAR
                      Queue_16_word : FifoW16;
                      Pulse1 : BOOL;
                      Pulse2 : BOOL;
                      Reset : BOOL;
                      QueueData : UINT;
                      Full : BOOL;
                      Empty : BOOL;
                      Outputdata : UINT;
                    END_VAR
                       .
                       .
                      CAL Queue_16_word(FillPulse := Pulse1,
                                        ReadOutPulse := Pulse2,
                                        ReSet := Reset,
                                        DataInput := QueueData)
                      LD Queue_16_word.Full
                      ST Full
                      LD Queue_16_word.Empty
                      ST Empty
                      LD Queue_16_word.DataOutput
                      ST Outputdata
                       .
                       .
END_PROGRAM
324
                                                       GetRealTimeClock
                                GetRealTimeClock
                                Evaluation of the Real-Time Clock
                         Meaning of operands
                         Year             Current year (two-digit)
Month Month
Day Day
Hour Hour
Minute Minute
Second Second
                         Description
                         The GetRealTimeClock function block gets the
                         current time and date from the real-time clock and
                         provides them at the output. An enable input is not
                         required. The function block provides values as soon
                         as it is called.
06/99 AWB 2700-1306 GB
                                                                          325
  Function Blocks
      PS 4-300          IEEE_To_Real
      PS 416            Conversion of numbers from IEEE 754
                        standard format to data type REAL
IEEE_To_Real
                    Meaning of operands
                    EXPO_In         IEEE floating-point number to be converted:
                                    exponent (inc. sign)
                    Mant_2_In       IEEE floating-point number to be converted:
                                    mantissa byte 2 (inc. 1 bit exponent)
                    Mant_1_In       IEEE floating-point number to be converted:
                                    mantissa byte 1
                    Mant_0_In       IEEE floating-point number to be converted:
                                    mantissa byte 0
                    Real_Out        Converted real number
                    Error           Error during conversion:
                                    IEEE cannot be represented
                    Description
                    The function block IEEE_To_Real converts a floating-
                    point number of the IEEE format to the data type REAL.
                    To represent the floating-point number, four bytes
                    (32 bit) are needed. The format used conforms to the
                    IEEE 754 standard format (32 bit):
326
                                                                   IncEncoder
                         PS 4-300       IncEncoder
                                        Control of local incremental encoder
IncEncoder
                                    Meaning of operands
                                    Enable           Enable for processing
                                                                                                  327
  Function Blocks
                    Description
                    The IncEncoder function block counts the pulses of
                    an encoder connected locally to the PS 4-300.
1311).
328
                                                  IncEncoder
                                                                           329
  Function Blocks
                                Example:
PROGRAM IncEncTest
VAR
   IncEncChannel:     IncEncoder ;
         ActualPosition :     UDINT ;
         ErrorIncEnc:         UINT ;
END_VAR
  CAL IncEncChannel (
        Enable :=1,         (* Enable Incremental Encoder *)
        SetRefValue :=0,
        RefMode :=1,        (* Reference step once via Hardware *)
        RefValue :=10000    (* Zero point with 10,000 increments *)
        |
          :=State,
          :=Error,
          :=CurrentValue
  )
  (* Errors? *)
  ld    IncEncChannel.Error
  st    ErrorIncEnc
  eq    0
  jmpcn ERROR
  (* Encoder calibrated? *)
  ld    IncEncChannel.State
  eq    1
  jmpcn NO_REF
NO_REF:
  (* Continue program code *)
ERROR:
  (* Troubleshooting *)
                                                                      06/99 AWB 2700-1306 GB
EOP:
  (* End Of Program *)
END_PROGRAM
330
                                                          LifoBx
                                LifoBx
                                8-Bit LastIn-FirstOut Register
                                (Stack Register)
                         Meaning of operands
                         FillPulse        Fill pulse
ReSet Reset
                         Description
                         There are 128 function block prototypes. The follow-
                         ing names can be used for *:
                         LifoB1
                         LifoB2
                           .
                           .
06/99 AWB 2700-1306 GB
LifoB128
                                                                         331
  Function Blocks
332
                                                     LifoBx
                                                                                333
  Function Blocks
VAR
  Queue_64_byte : LifoB32;
  Pulse1 : BOOL;
  Pulse2 : BOOL;
  Reset : BOOL;
  QueueData : USINT;
  Full : BOOL;
  Empty : BOOL;
  Outputdata : USINT;
END_VAR
   .
   .
  CAL Queue_64_byte(FillPulse := Pulse1,
                    ReadOutPulse := Pulse2,
                    ReSet := Reset,
                    DataInput := QueueData)
  LD   StackRegister_64_byte.Full
  ST   Full
  LD   StackRegister_64_byte.Empty
  ST   Empty
  LD   StackRegister_64_byte.DataOutput
  ST   Outputdata
   .
   .
END_PROGRAM
334
                                                          LifoWx
                                LifoWx
                                16-Bit LastIn-FirstOut Register
                                (Stack Register)
                         Meaning of operands
                         FillPulse        Fill pulse
ReSet Reset
                         Description
                         There are 128 function block prototypes. The follow-
                         ing names can be used for *:
                         LifoW1
                         LifoW2
                           .
06/99 AWB 2700-1306 GB
                           .
                         LifoW128
                                                                         335
  Function Blocks
336
                                                    LifoWx
                                                                               337
  Function Blocks
VAR
  Stackregister_32_byte : LifoW32;
  Pulse1 : BOOL;
  Pulse2 : BOOL;
  Reset : BOOL;
  StackData : UINT;
  Full : BOOL;
  Empty : BOOL;
  Outputdata : UINT;
END_VAR
   .
   .
  CAL Stackregister_32_word(FillPulse := Pulse1,
                            ReadOutPulse := Pulse2,
                            ReSet := Reset,
                            DataInput := StackData)
  LD Stackregister_32_word.Full
  ST Full
  LD Stackregister_32_word.Empty
  ST Empty
  LD Stackregister_32_word.DataOutput
  ST Outputdata
   .
   .
END_PROGRAM
338
                                                                  MI4K
                         PS 4-200       MI4K
                         PS 4-300       Communication Function Block MI 4
                                    Meaning of operands
                                    RDB_Start        Start address of the Suconet data exchange
                                                     interface input buffer (RDB)
                                                     e.g.. MI 4 as slave 1 on line 1
                                                     &%RDB1.1.0.0
                                    Description
                                    The MI4K function block is used for communication
                                    between the MI 4 series visualisation systems and
                                    the PLC via Suconet K.
                                    Status returns information on and error codes for the
                                    communication:
                                    01h: PLC is sending a data packet to the MI 4
                                    02h: PLC is receiving a data packet from the MI 4
                                    04h: PLC is receiving a data packet from the MI 4
                                    C0h: Error in input parameters
                                    80h: MI 4 has sent an invalid operation code /
06/99 AWB 2700-1306 GB
                                         communication error
                                    81h: Marker area exceeded / telegram length error
                                         when reading markers from the PLC
                                                                                                  339
  Function Blocks
340
                                                       MI4netK
                             MI4netK
                             Communication Function Block MI 4 and MV 4
                         Meaning of operands
                         RDB_Start        Suconet K data exchange interface input buffer
                                          (RDB), e. g. MI 4 as slave 1 on line 1 with data
                                          buffer 20/20:
                                          AT %RDB1.1.0.0 ARRAY [1..20] OF BYTE
                         Description
                         The MI4netK function block is used for communica-
                         tion between the MI 4 and MV 4 series of visualisa-
                         tion systems and the PLC via Suconet K.
                         Status returns information on and error codes for
                         communication:
                         01h: PLC is sending a data packet to the MI 4
                         02h: PLC is receiving a data packet from the MI 4
                         04h: No data request
                         C0h: Error in input parameters
                         80h: MI 4 has sent an invalid operation code /
06/99 AWB 2700-1306 GB
                              communication error
                         81h: Marker area exceeded / telegram length error
                              when reading markers from the PLC
                                                                                        341
  Function Blocks
342
                                                                MOD200
                         PS 416      MOD200
                                     Block for Serial Communication via
                                     MODBUS / JBUS
                                  Description:
                                  The MOD200 function block is used to handle serial
                                  communication via the MOD-BUS / JBUS card
                                  PS 416-MOD-200.
                                  Please refer to the manual “Hardware and
                                  Engineering, PS 416-MOD-200-MOD-BUS / JBUS
                                  Slave” (AWB-EM 27-1244-GB) for a description of
                                  this function block and some application notes.
06/99 AWB 2700-1306 GB
                                                                                343
  Function Blocks
                          MS_TimeFalling
                          Off-Delay Timer, Milliseconds
                    Meaning of operands
                    Set             Start condition, rising edge
344
                                                    MS_TimeFalling
Description
Time diagram
                                                                              345
  Function Blocks
                    VAR
                      Timer4 : S_TimeFalling;
                      Start AT %I0.0.0.0.0 : BOOL;
                      Halt AT %I0.0.0.0.1 : BOOL;
                      TimeValue4 : UINT := 25;
                                  (* TimeValue4 = 25 milliseconds *)
                        Output4 AT %Q0.0.0.0.0 : BOOL;
                    END_VAR
346
                                                       MS_TimeRising
                               MS_TimeRising
                               On-Delay Timer, Milliseconds
                         Meaning of operands
                         Set             Start condition, rising edge
                                                                             347
  Function Blocks
Description
Time diagram
348
                                                   MS_TimeRising
                         VAR
                           Timer3 : MS_TimeRising;
                           Start AT %I0.0.0.0.0 : BOOL;
                           Halt AT %I0.0.0.0.1 : BOOL;
                           Reset AT %I0.0.0.0.2 : BOOL;
                           TimeValue3: UINT := 7;
                                      (* TimeValue3 = 7 milliseconds *)
                           ActTime3 AT %QW0.0.0.2 : BOOL;
                           Output3 AT %Q0.0.0.0.0 : BOOL;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                           349
  Function Blocks
      PS 4-271          NItoCelsius
                        Linearisation of NI1000 values
NItoCelsius
                    Meaning of operands
                    InputValue         Value of resistance thermometer
                                       The input can accept the following values including
                                       offset (InputValue + Offset) depending on the
                                       resistance thermometer:
                                       695 (= –60.0 ºC) to 1500 (= 82.5 ºC)
                    Temperature        Limits in ºC
                                       –600 (= –60.0 ºC) to 825 (= 82.5 ºC)
                    Description
                    The function block is used in conjunction with the
                    NI1000 input of the PS 4-271-MM1.
                    It linearises the converted value (0 to 1500) of a
                    NI1000 resistance into a temperature value.
                    The process of linearisation conforms to DIN IEC 751
                    for NI1000 resistances. Since the value stated in the
                    tables is for the NI100 resistance, it is necessary to
                    multiply the value for the NI1000 resistor by 10.
                                                                                              06/99 AWB 2700-1306 GB
350
                                                   NItoCelsius
                         Example of linearisation
                         PROGRAM boiler_temperature
                         VAR
                           Temperature_sensed AT %IAW0.0.0.8: INT;
                           Offst:              2;
                           Temperature_value: INT;
                           Error:              BOOL;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                              351
  Function Blocks
      PS 4-271          NItoFahrenheit
                        Linearisation of NI1000 values
NItoFahrenheit
                    Meaning of operands
                    InputValue         Value of the resistance thermometer
                                       The input can accept the following values including
                                       offset (InputValue + Offset) depending on the
                                       resistance thermometer:
                                       695 (= –76.0 ºF) to 1500 (= 180.6 ºF)
                    Temperature        Limits in ºF
                                       –760 (= –76.0 ºF) to 1806 (= 180.6 ºF)
                    Description
                    The function block is used in conjunction with the
                    NI1000 input of the PS 4-271-MM1.
                    It linearises the converted value (0 to 1500) of a
                    NI1000 resistance into a temperature value. The
                    process of linearisation conforms to DIN IEC 751 for
                    NI1000 resistances. Since the value stated in the
                    tables is for the NI100 resistor, it is necessary to
                    multiply the value for the NI1000 resistance by 10.
                                                                                              06/99 AWB 2700-1306 GB
352
                                                   NItoFahrenheit
                         Example of linearisation
                         PROGRAM boiler_temperature
                         VAR
                           Temperature_sensed AT %IAW0.0.0.8: INT;
                           Offst:             2;
                           Temperature_value: INT;
                           Error:             BOOL;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                            353
354
                         Function Blocks
                             PdpFreezeSync
                             Send PROFIBUS-DP control commands to
                             DP slaves
PdpFreezeSync
Meaning of operands
                                                                                             355
  Function Blocks
356
                                                       PdpFreezeSync
                                                                                357
  Function Blocks
358
                                                   PdpFreezeSync
                                                                               359
  Function Blocks
                    Sync command:
                    The function block checks that the output data
                    from the PLC cycle are frozen by activating the
                    Sync command. The function block notifies the
                    user program that the slaves have executed the
                    Sync command by resetting (falling edge) the
                    Active output.
                    The Active output is reset after no less than 5
                    PLC cycles. The number of cycles increases if the
                    DP cycle is longer than the PLC cycle or there are
                    access conflicts when data is exchanged via the
                    DualPortRam of the DP master.
                    Sequence of the user program:
                    1. Output data processed and activate FB with
                       Sync command, Active = 1
                       (1st PLC cycle)
                    2. Wait for falling edge of Active,
                       (2nd to mth PLC cycle)
                    3. Falling edge of Active detected,
                       Sync was successfully executed, prepare new
                       output data,
                       next Sync command can be triggered
                       (5th to nth PLC cycle).
360
                                                    PdpFreezeSync
                         (*
                         A Freeze command is sent to slaves of group 3 in cycles
                         of 100 ms. If the FB is active longer than 100 ms, the
                         Strobe is not executed for a further 100 ms etc.
                         The frozen values are stored for further processing after
                         the falling edge of Active has been detected.
                         Edge detection is performed by the F_TRIG function block.
                         Freeze mode is terminated with an UnFreeze command if 100
                         Freeze input bytes (FreezeByteCounter) have been logged.
                         Condition:
                         Connected to the DP_Master are at least 3 slaves which
                         have the addresses 2, 4 and 125 and have at least 1 input
                         byte. The slaves were combined as Group 3 in the DP
                         configurator. In the topology configurator, the DP master
                         was configured at slot 7.
                         The DP line has the number 2.
                         *)
                         VAR
                           FBPulse                          :   TimeGenerator;
                           FBStrobe                         :   R_TRIG;
                           FBFreezeSync                     :   PdpFreezeSync;
                           FBActiveFallingEdge              :   F_TRIG;
                         (* FreezeValues *)
                           FreezeByte1                    : BYTE;
                           FreezeByte2                    : BYTE;
                           FreezeByte3                    : BYTE;
06/99 AWB 2700-1306 GB
(*...*)
                                                                                 361
  Function Blocks
                    (* Freeze Counter *)
                      FreezeByteCounter              : USINT;
                    (* UnFreezeFlag *)
                      UnFreezeFlag                   : BOOL;
                    END_VAR
                      (*...*)
                    (* FB call *)
                      CAL FBFreezeSync(
                            Strobe :=FBStrobe.Q,   (* ignored if
                                                   Active = 1 *)
                           MasterSlot :=7,         (* DP master located
                                                   in Slot 7*)
                           Command :=Freeze,
                           GroupSelect :=16#04     (* Bit 2 set =
                                                   Group 3 *)
                                                                            06/99 AWB 2700-1306 GB
                           |
                           :=Active,
                           :=Error)
362
                                                        PdpFreezeSync
                              LD    Slave2_IB0
                              ST    FreezeByte1
                              LD    Slave4_IB0
                              ST    FreezeByte2
                              LD    Slave125_IB0
                              ST    FreezeByte3
                              LD    FreezeByteCounter
                              ADD   1
                              ST    FreezeByteCounter
                              (*...*)
                         (* Error detection *)
                         _FBError:
                           (*...*)
JMP _End
                         _UnFreeze:
                         (* UnFreeze command ********************************)
                         (* FB call *)
                           CAL FBFreezeSync(
06/99 AWB 2700-1306 GB
                                                                                 363
  Function Blocks
                      LD      FBActiveFallingEdge.Q
                      JMPCN   _End
                      LD      FBFreezeSync.Error
                      EQ      0
                    JMPCN     _FBUnFreezeError
                    (* UnFreeze executed *)
                      LD     1
                      ST     UnFreezeFlag
JMP _UnFreezeEnd
                    (* Error detection *)
                    _FBUnFreezeError:
                      (*...*)
_UnFreezeEnd:
                      LD      Slave2_IB0
                      LD      Slave4_IB0
                      LD      Slave125_IB0
_End:
                    END_PROGRAM
                                                                   06/99 AWB 2700-1306 GB
364
                                                    PdpFreezeSync
                         (*
                         A Sync command is sent to slaves of group 3 in cycles of
                         100 ms. If the FB is active longer than 100 ms, the Strobe
                         is not executed for a further 100 ms etc.
                         The output values are changed after the falling edge of
                         Active is detected (increased by 1 in this case) and
                         transferred to the master.
                         The function block F_TRIG performs edge detection.
                         The Sync is terminated with an UnSync command when the
                         output value (SyncByteCounter) is 100.
                         Condition:
                         Connected to the DP master must be at least 3 slaves which
                         have the addresses 99, 4 and 125 and at least 1 output
                         byte. The slaves were combined as Group 8 in the DP
                         configurator. In the topology configurator, the DP master
                         must be configured at slot 7.
                         The DP line must have the number 2.
                         *)
                         VAR
                           FBPulse         : TimeGenerator;
                           FBStrobe        : R_TRIG;
                           FBFreezeSync        : PdpFreezeSync;
                           FBActiveFallingEdge        : F_TRIG;
                         (* SyncValue *)
                           SyncByteCounter                  : USINT;
                           (*...*)
06/99 AWB 2700-1306 GB
                         (* UnSync Flag *)
                           UnSyncFlag                       : BOOL;
END_VAR
                                                                               365
  Function Blocks
(*...*)
                    (* FB call *)
                      CAL FBFreezeSync(
                              Strobe :=FBStrobe.Q,       (* ignored when
                                                         Active = 1 *)
                                   MasterSlot :=7,       (* DP master located
                                                         in Slot 7*)
                                   Command :=Sync,
                                   GroupSelect :=16#80   (* Bit 7 set =
                                                         Group 8 *)
                                   |
                                   :=Active,
                                                                                  06/99 AWB 2700-1306 GB
:=Error)
366
                                                        PdpFreezeSync
                              LD        FBActiveFallingEdge.Q
                              JMPCN     _NextCycle
                              LD        FBFreezeSync.Error
                              EQ        0
                              JMPCN     _FBError
                              LD      SyncByteCounter
                              ADD     1
                              st      SyncByteCounter
                              USINT_TO_BYTE
                              ST      Slave4_QB0
                              ST      Slave99_QB0
                              ST      Slave125_QB0
(*...*)
                         (* Error detection *)
                         _FBError:
                           (*...*)
                              JMP       _End
06/99 AWB 2700-1306 GB
_Unsync:
                                                                               367
  Function Blocks
                    (* FB call *)
                      CAL FBFreezeSync(
                              Strobe :=1,             (* ignored when
                                                       Active = 1 *)
                                MasterSlot :=7,       (* DP master located
                                                      in Slot 7*)
                                Command :=UnSync,
                                GroupSelect :=16#80   (* Bit 7 set =
                                                      Group 8 *)
                                |
                                :=Active,
                                :=Error)
                      LD        FBActiveFallingEdge.Q
                      JMPCN     _End
                      LD        FBFreezeSync.Error
                      EQ        0
                      JMPCN     _FBUnSyncError
                    (* UnSync executed *)
                      LD      1
                      ST      UnSyncFlag
JMP _UnSyncEnd
                    (* Error detection *)
                    _FBUnSyncError:
                      (*...*)
_UnSyncEnd:
                      (*...*)
                                                                             06/99 AWB 2700-1306 GB
_End:
END_PROGRAM
368
                                                                    PdpStationDiag
                         PS 416       PdpStationDiag
                                      Request Diagnostics Data from PROFIBUS-
                                      DP Station
Meaning of operands
slave.
                                                                                                 369
  Function Blocks
                    Description
                    The “PdpStationDiag” enables the diagnostics
                    data of a PROFIBUS-DP slave to be scanned. The
                    function block must only be instantiated once in the
                    user program for each PS 416-NET-440.
                    The Diagnose parameter defines an array with
                    100 elements of type BYTE into which the PS 416-
                    NET-440 enters the extended diagnostics data of the
                    addressed slave.
                    A successful job will cause the PS 416-NET-440 to
                    return 100 bytes, irrespective of the actual
                    diagnostics data length.
370
                                                    PdpStationDiag
                          0   No error
                          1   FB faulty (faulty function block library)
                          2   Diagnostics data cannot be requested
                          3   Error when receiving diagnostics data
                          4   Invalid slot number (permissible values from
                              4 to 19)
                          5   Invalid station address (permissible values from
                              1 to 125)
                          7   No card defined in the topology configuration for
                              the slot specified.
                          8   No PS 416-NET-440 defined in the topology
                              configuration for the slot specified. Instead,
                              a different card was defined.
                          9   The PS 416-NET-440 is not ready for operation.
                         10   The specified station is not included in the
                              DP configuration.
                         11   No diagnostics data available for the specified
                              station.
                         12   The slot is already occupied by a different
                              function block; the function blocks
                              PdpStationDiag or PdpFreezeSync were not
                              called sequentially, at least one of these function
                              blocks is still active.
                         When job processing is successful, the function
                         block returns three standard PROFIBUS-DP
                         diagnostics bytes:
                         “State 1” diagnostics byte:
                         Bit 0: Station not responding
                         Bit 1: Station not ready for data exchange
                         Bit 2: Incorrect station parameters
                         Bit 3: Station-specific diagnostics data present
06/99 AWB 2700-1306 GB
                                                                             371
  Function Blocks
372
                                                                  PS_ApplicationHalt
                         PS 4-300       PS_ApplicationHalt
                         PS 416         Stop the User Program
                                    Meaning of operands
                                    Enable        Event which stops program execution
                                    Description
                                    The PS_ApplicationHalt function block can be used
                                    to halt a user program in the PS 4-300 or PS 416
                                    controller in the event of a fatal error status defined
                                    by the user. The error status is defined as an event in
                                    the program.
                                    The status of the event is assigned to the Enable
                                    input which stops the program when its value
                                    changes to “1”.
                                    Errorcode specifies a user-defined error number
                                    which the function block outputs to Sucosoft S 40
                                    when the event occurs.
                                    If status “1” occurs at the Enable input, the user
                                    program is stopped. The PS 4-300 and PS 416
06/99 AWB 2700-1306 GB
                                                                                                373
  Function Blocks
                    VAR
                      Halt_on_Error : PS_ApplicationHalt;
                      Error17 AT %I0.0.0.0.0 : BOOL;
                    END_VAR
END_PROGRAM
374
                                                                    PS_ClearKOMBit
                         PS 416          PS_ClearKOMBit
                                         Clear “KOM” Diagnostic Bit
                                      Meaning of operands
                                      Enable        Enables function block
                                      Description
                                      The PS_ClearKOMBit function block is used to clear
                                      the “KOM” diagnostic bit. In certain situations it is
                                      necessary to temporarily suppress the setting of the
                                      “KOM” error bit (“Suconet K communication partner
                                      has failed”). This may be necessary e. g. for
                                      Suconet K stations which start up very slowly (PC
                                      with EPC 335 card) or when replacing a Suconet K
                                      station.
                                      If the operating system of the PS 416 CPU has not
                                      detected any other errors when the function block is
                                      called, the call will clear the “error” LED on the front
                                      of the CPU.
                                                                                          375
  Function Blocks
                    VAR
                      ClearKOMBit : PS_ClearKOMBit ;
                      CheckKOMBit : PS_Message;
                      StartupDelay : TON ;
                      KOMError   AT%Q0.0.0.0.0 : BOOL;
                    END_VAR
                      CAL StartupDelay( IN := 1,
                                        PT := t#120s )
                      LDN StartupDelay.Q
                      CALC ClearKOMBit(Enable := 1)
                      CAL CheckKOMBit(MessageType := KOM
                                      |
                                      KOMError := Result )
END_PROGRAM
376
                                                                  PS_Diagnostic
                         PS 416         PS_Diagnostic
                                        Read Diagnostic Flags
                                  Meaning of operands
                                  DiagnosticType   Read diagnostic flags using the Moeller enumerated
                                                   data type DIAGNOSTIC_TYPE
                                  Description
                                  When calling the PS_Diagnostic function block, the
                                  diagnostics flag to be monitored must be specified in
                                  DiagnosticType.
                                  DIAGNOSTIC_TYPE is defined as follows:
                                  TYPE DIAGNOSTIC_TYPE:
                                               (   DBM,
                                                   DBC,
                                                   DAK) := DBM;
                                  END_TYPE
                                                                                                377
  Function Blocks
                    VAR
                      CPU_Bat_Test : PS_Diagnostic;
                      MC_Bat_Test : PS_Diagnostic;
                      CPU_Bat_Empty : BOOL;
                      MC_Bat_Empty : BOOL;
                    END_VAR
END_PROGRAM
378
                                                                    PS_GetDateAndTime
                         PS 4-300         PS_GetDateAndTime
                         PS 416           Get Date and Time
                                    Meaning of operands
                                    Item    Scan of real-time clock via Moeller structure
                                            ELEMENT_OF_DATE
                                    CDT     Returns the current date and time from the CPU in the format
                                            of the DT data type
                                    Description
                                    The PS_GetDateAndTime function block is used to
                                    read the real time clock and allows the PLC program
                                    to react to particular time-related events and / or
                                    execute time-dependent routines (e.g. to execute a
                                    particular action at midday).
                                    Item is a VAR_IN_OUT data element. When the
                                    function block is invoked, the date elements are
                                    automatically stored in the structure.
                                    ELEMENT_OF_DATE is defined as follows:
                                    TYPE ELEMENT_OF_DATE:
                                         STRUCT
                                             Millisecond : UINT;
                                             Second : USINT;
                                             Minute : USINT;
                                             Hour : USINT;
                                             Day : USINT;
                                             Month : USINT;
                                             Year : USINT;
06/99 AWB 2700-1306 GB
                                             WeekDay : USINT;
                                         END_STRUCT;
                                    END_TYPE
                                                                                                   379
  Function Blocks
                    VAR
                      RealtimeClock : PS_GetDateAndTime;
                      Date : ELEMENT_OF_DATE
                      Year : USINT;
                      Month : USINT;
                      Day : USINT;
                      DateTime : DT
                    END_VAR
END_PROGRAM
380
                                                                PS_Message
                         PS 416       PS_Message
                                      Read Cycle Status
                                  Meaning of operands
                                  MessageType   Read the cycle flag via the Moeller enumerated data
                                                type MESSAGE_TYPE
                                  Description
                                  The messages and error messages output from a
                                  running PLC program which can be displayed in
                                  Sucosoft S 40 with the “Diagnostics” button in the
                                  “Program Status” window of the “Test and
                                  Commissioning” tool can be read and processed by
                                  the PLC program itself by using the PS_Message
                                  function block. For example, this can be used to
                                  carry out a particular initialisation routine when the
                                  program has just started (i. e. during the first cycle).
                                  The Moeller enumerated data type MESSAGE_TYPE
                                  is defined as follows:
                                  TYPE MESSAGE_TYPE:
                                              ( ICS,
                                                 ISA,
                                                 RTW,
                                                 REC,
                                                 DAKE,
06/99 AWB 2700-1306 GB
                                                 KOM) := ICS;
                                  END_TYPE
                                                                                              381
  Function Blocks
                    VAR
                      Coldstart_Test : PS_Message;
                      RestCycle_Test : PS_Message;
                      Coldstart : BOOL;
                      RestCycle : BOOL;
                    END_VAR
                    END_PROGRAM
                                                                                              06/99 AWB 2700-1306 GB
382
                                                             PS_ReadOSInfo
                                 PS_ReadOSInfo
                                 Read Operating System Information
                             Meaning of operands
                             OSIdentification Operating system identification text
                             Description
                             This function block is used to read the type and
                             version number of the operating system running in
                             the PLC.
                             If the Enable input is set to “1”, the operating system
                             version number is output to “OSVersion” and the
                             operating system identification text is output to
                             “OSIdentification”. The information is still available if
                             the Enable input returns to “0”.
                             The operand “OSIdentification” must be assigned to
                             an IN_OUT variable of type STRING and length 16.
                                                                                     383
  Function Blocks
                    VAR
                      FB_OS_Info : PS_ReadOSInfo;
                      Ident : STRING(16);
                      Enable AT %I0.0.0.0.0 : BOOL;
                      Version: UINT;
                    END_VAR
END_PROGRAM
384
                                                                  PS_SwitchPosition
                         PS 4-300       PS_SwitchPosition
                         PS 416         Read Switch Position
                                    Meaning of operands
                                    Result        Check the position of the operating mode selector
                                                  switch via the Moeller enumerated data type
                                                  SWITCH_POSITION.
                                    Description
                                    The function block PS_SwitchPosition allows the
                                    PLC program to check the status of the operating
                                    mode switch, for example to react to a change in the
                                    switch position in order to output an appropriate
                                    warning.
                                    The data type SWITCH_POSITION is defined as
                                    follows:
                                    TYPE SWITCH_POSITION:
                                                (    RUN,
                                                     RUN_MR,
                                                     HALT) := RUN;
                                    END_TYPE
06/99 AWB 2700-1306 GB
                                                                                                385
  Function Blocks
                      CAL SWITCH
                      LD SWITCH.Result
                      EQ RUN
                      JMPCN _RUN_MR
                      LD 1
                      ST Indicate_RUN
                      LD 0
                      ST Indicate_RUN_MR
                      ST Indicate_HALT
                      JMP _OUT
                    _RUN_MR :
                      LD SWITCH.Result
                      EQ RUN_MR
                      JMPCN _HALT
                      LD 1
                      ST Indicate_RUN_MR
                      LD 0
                      ST Indicate_RUN
                      ST Indicate_HALT
                      JMP _OUT
                    _HALT :
                      LD1
                      ST Indicate_HALT
                      LD 0
                      ST Indicate_RUN
                      ST Indicate_RUN_MR
                    _OUT:
                    END_PROGRAM
                                                                      06/99 AWB 2700-1306 GB
386
                                                                   PSCO
                         PS 4-200         PSCO
                         PS 4-300         Profibus FMS Communication Block
                                    Meaning of operands
                                    Set             Initiate job
                                    Description
                                    The PSCO function block is used for handling
                                    PROFIBUS communication via the LE 4-503-BS1
                                    local expansion module. A function block instance is
                                    used by the PLC program to access objects from the
06/99 AWB 2700-1306 GB
                                    LE 4.
                                    To find out more about possibilities and procedures
                                    in PROFIBUS communication with the LE 4-503-BS1
                                    local expansion module please refer to the manual
                                                                                                    387
  Function Blocks
388
                                                  PSCO
                                                                           389
  Function Blocks
      PS 4-271          PTtoCelsius
                        Linearisation of PT1000 values
PTtoCelsius
                    Meaning of operands
                    InputValue         Value of resistance thermometer
                                       The input can accept the following values including
                                       offset (InputValue + Offset) depending on the
                                       resistance thermometer:
                                       185 (= –200.0 ºC) to 1500 (= 130.5 ºC)
                    Temperature        Limits in ºC
                                       –2000 (= –200.0 ºC) to 1305 (= 130.5 ºC)
                    Description
                    The function block is used in conjunction with the
                    PT1000 input of the PS 4-271-MM1.
                    It linearises the converted value (0 to 1500) of a
                    PT1000 resistance into a temperature value. The
                    method of linearisation conforms to DIN IEC 751 for
                    PT1000 resistances. Since the value stated in the
                    tables is for the PT100 resistance, it is necessary to
                    multiply the value for the PT1000 resistance by 10.
                                                                                              06/99 AWB 2700-1306 GB
390
                                                    PTtoCelsius
                         Example of linearisation
                         PROGRAM boiler_temperature
                         VAR
                           Temperature_sensed AT %IAW0.0.0.8: INT;
                           Offst:             2;
                           Temperature_value:     INT;
                           Err:             BOOL;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                391
  Function Blocks
                        PTtoFahrenheit
                        Linearisation of PT1000 values
PTtoFahrenheit
                    Meaning of operands
                    InputValue         Value of the resistance thermometer
                                       The input can accept the following values including
                                       offset (InputValue + Offset) depending on the
                                       resistance thermometer:
                                       185 (= –328.0 ºF) to 1500 (= 266.8 ºF)
                    Temperature        Limits in ºF
                                       –3280 (= –328.0 ºF) to 2668 (= 266.8 ºF)
                    Description
                    The function block is used in conjunction with the
                    PT1000 input of the PS 4-271-MM1.
                    It linearises the converted value (0 to 1500) of a
                    PT1000 resistance into a temperature value. The
                    process of linearisation conforms to DIN IEC 751 for
                    PT1000 resistances. Since the value stated in the
                    tables is for the PT100 resistor, it is necessary to
                    multiply the value for the PT1000 resistance by 10.
                                                                                              06/99 AWB 2700-1306 GB
392
                                                   PTtoFahrenheit
                         Example: Linearisation
                         PROGRAM boiler_temperature
                         VAR
                           Temperature_sensed AT %IAW0.0.0.8: INT;
                           Offst:             2;
                           Temperature_value:     INT;
                           Err:             BOOL;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                            393
  Function Blocks
                          R_TRIG
                          Edge Detection, Rising Edge
                    Description
                    The function block R_TRIG evaluates the status of
                    the input operand “CLK”. It detects the status
                    change from “0” in a processing cycle to “1” in the
                    subsequent cycle and indicates this on the output
                    “Q” with the Boolean value “1”. The output is only set
                    to “1” during the processing cycle in which the
                    change of the status of “CLK” and a rising edge was
                    detected.
394
                                                                    ReadAnalogDirect
                         PS 416          ReadAnalogDirect
                                         Direct Reading of Analog Inputs
                                  Meaning of operands
                                  Slot             Slot for an analog card in the basic unit (4..20)
                                  Description:
                                  The ReadAnalogDirect function block allows direct
                                  reading of analog input channels in the PS 416 basic
                                  unit.
                                  The data is not read from the inputs at the start of
                                  the cycle but directly during the current cycle. This
                                  function block therefore allows a fast and direct
                                  response to events such as required in alarm
                                  routines. The maximum on/off delay of the analog
                                  cards for the controller should be taken into account
                                  when using this function block.
06/99 AWB 2700-1306 GB
                                                                                                       395
  Function Blocks
396
                                                                                 ReadAnalogDirect
                                                                                                    397
  Function Blocks
      PS 416               ReadCounterDirect
                           Direct Reading of Counter Inputs
                    Meaning of operands
                    Slot            Slot for a counter card in the basic unit
                    CountValues     Contains the current values after the call for the
                                    channel required
                    Description:
                    The ReadCounterDirect function block allows direct
                    reading of the counter channels in the basic unit of
                    the PS 416.
                    The data is not read from the inputs at the start of the
                    cycle but directly during the current cycle. This
                    function block therefore allows a fast and direct
                    response to events such as required in alarm
                    routines. The maximum on/off delay of the analog
                    cards for the controller should be taken into account
                    when using this function block.
                    The Slot input specifies the slot in which the PS 416
                                                                                         06/99 AWB 2700-1306 GB
398
                                                  ReadCounterDirect
                                                                         399
  Function Blocks
400
                                                                 ReadDirect
                         PS 416       ReadDirect
                                      Direct Reading of Digital Inputs
                                  Meaning of operands
                                  Mode           Access mode
                                  Description:
                                  The ReadDirect function block allows direct read
                                  access to digital input cards in the basic rack of the
                                  PS 416. The data is read directly from the inputs
                                  during the user program cycle rather than at the start
                                  of the cycle. This function block can thus be used for
                                  fast and direct reactions to events, e. g. in alarm
                                  routines. When using this function block, observe the
                                  maximum on/off delay of the digital I/O cards for the
06/99 AWB 2700-1306 GB
PS 416 system.
                                                                                              401
  Function Blocks
402
                                                                                  ReadDirect
                                                                                                    403
  Function Blocks
                            ReadMC
                            Read Data from Memory Card
                    Meaning of operands
                    DestinationAddress   Buffer for data to be read
                    Strobe               Start transfer
                    SegmentNumber        Source segment number (0 – n)
                    DataLength           Number of data bytes of type USINT to be read
                    Active               Data read operation active
                    MaxSegmentNumber Highest possible segment number in the file
                    Error                Error code
                    Description
                    The ReadMC function block allows data to be read
                    from the PLC's memory card (MC). Together with the
                    WriteMC function block, important applications of
                    this function block are data backup, process data
                    acquisition, saving recipe data and / or saving
                    variables before a program update.
404
                                                  ReadMC
                                                                           405
  Function Blocks
406
                                                                                  ReadMC
                                                                                                407
  Function Blocks
      PS 4-300          Real_To_IEEE
      PS 416            Conversion of numbers of data type REAL into
                        IEEE 754 standard format
Real_To_IEEE
                    Meaning of operands
                    Real_In                Real number to be converted
                    EXPO_Out               IEEE floating-point number: exponent (inc. sign)
                    Mant_2_Out             IEEE floating-point number: mantissa byte 2
                                           (inc. 1 bit exponent)
                    Mant_1_Out             IEEE floating-point number: mantissa byte 1
                    Mant_0_Out             IEEE floating-point number: mantissa byte 0
                    Description
                    The function block Real_To_IEEE converts a number
                    of data type REAL into an IEEE floating-point
                    number.
                    To represent the floating-point number, four bytes
                    (32 bit) are needed. The format used conforms to the
                    IEEE 754 standard format (32 bit):
PROFIBUS).
408
                                                       RealTimeClock
                               RealTimeClock
                               Compare With Real-Time Clock
                         Meaning of operands
                         Set           Enable signal for comparing the time of the PLCs
                                       real-time clock with the input values
                                                    Friday,
                                                    Saturday ) := Monday;
                                       END_TYPE
                                                                                      409
  Function Blocks
                    RealDate       Date (day and month) that is compared with the PLCs
                                   real-time clock. This is a constant that is entered
                                   during programming and is not changed while the
                                   program is running.
                    Description
                    The function block compares the current status of
                    the real time clock with the specified values “tREF”,
                    that are entered via input operands. Two different
                    types of comparison are possible.
                                                                                             06/99 AWB 2700-1306 GB
410
                                                RealTimeClock
Example 1:
                                                                        411
  Function Blocks
Example 2:
412
                                                   RealTimeClock
                         VAR
                           Time : RealTimeClock;
                           Clock_free : BOOL;
                           Time : TIME_OF_DAY := TOD#12:00:00;
                           Date : DATE := D#1996-12-12;
                           Midday AT %Q0.0.0.0.0 : BOOL;
                         END_VAR
                             .
                             .
                           CAL Time(Set := Clock_free,
                                    RealTime := Time,
                                    RealDate := Date
                                    WeekDay := Monday)
                           LD Time.Equal
                           ST Midday
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                   413
  Function Blocks
      PS 4-200               ReloadData
      PS 4-300               Read Data From Memory Card
                      Meaning of operands
                    Strobe               Start transfer
                      Description
                      The ReloadData function block is used to read data
                      from the PLC's memory card and store it in a marker
                      area in the PLC memory.
                      The memory card is logically divided into 512
                      segments of 128 bytes each. The function block can
                      read up to 128 bytes with one invocation.
                      An important application of this function block is to
                                                                                          06/99 AWB 2700-1306 GB
414
                                                       ReloadData
                                                                                415
  Function Blocks
   LD   ReadData.Error
   ST   ErrorMessage
   NE   0 (*If content not equal to 0, then error *)
   JMPC ErrorEvaluation
    .
    .
   ErrorEvaluation:
    .
    .
END_PROGRAM
416
                                                       RS
                               RS
                               Flip Flop With Reset Dominant
                         Meaning of operands
                         SET             Set condition
                         Description
                         The characteristic feature of the “RS” function block
                         is to statically set a data element – the output “Q1” –
                         to the Boolean status “1” or “0”. Switching between
                         the two states is controlled by the Boolean input
                         operands “SET1” and “RESET1”.
                         The output “Q1” is initialised with the value “0” when
                         starting the process. The first processing of the
                         function block with the value “1” of the operand
                         “SET” causes the output “Q1” to be set to “1”.
                         A change of the value of “SET” no longer then effects
                         the output “Q1”. The value “1” of the input operand
                         “RESET1” sets the output “Q1” to “0” – the output is
                         reset.
                         If both input operands have the value “1”, the fulfilled
                         set condition is dominant, i. e. Q1 is reset with
                         priority.
06/99 AWB 2700-1306 GB
                                                                                417
  Function Blocks
                    VAR
                      Valve1 : RS;
                      Position AT %I0.0.0.0.0 : BOOL;
                      Barrel_Full AT %I0.0.0.0.1 : BOOL;
                      Halt AT %I0.0.0.0.2 : BOOL;
                      Valve1_Shut : BOOL;
                      Valve1_Open_Shut AT %Q0.0.0.0.3 : BOOL;
                    END_VAR
                      LD Barrel_Full
                      OR Halt
                      ST Valve1_Shut
                      CAL Valve1(SET := Position,
                                 RESET1 := Valve1_Shut)
                      LD Valve1.Q1
                      ST Valve1_Open_Shut
END_PROGRAM
418
                                                         RTC
                               RTC
                               Set Real-Time Clock
                         Meaning of operands
                         EN              Set condition
                         Description
                         The manipulated value Date and Time specified with
                         the operand PDT is transferred to the real-time clock
                         with the rising edge of the operand EN. The output
                         operand “Q” indicates the validity of CDT.
                         The current clock state is output via the operand CDT
                         independent of the state of “EN”.
06/99 AWB 2700-1306 GB
                                                                                       419
  Function Blocks
                    VAR
                      Set_Clock : RTC;
                      Set_Input AT %I0.0.0.0.0 : BOOL;
                      Date_and_Time: DATE_AND_TIME := DT#1995-01-
                                       01-00:00:00;
                      Clock_Set : BOOL;
                      Clock_Status : DATE_AND_TIME;
                    END_VAR
END_PROGRAM
420
                                                       S_TimeFalling
                               S_TimeFalling
                               Off-Delay Timer, Seconds
                         Meaning of operands
                         Set             Start condition, rising edge
                                                                        421
  Function Blocks
Description
Time diagram
delayed status 1.
422
                                                   S_TimeFalling
                         VAR
                           Timer2 : S_TimeFalling;
                           Start AT %I0.0.0.0.0 : BOOL;
                           Halt AT %I0.0.0.0.1 : BOOL;
                           TimeValue2 : UINT:= 32;
                           (* TimeValue2 = 32 seconds *)
                           Output2 AT %Q0.0.0.0.0 : BOOL;
                           ActTime2 AT %QW0.0.0.2 : UINT;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                           423
  Function Blocks
                          S_TimeRising
                          On-Delay Timer, Seconds
                    Meaning of operands
                    Set             Start condition, rising edge
424
                                                   S_TimeRising
Description
Time diagram
                                                                             425
  Function Blocks
                    VAR
                      Timer1 : S_TimeRising;
                      Start AT %I0.0.0.0.0 : BOOL;
                      Halt AT %I0.0.0.0.1 : BOOL;
                      TimeValue1 : UINT := 12;
                                (* TimeValue1 = 12 seconds *)
                      Output1 AT %Q0.0.0.0.0 : BOOL;
                    END_VAR
                    END_PROGRAM
                                                                                 06/99 AWB 2700-1306 GB
426
                                                                           SaveData
                         PS 4-200                SaveData
                         PS 4-300                Save Data on Memory Card
                                             Meaning of operands
                                    Strobe                 Start save operation
                                    SegmentNumber          Segment number (0 – n)
                                    DataLength             Number of data bytes of type USINT to be stored,
                                                           range of values: 1 – 128
                                    SourceAddress          Start address of the data area to be saved
                                    Active                 Data save operation active
                                    MaxSegmentNumber       Highest segment number in the file
                                    Error                  Error code
                                             Description
                                             The SaveData function block allows data to be saved
                                             to the PLC's memory card. The memory card is
                                             logically divided into 512 segments of 128 bytes
                                             each. The function block can transfer up to 128 bytes
                                             to the memory card.
                                             An important application of this function block is to
                                             save the retentive marker area (the recipe range that
                                             was specified in the compiler configuration during
                                             code generation) and to read it back again with
06/99 AWB 2700-1306 GB
                                                                                                         427
  Function Blocks
428
                                                   SaveData
                         VAR
                           SendData : SaveData;
                           Start AT %I0.0.0.0.2 : BOOL;
                           Mem_start AT %MB0.0.0.100 : BYTE;
                           Segment_NR : UINT;
                           DataLength : USINT;
                           ErrorMessage : USINT;
                         END_VAR
                           LD    SendData.Error
                           ST    ErrorMessage
                           NE    0 (*If content not equal then error*)
                           JMPC ErrorEvaluation
                            .
                            .
                           ErrorEvaluation:
                            .
                            .
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                         429
  Function Blocks
      PS 4-200                       SCO
      PS 4-300                       Serial Communication Function Block:
SCO
                         BOOL          Strobe
                         USINT       Command                                      Busy          BOOL
                         USINT       CardAddress                         ElementNumber          USINT
                    ADDRESS          MemoryAddress                                Error         USINT
                         USINT       DataSize
                    tBaudrate        Baudrate**
                     tSTOPBIT        StopBits*
                       tPARITY       Parity*
                                 Meaning of operands
                                 Strobe          Initiate job (rising edge)
                                 Command         Job type
                                 CardAddress     Interface selection (0 = RS 232, 1 = RS 485)
                                 MemoryAddress   Start address of send or receive range
                                 DataSize        Size of send or receive data
                                 Busy            Function block status
                                 ElementNumber   Number of data bytes sent/received
                                 Error           Error messages
                                 Baudrate*       Transfer speed,
                                                 Default: 9600 Baud
                                 StopBit         Number of stopbits, Default: 1
                                 Parity          Transmission parity, Default: without
                                                                                                        06/99 AWB 2700-1306 GB
430
                                                   SCO
                         Description
                         The SCO function block allows transparent
                         communication between the user program and the
                         connected data terminals via the RS 232 and RS 485
                         interfaces of the PLC.
                         The function block can control send operations and
                         (non-simultaneously) receive operations. Since the
                         transfer is executed in half-duplex mode,
                         simultaneous sending and receiving is not possible.
                         A send job has priority over a receive job.
                         The SCO function block must be called twice for
                         communication using both the RS 232 and RS 485
                         interfaces simultaneously: once for operating the
                         RS 232 interface and once for operating the RS 485
                         interface. For ease of operation it is advisable to
                         create a separate function block instance for each
                         interface.
                         There are no retentive settings for the function block.
                         No CTS/RTS handshake lines are used.
                         The Strobe input is edge-triggered. A change from 0
                         to 1 or from FALSE to TRUE starts the job specified
                         via the Command input. All input parameters of the
                         function block are saved with the Strobe signal.
                         If the Strobe input triggers a send job or readiness to
                         receive, this is indicated at the Busy output by a 1.
                         The Busy output shows the active status of the
                         function block. Readiness to receive can be stopped
                         with a falling edge on the Strobe input.
                         The response of the SCO function block to a
                         communication abort depends on the interface used.
06/99 AWB 2700-1306 GB
                                                                            431
  Function Blocks
432
                                                        SCO
                                                                                  433
  Function Blocks
434
                                                  SCO
                                                                          435
  Function Blocks
                    Interface settings
                    The RS 232 and RS485 interfaces are available for
                    operating the SCO function block.
                    The RS 232 interface parameters for the PS 4-300
                    are set via the SCO inputs tBaudrate, tStopBits and
                    tParity.
                    PS 4-200 communication via the RS232 interface is
                    done with the fixed transfer parameters: baud rate
                    9600 Baud, 8 Data bit, 1 Stop bit without parity
                    check. Up to 63 bytes can be transferred..
                    The RS 485 interface is assigned with parameters via
                    the Sucosoft S 40 Topology Configurator. For this
                    choose Edit->Parameters, select Transparent mode
                    and click the Interface Parameters button. The
                    permissible data volume that can be transferred is
                    between one and 127 bytes.
                    Impermissible combinations are detected by the
                    software and are not accepted.
                    The application of the SCO function block will be
                    demonstrated in the following example.
                    Communication PLC <-> Terminal
                        Data communication between a PLC and a
                        terminal
                                                                           06/99 AWB 2700-1306 GB
436
                                                  SCO
                                                                            437
  Function Blocks
                    Function
                    The data exchange between the controller and the
                    terminal is carried out via the program SCO_BSP1.
                    Send
                    Input %I0.0.0.0.3 is used to set the required
                    interface. Set 1 for the RS 485 interface.
                    Input %I0.0.0.0.4 is used to select between text 1
                    and text 2:
                    %I0.0.0.0.4 = 1On condition 1 fulfilled
                    %I0.0.0.0.4 = 0Limit switch 2 reached.
                    The bytes to be sent are located in the memory from
                    marker byte 200. The address of this marker byte is
                    automatically sent to the MemoryAddress input.
                    The DataSize input is automatically set according to
                    the text selected.
                    The Command input is automatically set to mode 1
                    (send).
                    A rising edge at input %I0.0.0.0.0 sends the text to
                    the terminal.
438
                                                       SCO
                         
                             Receive
                               For receive operations use the same interface
                               settings as for send operations.
                                                                                439
  Function Blocks
440
                                                                                   SCO
PROGRAM SCO_BSP1
                         VAR
                            (* Directly represented variables *)
                         Send_Strobe             : BOOL AT %I0.0.0.0.0;
                         Rcve_Strobe             : BOOL AT %I0.0.0.0.1;
                         Changeover_Strobe       : BOOL AT %I0.0.0.0.2;
                         PRG_SBI                 : BOOL AT %I0.0.0.0.3; (* 0 = RS232; 1 = RS485 *)
                         SendText_No             : BOOL AT %I0.0.0.0.4; (* 0 = Text1; 1 = Text2 *)
                         SCO_outputs             : BYTE AT %QB0.0.0.0;
                         (*Indication: Receive volume if Bit7=0, Error message if Bit7=1*)
                         Send_active              : BOOL;
                         Rcve_active              : BOOL;
                         Changeover_active        : BOOL;
                         Receive_No: USINT := 16;     (* 16 Char. for example *)
                         (* FB instances *)
                         CommunicationFB         : SCO;              (*SCO instance for send/receive*)
                         Send_converter          : STRtoADR;
                         Rcve_converter          : ADRtoSTR;
                         END_VAR
                         LD Changeover_active
                         JMPCChangeover_Scan     (*Changeover job in progress*)
                         LD Changeover_Strobe
                         JMPCChangeover_Job      (*Changeover to Sucom mode *)
                                                                                                         441
     Function Blocks
LD Rcve_active
JMPCRcve_Scan             (* Receive job in progress *)
LD Send_active
JMPCSende_Scan            (* Send job in progress *)
LD Rcve_Strobe
ANDNSend_Strobe           (* Send and receive not at same time *)
JMPCRcve_Job              (* Start receive job *)
LD Send_Strobe
ANDNRcve_Strobe
JMPCSend_ Job
LD 0
ST CommunicationFB.Strobe
JMPSCO_Call
TextConvert:
CALSend_converter(        Enable             := 1,
                                             TextString:= Text,
                                             TransmitVariable:= &Send_buffer
                                                                               06/99 AWB 2700-1306 GB
LD Send_converter.StrLen
UINT_TO_USINT
ST CommunicationFB.DataSize(* Parameter transfer to SCO FB*)
442
                                                                                   SCO
                         LD   1
                         ST   CommunicationFB.Command(* Send Mode *)
                         LD   &Send_buffer
                         ST   CommunicationFB.MemoryAddress
                         LD   1
                         ST   CommunicationFB.Strobe                   (* Send*)
                         LD CommunicationFB.Error
                         NE 0
                         JMPCCommunication_Error
                         LD CommunicationFB.Busy
                         ST Send_active
                         Send_Scan:
                         LD CommunicationFB.Busy
                         JMPCNSend_Mark
                         LD 0
                         ST CommunicationFB.Strobe
                         (* Send job in progress, complete job *)
                         JMPSCO_call
                         Send_Mark:
                         LD Send_Strobe
                         (* New send job should not be possible until after edge change *)
                         JMPCEnd
                         LD 0
                         ST Send_active
                         JMPEnd
                         Rcv_Scan:
                         LD Receive_No
                         ST CommunicationFB.DataSize(*Receive job, 16 Char. *)
                         LD 2
                         ST CommunicationFB.Command(* Receive mode *)
                                                                                             443
     Function Blocks
LD   &Receive_buffer
ST   CommunicationFB.MemoryAddress
LD   1
ST   CommunicationFB.Strobe(* Receive *)
LD CommunicationFB.Error
NE 0
JMPCCommunication_Error
LD CommunicationFB.Busy
ST Rcve_active
LD CommunicationFB.ElementNumber
USINT_TO_BYTE
ST SCO_outputs
LD 0
ST CommunicationFB.Strobe
ST Rcve_active
(* Receive job in progress, Complete job *)
JMPEnd
Communication_Error:
LD CommunicationFB.Error
USINT_TO_BYTE
                                                                                      06/99 AWB 2700-1306 GB
444
                                                                                 SCO
                         Changeover_Scan:
                         LDN Send_Strobe
                         ANDN    Rcve_Strobe
                         ANDNChangeover_Strobe
                         (*New send / receive job not possible until after edge change *)
                         JMPCNEnd
                         LD   0
                         ST   Send_active
                         ST   Rcve_active
                         ST   Changeover_active
                         ST   CommunicationFB.Strobe
                         SCO_call:
                         CAL CommunicationFB                        (* SCO call *)
                         End:
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                            445
  Function Blocks
      PS 4-300          SendATCommand
      PS 416            Send AT Commands to a Modem
                    Meaning of operands
                    ATCommand      AT command to send to modem (max. 254 bytes)
446
                                                        SendATCommand
                         Description
                         The SendATCommand function block is used to
                         send AT commands to a modem which is attached to
                         one of the following PLC interfaces
                             CPU 400/300/200-PRG interface,
                             CPU 400/300-SBI interface or
                             PS 4-341-MM1-SBI/PRG interface
                             COM-200 interface.
                         To allow the PLC and modem to communicate with
                         each other, the interface parameters baud rate, stop
                         bits, parity and data bits should be set to the same
                         values on the PLC and the modem. Refer to your
                         modem manual for information on setting the
                         modem interface parameters.
                         The SendATCommand function block controls the
                         TxD (transmit data) and RxD (receive data) lines.
                         Control lines are not supported.
                         Before sending an AT command, you must set
                         parameters for the CPU PRG interface. You must
                         specify the baud rate, stop bits and parity with the
                         following data types. The number of data bits is
06/99 AWB 2700-1306 GB
always 8.
                                                                                 447
  Function Blocks
                    TYPE tBAUDRATE:
                           ( Baud_2400,
                             Baud_4800,
                             Baud_9600,
                             Baud_19200,
                             Baud_38400,
                             Baud_57600 ):=Baud_9600;
                    END_TYPE
                    TYPE tSTOPBIT:
                           ( ONE_Stop_Bit,
                             TWO_Stop_Bits) := ONE_Stop_Bit;
                    END_TYPE
                    TYPE tPARITY:
                          ( NONE_Parity,
                             ODD_Parity,
                             EVEN_Parity ):=NONE_Parity;
                    END_TYPE
448
                                                       SendATCommand
                                                                                  449
  Function Blocks
450
                                                                              SendATCommand
                                           
                                                         error
                                                         The function block automatically configures the
                                                         modem as follows
                                                         – Modem result codes on,
                                                         – Modem result codes plain text on
                                                         – Modem command echo off.
                                                         Other function blocks can also be used to access
                                                         the COM or SBI interface. Conflicts can occur if
                                                         several function blocks try to access the same
                                                         interface. If necessary, the user program should
                                                         include interlocks to make sure that this cannot
                                                         happen.
                                                                                                     451
  Function Blocks
452
                                                       Serialize
                             Serialize
                             Copy Data Structure to Array
                         Meaning of operands
                         Source           Source variable
                         Description
                         The Serialize function block copies any required data
                         type to a destination area at a starting position
                         specified by “Buffer + Bufferoffset”. The data can
                         then be sent, for example as an array to another PLC
                         and then unpacked with the Deserialize function
                         block.
                         The SourceLength output specifies the length of the
                         source data type in bytes.
                         Buffer is an ARRAY OF BYTE, ARRAY OF USINT or
                         ARRAY OF SINT of any required size.
06/99 AWB 2700-1306 GB
                                                                               453
  Function Blocks
                    VAR
                      serie_fb : Serialize;
                      struct_buffer AT %SDB1.1.0.0 :
                                            ARRAY [1..30] OF BYTE;
                      CheckSumOffset : UINT := 0;
                      CheckSum : UINT;
                      DTOffset : UINT := 2;
                      TransDate : DT;          (* Send date *)
                      DataOffset: UINT := 10;
                      TransmitData : Array [1..20] OF BYTE;
                                                (* User data *)
                                                                               06/99 AWB 2700-1306 GB
                      SerializedLength : UINT;
                      Error : USINT;
                    END_VAR
454
                                                     Serialize
                           LD serie_fb.Error
                           USINT_TO_BOOL             (* Any error ? *)
                           JMPC _Fail                  (* Error handling *)
                           LD serie_fb.Error
                           USINT_TO_BOOL             (* Any Error ? *)
                           JMPC _Fail                 (* Error handling   *)
                                                                               455
  Function Blocks
      PS 416            SetMCFileLength
                        Create and Initialise Data File
                    Meaning of operands
                    Strobe             Create file RSDAT.DAT
                    Description:
                    The SetMCFileLength function block creates the file
                    RSDAT.DAT on an SRAM memory card (MC).
                    The number of 128 byte data segments is specified
                    with NumberOfSegments and is only limited by the
                    capacity of the memory card used. The following
                    maximum values apply if the memory card is
                    formatted with a PS 416:
                                                                                         06/99 AWB 2700-1306 GB
456
                                                   SetMCFileLength
block
                                                                            457
  Function Blocks
458
                                                                  SetRealTimeClock
                         PS 4-200         SetRealTimeClock
                         PS 4-300         Set Real-Time Clock
                                    Meaning of operands
                                    Set             Enable for accepting the set values, rising edge
                                    Description
                                    A rising edge at the Set input sets the real-time clock
                                    with the values stored in the DataAddress data
                                    range. The set or default values are provided in seven
                                    consecutive byte data elements. The bytes are in the
                                    order year, month, day, weekday, hours, minutes
                                    and seconds.
                                    A rising edge at the Set input causes all values to be
                                    transferred, but not, however, selected data such as
                                    only hour or year.
                                    The data type declared for the data elements in
                                    which the set values are stored must be in byte
                                    format, i. e. data types BYTE, SINT or USINT.
                                    Using data type USINT is recommended.
06/99 AWB 2700-1306 GB
                                                                                                  459
  Function Blocks
460
                                                    SetRealTimeClock
                         VAR
                           Year AT %MB0.0.0.0 : USINT := 97;
                           Month AT %MB0.0.0.1 : USINT := 1;
                           Day AT %MB0.0.0.2 : USINT := 1;
                           Weekday AT %MB0.0.0.3 : USINT := 2;
                               (* 2 = Tuesday*)
                           Hour AT %MB0.0.0.4 : USINT := 12;
                           Minute AT %MB0.0.0.5 : USINT;
                           Second AT %MB0.0.0.6 : USINT;
                               (* Default value
                                  Tuesday, 1.1.1997 12.00h *)
                           Set_time : SetRealTimeClock;
                               (* Function block declaration *)
                           Set : BOOL AT %I0.0.0.0.0;
                               (* Declare set input*)
                         END_VAR
                          LD   98
                          ST   Year      (* Set year to 1998 *)
                          LD   9
                          ST   Month     (* Set month to September *)
                          LD   12
                          ST   Day       (* Set day to the 12th *)
                          LD   6
                          ST   Weekday  (* Set weekday to Saturday *)
                                        (* Clock is completely reset
                                           via function block *)
                           (*CAUTION: 12.00 is used as default setting *)
                           CAL Set_time (Set := Set,
                                               DataAddress := &Year)
                           LD   Set_time.Error
                           NE   0        (* Scan for no errors *)
                           JMPC Error evaluation
                            .
                            .
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                            461
  Function Blocks
      PS 4-200            Sfc_x
      PS 4-300            Sequence Control Function Block
                          (x = 1..128)
                    Meaning of operands
                    Set                Activate the sequential control function block
                    Description
                                                                                        06/99 AWB 2700-1306 GB
462
                                                      Sfc_x
                                                                               463
  Function Blocks
                    executed.
                    The Error output indicates the error code (further
                    information below).
                    The StepOutputNumber output shows the number of
                    the current step.
                    The StepToggle output shows the step transition.
                    Normally this output is 1 or TRUE; only in the first
                    cycle after a transition is the output assigned a 0 or
                    FALSE.
                    Program sequence with the SFC_x function block
                    The use of the sequential control function block
                    involves the following three program stages:
                    1. Initialising the sequential control function block
                    2. Processing the sequential control function block
                    3. Processing status signals of the sequential
                       control function block
                    1. Initialising
                    The StepInputNumber input specifies which step
                    should be edited. Before calling the sequence for the
                    first time, the number of the first step to be
                    processed should be assigned.
                    The sequential control function block is initialised
                    with the Init function block. It is called for as long as
                    the ReSet input is 1.
                    To implement an automatic initialisation with the Init
                    function block use the status bit of the PLC for
                    marking the first cycle. This will set the Reset input
                    to 1 or TRUE during the first cycle.
                    The Init function block assigns the StepInputNumber
                                                                                06/99 AWB 2700-1306 GB
464
                                                   Sfc_x
                         VAR_GLOBAL
                           StepNumber : USINT ;
                           BasicSetting AT %I0.0.0.0.0 : BOOL ;
                           SafetyDoorClosed AT %I0.0.0.0.1 : BOOL ;
                         END_VAR
                         VAR
                           sequence : SFC_3 ;
                           First_Cycle : BOOL ;
                           Initial : Init_FB ;
                           fill : FB1 ;
                           heat : FB2 ;
                           drain : FB3 ;
                         END_VAR
                           LD ISA
                           PLC_Message
                           ST First_Cycle
                           CAL sequence (Set := TRUE,
                                          ReSet := First_Cycle,
                                          StepInputNumber := StepNumber,
                                          InitStep := Initial,
                                          Step_1 := fill,
                                          Step_2 := heat,
                                          Step_3 := drain
                                          |
                                          :=Error,
                                          :=StepOutputNumber,
                                          :=StepToggle)
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                             465
  Function Blocks
                    FUNCTION_BLOCK Init_FB
                    VAR_EXTERNAL
                      StepNumber : USINT ;
                      BasicSetting : BOOL ;
                      SafetyDoorClosed : BOOL ;
                    END_VAR
                      LD   BasicSetting
                      AND SafetyDoorClosed
                      (* If safety not fulfilled then return to
                         to program.
                       The StepInputNumber = 0 => neutral*)
                      RETCN
                      LD   1     (* Step 1 "fill is defined
                                  as first step *)
                      ST   StepNumber
                    END_FUNCTION_BLOCK
                    2. Processing
                    In order to activate the function block the Set input
                    must be 1 or TRUE. This activates simultaneously the
                    step that is defined at the StepInputNumber input. If
                    the Set and ReSet inputs are set to 1 at the same
                    time, only the initialisation function block is
                    processed. In the following examples, the Set input
                    is permanently set to TRUE. The logical sequences
                    before the RETC or RETCN commands are
                    transitions that can be selected as required Step
                    enabling conditions (=transitions).
                    The sequential control function block can call several
                    actions. These actions are active for as long as the
                    transition condition at the end of the step concerned
                    is fulfilled. If the transition condition is fulfilled the
                    StepInputNumber input is assigned the number of
                    the next step to be processed. In the following cycle
                    the new step is automatically activated and the old
                    one deactivated.
                                                                                 06/99 AWB 2700-1306 GB
466
                                                   Sfc_x
                         VAR_GLOBAL
                           StepNumber : USINT ;
                           BasicSetting AT %I0.0.0.0.0 : BOOL ;
                           SafetyDoor_closed AT %I0.0.0.0.1 : BOOL ;
                           OFF AT %I0.0.0.0.2 : BOOL ;
                           Boiler_full AT %I0.0.0.0.3 : BOOL ;
                           Temperature_reached AT %I0.0.0.0.4 : BOOL ;
                           Valve_open AT %Q0.0.0.0.0 : BOOL ;
                           Heating_on AT %Q0.0.0.0.1 : BOOL ;
                         END_VAR
                         VAR
                           sequence : SFC_3 ;
                           First_cycle : BOOL ;
                           Initial : Init_FB ;
                           fill : FB1 ;
                           heat : FB2 ;
                           drain : FB3 ;
                         END_VAR
                           LD ISA
                           PLC_Message
                           ST First_cycle
                           CAL sequence(Set := TRUE,
                                        ReSet := First_cycle,
                                        StepInputNumber := Schrittnummer,
                                        InitStep := Initial,
                                        Step_1 := fill,
                                        Step_2 := heat,
                                        Step_3 := drain
                                        |
                                        :=Error,
                                        :=StepOutputNumber,
                                        :=StepToggle)
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                            467
  Function Blocks
FUNCTION_BLOCK FB1
                    VAR_EXTERNAL
                      StepNumber : USINT ;
                      OFF : BOOL ;
                      Boiler_full : BOOL ;
                      Valve_open : BOOL ;
                    END_VAR
                      LD     Boiler_full
                      OR     OFF
                      RETC
                      LD     TRUE
                      S      Valve_open
                      LD     2 (*Step "2" heat is defined as next
                                 step*)
                      ST     StepNumber
END_FUNCTION_BLOCK
FUNCTION_BLOCK FB2
                    VAR_EXTERNAL
                      StepNumber : USINT ;
                      OFF : BOOL ;
                      Heating_on : BOOL ;
                      Temperature_reached : BOOL ;
                      Boiler_full : BOOL ;
                      Valve_open : BOOL ;
                    END_VAR
                      LD     Boiler_full
                      OR     OFF
                      OR     Temperature_reached
                      RETC
                      LD     TRUE
                      R      Valve_open
                      S      Heating_on
                      LD     3 (* Step 3 "drain" is defined as next
                                  step *)
                      ST     StepNumber
                    END_FUNCTION_BLOCK
                                                                      06/99 AWB 2700-1306 GB
468
                                                   Sfc_x
                                                                            469
  Function Blocks
                    3. Status indication
                    Various status outputs are provided for monitoring a
                    step sequence. Error output indicates the following
                    error codes during processing:
                    Error     Cause of error          Error behaviour
                    number
                    1         0 present at the        Function block is not active No
                              StepInput number        step processed.
                              input (when Set = 1).
                    2         Step number entered     Error output set. The function
                              exceeds maximum         block stays in the current status.
                              permissible number of
                              steps.
                    4         No function block     Error output set. The selected
                              name at the parameter step is accepted. No processing
                              of the selected step  present since no step function
                                                    block entered.
470
                                                  Sfc_x
                                                                           471
  Function Blocks
472
                                                  Sfc_x
                                                                           473
  Function Blocks
PROGRAM linear
                    VAR_GLOBAL
                      Sequence : SFC_4 ;
                      Init : Init_FB ;
                      FB_Start : Start_FB ;
                      Motor_on : MotonFB ;
                      Motor_off : MotoffFB ;
                      Valve_closed : VentClFB ;
                      First_cycle : BOOL ;
                      StepNumber : USINT ;
                      Start AT %I0.0.0.0.0 : BOOL ;
                      LightBarrier AT %I0.0.0.0.1 : BOOL ;
                      Quantity AT %I0.0.0.0.2 : BOOL ;
                      Flow AT %I0.0.0.0.3 : BOOL ;
                      Motor AT %Q0.0.0.0.0 : BOOL ;
                      FillingValve AT %Q0.0.0.0.1 : BOOL ;
                    END_VAR
                      LD ISA
                      PLC_Message
                      ST First_cycle
                      CAL Sequence(Set := TRUE,
                                   ReSet := First_cycle,
                                   StepInputNumber := StepNumber,
                                   InitStep := Init,
                                   Step_1 := FB_Start,
                                   Step_2 := Motor_on,
                                   Step_3 := Motor_off,
                                   Step_4 := Valve_closed)
END_PROGRAM
FUNCTION_BLOCK Init_FB
                    VAR_EXTERNAL
                      StepNumber : USINT ;
                    END_VAR
                      LD   1
                      ST   StepNumber
END_FUNCTION_BLOCK
474
                                                    Sfc_x
FUNCTION_BLOCK Start_FB
                         VAR_EXTERNAL
                           Start : BOOL ;
                           StepNumber : USINT ;
                         END_VAR
                           LD   Start
                           RETCN   (* Return to main program
                                      if start button not pressed *)
                           LD    2 (* otherwise move to step two *)
                           ST   StepNumber
END_FUNCTION_BLOCK
FUNCTION_BLOCK MotonFB
                         VAR_EXTERNAL
                           LightBarrier : BOOL ;
                           Motor : BOOL ;
                           StepNumber : USINT ;
                         END_VAR
                           LD     TRUE
                           ST     Motor (* Conveyor motor switched on *)
                           LD     LightBarrier
                         END_FUNCTION_BLOCK
06/99 AWB 2700-1306 GB
                                                                           475
  Function Blocks
FUNCTION_BLOCK MotoffFB
                    VAR_EXTERNAL
                      Motor : BOOL ;
                      Quantity : BOOL ;
                      FillingValve : BOOL ;
                      StepNumber : USINT ;
                    END_VAR
END_FUNCTION_BLOCK
                    FUNCTION_BLOCK ValveClFB
                    VAR_EXTERNAL
                      Flow : BOOL ;
                      FillingValve : BOOL ;
                      StepNumber : USINT ;
                    END_VAR
                      LD    FALSE
                      ST    FillingValve (*Valve closed *)
                      LD    Flow
                      RETC                  (*When flow really 0 then
                                              step 2 again*)
                      LD    2
                      ST    StepNumber
                    END_FUNCTION_BLOCK
                                                                        06/99 AWB 2700-1306 GB
476
                                                   Sfc_x
                         Example: OR Sequence
                         Red or blue paint is to be filled alternately.
                         A selector can be used to select either the red or blue
                         containers.
                                                                            477
  Function Blocks
PROGRAM or1
                    VAR_GLOBAL
                      Sequence : SFC_4 ;
                      Init : Init_FB ;
                      Motor_off : MotoffFB ;
                      Selector_red : RED_FB ;
                      Selector_blue : BLUE_FB ;
                      Valve_open : Valve_FB ;
                      First_cycle : BOOL ;
                      StepNumber : USINT ;
                      Paint_RED AT %I0.0.0.0.0 : BOOL ;
                      Paint_BLUE AT %I0.0.0.0.1 : BOOL ;
                      Tank_RED AT %I0.0.0.0.2 : BOOL ;
                      Tank_BLUE AT %I0.0.0.0.3 : BOOL ;
                      PaintSelector AT %Q0.0.0.0.0 : BOOL ;
                      FillingValve AT %Q0.0.0.0.1 : BOOL ;
                      Motor AT %Q0.0.0.0.2 : BOOL ;
                    END_VAR
                      LD ISA
                      PLC_Message
                      ST First_cycle
                      CAL Sequence(Set := TRUE,
                                   ReSet := First_cycle,
                                   StepInputNumber := StepNumber,
                                   InitStep := Init,
                                   Step_1 := Motor_off,
                                   Step_2 := Selector_red,
                                   Step_3 := Selector_blue,
                                   Step_4 := Valve_open)
END_PROGRAM
FUNCTION_BLOCK Init_FB
                    VAR_EXTERNAL
                      StepNumber : USINT ;
                    END_VAR
                      (*Initialise function block and move to
                        first step *)
                                                                    06/99 AWB 2700-1306 GB
                      LD 1
                      ST StepNumber
END_FUNCTION_BLOCK
478
                                                    Sfc_x
FUNCTION_BLOCK MotoffFB
                         VAR_EXTERNAL
                           Motor : BOOL ;
                           Paint_RED : BOOL ;
                           Paint_BLUE : BOOL ;
                           StepNumber : USINT ;
                         END_VAR
                         Not_RED:
                           LD     Paint_BLUE
                           RETCN             (*Test colour wish BLUE *)
                           LD     3          (*If BLUE move to step 3*)
                           ST     StepNumber
END_FUNCTION_BLOCK
FUNCTION_BLOCK RED_FB
                         VAR_EXTERNAL
                           PaintSelector : BOOL ;
                           Tank_RED : BOOL ;
                           StepNumber : USINT ;
                         END_VAR
                           (*PaintSelector set to RED *)
                           LD      TRUE
                           ST      PaintSelector
                           LD      Tank_RED
                           RETCN                 (*Return if tank empty *)
                           LD    4               (*Continue to valve opening *)
                           ST    StepNumber
06/99 AWB 2700-1306 GB
END_FUNCTION_BLOCK
                                                                              479
  Function Blocks
FUNCTION_BLOCK BLUE_FB
                    VAR_EXTERNAL
                      PaintSelector : BOOL ;
                      Tank_BLUE : BOOL ;
                      StepNumber : USINT ;
                    END_VAR
END_FUNCTION_BLOCK
FUNCTION_BLOCK Valve_FB
                    VAR_EXTERNAL
                      FillingValve : BOOL ;
                      StepNumber : USINT ;
                    END_VAR
                      LD     TRUE
                      ST     FillingValve
                      (*Further actions could be followed
                         here then transition condition for
                         a next step *)
480
                                                  Sfc_x
                                                                           481
  Function Blocks
482
                                                   Sfc_x
PROGRAM ANDsequence
                         VAR_GLOBAL
                           MainSequence : SFC_3 ;
                           Main_Init : Init_FB ;
                           Sequence_1 : SFC_2 ;
                           Init_Sequence_1 : Init_1 ;
                           Sequence_2 : SFC_2 ;
                           Init_Sequence_2 : Init_2 ;
                           Motor_on : MotonFB ;
                           Motor_off : MotoffFB ;
                           Red_open : REDopenFB ;
                           Blue_open : BLUEopenFB ;
                           Red_closed : REDclosedFB ;
                           Blue_closed : BLUEclosedFB ;
                           First_Cycle : BOOL ;
                           StepNumber : USINT ;
                           Speed : UINT ;
                           Supply AT %I0.0.0.0.0 : BOOL ;
                           RedProportion AT %I0.0.0.0.1 : BOOL ;
                           BlueProportion AT %I0.0.0.0.2 : BOOL ;
                           FillingValve_red AT %Q0.0.0.0.0 : BOOL ;
                           FillingValve_blue AT %Q0.0.0.0.1 : BOOL ;
                           Conveyormotor AT %Q0.0.0.0.2 : BOOL ;
                           Mix : MixFB
                         END_VAR
                           LD   ISA
                           PLC_Message
                           ST   First_Cycle
                           CAL MainSequence(Set := TRUE,
                                            ReSet := First_Cycle,
                                            StepInputNumber :=
                                                             StepNumber,
                                            InitStep := Main_Init,
                                            Step_1 := Motor_off,
                                            Step_2 := MixFB,
                                            Step_3 := Motor_on
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                           483
  Function Blocks
FUNCTION_BLOCK Init_FB
                    VAR_EXTERNAL
                      StepNumber : USINT ;
                    END_VAR
END_FUNCTION_BLOCK
FUNCTION_BLOCK MotoffFB
                    VAR_EXTERNAL
                      ConveyorMotor : BOOL ;
                      Speed : UINT ;
                      StepNumber : USINT ;
                    END_VAR
END_FUNCTION_BLOCK
FUNCTION_BLOCK MixFB
                    VAR_EXTERNAL
                      MainSequence : SFC_3 ;
                      Main_Init : Init_FB ;
                                                                      06/99 AWB 2700-1306 GB
                      Sequence_1 : SFC_2 ;
                      Init_Sequence_1 : Init_1 ;
                      Sequence_2 : SFC_2 ;
                      Init_Sequence_2 : Init_2 ;
                      Motor_on : MotonFB ;
                      Motor_off : MotoffFB ;
484
                                                   Sfc_x
                           Conveyormotor : BOOL ;
                           Red_open : REDopenFB ;
                           Red_closed : REDclosedFB ;
                           Blue_open : BLUEopenFB ;
                           Blue_closed : BLUEclosedFB ;
                           First_Cycle : BOOL ;
                           StepNumber : USINT ;
                           Speed : UINT ;
                           Supply : BOOL ;
                           FillingValve_red : BOOL ;
                           FillingValve_blue : BOOL ;
                         END_VAR
                         VAR
                           Reset_Subsequence : BOOL ;
                         END_VAR
                           LD  MainSequence.StepToggle
                           STN Reset_Subsequence (*Reset if
                                       MainSequence does not toggle *)
                                                                         485
  Function Blocks
End:
END_FUNCTION_BLOCK
FUNCTION_BLOCK MotonFB
                    VAR_EXTERNAL
                      Conveyormotor : BOOL ;
                    END_VAR
                      LD 1
                      ST Conveyormotor
                      (*...*)
END_FUNCTION_BLOCK
FUNCTION_BLOCK Init_1
                    VAR_EXTERNAL
                      Sequence_1 : SFC_2 ;
                    END_VAR
                      LD 1
                      ST Sequence_1.StepInputNumber
                    END_FUNCTION_BLOCK
                                                                   06/99 AWB 2700-1306 GB
486
                                                      Sfc_x
FUNCTION_BLOCK REDopenFB
                         VAR_EXTERNAL
                           Sequence_1 : SFC_2 ;
                           FillingValve_red : BOOL ;
                           RedProportion : BOOL ;
                         END_VAR
End:
END_FUNCTION_BLOCK
FUNCTION_BLOCK REDclosedFB
                         VAR_EXTERNAL
                           FillingValve_red : BOOL ;
                         END_VAR
                         LD 0
                         ST FillingValve_red
END_FUNCTION_BLOCK
FUNCTION_BLOCK Init_2
                         VAR_EXTERNAL
                           Sequence_2 : SFC_2 ;
                         END_VAR
                                             send sequence;
                                             Initialisation*)
                           LD 1
                           ST Sequence_2.StepInputNumber
END_FUNCTION_BLOCK
                                                                            487
  Function Blocks
FUNCTION_BLOCK BLUEopenFB
                    VAR_EXTERNAL
                       Sequence_2 : SFC_2;
                      FillingValve_blue : BOOL ;
                      BlueProportion : BOOL ;
                    END_VAR
End:
END_FUNCTION_BLOCK
FUNCTION_BLOCK BLUEclosedFB
                    VAR_EXTERNAL
                      FillingValve_blue : BOOL ;
                    END_VAR
                      LD 0
                      ST FillingValve_blue
                    END_FUNCTION_BLOCK
                                                               06/99 AWB 2700-1306 GB
488
06/99 AWB 2700-1306 GB
Sfc_x
489
  Function Blocks
                         SR
                         Flip Flop with Set Dominant
SR
                    BOOL      SET1
                    BOOL      RESET                                    Q1    BOOL
                    Meaning of operands
                    SET1              Set condition
                    Description
                    The characteristic feature of the SR function block is
                    to statically set a data element – the output Q1 – to
                    the Boolean status 1 or 0.
                    Switching between the two states depends on the
                    value of the Boolean input operands Set1 and ReSet.
                    The output Q1 is initialised with the value 0 when
                    starting the process. The first processing of the
                    function block with the value 1 of the operand Set1
                    causes the output Q1 to be set to 1. A change of the
                    value of Set1 no longer then effects the output Q1.
                    The value 1 at the input operand ReSet sets the
                    output Q to 0 – the output is reset.
                    If both input operands have the value 1, the fulfilled
                    set condition will be dominant, i. e. Q1 is set with
                    priority.
                                                                                    06/99 AWB 2700-1306 GB
490
                                                                                 SR
                         VAR
                           Malfunction1_message : SR;
                           Malfunction1 AT %I0.0.0.0.0 : BOOL;
                           Acknowledge_malfunction AT %I0.0.0.0.1 : BOOL;
                           Display_malfunction1 AT %Q0.0.0.0.6 : BOOL;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                                   491
  Function Blocks
                       SR_x
                       1-Bit Shift Register
                    Meaning of operands
                    ForwardPulse   Pulse input, forward
ReSet Reset
Output_1 Output 1
                    Description
                    There are 128 prototypes of the function block.
                    The following names can be used for *:
                    SR_1
                    SR_2
                                                                      06/99 AWB 2700-1306 GB
                     .
                     .
                    SR_128
492
                                                     SR_x
                                                                                  493
  Function Blocks
494
                                                                                  SR_x
                         VAR
                           Shift_register_4_bit : SR_4;
                           Pulse1 : BOOL;
                           Pulse2 : BOOL;
                           Reset : BOOL;
                           Data_bit1 : BOOL;
                           Data_bit2 : BOOL;
                           Output1 : BOOL;
                           Output2 : BOOL;
                           Output3 : BOOL;
                           Output4 : BOOL;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                                     495
  Function Blocks
                       SRB_x
                       8-Bit shift register
                    Meaning of operands
                    ForwardPulse   Pulse input, forward
ReSet Reset
Output_1 Output 1
                    Description
                    There are 128 function block prototypes. The follow-
                    ing names can be used for *:
                    SRB_1
                    SRB_2
                     .
                                                                           06/99 AWB 2700-1306 GB
                     .
                    SRB_128
496
                                                     SRB_x
                                                                                   497
  Function Blocks
498
                                                                                 SRB_x
                         VAR
                           Shift_register_2_byte : SRB_2;
                           Pulse1 : BOOL;
                           Pulse2 : BOOL;
                           Res : BOOL;
                           Data1 : USINT;
                           Data2 : USINT;
                           Output1 : USINT;
                           Output2 : USINT;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                                      499
  Function Blocks
                       SRW_x
                       16-Bit shift register
                    Meaning of operands
                    ForwardPulse   Pulse input, forward
ReSet Reset
Output_1 Output 1
                    Description
                    There are 128 function block prototypes. The follow-
                    ing names can be used for *:
                    SRW_1
                    SRW_2
                     .
                     .
                                                                           06/99 AWB 2700-1306 GB
                    SRW_128
                    The numbers 1 ... 128 indicate the register length,
                    the number of 16-bit output register fields of the
                    individual prototypes.
500
                                                    SRW_x
                                                                               501
  Function Blocks
502
                                                                                 SRW_x
                         VAR
                           Shift_register_2_word : SRW_2;
                           Pulse1 : BOOL;
                           Pulse2 : BOOL;
                           Res : BOOL;
                           Data1 : UINT;
                           Data2 : UINT;
                           Output1 : UINT;
                           Output2 : UINT;
                         END_VAR
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                                  503
  Function Blocks
      PS 4-300          SSIEncoder
                        Control of LE 4-633-CX1 local expansion
                        module
SSIEncoder
504
                                                    SSIEncoder
                         Description
                         The SSIEncoder function block controls the
                         LE 4-633-CX1. The following functions are possible:
                             Set LE number
                             Set channel number
                             Set absolute value encoder parameters
                             Scan actual position
                             Scan special bit
                             Scan error messages
                         Each LE channel can be assigned one function block
                         instance. The “LENumber” and “ChannelNumber”
                         are used to specify the SSI absolute encoder for
                         which the current position is to be scanned. The
                         current position value is updated every time the
                         “SSIEncoder” function block is processed.
06/99 AWB 2700-1306 GB
                                                                                    505
  Function Blocks
VAR
  ssiLE1_Channel1 :        SSIEncoder ;
  ActualPosition24Bit :    UDINT ;
  Error :                  USINT ;
END_VAR
 CAL ssiLE1_Channel1(
   LENumber :=1,                          (*   1st LE                         *)
   ChannelNumber :=1,                     (*   Channel no. 1                  *)
   ClockFrequency :=125,                  (*   Clockfrequency = 125 kHz       *)
   ResolutionPerRevolution :=12,          (*   No. of bits per revolution=12-bit*)
   NumberPerRevolution :=12,              (*   No. of bits per revolution=12-bit*)
   SpecialBitUsed :=0,                    (*   No special bit                 *)
    GrayCode :=1,                         (*   Graycode                       *)
   CountDirection :=0                     (*   No direction change            *)
  )
  ld   ssiLE1_Channel1.Error
  st   Error
  ld   ssiLE1_Channel1.ActualPosition
  st   ActualPosition24Bit
END_PROGRAM
                                                                                     06/99 AWB 2700-1306 GB
506
                                                                    STRtoADR
                         PS 4-200       STRtoADR
                         PS 4-300       Copy String to Marker Area
                                    Meaning of operands
                                    TextString         String to be stored in the marker range
                                    Description
                                    The STRtoADR function block is primarily used to
                                    copy a string to a marker area with the start address
                                    “TransmitVariable” The SCO function block which
                                    requires the same start address as an input para-
                                    meter then outputs this string through a serial
                                    interface.
                                    A “1” or TRUE on the Enable input starts the
                                    conversion. The output parameter StrLen indicates
                                    the number of characters which were copied to the
                                    marker area and can pass on the amount of data to
                                    be transferred to a communication function block
                                    such as SCO.
06/99 AWB 2700-1306 GB
                                                                                                     507
  Function Blocks
VAR
String_to_Marker : STRtoADR;
SendText : STRING := 'Small Example';
StartAddress AT %MB0.0.0.100 : BYTE;
SendLength : UINT;
END_VAR
  CAL String_to_Marker(Enable := 1,
                       TextString := SendText,
                       TransmitVariable := &StartAddress)
END_PROGRAM
508
                                                          STRtoCOM
                             STRtoCOM
                             Copy string to Array
                         Meaning of operands
                         TextString         String to be stored in the array
                         Description
                         The STRtoCOM function block is primarily used to
                         store a string from the start address TransmitVariable
                         to the marker range. The COM or SCO function block
                         which requires the same start address as an input
                         parameter then outputs this string on a serial
                         interface.
                         A 1 or TRUE on the Enable input starts the
                         conversion. The output parameter StrLen indicates
                         the number of characters copied to the marker range
                         and passes on the number of data units to be
                         transferred to a communication function block such
                         as COM or SCO. If the length of the string is longer
06/99 AWB 2700-1306 GB
                                                                                            509
  Function Blocks
VAR
  String_to_Array : STRtoCOM;
  SendText : STRING := 'Small Example';
  SendArray : ARRAY [1..100] OF BYTE;
  SendLength : UINT;
END_VAR
END_PROGRAM
510
                                                                     SUCOM_A
                         PS 4-300       SUCOM_A
                         PS 416         Protocol Emulation for Direct Memory Access
                                    Meaning of operands
                                    Enable            Enable
                                                                                                      511
  Function Blocks
                    Description
                    The SUCOM_A function block is used to emulate the
                    programming protocol for direct access to markers,
                    diagnostics and the status word.
                    The following interfaces can be used to access the
                    marker, status and diagnostic bits of the PS 416
                    controller:
                       PRG interface of a PS 416-CPU-400/300/200
                       card
                       SBI interface of a PS 416-CPU-400/300 card
                       (Transparent mode)
                       SBI interface of the PS 4-341-MM1
                       (Transparent mode)
                       RS 232 interface of a PS 416-COM-200 card
                    Access takes place through the proprietary Moeller
                    SUCOM-A protocol using external software. The
                    marker area can be read and written to. Status and
                    diagnostic bits can only be read.
                    The SUCOM-A protocol is detected automatically on
                    the PRG interface of the PS 416-CPU-400 card by
                    the operating system.
                    If you are using the SBI interface of the
                    PS 416-CPU-400 card or the RS 232 interface of
                    the PS 416-COM-200 card, it is first necessary to
                    initialize the interface accordingly. Specify in the
                    Interface Parameters window of the Topology
                    Configurator the Baud rate, Data format, Parity and
                    Stop bits parameters for the connected device.
                    If data communication in a PS 416 system takes
                    place both through the SBI interface of the CPU card
                                                                            06/99 AWB 2700-1306 GB
512
                                                  SUCOM_A
                                                                           513
  Function Blocks
                    VAR
                      Sucom_A_FB : SUCOM_A;
                      Enable_SucomA AT %I0.0.0.0.0 : BOOL;
                    END_VAR
                    END_PROGRAM
                                                                               06/99 AWB 2700-1306 GB
514
                                                             SuconetP
                         PS 416      SuconetP
                                     Profibus-FMS Communication
                                  Description
                                  The SuconetP function block is used to handle
                                  PROFIBUS communication via the PROFIBUS-FMS
                                  card PS 416-NET230.
                                  Please refer to the manual “Additional Information on
                                  PROFIBUS, PS 416-NET230 - Suconet-P Card”
                                  (AWB 27-1235-GB) for a description of this function
                                  block and some application notes.
06/99 AWB 2700-1306 GB
                                                                                   515
  Function Blocks
      PS 416               SuconetS_BGKS
                           InterBus Communication
                    Meaning of operands
                    Strobe         Start bit-controlled command sequence
                    Description
                    The SuconetS_BGKS function block is used to
                    access the bit-mapped command sequences of the
                    PS 416-NET-220 card.
                    Please refer to the manual “Hardware and
                    Engineering, PS 416-NET-220, Suconet-S Card”
                    (AWB 27-1236-GB) for a description of this function
                    block.
                                                                                       06/99 AWB 2700-1306 GB
516
                                                       TimeConcat
                                TimeConcat
                                Generate time duration
                         Meaning of operands
                         MilliSeconds   Milliseconds part of a time duration
Overflow Overflow
                         Description
                         The individual time elements that are specified as
                         input operands are combined to form a time duration
                         value of data type TIME in the OutputTime output
06/99 AWB 2700-1306 GB
                         operand.
                         The function block converts the individual values into
                         the appropriate component of the time duration
                         concerned and also forms a carry if necessary.
                                                                               517
  Function Blocks
VAR
  TimeConcaten : TimeConcat;
  Millisec : UINT;
  Sec : UINT;
  Min : UINT;
  Hrs : UINT;
  Dys : UINT;
  Sgn : BOOL := 0;
  TimeStructure : TIME;
  Overflow : BOOL;
END_VAR
END_PROGRAM
                                                                                      06/99 AWB 2700-1306 GB
518
                                                       TimeGenerator
                               TimeGenerator
                               Pulse generator
                         Meaning of operands
                         Set            Start condition, rising edge
Time diagram
                         Description
                         A rising edge on the Set input transfers the Period
                         value as period duration T in milliseconds to the
                         timer. As long as the Set input is 1 the PulseOutput
                         will then supply an output pulse sequence for the
                         duration defined on the Period input at a pulse/pause
                         ratio of 1 : 1.
                         The period duration can be set at the Period input
06/99 AWB 2700-1306 GB
                                                                          519
  Function Blocks
                    VAR
                      ClockGenerator : TimeGenerator;
                      Start AT %I0.0.0.0.0 : BOOL;
                      PeriodTime: UINT := 320;
                      Pulse : BOOL;
                    END_VAR
                    END_PROGRAM
                                                                            06/99 AWB 2700-1306 GB
520
                                                       TimePulse
                               TimePulse
                               Time pulse
                         Meaning of operands
                         Set                Start condition, rising edge
Description
Time diagram
                                                                                521
  Function Blocks
                    VAR
                      Pause : TimePulse;
                      Start AT %I0.0.0.0.0 : BOOL;
                      PulseDuration: UINT := 125;
                      OutputPulse : BOOL;
                      ActualTime : UINT;
                    END_VAR
END_PROGRAM
522
                                                                                TimerAlarm
                         PS 4-200                    TimerAlarm
                         PS 4-300                    Alarm function block Time
                         PS 416
TimerAlarm
                                         BOOL          EnableDisable
                                         USINT       Mode                                           Error      UINT
                                          UINT       Predivide                              CallUpNumber       UINT
                                          UINT       SetpointValue
                           ANY_FUNCTION_BLOCK        SubRoutine
                                                 Meaning of operands
                                                 EnableDisable     Enable and disable of alarm execution
                                                                    (0 = Disable, 1 = Enable)
                                                 Mode              Operating mode (1 = Timer, 2 = Pulse generator)
                                                 Predivide         Predivider for the counter
                                                 SetPointValue     Setpoint number pulses
                                                 SubRoutine        Instance name of the function block called by the
                                                                   alarm
                                                 Error             Error messages
                                                 CallUpNumber      Number of alarm-controlled function block
                                                                   invocations
                                                 Description
                                                 The input EnableDisable controls the start of the
                                                 counter. The counter is started if this input is set to 1
                                                 or TRUE and the function block instance to be called,
                                                 Predivide and SetPointValue are accepted and
                                                 temporarily saved. The value of CallUpNumber is
                                                 reset. The function block is stopped and reset if the
06/99 AWB 2700-1306 GB
                                                                                                                523
  Function Blocks
524
                                                  TimerAlarm
                                                                          525
  Function Blocks
526
                                                      TimerAlarm
                                                                               527
  Function Blocks
                    VAR
                      T_Alarm : TimerAlarm;
                      Error : USINT;
                      CountValue : UINT;
                    END_VAR
528
                                                        TimeSplit
                                TimeSplit
                                Split TIME variable type
                         Meaning of operands
                         InputTime       Time duration to be divided in time elements
                         Description
                         The time duration value specified via the InputTime
                         input operand is divided into time elements that are
                         each output as UINT data types.
                         The sign of the time duration specified is indicated by
06/99 AWB 2700-1306 GB
                                                                                        529
  Function Blocks
                    VAR
                      TimeElements : TimeSplit;
                      Duration : TIME := T#20d22h13m12s800ms;
                      Millisec : UINT;
                      Sec : UINT;
                      Min : UINT;
                      Hrs : UINT;
                      Dys : UINT;
                      Sgn : BOOL;
                    END_VAR
END_PROGRAM
530
                                                       TODconcat
                             TODconcat
                             Generate time
                         Meaning of operands
                         MilliSecond   Milliseconds part of time
                         Description
                         The individual time elements specified as input
                         operands are combined to a time value in the output
                         operand OutputTOD. The input operands must not
                         exceed the permissible value ranges for a time.
                         The output operand Error will be set to 1 if the
                         permissible range of a time value is exceeded.
06/99 AWB 2700-1306 GB
                                                                            531
  Function Blocks
                    VAR
                      TimeOfDay : TODconcat;
                      Millisecond : UINT;
                      Sec : UINT;
                      Min : UINT;
                      Hr : UINT;
                      TODStructure : TIME_OF_DAY;
                      Error : BOOL;
                    END_VAR
END_PROGRAM
532
                                                      TODsplit
                             TODsplit
                             Split TIME_OF_DAY data type
                         Meaning of operands
                         InputTOD       Time
                         Description
                         The time value specified via the InputTOD input
                         operand is divided into time elements that are output
                         as UINT data types.
06/99 AWB 2700-1306 GB
                                                                          533
  Function Blocks
VAR
  Split_time : TODsplit;
  TimeOfDay : TOD := TOD#12:13:12;
  Millisec : UINT;
  Sec : UINT;
  Min : UINT;
  Hrs : UINT;
END_VAR
END_PROGRAM
534
                                                       TOF
                              TOF
                              Off delay
                         Meaning of operands
                         IN               Start condition
Description
Time diagram
                                                                            535
  Function Blocks
                    VAR
                      Timer3 : TOF;
                      Start AT %I0.0.0.0.0 : BOOL;
                      Duration : TIME := T#125ms;
                      Output AT %Q0.0.0.0.0 : BOOL;
                      Actual_time : TIME;
                    END_VAR
                    END_PROGRAM
                                                                              06/99 AWB 2700-1306 GB
536
                                                      TON
                              TON
                              On delay
                         Meaning of operands
                         IN              Start condition
Description
Time diagram
                                                                            537
  Function Blocks
                    VAR
                      Timer2 : TON;
                      Start AT %I0.0.0.0.0 : BOOL;
                      Duration : TIME := T#12ms;
                      Output AT %Q0.0.0.0.0 : BOOL;
                      Actual_time : TIME;
                    END_VAR
                    END_PROGRAM
                                                                              06/99 AWB 2700-1306 GB
538
                                                      TP
                              TP
                              Impulse
                         Meaning of operands
                         IN              Start condition
Description
Time diagram
                                                                           539
  Function Blocks
                    VAR
                      Timer1 : TP;
                      Start AT %I0.0.0.0.0 : BOOL;
                      Impulse_duration: TIME := T#125ms;
                      Output_impulse : BOOL;
                      Actual_time : TIME;
                    END_VAR
END_PROGRAM
540
                                                          TransferArray
                             TransferArray
                             Copy or Initialise Array
                         Meaning of operands
                         Source             Source area
                         Description
                         The TransferArray function block has two operating
                         modes: Initialise and copy.
                         The mode is set with the Mode input.
06/99 AWB 2700-1306 GB
                                                                                        541
  Function Blocks
542
                                                                   WriteAnalogDirect
                         PS 416          WriteAnalogDirect
                                         Direct Writing to Analog Outputs
                                  Meaning of operands
                                  AnalogOutValues Contains the values for all required channels that are
                                                  to be output
                                  Description
                                  The WriteAnalogDirect function block allows direct
                                  write access to analog output channels in the basic
                                  unit of the PS 416. The data is not written to the
                                  outputs at the end of a cycle but directly during the
                                  current cycle. This function block therefore allows
                                  fast and direct response to events such as required
                                  in alarm routines. The maximum on/off delay of the
                                  analog cards for the controller should be taken into
                                  account when using this function block.
                                  The Slot input specifies the slot in which the card to
                                  be accessed is fitted. The WordMask input specifies
                                  which channels are to be write accessed on the card.
06/99 AWB 2700-1306 GB
                                                                                                    543
  Function Blocks
544
                                                                                WriteAnalogDirect
                         VAR
                           WriteAnalog : WriteAnalogDirect;
                           AnalogData : ARRAY[0..3] OF UINT;
                           WriteError : UINT;
                         END_VAR
                           LD  1234
                           ST  AnalogData[0]                 (* Data channel no.0 *)
                           LD  567
                           ST  Analogdata[1]                 (* Data channel no.1 *)
                           CAL WriteAnalog(Slot := 5,        (* Card fitted in slot 5 *)
                                           Wordmask := 16#3, (* Write channel no. 0 and no.1 *)
                                           AnalogOutValues := AnalogData
                                           |
                                           WriteError = Error)
                           LD WriteError
                           EQ 0
                           JMPC WRITE_DONE
(* Error handling *)
WRITE_DONE:
                         END_PROGRAM
06/99 AWB 2700-1306 GB
                                                                                                    545
  Function Blocks
      PS 416            WriteDirect
                        Direct Writing to Digital Outputs
                    Meaning of operands
                    Mode           Access mode
                    Description
                    The WriteDirect function block allows direct write
                    access to digital output cards in the basic rack of the
                    PS 416-CPU. The data is written directly to the
                    outputs during the user program cycle rather than at
                    the start of the cycle. This function block can thus be
                    used for fast and direct reactions to events, e. g. in
                    alarm routines. When using this function block,
                                                                                 06/99 AWB 2700-1306 GB
546
                                                  WriteDirect
                                                                           547
  Function Blocks
                       Warning
                       Undeclared outputs written by the WriteDirect
                       function block can result in hazardous states
                       of the machine, since they are not
                       automatically reset in the READY state of the
                       PLC.
                       Ensure that the outputs that are written with
                       “WriteDirect” are declared in the user program
                       and that the declaration and the values output
                       with “WriteDirect” are identical.
548
                                                                                 WriteDirect
                         VAR
                           WriteEnable AT%I0.0.0.0.1:BOOL;
                           WriteIODirect                         :WriteDirect;
                           WriteData                             :WORD;
                           WriteError                            :UINT;
                           LD   IOByte32
                           USINT_TO_WORD
                           ST   WriteData
                           LD    WriteError
                           EQ    0
                           JMPCN WRITE_DONE
WRITE_ERROR:
                           (*Error handling *)
06/99 AWB 2700-1306 GB
WRITE_DONE:
END_PROGRAM
                                                                                                             549
  Function Blocks
                             WriteMC
                             Save Data on Memory Card
                     Meaning of operands
                    SourceAddress        Data buffer with the data to be saved
                     Description
                     The WriteMC function block allows data to be saved
                     to the PLCs memory card (MC). Together with the
                     ReadMCFB_ReadMC function block, important
                     applications of this function block are data backup,
                     process data acquisition, saving recipe data and/or
                     saving variables before a program update or the
                     handing of recipe data.
                
                                                                                    06/99 AWB 2700-1306 GB
550
                                                   WriteMC
                                                                            551
  Function Blocks
552
                                                      WriteMC
                                                                                553
  Function Blocks
  LD    ActiveSave
  JMPCN CONTINUE
CONTINUE:
  LD    47
  ST    SegmentNumber
  LD    32
  ST    DataLength
  LD   ErrorSave
  EQ   0
  JMPC NO_ERROR
(* Error handling *)
NO_ERROR:
                                                                           06/99 AWB 2700-1306 GB
END_PROGRAM
554
                         7   Language Extension
                             Single-bit access
                             In the program you can access an individual bit
                             located in a data element declared as BYTE, WORD
                             or DWORD and specify the corresponding bit
                             number, separated by a dot. The bit number,
                             beginning with '0' for the least significant bit, is
                             specified:
                                0..7 in the byte
                                0..15 in the word
                                0...31 in the double word
                             Example
                             PROGRAM only1bit
                             VAR
                               BitPattern1 : BYTE := 2#10101010;
                               BitPattern2 AT %IW0.0.0.0 : WORD;
                             END_VAR
                                                 (*Copying of bit 15 *)
                               LD BitPattern2.15 (*from BitPattern2 *)
                               ST BitPattern1.0 (*to bit 0 of BitPattern1 *)
                                .
                                .
END_PROGRAM
                                                                               555
  Language Extension
556
                         The image register is refreshed at the end of a cycle.
                         The image register of the PS 4-300 is refreshed
                         immediately.
                         Example
                         VAR
                           Input AT %IP0.0.0.0.0: BOOL_EXP;
                           Output AT %QPB0.0.0.0: USINT_EXP;
                         END_VAR
                                                                           557
  Language Extension
                       Parameter passing
                       A Moeller variation of function block calls allows the
                       direct passing of function block inputs (VAR_INPUT
                       parameters) and outputs (VAR_OUTPUT parameters)
                       via instruction sequences in the call. This call
                       variation is not part of the IEC standard.
                       With conditional function block calls, the input and
                       output allocations are only processed if the function
                       block is called.
                          Passing of FB input parameters
                       Before the function block call the instruction
                       sequence is processed and the sequence result is
                       assigned to the function block input. Other direct
                       parameter passing is then carried out and the
                       function block is called.
                       Example “Passing of inputs”
                       (* FUNCTION_BLOCK meanval
                          VAR_INPUT
                             Val1 : USINT;
                             Val2 : USINT;
                          END_VAR
                         AR_OUTPUT
                             Average : USINT;
                          END_VAR                     *)
PROGRAM Pou4
                       VAR
                         Instance : meanval;
                         Measval1 AT %IB0.0.0.0 : USINT;
                         Measval2 AT %IB0.0.0.1 : USINT;
                       END_VAR
                                              ),
                                      Val2 := (Measval2
                                                add 2add 3
                                              )
                                    )
558
                             Passing of FB outputs
                         After the function block is called the instruction
                         sequence is processed and the sequence result is
                         assigned to the variables in front of the assignment
                         operator “:=”. The first operand of the sequence
                         must be the output parameter of the function block
                         called.
                         Example “Passing of outputs”
                         VAR
                           Instance : meanval;
                           Measval1 AT %IB0.0.0.0 : USINT;
                           Measval2 AT %IB0.0.0.1 : USINT;
                           Result AT %QB0.0.0.0 : USINT;
                           Measval : USINT;
                         END_VAR
to right.
                                                                            559
  Language Extension
                         LD a
                         SHR (b
                              WORD_TO_UINT
                             )
560
                                               Appendix
                                                                                               561
   Appendix
562
                                                                                                Limit values of Sucosoft
                                                                                                                            563
     Appendix
1)
     Depending on data type. If the limit value is exceeded, “?” will be inserted instead of values.
2)
     Restricted also by the PLC main memory available.
564
                                                   Program examples LD/FBD
                                                                            565
  Appendix
             Task 2
             The variable Act_Position in task 1 shows the
             distance of the robot arm from the reference point as
             a pulse number. Eight pulses are equivalent to a 1 cm
             movement. In network 0007 the absolute position is
             to be output in centimetres. The SHR shift function is
             used for converting the pulse number into
             centimetres.
             Additional declaration:
             VAR
               Position_in_cm : INT;
             END_VAR
566
                                                   Program examples LD/FBD
                         Task 3
                         A part of the operating elements of an operator
                         panel is connected with the IB0.0.0.0 input byte.
                         The program section where the operating elements
                         are evaluated should only be executed if there is a
                         different status compared with the previous program
                         cycle in the operator panel.
                         VAR
                           Operator_panel_new AT %IB0.0.0.0 : BYTE;
                           Operator_panel_old : BYTE;
                         END_VAR
06/99 AWB 2700-1306 GB
                                                                        567
  Appendix
             Task 4
             The robot arm is moved into the Hand operating
             mode via bits 0 to 5 of the operating elements listed
             in task 3. In this operating mode only one single
             process activity may be executed by a short key
             stroke. Variable declaration will be completed.
             The program is continued from network 0007 task 3.
             Additional declarations:
             VAR
               Automatic AT %I0.0.0.1.6 : BOOL;
               Hand AT %I0.0.0.1.7 : BOOL;
               Raise_Arm AT %Q0.0.0.1.0 : BOOL;
               Lower_Arm AT %Q0.0.0.1.1 : BOOL;
               Move_Arm_ri AT %Q0.0.0.1.2 : BOOL;
               Move_Arm_le AT %Q0.0.0.1.3 : BOOL;
               Close_Clamp AT %Q0.0.0.1.4 : BOOL;
               Open_Clamp AT %Q0.0.0.1.5 : BOOL;
               Arm_up AT %I0.0.0.1.0 : BOOL;
               Arm_down AT %I0.0.0.1.1 : BOOL;
               Arm_right AT %I0.0.0.1.2 : BOOL;
               Arm_left AT %I0.0.0.1.3 : BOOL;
               Clamp_closed AT %I0.0.0.1.4 : BOOL;
               Clamp_opened AT %I0.0.0.1.5 : BOOL;
             END_VAR
568
                         Program examples LD/FBD
06/99 AWB 2700-1306 GB
                                            569
570
                         Appendix
                         Function blocks
                         A single function block can be programmed in a
                         network in the LD/FBD editor. There are two ways of
                         transferring the parameters to the function block:
                            Entering the variable names or values at the indi-
                            vidual connection lines directly when calling the
                            function block where only the parameters for the
                            relevant operands must be set.
                            Assigning the variable names or values to the in-
                            put operands in the networks before calling the
                            function block and sequencing the output oper-
                            ands in networks after calling the function block.
06/99 AWB 2700-1306 GB
                                                                          571
  Appendix
572
                         Program examples LD/FBD
06/99 AWB 2700-1306 GB
                                            573
  Appendix
             Task 6
             A conveyor belt is controlled by a motor at the drive
             shaft. There are proximity switches at the two drive
             shafts which provide at least 5 pulses per second
             when the belt is running at the required speed.
             A monitoring program outputs an error message if
             the number of revolutions is too low after a startup
             time of 8 seconds
             or
             the belt is broken.
             With an error message the motor is switched off and
             a fault indication is activated.
             VAR
               Belt_Motor : RS ;
               Message : SR ;
               Revolutions : TOF ;
               Belt_broken : CTUD ;
               Startup_Time : TP ;
               Acknow_Edge : R_TRIG ;
               Motor_ON AT %I0.0.0.0.0 : BOOL ;
               OFF AT %I0.0.0.0.1 : BOOL ;
               EMERG_STOP AT %I0.0.0.0.2 : BOOL ;
               Lamp_Acknow AT %I0.0.0.0.3 : BOOL ;
               NS_Drive AT %I0.0.0.0.4 : BOOL ;
               NS_2 AT %I0.0.0.0.5 : BOOL ;
               Lamp AT %Q0.0.0.0.0 : BOOL ;
               Motor AT %Q0.0.0.0.1 : BOOL ;
             END_VAR
                                                                     06/99 AWB 2700-1306 GB
574
                         Program examples LD/FBD
06/99 AWB 2700-1306 GB
                                            575
576
                         Appendix
                         Task 7
                         An installation report can be created and printed out.
                         A manually initiated protocol job is executed
                         immediately or within 24 hours. With a time-
                         dependent job the time is set via a 4-digit decade
                         switch which is used to set hours and minutes in
                         decimal form.
                         VAR
                           Clock : PS_GetDateAndTime ;
                           Job : RS ;
                           Edge_1 : R_TRIG ;
                           Edge_2 : R_TRIG ;
                           TimeValue : ELEMENT_OF_DATE ;
                           Hours AT %IB0.0.0.0 : BYTE ;
                           Minutes AT %IB0.0.0.1 : BYTE ;
                           Time_Job AT %I0.0.0.2.0 : BOOL ;
                           Immediate_Job AT %I0.0.0.2.1 : BOOL ;
                           Printing : BOOL ;
                         END_VAR
06/99 AWB 2700-1306 GB
                                                                           577
578
                         Appendix
                                            579
  Appendix
             Task 8
             In a paint preparation plant paints are mixed
             according to different recipes from various basic
             elements and the prepared paint is poured into cans
             of different sizes. Selection of an ordered recipe and
             a type of can is carried out by setting the corres-
             ponding 4-digit order number on a decade switch.
             After a button is pushed as confirmation the job goes
             into a queue which can manage up to 10 jobs.
             If the plant is in status Ready and the jobs are stored
             in the queue, the first job is read automatically and
             the process is started.
             VAR
               Converter_1:BCDTo16BitBinary;
               Converter_2:_16BitBinaryToBCD;
               Queue:FifoW10;
               Job AT %IW0.0.0.0:UINT;
               Release_Job AT %I0.0.1.0.0:BOOL;
               Delete_Jobs AT %I0.0.1.0.1:BOOL;
               Display_Current_Job AT%QW0.0.3.0:UINT;
               Display_Input_Disable AT %Q0.0.2.0.0:BOOL;
               System_Ready: BOOL;
             END_VAR
580
                         Program examples LD/FBD
06/99 AWB 2700-1306 GB
                                            581
582
                         Appendix
                         Symbols                   B
                         # character 203           BCD_TO_DINT 133
                         & 40                      BCD_TO_INT 133
                         &N 42                     BCD_TO_SINT 133
                         *_TO_** 114               BCD_TO_UDINT 133
                         _16Bit_Compare 210        BCD_TO_UINT 133
                         _16BitBinaryToBCD 212     BCD_TO_USINT 133
                         _16BitCounter 214         BCDTo16BitBinary 227
                         _32Bit_Compare 216        BCDTo32BitBinary 229
                         _32BitBinaryToBCD 218     Bistable data elements 38
                         _32BitCounter 220         Bistable elements 490
                                                   Bit string functions
                         A                           Rotation functions 190,
                         ABS 136                        191
                         ADD                         Shift functions 194, 195,
                           Addresses 141                196, 197
                           Numeric 137             BlockCompare 231
                           numeric 47              BlockTransfer 236
                           Time values 139         BOOL_TO_BYTE 124
                         Addition 47, 99           BOOL_TO_DINT 121
                         ADDRESS_TO_UINT 135       BOOL_TO_DWORD 124
                         ADRtoSTR 222, 224         BOOL_TO_INT 121
                         Alarm                     BOOL_TO_SINT 121
                           Disabling 147           BOOL_TO_UDINT 121
                           Enabling 153            BOOL_TO_UINT 121
                         Alarm Function Block      BOOL_TO_USINT 121
                           Counter 240, 256        BOOL_TO_WORD 124
                         Alarm function block      BYTE_TO_BOOL 124
                           Edge-controlled 310     BYTE_TO_DINT 121
                         AND 40                    BYTE_TO_DWORD 124
                         AND sequence              BYTE_TO_INT 121
                           in FBD 92               BYTE_TO_SINT 121
                           in IL 40                BYTE_TO_UDINT 121
                           in LD 79                BYTE_TO_UINT 121
06/99 AWB 2700-1306 GB
                                                                          583
  Index
584
                                                    Index
                                                                             585
  Index
586
                                                       Index
                         M                                Arithmetic operators 47
                         Marker 18                        assignments 36
                         MAX 170                          Bistable data elements
                         Memory card                         38
                           Initialising 456               Comparison operators
                           Readout 414                       50
                           Save data 427, 550             Conditional and uncon-
                         MID 172                             ditional jumps 52
                         MIN 174                          Conditional and uncon-
                         Mixed sequences 80                  ditional returns 54
                         MOD 200 343                      Invocation function
                         Modem                               blocks 56
                           Establish data connec-         Invocation of functions
                              tion 301                       58
                           Sending data to 446            Load instructions 34
                         MS_TimeFalling 344               Logic operators 40
                         MS_TimeRising 347                Overview 29
                         MUL                             OR 43
                           Addresses 179                 OR sequence
                           Multiplication of numeric      in FBD 94
                              data types 176              in IL 43
                           Numeric 48                     in LD 80
                           Time duration 178             ORN 44
                         Multiple instancing 314         Output symbols 78, 97
                         Multiplexer 180                 Output variable 21, 78, 98
                         Multiplication 48, 100          Outputs, writing direct to
                           Carry 158                      543, 546
                         MUX 180                         Overloaded function 113
                         N                               P
                         NE 50, 101                      Parameter passing, direct
                         NEG 182                           555
                         Negation symbol                 PdpFreezeSync 355
                           in FBD 92                     PdpStationDiag 369
                           in LD 82                      PLC_Message 184
                         NItoCelsius 350                 PLC_ReadClock 186
                         NItoFahrenheit 352              POU Editor 73
                         NOT 96, 183                     PROFIBUS diagnostic data
06/99 AWB 2700-1306 GB
                         Numeric 49                        369
                                                         Program 64
                         O                               Program organisation units
                         Operand 31                        5
                         Operators                         Comments 6
                                                                                587
  Index
          ReadDirect 401              S 38
          Reading diagnostic flags    S_TimeFalling 421
            18                        S_TimeRising 424
          Reading inputs directly     SaveData 427
            Analog inputs 395         SCO 430
588
                                                     Index
                                                                             589
  Index
590
06/99 AWB 2700-1306 GB
                         XORN 46
                                   Index
591
592
06/99 AWB 2700-1306 GB