Simatic Function Block Diagram (FBD) For S7-300 and S7-400 Programming
Simatic Function Block Diagram (FBD) For S7-300 and S7-400 Programming
Simatic Function Block Diagram (FBD) For S7-300 and S7-400 Programming
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A B C
SIMATIC
Counter Instructions
Data Block Instructions Jump Instructions Integer Math Instructions Floating-Point Math Instructions Move Instructions Program Control Instructions Shift and Rotate Instructions Status Bit Instructions Timer Instructions Word Logic Instructions
This manual is part of the documentation package with the order number: 6ES7810-4CA10-8BW1
05/2010
A5E02790131-01
Qualified Personnel
The product/system described in this documentation may be operated only by personnel qualified for the specific task in accordance with the relevant documentation for the specific task, in particular its warning notices and safety instructions. Qualified personnel are those who, based on their training and experience, are capable of identifying risks and avoiding potential hazards when working with these products/systems.
Trademarks
All names identified by are registered trademarks of the Siemens AG. The remaining trademarks in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owner.
Disclaimer of Liability
We have reviewed the contents of this publication to ensure consistency with the hardware and software described. Since variance cannot be precluded entirely, we cannot guarantee full consistency. However, the information in this publication is reviewed regularly and any necessary corrections are included in subsequent editions.
A5E02790131-01 02/2010
Preface
Purpose
This manual is your guide to creating user programs in the Function Block Diagram (FBD) programming language. The manual also includes a reference section that describes the syntax and functions of the language elements of Function Block Diagram.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Preface
Requirements
To use the Function Block Diagram manual effectively, you should already be familiar with the theory behind S7 programs which is documented in the online help for STEP 7. The language packages also use the STEP 7 standard software, so you should be familiar with handling this software and have read the accompanying documentation. This manual is part of the documentation package "STEP 7 Reference". The following table displays an overview of the STEP 7 documentation:
Documentation STEP 7 Basic Information with Working with STEP 7, Getting Started Manual Programming with STEP 7 Configuring Hardware and Communication Connections, STEP 7 From S5 to S7, Converter Manual Ladder Logic (LAD)/Function Block Diagram (FBD)/Statement List (STL) for S7-300/400 manuals Standard and System Functions for S7-300/400 Volume 1 and Volume 2 Provides reference information and 6ES7810-4CA10-8BW1 describes the programming languages LAD, FBD, and STL, and standard and system functions extending the scope of the STEP 7 basic information. Purpose Order Number
Basic information for technical 6ES7810-4CA10-8BW0 personnel describing the methods of implementing control tasks with STEP 7 and the S7-300/400 programmable controllers.
Purpose Basic information on programming and configuring hardware with STEP 7 in the form of an online help. Context-sensitive reference information.
Reference helps on STL/LAD/FBD Reference help on SFBs/SFCs Reference help on Organization Blocks
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Preface
Online Help
The manual is complemented by an online help which is integrated in the software. This online help is intended to provide you with detailed support when using the software. The help system is integrated in the software via a number of interfaces: The context-sensitive help offers information on the current context, for example, an open dialog box or an active window. You can open the context-sensitive help via the menu command Help > Context-Sensitive Help, by pressing F1 or by using the question mark symbol in the toolbar. You can call the general Help on STEP 7 using the menu command Help > Contents or the "Help on STEP 7" button in the context-sensitive help window. You can call the glossary for all STEP 7 applications via the "Glossary" button.
This manual is an extract from the "Help on FBD". As the manual and the online help share an identical structure, it is easy to switch between the manual and the online help.
Further Support
If you have any technical questions, please get in touch with your Siemens representative or responsible agent. You will find your contact person at: http://www.siemens.com/automation/partner You will find a guide to the technical documentation offered for the individual SIMATIC Products and Systems at: http://www.siemens.com/simatic-tech-doku-portal The online catalog and order system is found under: http://mall.automation.siemens.com/
Training Centers
Siemens offers a number of training courses to familiarize you with the SIMATIC S7 automation system. Please contact your regional training center or our central training center in D 90026 Nuremberg, Germany for details: http://www.sitrain.com Internet:
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Preface
Technical Support
You can reach the Technical Support for all Industry Automation and Drive Technology products Via the Web formula for the Support Request http://www.siemens.com/automation/support-request
Additional information about our Technical Support can be found on the Internet pages http://www.siemens.com/automation/service
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Contents
1 Bit Logic Instructions ...............................................................................................................................11 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 2 2.1 2.2 2.3 2.4 3 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 Overview of Bit Logic Instructions................................................................................................11 >=1 : OR Logic Operation ............................................................................................................12 & : AND Logic Operation..............................................................................................................13 AND-before-OR Logic Operation and OR-before-AND Logic Operation.....................................14 XOR : Exclusive OR Logic Operation ..........................................................................................16 Insert Binary Input........................................................................................................................17 Negate Binary Input .....................................................................................................................18 = : Assign .....................................................................................................................................19 # : Midline Output.........................................................................................................................21 R : Reset Output ..........................................................................................................................23 S : Set Output...............................................................................................................................24 RS : Reset_Set Flip Flop .............................................................................................................25 SR : Set_Reset Flip Flop .............................................................................................................27 N : Negative RLO Edge Detection ...............................................................................................28 P : Positive RLO Edge Detection .................................................................................................29 SAVE : Save RLO to BR Memory................................................................................................30 NEG : Address Negative Edge Detection ....................................................................................31 POS : Address Positive Edge Detection......................................................................................32 Overview of Comparison Instructions ..........................................................................................33 CMP ? I : Compare Integer ..........................................................................................................34 CMP ? D : Compare Double Integer............................................................................................35 CMP ? R : Compare Real ............................................................................................................36 Overview of Conversion Instructions ...........................................................................................37 BCD_I : BCD to Integer................................................................................................................38 I_BCD : Integer to BCD................................................................................................................39 BCD_DI : BCD to Double Integer.................................................................................................40 I_DI : Integer to Double Integer....................................................................................................41 DI_BCD : Double Integer to BCD.................................................................................................42 DI_R : Double Integer to Real......................................................................................................43 INV_I : Ones Complement Integer...............................................................................................44 INV_DI : Ones Complement Double Integer................................................................................45 NEG_I : Twos Complement Integer .............................................................................................46 NEG_DI : Twos Complement Double Integer..............................................................................47 NEG_R : Negate Real Number....................................................................................................48 ROUND : Round to Double Integer .............................................................................................49 TRUNC : Truncate Double Integer Part.......................................................................................50 CEIL : Ceiling ...............................................................................................................................51 FLOOR : Floor..............................................................................................................................52
Comparison Instructions..........................................................................................................................33
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Contents
Counter Instructions .................................................................................................................................53 4.1 4.2 4.3 4.4 4.5 4.6 4.7 Overview of Counter Instructions.................................................................................................53 S_CUD : Assign Parameters and Count Up/Down......................................................................55 S_CU : Assign Parameters and Count Up...................................................................................57 S_CD : Assign Parameters and Count Down ..............................................................................59 SC : Set Counter Value................................................................................................................61 CU : Up Counter...........................................................................................................................63 CD : Down Counter ......................................................................................................................64 OPN : Open Data Block ...............................................................................................................65 Overview of Jump Instructions.....................................................................................................67 JMP : Unconditional Jump in a Block...........................................................................................68 JMP : Conditional Jump in a Block ..............................................................................................69 JMPN : Jump-If-Not......................................................................................................................70 LABEL : Jump Label ....................................................................................................................71 Overview of Integer Math Instructions .........................................................................................73 Evaluating the Bits of the Status Word with Integer Math Instructions ........................................74 ADD_I : Add Integer .....................................................................................................................75 SUB_I : Subtract Integer ..............................................................................................................76 MUL_I : Multiply Integer ...............................................................................................................77 DIV_I : Divide Integer ...................................................................................................................78 ADD_DI : Add Double Integer......................................................................................................79 SUB_DI : Subtract Double Integer ...............................................................................................80 MUL_DI : Multiply Double Integer ................................................................................................81 DIV_DI : Divide Double Integer....................................................................................................82 MOD_DI : Return Fraction Double Integer...................................................................................83 Overview of Floating-Point Math..................................................................................................85 Evaluating the Bits of the Status Word with Floating-Point Instructions ......................................86 Basic Instructions .........................................................................................................................87 ADD_R : Add Real .......................................................................................................................87 SUB_R : Subtract Real ................................................................................................................88 MUL_R : Multiply Real .................................................................................................................89 DIV_R : Divide Real .....................................................................................................................90 ABS : Forming the Absolute Value of a Floating-Point Number ..................................................91 Extended Instructions...................................................................................................................92 SQR : Forming the Square of a Floating-Point Number ..............................................................92 SQRT : Forming the Square Root of a Floating-Point Number ...................................................93 EXP : Forming the Exponential Value of a Floating-Point Number .............................................94 LN : Forming the Natural Logarithm of a Floating-Point Number ................................................95 Forming Trigonometric Functions of Angles as Floating-Point Numbers ....................................96 MOVE : Assign Value...................................................................................................................99
5 6
Data Block Instructions ............................................................................................................................65 5.1 6.1 6.2 6.3 6.4 6.5 Jump Instructions .....................................................................................................................................67
Integer Math Instructions..........................................................................................................................73 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 7.10 7.11
Floating-Point Math Instructions .............................................................................................................85 8.1 8.2 8.3 8.3.1 8.3.2 8.3.3 8.3.4 8.3.5 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Contents
10
Program Control Instructions ................................................................................................................101 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11 10.12 10.13 Overview of Program Control Instructions .................................................................................101 CALL : Calling an FC/SFC without Parameters.........................................................................102 CALL_FB : Call FB as Box.........................................................................................................104 CALL_FC (Call FC as Box)........................................................................................................106 CALL_SFB : Call System FB as Box .........................................................................................108 CALL_SFC (Call System FC as Box) ........................................................................................110 Calling Multiple Instances ..........................................................................................................112 Calling a Block from a Library ....................................................................................................112 Master Control Relay Instructions..............................................................................................113 Important Notes on Using MCR Functions ................................................................................114 MCR</MCR> : Master Control Relay On/Off.............................................................................115 MCRA/MCRD : Master Control Relay Activate/Deactivate........................................................118 RET : Return ..............................................................................................................................121 Shift Instructions ........................................................................................................................123 Overview of Shift Instructions ....................................................................................................123 SHR_I : Shift Right Integer.........................................................................................................124 SHR_DI : Shift Right Double Integer .........................................................................................126 SHL_W : Shift Left Word............................................................................................................127 SHR_W : Shift Right Word.........................................................................................................129 SHL_DW : Shift Left Double Word.............................................................................................130 SHR_DW : Shift Right Double Word..........................................................................................131 Rotate Instructions .....................................................................................................................133 Overview of Rotate Instructions .................................................................................................133 ROL_DW : Rotate Left Double Word .........................................................................................133 ROR_DW : Rotate Right Double Word......................................................................................135 Overview of Status Bit Instructions ............................................................................................137 OV : Exception Bit Overflow.......................................................................................................138 OS : Exception Bit Overflow Stored...........................................................................................140 UO : Exception Bit Unordered....................................................................................................142 BR : Exception Bit BR Memory ..................................................................................................143 <> 0 : Result Bits........................................................................................................................144 Overview of Timer Instructions ..................................................................................................147 Memory Areas and Components of a Timer..............................................................................148 S_PULSE : Assign Pulse Timer Parameters and Start .............................................................152 S_PEXT : Assign Extended Pulse Timer Parameters and Start.............................................154 S_ODT : Assign On-Delay Timer Parameters and Start ...........................................................156 S_ODTS : Assign Retentive On-Delay Timer Parameters and Start ......................................158 S_OFFDT : Assign Off-Delay Timer Parameters and Start.......................................................160 SP : Start Pulse Timer ...............................................................................................................162 SE : Start Extended Pulse Timer ...............................................................................................164 SD : Start On-Delay Timer .........................................................................................................166 SS : Start Retentive On-Delay Timer.........................................................................................168 SF Start Off-Delay Timer .....................................................................................................170
11
Shift and Rotate Instructions .................................................................................................................123 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.1.5 11.1.6 11.1.7 11.2 11.2.1 11.2.2 11.2.3
12
Status Bit Instructions ............................................................................................................................137 12.1 12.2 12.3 12.4 12.5 12.6
13
Timer Instructions ...................................................................................................................................147 13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9 13.10 13.11 13.12
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Contents
14
Word Logic Instructions .........................................................................................................................173 14.1 14.2 14.3 14.4 14.5 14.6 14.7 Overview of Word Logic Instructions .........................................................................................173 WAND_W : AND Word (Word)...................................................................................................174 WOR_W : OR Word (Word) .......................................................................................................175 WXOR_W : Exclusive OR Word (Word) ....................................................................................176 WAND_DW : AND Double Word (Word) ...................................................................................177 WOR_DW : OR Double Word (Word)........................................................................................178 WXOR_DW : Exclusive OR Double Word (Word) .....................................................................179 FBD Instructions Sorted According to German Mnemonics (SIMATIC) ....................................181 FBD Instructions Sorted According to English Mnemonics (International) ................................184 Overview of Programming Examples.........................................................................................187 Example: Bit Logic Instructions..................................................................................................188 Example: Counter and Comparison Instructions .......................................................................191 Example: Timer Instructions.......................................................................................................194 Example: Integer Math Instructions ...........................................................................................198 Example: Word Logic Instructions .............................................................................................199 EN/ENO Mechanism ..................................................................................................................201 Adder with EN and with ENO Connected ..................................................................................203 Adder with EN and without ENO Connected .............................................................................204 Adder without EN and with ENO Connected .............................................................................204 Adder without EN and without ENO Connected ........................................................................205 Parameter Transfer ....................................................................................................................206
Working with Function Block Diagram .................................................................................................201 C.1 C.1.1 C.1.2 C.1.3 C.1.4 C.2
Index ...................................................................................................................................................................207
10
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
1
1.1
Description
Bit logic instructions work with two digits, 1 and 0. These two digits form the base of a number system called the binary system. The two digits 1 and 0 are called binary digits or bits. In conjunction with AND, OR, XOR and outputs, a 1 stands for logical YES and a 0 for logical NO. The bit logic instructions interpret signal states of 1 and 0 and combine them according to Boolean logic. These combinations produce a result of 1 or 0 that is called the result of logic operation (RLO). There are bit logic instructions to perform the following functions: AND, OR and Exclusive OR: these instructions check the signal state and produce a result that is either copied to the RLO bit or combined with it. AND-before-OR Logic Operation and OR-before-AND Logic Operation Assign and Midline Output. These instructions assign the RLO or store it temporarily. The following instructions react to an RLO of 1: S : Set Output R : Reset Output SR : Set_Reset Flip Flop RS : Reset_Set Flip Flop Other instructions react to a positive or negative edge transition to perform the following functions: N : Negative RLO Edge Detection P : Positive RLO Edge Detection NEG : Address Negative Edge Detection POS : Address Positive Edge Detection The remaining instructions affect the RLO directly in the following ways: Insert Binary Input Negate Binary Input SAVE : Save RLO to BR Memory
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
11
1.2
Symbol
<address> <address>
>=1
Parameter <address>
Memory Area I, Q, M, T, C, D, L
Description The address indicates the bit whose signal state will be checked.
Description
With the OR instruction, you can check the signal states of two or more specified addresses at the inputs of an OR box. If the signal state of one of the addresses is 1, the condition is satisfied and the instruction produces the result 1. If the signal state of all addresses is 0, the condition is not satisfied and the instruction produces the result 0. If the OR instruction is the first instruction in a string of logic operations, it saves the result of its signal state check in the RLO bit. Each OR instruction that is not the first instruction in the string of logic operations combines the result of its signal state check with the value stored in the RLO bit. These values are combined according to the OR truth table.
Status Word
BR writes CC1 CC0 OV OS OR X STA X RLO X FC 1
Example
I 0.0 I 0.1 >=1
Q 4.0 =
Output Q4.0 is set when the signal state is 1 at input I0.0 OR at input I0.1.
12
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
1.3
Symbol
<address> <address>
&
Parameter <address>
Memory Area I, Q, M, T, C, D, L
Description The address indicates the bit whose signal state will be checked.
Description
With the AND instruction, you can check the signal states of two or more specified addresses at the inputs of an AND box. If the signal state of all operands is 1, the condition is satisfied and the instruction provides the result 1. If the signal state of an address is 0, the condition is not satisfied and the instruction produces the result 0. If the AND instruction is the first instruction in a string of logic operations, it saves the result of its signal state check in the RLO bit. Every AND instruction that is not the first instruction in the string of logic operations, combines the result of its signal state check with the value stored in the RLO bit. These values are combined according to the AND truth table.
Status Word
BR writes CC1 CC0 OV OS OR X STA X RLO X FC 1
Example
I 0.0 I 0.1 &
Q 4.0 =
Output Q4.0 is set when the signal state is 1 at input I0.0 AND I0.1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
13
Bit Logic Instructions 1.4 AND-before-OR Logic Operation and OR-before-AND Logic Operation
1.4
Description
With the AND-before-OR instruction, you can check the result of a signal state according to the OR truth table. With an AND-before-OR logic operation the signal state is 1 when at least one AND logic operation is satisfied.
Status Word
BR writes CC1 CC0 OV OS OR X STA X RLO X FC 1
Example
I 1.0 I 1.1 I 1.2 I 1.3 & & >=1 Q 3.1 =
The signal state is 1 at output Q3.1 when at least one AND logic operation is satisfied The signal state is 0 at output Q3.1 when no AND logic operation is satisfied.
Description
With the OR-before-AND instruction, you can check the result of a signal state check according to the AND truth table. With an OR-before-AND logic operation the signal state is 1 when all OR logic operations are satisfied.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
14
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Bit Logic Instructions 1.4 AND-before-OR Logic Operation and OR-before-AND Logic Operation
Example
I 1.0 I 1.1 I 1.2 I 1.3 >=1 >=1 & Q 3.1 =
The signal state is 1 at output Q3.1 when both OR logic operations are satisfied. The signal state is 0 at output Q3.1 when at least one OR logic operation is not satisfied.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
15
1.5
Symbol
<address> <address>
XOR
Parameter
Data Type
Memory Area
Description
<address>
BOOL
I, Q, M, T, C, D, L
The address indicates the bit whose signal state will be checked.
Description
With the Exclusive OR instruction, you can check the result of a signal state check according to the Exclusive OR truth table. With an Exclusive OR logic operation, the signal state is 1 when the signal state of one of the two specified addresses is 1. You can also use the Exclusive OR function several times. The mutual result of logic operation is then "1" if an impair number of checked addresses is "1".
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 I 0.2 XOR
Q 3.1 =
The signal state is 1 at output Q3.1 when the signal state is 1 at either input I0.0 OR at input I0.2 (exclusively, in other words not at both).
16
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
1.6
Symbol
<address>
Parameter
Data Type
Memory Area
Description
<address>
BOOL
I, Q, M, T, C, D, L
The address indicates the bit whose signal state will be checked.
Description
The Insert Binary Input instruction inserts a further binary input to an AND, OR, or XOR box.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 1.0 I 1.1 I 1.2 &
Q 4.0 =
Output Q4.0 is 1 when the signal state at I1.0 AND I1.1 AND I1.2 is 1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
17
1.7
Symbol
Description
The Negate Binary Input instruction negates the RLO. When you negate the result of logic operation, you must remember certain rules: If the result of logic operation at the first input of an AND or OR box is negated, there is no nesting. If the result of logic operation is negated but not at the first input of an OR box, the entire binary logic operation before the input is included in the OR logic operation. If the result of logic operation is negated but not at the first input of a AND box, the entire binary logic operation before the input is included in the AND logic operation.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 1.0 I 1.1 I 1.2 I 1.3 I 1.4 & >=1 Q 4.0 = & &
Output Q4.0 is 1 when: the signal state at I1.0 AND I1.1 is NOT 1 AND the signal state at I1.2 AND I1.3 is NOT 1 OR the signal state at I1.4 is NOT 1.
18
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
1.8
Symbol
= : Assign
<address> =
Parameter
Data Type
Memory Area
Description
<address>
BOOL
I, Q, M, D, L
The address specifies the bit to which the signal state of the string of logic operations is assigned.
Description
The Assign instruction produces the result of logic operation. The box at the end of a logic operation has the signal 1 or 0 according to the following criteria: The output has the signal 1 when the conditions of the logic operation before the output box are satisfied. The output has the signal 0 when the conditions of the logic operation before the output box are not satisfied. The FBD logic operation assigns the signal state to the output that is addressed by the instruction (to achieve the same effect, the signal state of the RLO bit could also be assigned to the address). If the conditions of the FBD logic operations are satisfied, the signal state at the output box is 1. Otherwise the signal state is 0. The Assign instruction is influenced by the Master Control Relay (MCR). For more detailed information about the functions of the MCR, refer to MCR on/off. You can only place the Assign box at the right-hand end of the string of logic operations. You can, however, use several Assign boxes. You can create a negated assignment with the Negate Input instruction.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
19
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 I 0.1 I 0.2 & >=1 Q 4.0 =
The signal state at output Q4.0 is 1 when: the signal state is 1 at inputs I0.0 AND I0.1 OR I0.2 is 0
20
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
1.9
Symbol
# : Midline Output
<address> #
Parameter
Data Type
Memory Area
Description
<address>
BOOL
I, Q, M, D, *L
The address specifies the bit to which the RLO will be assigned.
* You can only use an address in the local data stack if it is declared in the variable declaration table in the TEMP area of a code block (FC, FB, OB).
Description
The Midline Output instruction is an intermediate element that buffers the RLO. More precisely, this element buffers the bit logic operation of the last branch to be opened before the Midline Output. The Midline Output instruction is is affected by the Master Control Relay (MCR). For more detailed information about how the MCR functions, refer to MCR on/off. You can create a negated Midline Output by negating the input of the Midline Output.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
21
Example
M 0.0 I 1.0 I 1.1 I 1.2 I 1.3 I 1.4 & M 1.1 # M 2.2 # >=1 M 3.3 # Q 4.0 = & # &
The Midline Outputs buffer the following results of the logic operations: M0.0 buffers the negated RLO of
I 1.0 I 1.1 &
M2.2 saves the RLO of I1.4 M3.3 saves the negated RLO of the entire bit logic operation
22
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
1.10
Symbol
R : Reset Output
<address>
Parameter
Data Type
Memory Area
Description
<address>
I, Q, M, T, C, D, L
Description
The Reset Output instruction is only executed when the RLO is 1. If the RLO is 1, this instruction resets the specified address to 0. If the RLO is 0, the instruction does not affect the specified address which remains unchanged. The Reset Output instruction is affected by the Master Control Relay (MCR). For more detailed information about how the MCR functions, refer to MCR on/off.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 I 0.1 I 0.2 & >=1 Q 4.0 R
The signal state at output Q4.0 is reset to 0 only when: The signal state is 1 at inputs I0.0 AND I0.1 OR the signal state at input I0.2 is 0. If the RLO of the branch is 0, the signal state at output Q4.0 is unchanged.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
23
1.11
Symbol
S : Set Output
<address>
Parameter
Data Type
Memory Area
Description
<address>
BOOL
I, Q, M, D, L
Description
The Set Output instruction is only executed when the RLO is 1. If the RLO is 1, this instruction sets the specified address to 1. If the RLO is 0, the instruction does not affect the specified address which remains unchanged. The Set Output instruction is affected by the Master Control Relay (MCR). For more detailed information about how the MCR functions, refer to MCR on/off.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 I 0.1 I 0.2 & >=1 Q 4.0 S
The signal state at output Q4.0 is set to 1 only when: The signal state is 1 at inputs I0.0 AND I0.1 OR the signal state at input I0.2 is 0. If the RLO of the branch is 0, the signal state of Q4.0 is not changed.
24
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
1.12
Symbol
<address>
RS R S Q
Parameter
Data Type
Memory Area
Description
<address> S R Q
I, Q, M, D, L I, Q, M, D, L, T, C I, Q, M, D, L, T, C I, Q, M, D, L
The address specifies which bit will be set or reset. Reset instruction enabled Set instruction enabled Signal state of <address>
Description
The Reset_Set Flip Flop instruction executes instructions such as Set (S) or Reset (R) only when the RLO is 1. An RLO of 0 does not affect these instructions, the address specified in the instruction is not changed. Reset_Set Flip Flop is reset when the signal state at input R is 1 and the signal state at input S is 0. If input R is 0 and input S is 1, the flip flop is set. If the RLO at both inputs is 1, the flip flop is set. The Reset_Set Flip Flop instruction is affected by the Master Control Relay (MCR). For more detailed information about how the MCR functions, refer to MCR on/off.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
25
Example
M 0.0 I 0.0 I 0.1 I 0.0 I 0.1 & R & S Q Q 4.0 = RS
If I0.0 is 1 and I0.1 is 0, the memory bit M0.0 is reset and output Q4.0 is 0. If I0.0 is 0 and I0.1 is 1, the memory bit M0.0 is set and output Q4.0 is 1. If both signal states are 0, there is no change. If both signal states are 1, the Set instruction dominates due to the order of the instructions. M 0.0 is set and Q4.0 is 1.
26
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
1.13
Symbol
<address>
SR S R Q
Parameter
Data Type
Memory Area
Description
<address> S R Q
I, Q, M, D, L I, Q, M, D, L, T, C I, Q, M, D, L, T, C I, Q, M, D, L
The address specifies which bit will be set or reset. Set instruction enabled Reset instruction enabled Signal state of <address>
Description
The Set_Reset Flip Flop instruction executes Set (S) or Reset (R) instructions only when the RLO is 1. An RLO of 0 has no effect on these instructions, the address specified in the instruction remains unchanged. Set_Reset Flip Flop is set when the signal state at input S is 1 and the signal state at input R is 0. If input S is 0 and input R is 1, the flip flop is reset. If the RLO at both inputs is 1 the flip flop is reset. The Set_Reset Flip Flop instruction is affected by the Master Control Relay (MCR). For more detailed information about how the MCR functions, refer to MCR on/off.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
M 0.0 I 0.0 I 0.1 I 0.0 I 0.1 & S & R Q Q 4.0 = SR
If I0.0 is 1 and I0.1 is 0, memory bit M0.0 is set and Q4.0 is 1.If I0.0 is 0 and I0.1 is 1, the memory bit M0.0 is reset and Q4.0 is 0. If both signal states are 0, there is no change. If both signal states are 1, the reset instruction dominates due to the order of the instructions. M0.0 is reset and Q 4.0 is 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
27
1.14
Symbol
<address> N
Parameter
Data Type
Memory Area
Description
<address>
BOOL
I, Q, M, D, L
The address specifies which edge memory bit will store the previous RLO.
Description
The Negative RLO Edge Detection instruction detects a change from 1 to 0 (falling edge) at the specified address and indicates this by setting the RLO to 1 after the instruction. The current signal state of the RLO is compared with the signal state of the address (the edge memory bit). If the signal state of the address is 1 and the RLO prior to the instruction was 0, the RLO is 1 (pulse) after the instruction, in all other cases it is 0. The RLO prior to the instruction is stored in the address.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 1.0 I 1.1 I 1.2 I 1.3 I 1.4 & & M 1.1 N M 2.2 P M 0.0 P
&
&
The edge memory bit M3.3 stores the signal state of the previous RLO.
28
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
1.15
Symbol
<address> P
Parameter
Data Type
Memory Area
Description
<address>
BOOL
I, Q, M, D, L
The address specifies which edge memory bit will store the previous RLO.
Description
The Positive RLO Edge Detection instruction detects a change from 0 to 1 (rising edge) at the specified address and indicates this with an RLO of 1 after the instruction. The current signal state at the RLO is compared with the signal state of the address (the edge memory bit). If the signal state of the address is 0 and the RLO is 1 before the instruction, the RLO will be 1 (pulse) after the instruction, in all other cases the RLO is 0. The RLO prior to the instruction is stored in the address.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 1.0 I 1.1 I 1.2 I 1.3 I 1.4 & & M 1.1 N M 2.2 P M 0.0 P
&
&
The edge memory bit M3.3 stores the signal state of the previous RLO.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
29
1.16
Symbol
SAVE
Description
The Save RLO to BR Memory instruction saves the RLO in the BR bit of the status word. The first check bit FC is not reset. For this reason, if there is an AND logic operation in the next network, the state of the BR bit is included in the logic operation. For the instruction SAVE (LAD, FBD, STL), the following applies and not the recommended use specified in the manual and online help: We do not recommend that you use SAVE and then check the BR bit in the same block or in subordinate blocks, because the BR bit can be modified by many instructions occurring inbetween. It is advisable to use the SAVE instruction before exiting a block, since the ENO output (= BR bit) is then set to the value of the RLO bit and you can then check for errors in the block. With the Save RLO to BR Memory instruction, the RLO of a network can form part of a logic operation in a subordinate block. The CALL instruction in the calling block resets the first check bit.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 1.2 I 1.3 & SAVE
The result of logic operation (RLO) is written to the BR bit. BR Binary Result Bit (Status Word, Bit 8)
30
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
1.17
Symbol
Parameter
Data Type
Memory Area
Description
<address1> M_BIT
BOOL BOOL
I, Q, M, D, L Q, M, D
Signal to be checked for a negative (falling) edge change. The M_BIT address specifies the edge memory bit in which the previous signal state of NEG is stored. Only use the process input image I memory area for the M_BIT when no input module is already using this address. One-shot output.
BOOL
I, Q, M, D, L
Description
The Address Negative Edge Detection instruction compares the signal state of <address1> with the signal state of the previous check that is stored in the M_BIT parameter. If a change from 1 to 0 occurred, output Q has the value 1, in all other situations it has the value 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.3 NEG M 0.0 M_BIT Q I 0.4 & Q 4.0 =
Output Q4.0 is 1 when: there is a falling edge at input I0.3 AND the signal state at input I0.4 is 1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
31
1.18
Symbol
<address1>
POS M_BIT Q
Parameter
Data Type
Memory Area
Description
<address1> M_BIT
BOOL BOOL
I, Q, M, D, L Q, M, D
Signal to be checked for a positive (rising) edge. The M_BIT address specifies the edge memory bit used to store the previous signal state of POS. You should only use the process image input area I for the M_BIT when no input module is already using this address. One-shot output.
BOOL
I, Q, M, D, L
Description
The Address Positive Edge Detection instruction compares the signal state of <address1> with the signal state of the previous signal check that is stored in the parameter M_BIT. If there has been a change from 0 to 1, output Q has the value 1, in all other cases it has the value 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
Output Q4.0 is 1 when: there is a rising edge at input I0.3 AND the signal state is 1 at input I0.4.
32
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
2
2.1
Comparison Instructions
Overview of Comparison Instructions
Description
IN1 and IN2 are compared according to the type of comparison you choose: == <> > < >= <= IN1 IN1 IN1 IN1 IN1 IN1 is equal to IN2 is not equal to IN2 is greater than IN2 is less than IN2 is greater than or equal to IN2 is less than or equal to IN2
If the comparison is true, the RLO of the function is "1". Otherwise, it is 0. You cannot negate the comparison result itself, but you can achieve the same effect as negation by using the opposite compare function. The following comparison instructions are available: CMP ? I : Compare Integer CMP ? D : Compare Double Integer CMP ? R : Compare Real
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
33
2.2
Symbol
CMP == I
IN1 IN2
CMP >I
IN1 IN2
CMP >= I
IN1 IN2
CMP <> I
IN1 IN2
CMP <I
IN1 IN2
CMP <= I
IN1 IN2
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L
Description
The Compare Integer instruction compares two values on the basis of 16bit floatingpoint numbers. This instruction compares inputs IN1 and IN2 according to the type of comparison you select from the list box.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
CMP == I IN1 IN2
&
I 0.0 Q 4.0 S
MW0 MW2
Q 4.0 is set when: MW0 is equal to MW2 AND the signal state is 1 at input I0.0.
34
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
2.3
Symbol
CMP == D
IN1 IN2
CMP >D
IN1 IN2
CMP >= D
IN1 IN2
CMP <> D
IN1 IN2
CMP <D
IN1 IN2
CMP <= D
IN1 IN2
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L or constant I, Q, M, D, or constant L I, Q, M, D, L
Description
The Compare Double Integer instruction compares two values on the basis of 32bit floatingpoint numbers. This instruction compares inputs IN1 and IN2 according to the type of comparison you select from the list box.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
CMP <> D IN1 IN2
&
I 0.0 Q 4.0 S
MD0 MD4
Q 4.0 is set when: MD0 is not equal to MD4 AND the signal state at input I 0.0 is 1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
35
2.4
Symbol
CMP == R
IN1 IN2
CMP >R
IN1 IN2
CMP >= R
IN1 IN2
CMP <> R
IN1 IN2
CMP <R
IN1 IN2
CMP <= R
IN1 IN2
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L
Description
The Compare Real instruction compares two values on the basis of real numbers. This instruction compares inputs IN1 and IN2 according to the type of comparison you select from the list box.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
CMP <R IN1 IN2
&
I 0.0 Q 4.0 S
MD0 MD4
Q 4.0 is set when: MD0 is less than MD4 AND the signal state at input I 0.0 is 1.
36
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
3
3.1
Conversion Instructions
Overview of Conversion Instructions
Description
You can use the following instructions to convert binary coded decimal numbers and integers to other types of numbers: BCD_I : BCD to Integer I_BCD : Integer to BCD BCD_DI : BCD to Double Integer I_DI : Integer to Double Integer DI_BCD : Double Integer to BCD DI_R : Double Integer to Real You can use one of the following instructions to form the complement of an integer or to invert the sign of a floating-point number: INV_I : Ones Complement Integer INV_DI : Ones Complement Double Integer NEG_I : Twos Complement Integer NEG_DI : Twos Complement Double Integer NEG_R : Negate Real Number You can use any of the following instructions to convert a 32-bit IEEE floating-point number in accumulator 1 to a 32-bit integer (double integer). The individual instructions differ in their method of rounding: ROUND : Round to Double Integer TRUNC : Truncate Double Integer Part CEIL : Ceiling FLOOR : Floor
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
37
3.2
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Number in BCD format Integer value of the BCD number Enable output
Description
The BCD to Integer instruction reads the content of the input parameter IN as a threedigit number in binary coded decimal format (BCD, 999) and converts this number to an integer value. The output parameter OUT contains the result. ENO always has the same signal state as EN. If any of the individual decimal numbers in the BCD number is in the invalid range between 10 and 15, a BCD error occurs when the conversion is attempted, causing the following reaction: The CPU changes to the STOP mode. BCD Conversion Error" is entered in the diagnostic buffer with event ID number 2521. If OB121 is programmed, it is called.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MW10 BCD_I EN OUT IN ENO MW12
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The content of memory word MW10 is read as a threedigit number in BCD format and converted to an integer. The result is stored in memory word MW12. If the conversion is executed, the signal state of output Q4.0 is 1 (ENO = EN).
38
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
3.3
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
The Integer to BCD instruction reads the content of the input parameter IN as an integer value and converts this value to a threedigit number in binary coded decimal format (BCD, 999). The output parameter OUT contains the result. If an overflow occurs, ENO is set to 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MW10 I_BCD EN OUT IN ENO MW12
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The content of memory word MW10 is read as an integer and converted to a threedigit number in BCD format. The result is stored in memory word MW12. If an overflow occurs, the signal state of output Q4.0 is 0. If the signal state at input EN is 0 (meaning that the conversion is not executed), the signal state of output Q4.0 is also 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
39
3.4
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Number in BCD format Double integer value of the BCD number Enable output
Description
The BCD to Double Integer instruction reads the content of the input parameter IN as a sevendigit number in binary coded decimal format (BCD, 9,999,999) and converts this number to a double integer value. The output parameter OUT contains the result. ENO always has the same signal state as EN. If any of the individual decimal numbers in the BCD number is in the invalid range between 10 and 15, a BCD error occurs when the conversion is attempted, causing the following reaction: The CPU changes to the STOP mode. BCD Conversion Error" is entered in the diagnostic buffer with event ID number 2521. If OB121 is programmed, it is called.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD8 BCD_DI EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The content of memory double word MD8 is read as a sevendigit number in BCD format and converted to a double integer. The result is stored in MD12. If the conversion is executed, the signal state of output Q4.0 is 1 (ENO = EN).
40
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
3.5
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
The Integer to Double Integer instruction reads the content of the input parameter IN as an integer and converts the integer to a double integer. The output parameter OUT contains the result. ENO always has the same signal state as EN.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MW10 I_DI EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The content of memory word MW10 is read as an integer and converted to a double integer. The result is stored in memory double word MD12. If the conversion is executed, the signal state of output Q4.0 is 1 (ENO = EN).
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
41
3.6
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Double Integer BCD value of the double integer Enable output
Description
The Double Integer to BCD instruction instruction reads the content of the input parameter IN as a double integer value and converts this value to a sevendigit number in BCD format ( 9 999 999). The output parameter OUT contains the result. If an overflow occurs, ENO is set to 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD8 DI_BCD EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The content of memory double word MD8 is read as a double integer and converted to a sevendigit number in BCD format. The result is stored in MD12. If an overflow occurs, the signal state of output Q4.0 is 0. If the signal state at input EN is 0 (meaning that the conversion is not executed), the signal state of output Q4.0 is also 0.
42
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
3.7
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
The Double Integer to Real instruction reads the content of the input parameter IN as a double integer value and converts this value to a real number. The output parameter OUT contains the result. ENO always has the same signal state as EN.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD8 DI_R EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The contents of memory double word MD8 is read as an integer and converted to a real number. The result is stored in memory double word MD12. If the conversion is not executed, the signal state of output Q4.0 is 0 (ENO=EN).
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
43
3.8
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Input value Ones complement of the integer Enable output
Description
The Ones Complement Integer instruction reads the content of the input parameter IN and performs the Boolean word logic instruction Exclusive Or Word masked by FFFFH, so that the value of every bit is inverted. The output parameter OUT contains the result. ENO always has the same signal state as EN.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MW8 INV_I EN OUT IN ENO MW10
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The value of every bit in MW8 is inverted: MW8 = 01000001 10000001 MW10 = 10111110 01111110 The conversion is not executed when the signal state of I0.0 is 0 and Q4.0 is 0 (ENO = EN).
44
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
3.9
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Input value Ones complement of the double integer Enable output
Description
The Ones Complement Double Integer instruction reads the content of the input parameter IN and performs the Boolean word logic operation Exclusive Or Word masked by FFFF FFFFH, so that the value of every bit is inverted. The output parameter OUT contains the result. ENO always has the same signal state as EN.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD8 INV_DI EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The value of every bit of memory double word MD8 is inverted: MD8 = F0FF FFF0 MD12 = 0F00 000F If the conversion is not executed, Q4.0 is 0 (ENO = EN).
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
45
3.10
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Input value Twos complement of the integer Enable output
Description
The Twos Complement Integer instruction reads the content of the input parameter IN and changes the sign (for example, from a positive value to a negative value). The output parameter OUT contains the result. The signal state of EN is and ENO is always the same except when the signal state of EN is 1 and an overflow occurs. In this case, the signal state of ENO is 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MW8 NEG_I EN OUT IN ENO MW10
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The value of memory word MW8 is output at O to memory word MW10 with the opposite sign: MW8 = +10 MW10 = -10 If the signal state of EN is 1 and an overflow occurs, ENO is 0 and the signal state of Q4.0 is 0. If the conversion is not executed, Q4.0 is 0 (ENO = EN).
46
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
3.11
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Input value Twos complement of the double integer Enable output
Description
The Twos Complement Double Integer instruction reads the content of the input parameter IN and changes the sign (for example, from a positive value to a negative value). The output parameter OUT contains the result. The signal state of EN is and ENO is always the same except when the signal state of EN is 1 and an overflow occurs. In this case, the signal state of ENO is 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD8 NEG_DI EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The value of memory double word MD8 is output at O to memory double word MD10 with the opposite sign. MW8 = +10 MW10 = -10 If the signal state of EN is 1 and an overflow occurs, ENO is 0 and the signal state of Q4.0 is 0. If the conversion is not executed, Q4.0 is 0 (ENO = EN).
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
47
3.12
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Input value The result is the negated input value. Enable output
Description
The Negate Real Number instruction reads the content of the input parameter IN and inverts the sign bit (the instruction changes the sign of the number. for example, from 0 for plus to 1 for minus). The bits of the exponent and mantissa remain the same. The output parameter OUT provides the result. ENO always has the same signal state as EN except when the signal state of EN is 1 and an overflow occurs. In this case, the signal state of ENO is 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD8 NEG_R EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The value of memory double word MD8 is output at O to memory double word MD12 with the opposite sign as shown in the following example: MD8 = + 6.234 MD12 = - 6.234 If the conversion is not executed, the signal state of output Q4.0 is 0 (ENO = EN).
48
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
3.13
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Value to be rounded IN rounded to the next double integer Enable output
Description
The Round to Double Integer instruction reads the content of the input parameter IN as a real number and converts this number to a double integer. The result is the nearest integer and is contained in output parameter OUT. If the fraction is x.5, the number is rounded to the even number (for example: 2.5 -> 2, 1.5 -> 2). If an overflow occurs, ENO is set to 0. If the input value is not a real number, the OV bit and the OS bit have the value 1 and ENO has the value 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD8 ROUND EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if I0.0 is 1. The content of memory double word MD8 is read as a real number and converted to a double integer. The result of this roundtonearest function is stored in memory double word MD12. If an overflow occurs, the signal state of output Q4.0 is 0. If the signal state at input EN is 0 (meaning that the conversion is not executed), the signal state of output Q4.0 is also 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
49
3.14
Symbol
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
The Truncate Double Integer Part instruction reads the content of the input parameter IN as a real number and converts this number to a double integer (for example 1.5 becomes 1). The result is the integer component of the real number). The output parameter OUT contains the result. If an overflow occurs, ENO is set to 0. If the input value is not a real number, the OV bit and the OS bit have the value 1 and ENO has the value 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD8 TRUNC EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if the signal state of I0.0 is 1. The content of memory double word MD8 is read as a real number and converted to a double integer according to the round to zero principle". The integer component is the result and is stored in memory double word MD12. If an overflow occurs, the signal state of output Q4.0 is 0. If the signal state at input EN is 0 (meaning that the conversion is not executed), the signal state of output Q4.0 is also 0.
50
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
3.15
Symbol
CEIL : Ceiling
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
The Ceiling instruction reads the content of the input parameter IN as a real number and converts this number to a double integer (for example: +1.2 -> +2; -1.5 -> -1). The result is the lowest integer which is greater than or equal to the specified real number. The output parameter OUT contains the result. If an overflow occurs, ENO is 0. If the input value is not a real number, the OV bit and the OS bit have the value 1 and ENO has the value 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD8 CEIL EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if I0.0 is 1.The content of memory double word MD8 is read as a real number and converted to a double integer by rounding to the next higher (or equal) whole number. The result is stored in memory double word MD12. If an overflow occurs, the signal state of output Q4.0 is 0. If the signal state at input EN is 0 (meaning that the conversion is not executed), the signal state of output Q4.0 is also 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
51
3.16
Symbol
FLOOR : Floor
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
The Floor instruction reads the content of the input parameter IN as a real number and converts this number to a double integer. The result is the highest integer which is lower than or equal to the specified real number. The output parameter OUT contains the result. If an overflow occurs, ENO is set to 0. If the input value is not a real number, the OV bit and the OS bit have the value 1 and ENO has the value 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD8 FLOOR EN OUT IN ENO MD12
Q 4.0 =
The conversion is executed if I0.0 is 1. The content of memory double word MD8 is read as a real number and converted to a double integer by rounding to the next lower (or equal) whole number. The result is stored in memory double word MD12. If an overflow occurs, the signal state of output Q4.0 is 0. If the signal state at input EN is 0 (meaning that the conversion is not executed), the signal state of output Q4.0 is also 0.
52
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
4
4.1
Counter Instructions
Overview of Counter Instructions
Area in Memory
Counters have an area reserved for them in the memory of your CPU. This memory area reserves one 16-bit word for each counter address. When you program in FBD, 256 counters are supported. The counter instructions are the only functions that have access to the counter memory area.
Count Value
Bits 0 through 9 of the counter word contain the count value in binary code. The count value is moved to the counter word when a counter is set. The range of the count value is 0 to 999. You can vary the count value within this range by using the following counter instructions: S_CUD : Assign Parameters and Count Up/Down S_CU : Assign Parameters and Count Up S_CD : Assign Parameters and Count Down SC : Set Counter Value CU : Up Counter CD : Down Counter
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
53
15 14 13 12 11 10 0 irrelevant 0 1
9 0
8 1
7 0
6 0 2
5 1
4 0
3 0
2 1 7
1 1
0 1
15 14 13 12 11 10
9 0
8 0
7 0
6 1
5 1
4 1
3 1
2 1
1 1
0 1
irrelevant
54
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
4.2
Symbol
English
German
C no. S_CUD CU CD S PV R
CV CV_BCD Q
Parameter English
Parameter German
Data Type
Memory Area
Description
no. CU CD S PV
Nr. ZV ZR S ZW
C I, Q, M, D, L I, Q, M, D, L I, Q, M, D, L, T, C I, Q, M, D, L or constant
Counter identification number. The range depends on the CPU. ZV input: Up Counter ZR input: Down Counter Input for presetting the counter Count value in the range between 0 and 999 or Count value entered as C#<value> in BCD format Reset input Current count value (hexadecimal number) Current count value (BCD format) Status of the counter
R CV CV_BCD Q
R DUAL DEZ Q
I, Q, M, D, L, T, C I, Q, M, D, L I, Q, M, D, L I, Q, M, D, L
Description
A rising edge (change in signal state from 0 to 1) at input S of the Assign Parameters and Count Up/Down instruction sets the counter with the value at the Preset Value (PV) input. The counter is incremented by 1 if the signal state at input CU changes from 0 to 1 (rising edge) and the value of the counter is less than 999. The counter is decremented by 1 if the signal state at input CD changes from 0 to 1 (rising edge) and the value of the counter is higher than 0. If there is a rising edge at both count inputs, both operations are executed and the count remains the same. If the counter is set and if RLO = 1 at the inputs CU/CD, the counter will count once in the next scan cycle, even if there was no change from a positive to a negative edge or vice versa. The counter is reset if the signal on input R is "1". Resetting the counter sets the count value to 0. A signal state check for 1 at output Q produces a result of 1 when the count is greater than 0; the check produces a result of 0 when the count is equal to 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
55
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
C10 S_CUD I 0.0 I 0.1 I 0.2 C#55 I 0.3 CU CD S CV
Q 4.0
PV CV_BCD R Q
A change in signal state from 0 to 1 at input I0.2 sets counter C10 with the value 55. If the signal state of input I0.0 changes from 0 to 1, the value of counter C10 is incremented by 1, except when the value of counter C10 is already 999. If input I0.1 changes from 0 to 1, counter C10 is decremented by 1, except when the value of counter C10 is already 0. If I0.3 changes from 0 to 1, the value of C10 is set to 0. Q4.0 is 1, when C 10 is not equal to 0. Note Avoid to use a counter at several program points (risk of counting errors).
56
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
4.3
Symbol
Description Counter identification number. The range depends on the CPU. ZV input: Up Counter Input for presetting the counter Count value in the range between 0 and 999 or Count value entered as C#<value> in BCD format Reset input Current count value (hexadecimal number) Current count value (BCD format) Status of the counter
R CV CV_BCD Q
R DUAL DEZ Q
I, Q, M, D, L, T, C I, Q, M, D, L I, Q, M, D, L I, Q, M, D, L
Description
A rising edge (change in signal state from 0 to 1) at input S of the Assign Parameters and Count Up instruction sets the counter with the value at the Preset Value (PV) input. With a rising edge at input CU, the count value is incremented by 1 when the count value is less than 999. If the counter is set and if RLO = 1 at the inputs CU, the counter will count once in the next scan cycle, even if there was no change from a positive to a negative edge or vice versa. The counter is reset if the signal on input R is "1". Resetting the counter sets the count value to 0. A signal state check for 1 at output Q produces a result of 1 when the count is greater than 0. The check produces a result of 0 when the count is equal to 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
57
Status Word
BR writes CC1 CC0 OV OS OR X STA X RLO X FC 1
Example
C10 S_CU I 0.0 I 0.2 C#901 I 0.3 CU S R CV Q Q 4.0 = PV CV_BCD
A change in signal state from 0 to 1 at input I0.2 sets counter C10 with the value 901. If the signal state of I0.0 changes from 0 to 1, the value of counter C10 is incremented by 1, unless the value of C10 is equal to 999. If I0.3 changes from 0 to1, the value of C10 is set to 0. The signal state of output Q4.0 is 1 if C10 is not equal to 0. Note Avoid to use a counter at several program points (risk of counting errors).
58
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
4.4
Symbol
Description Counter identification number. The range depends on the CPU. CD input: Down Counter Input for presetting the counter Count value in the range between 0 and 999 or Count value entered as C#<value> in BCD format Reset input Current count value (hexadecimal number) Current count value (BCD format) Status of the counter
R CV CV_BCD Q
R DUAL DEZ Q
I, Q, M, D, L, T, C I, Q, M, D, L I, Q, M, D, L I, Q, M, D, L
Description
A rising edge (change in signal state from 0 to 1) at input S of the Assign Parameters and Count Down instruction sets the counter with the value at the Preset Value input (PV). With a rising edge at input CD, the counter is decremented by 1 when the count value is greater than 0. If the counter is set and if RLO = 1 at the inputs CD, the counter will count once in the next scan cycle, even if there was no change from a positive to a negative edge or vice versa. The counter is reset if the signal on input R is "1". Resetting the counter sets the count value to 0. A signal state check for 1 at output Q produces a result of 1 when the count is greater than 0; the check produces a result of 0 when the count is equal to 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
59
Status Word
BR writes CC1 CC0 OV OS OR X STA X RLO X FC 1
Example
C10 S_CD I 0.0 I 0.2 C#89 I 0.3 CD S PV R CV CV_BCD Q Q 4.0 =
A change in signal state from 0 to 1 at input I0.2 sets counter C10 with the value 89. If the signal state of input I0.0 changes from 0 to 1, the value of counter C10 is decreased by 1, unless the value of counter C10 is equal to 0. The signal state of output Q4.0 is 1 if counter C10 is not equal to 0. If I0.3 changes from 0 to 1, the value of C10 is set to 0. Note Avoid to use a counter at several program points (risk of counting errors).
60
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
4.5
Symbol
Description The address1 specifies the number of the counter which is to be preset with a value. The value to be preset (address2) can lie between 0 and 999. When you enter a constant, C# must stand in front of the value specified by the BCD format, for example, C#100.
Description
The Set Counter Value instruction assigns a preset value to the counter you specified. This instruction is only executed if there is a rising edge (change in signal state from 0 to 1) in the RLO. You can only place the box Set Counter Value at the right-hand end of a logic string. You can use a number of Set Counter Value boxes.
Status Word
BR writes CC1 CC0 OV OS OR 0 STA RLO FC 0
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
61
Example
C5 SC CV
I 0.0 C#100
The counter C5 is preset with the value 100 if the signal state at input I0.0 changes from 0 to 1 (rising edge in the RLO). C# indicates that you are entering a value in BCD format. If there is no rising edge, the counter value of C5 is not changed.
62
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
4.6
Symbol
CU : Up Counter
English <address> CU
German <address> ZV
Memory Area C
Description The address specifies the number of the counter which is to be incremented.
Description
The Up Counter instruction increments the value of a specified counter by 1 if there is a rising edge (change in signal state from 0 to 1) in the RLO and the value of the counter is less than 999. If there is no rising edge in the RLO or if the counter already has the value 999, it is not incremented. The Set Counter Value instruction sets the value of the counter. You can only place the box Up Counter at the right-hand end of a logic string. You can use a number of Up Counter boxes.
Status Word
BR writes CC1 CC0 OV OS OR 0 STA RLO FC 0
Example
C10 I 0.0 CU
If the signal state at input I0.0 changes from 0 to 1 (rising edge in the RLO), the value of the counter C10 is incremented by 1 (unless the value of C10 is already 999). If there is no rising edge, the value of C10 remains unchanged.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
63
4.7
Symbol
CD : Down Counter
English
<address> CD
German
<address> ZR
Parameter
Counter no.
Data Type
COUNTER
Memory Area
C
Description
The address specifies the number of the counter which is to be decremented.
Description
The Down Counter instruction decrements the value of a specified counter by 1 if there is a rising edge (change in signal state from 0 to 1) in the RLO and the value of the counter is greater than 0. If there is no rising edge in the RLO or if the counter already has the value 0, it is not decremented. The Set Counter Value instruction sets the value of the counter. You can only place the box Down Counter at the right-hand end of a logic string. You can use a number of Down Counter boxes.
Status Word
BR
writes -
CC1
-
CC0
-
OV
-
OS
-
OR
0
STA
-
RLO
-
FC
0
Example
C10 I 0.0 CD
If the signal state at input I0.0 changes from 0 to 1 (rising edge in the RLO), the value of the counter C10 is decremented by 1 (unless the value of C10 is already 0). If there is no rising edge, the value of C10 remains unchanged.
64
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
5
5.1
Symbol
Parameter
Number of the DB or DI
Data Type
BLOCK_DB
Memory Area
-
Description
Number of the DB or DI; Range depends on the CPU.
Description
You can use the Open Data Block instruction to open an existing data block as a shared data block (DB) or instance data block (DI). The number of the data block is transferred to the DB or DI register. The subsequent DB and DI commands access the corresponding blocks depending on the register contents.
Status Word
BR
writes -
CC1
-
CC0
-
OV
-
OS
-
OR
-
STA
-
RLO
-
FC
-
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
65
Example
Network 1
DB10 OPN
Network 2
DB10 is the currently opened data block. The scan at DBX0.0 therefore refers to bit 0 of data byte 0 of data block DB10. The signal state of this bit is assigned to output Q 4.0.
66
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
6
6.1
Jump Instructions
Overview of Jump Instructions
Description
You can use this instruction in all logic blocks, for example in organization blocks (OBs), function blocks (FBs) and functions (FCs). The following Jump instructions are available: JMP JMP JMPN Unconditional Jump in a Block Conditional Jump in a Block Jump-If-Not
. .
Network X SEG3 Q 4.1 I 0.4 R
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
67
6.2
Symbol
<Operand> JMP
Parameter
Data Type
Memory Area
Description
The address specifies the label to which the program will jump unconditionally.
Description
The Unconditional Jump in a Block instruction corresponds to a go to label" instruction. None of the instructions between the jump operation and the label is executed. You can use this instruction in all logic blocks, for example in organization blocks (OBs), function blocks (FBs) and functions (FCs). There must not be any logic operation before the Unconditional Jump in a Block box.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
The instruction does not change the bits in the status word.
Example
Network 1 CAS1 ??.? JMP
. .
Network X CAS1 Q4.1 I 0.4 R
The jump is always executed. None of the instructions between the jump instruction and the label is executed.
68
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
6.3
Symbol
<address> JMP
Parameter
Data Type
Memory Area
Description
The address specifies the label to which the program will jump if the RLO is 1.
Description
The Conditional Jump in a Block instruction corresponds to a go to label" instruction if the RLO is 1. The FBD element Unconditional Jump" is also used for this operation, however it is made conditional by the preceding logic operation. The conditional jump is only executed when the result of this logic operation is 1. None of the instructions between the jump operation and the label is executed. You can use this instruction in all logic blocks, for example in organization blocks (OBs), function blocks (FBs) and functions (FCs).
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
Network 1 CAS1 I 0.0 Network 2 Q4.0 I 0.3 Network 3 CAS1 Q4.1 I 0.4 R R JMP
If the signal state of input I0.0 is 1, the jump to label CAS1 is executed. The instruction to reset output Q4.0 is not executed, even if the signal state of input I0.3 is 1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
69
6.4
Symbol
JMPN : Jump-If-Not
<address> JMPN
Parameter
Data Type
Memory Area
Description
The address specifies the label to which the program will jump if the RLO is 0.
Description
The Jump-If-Not instruction corresponds to a go to label" instruction that is executed if the RLO is 0. You can use this instruction in all logic blocks, for example in organization blocks (OBs), function blocks (FBs) and functions (FCs).
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
Network 1 CAS1 I 0.0 Network 2 Q4.0 I 0.3 Network 3 CAS1 Q4.1 I 0.4 R R JMPN
If the signal state of input I0.0 is 0, the jump to label CAS1 is executed. The instruction to reset output Q4.0 is not executed, even if the signal state of input I0.3 is 1. None of the instructions between the jump operation and the label is executed.
70
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
6.5
Symbol
LABEL
Description
The jump label is the identifier for the destination of a jump instruction. A label consists of a maximum of four characters. The first character must be a letter; the other characters can be letters or numbers, for example CAS1. A jump label must exist for every jump or jump-if-not instruction (JMP or JMPN).
Example
Network 1 CAS1 I 0.0 Network 2 Q4.0 I 0.3 Network 3 CAS1 Q4.1 I 0.4 R R JMP
If I0.0 = 1, the jump to label CAS1 is executed. Due to the jump, the operation Reset output" at Q 4.0 is not executed even if I0.3 = 1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
71
72
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
7
7.1
Description
Using integer math, you can carry out the following operations with two integer numbers (16 and 32 bits): ADD_I : Add Integer SUB_I : Subtract Integer MUL_I : Multiply Integer DIV_I : Divide Integer ADD_DI : Add Double Integer SUB_DI : Subtract Double Integer MUL_DI : Multiply Double Integer DIV_DI : Divide Double Integer MOD_DI : Return Fraction Double Integer See also Evaluating the Bits of the Status Word with Integer Math Instructions
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
73
Integer Math Instructions 7.2 Evaluating the Bits of the Status Word with Integer Math Instructions
7.2
Evaluating the Bits of the Status Word with Integer Math Instructions
Description
The integer math instructions affect the following bits in the status word: CC1 and CC0, OV and OS. The following tables show the signal state of the bits in the status word for the results of instructions with Integers (16 and 32 bits):
Valid Range for the Result CC 1 CC 0 OV OS
0 (zero) 16 bits: -32 768 <= result < 0 (negative number) 32 bits: -2 147 483 648 <=result < 0 (negative number) 16 bits: 32 767 >= result > 0 (positive number) 32 bits: 2 147 483 647 >= result > 0 (positive number)
0 0 1
0 1 0
0 0 0
* * *
Underflow (addition) 16 bits: result = -65536 32 bits: result = -4 294 967 296 Underflow (multiplication) 16 bits: result < -32 768 (negative number) 32 bits: result < -2 147 483 648 (negative number) Overflow (addition, subtraction) 16 bits: result > 32 767 (positive number) 32 bits: result > 2 147 483 647 (positive number) Overflow (multiplication, division) 16 bits: result > 32 767 (positive number) 32 bits: result > 2 147 483 647 (positive number) Underflow (addition, subtraction) 16 bits: result < -32. 768 (negative number) 32 bits: result < -2 147 483 648 (negative number) Division by 0
Operation
A1
A0
OV
OS
+D:
0 1
0 1
1 1
1 1
/D or MOD: division by 0
74
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
7.3
Symbol
ADD_I
EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input First value for addition Second value for addition Result of addition Enable output
Description
A signal state of 1 at the Enable (EN) input activates the Add Integer instruction. This instruction adds inputs IN1 and IN2. The result can be scanned at OUT. If the result is outside the permissible range for an integer, the OV and OS bit of the status word are 1 and the ENO is 0. See also Evaluating the Bits of the Status Word with Integer Math Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MW0 MW2
ADD_I
EN IN1 IN2 OUT ENO MW10 Q 4.0 =
A signal state of 1 at input I0.0 activates the ADD_I box. The result of the addition MW0 + MW2 is entered in memory word MW10. If the result is outside the permitted range for an integer or the signal state of input I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
75
7.4
Symbol
SUB_I
EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Minuend (value from which second value is subtracted) Subtrahend (value subtracted from the first value) Result of subtraction Enable output
Description
A signal state of 1 at the Enable (EN) input activates the Subtract Integer instruction. This instruction subtracts input IN2 from IN1. The result can be scanned at OUT. If the result is outside the permitted range for an integer, the OV and the OS bit of the status word are 1 and the ENO is 0. See also Evaluating the Bits of the Status Word with Integer Math Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MW0 MW2
SUB_I
EN IN1 IN2 OUT ENO MW10 Q 4.0 =
A signal state of 1 at input I0.0 activates the SUB_I box. The result of the subtraction MW0 - MW2 is entered in memory word MW10. If the result is outside the permitted range for an integer or the signal state of input I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
76
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
7.5
Symbol
MUL_I
EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Multiplicand (value that is multiplied by the second value) Multiplier (value by which the first value is multiplied) Result of the multiplication Enable output
Description
A signal state of 1 at the Enable (EN) input activates the Multiply Integer instruction. This instruction multiplies input IN1 by IN2. The result is a 32bit integer that can be scanned at OUT. If the result is outside the permitted range for a 16bit integer, the OV and the OS bit of the status word are 1 and the ENO is 0. See also Evaluating the Bits of the Status Word with Integer Math Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MW0 MW2
MUL_I
EN IN1 IN2 OUT ENO MW10 Q 4.0 =
A signal state of 1 at input I0.0 activates the MUL_I box. The result of the multiplication MW0 x MW2 is entered in memory word MW10. If the result is outside the permitted range for a 16bit integer or the signal state of input I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
77
7.6
Symbol
DIV_I
EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
A signal state of 1 at the Enable (EN) input activates the Divide Integer instruction. This instruction divides input IN1 by IN2. The integer quotient (truncated result) can be scanned at OUT. The remainder cannot be scanned. If the quotient is outside the permitted range for an integer, the OV and the OS bit of the status word are 1 and the ENO is 0. See also Evaluating the Bits of the Status Word with Integer Math Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MW0 MW2
DIV_I
EN IN1 IN2 OUT ENO MW10 Q 4.0 =
A signal state of 1 at input I0.0 activates the DIV_I box. The quotient of dividing MW0 by MW2 is entered in memory word MW10. If the quotient is outside the permitted range for an integer or the signal state of input I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
78
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
7.7
Symbol
ADD_DI
EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input First value for addition Second value for addition Result of addition Enable output
Description
A signal state of 1 at the Enable (EN) input activates the Add Double Integer instruction. This instruction adds inputs IN1 and IN2. The result can be scanned at OUT. If the result is outside the permissible range for a double integer, the OV and the OS bit of the status word are 1 and the ENO is 0. See also Evaluating the Bits of the Status Word with Integer Math Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD0 MD4
ADD_DI
EN IN1 IN2 OUT ENO MD10 Q 4.0 =
A signal state of 1 at input I0.0 activates the ADD_DI box. The result of the addition MD0 + MD4 is entered in memory double word MD10. If the result is outside the permitted range for a double integer or the signal state of input I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
79
7.8
Symbol
SUB_DI
EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Minuend (value from which second value is subtracted) Subtrahend (value subtracted from the first value) Result of subtraction Enable output
Description
A signal state of 1 at the Enable (EN) input activates the Subtract Double Integer instruction. This instruction subtracts input IN2 from IN1. The result can be scanned at OUT. If the result is outside the permitted range for a double integer, the OV and the OS bit of the status word are 1 and the ENO is 0. See also Evaluating the Bits of the Status Word with Integer Math Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD0 MD4
SUB_DI
EN IN1 IN2 OUT ENO MD10 Q 4.0 =
A signal state of 1 at input I0.0 activates the SUB_DI box. The result of the subtraction MD0 - MD4 is entered in memory double word MD10. If the result is outside the permitted range for a double integer or the signal state of input I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
80
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
7.9
Symbol
MUL_DI
EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Multiplicand (value that is multiplied by the second value) Multiplier (value by which the first value is multiplied) Result of the multiplication Enable output
Description
A signal state of 1 at the Enable (EN) input activates the Multiply Double Integer instruction. This instruction multiplies inputs IN1 and IN2. The result can be scanned at OUT. If the result is outside the permitted range for a double integer, the OV and the OS bit of the status word are 1 and the ENO is 0. See also Evaluating the Bits of the Status Word with Integer Math Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD0 MD4
MUL_DI
EN IN1 IN2 OUT ENO MD10 Q 4.0 =
A signal state of 1 at input I0.0 activates the MUL_DI box. The result of the multiplication MD0 x MD4 is entered in memory double word MD10. If the result is outside the permitted range for a double integer or the signal state of input I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
81
7.10
Symbol
DIV_DI
EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
A signal state of 1 at the Enable (EN) input activates the Divide Double Integer instruction. This instruction divides input IN1 by IN2. The quotient (truncated result) can be scanned at OUT. The Divide Double Integer instruction stores the quotient as a single 32bit value in DINT format. This instruction does not produce a remainder. If the quotient is outside the permitted range for a double integer, the OV and the OS bit of the status word are 1 and the ENO is 0. See also Evaluating the Bits of the Status Word with Integer Math Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD0 MD4
DIV_DI
EN IN1 IN2 OUT ENO MD10 Q 4.0 =
A signal state of 1 at input I0.0 activates the DIV_DI box. The quotient of dividing MD0 by MD4 is entered in memory double word MD10. If the quotient is outside the permitted range for a double integer or the signal state of input I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
82
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
7.11
Symbol
MOD_DI
EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
A signal state of 1 at the Enable (EN) input activates the Return Fraction Double Integer instruction. This instruction divides input IN1 by IN2. The remainder (fraction) can be scanned at OUT. If the result is outside the permitted range for a double integer, the OV and the OS bit of the status word are 1 and the ENO is 0. See also Evaluating the Bits of the Status Word with Integer Math Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 MD0 MD4
MOD_DI
EN IN1 IN2 OUT ENO MD10 Q 4.0 =
A signal state of 1 at input I0.0 activates the MOD_DI box. The remainder (fraction) of dividing MD0 by MD4 is stored in memory double word MD10. If the result is outside the permitted range for a double integer or the signal state of input I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
83
84
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
8
8.1
Description
The IEEE 32-bit floating-point numbers belong to the data type called REAL. You can use the floating-point math instructions to perform the following math instructions using two 32-bit IEEE floating-point numbers: ADD_R : Add Real SUB_R : Subtract Real MUL_R : Multiply Real DIV_R : Divide Real You can carry out the following operations with one 32-bit IEEE floating-point number: Form the absolute value (ABS) of a floating-point number Form the square (SQR) or square root (SQRT) of a floating-point number Form the natural logarithm (LN) of a floating-point number Form the exponential value of a floating-point number (EXP) to base e (= 2.71828...) Form the following trigonometric functions of an angle, represented as a 32-bit floating-point number: sine (SIN) and arc sine (ASIN) cosine (COS) and arc cosine (ACOS) tangent (TAN) and arc tangent (ATAN)
See also Evaluating the Bits of the Status Word with Floating-Point Instructions.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
85
Floating-Point Math Instructions 8.2 Evaluating the Bits of the Status Word with Floating-Point Instructions
8.2
Description
Floating-point instructions affect the following bits in the status word: CC 1 and CC 0, OV and OS. The following tables show the signal state of the bits in the status word for the results of instructions with floating-point numbers (32 bits):
Valid Range for the Result CC 1 CC 0 OV OS
+0, -0 (zero) -3.402823E+38 < result < -1.175494E-38 (negative number) +1.175494E-38 < result < 3.402824E+38 (positive number)
0 0 1
0 1 0
0 0 0
* * *
Underflow -1.175494E-38 < result < - 1.401298E-45 (negative number) Underflow +1.401298E-45 < result < +1.175494E-38 (positive number) Overflow Result < -3.402823E+38 (negative number) Overflow Result > 3.402823E+38 (positive number) Not a valid floating-point number or illegal instruction (input value outside the valid range)
86
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
8.3
8.3.1
Basic Instructions
ADD_R : Add Real
Symbol
ADD_R EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input First number to be added Second number to be added Result of addition Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Add Real instruction. This instruction adds inputs IN1 and IN2. The result can be scanned at output OUT. If either of the inputs or the result is not a floating-point number, the OV bit and OS bit are set to 1 and ENO is set to 0. See also Evaluating the Bits of the Status Word with Floating Point Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
ADD_R
I 0.0 MD0 MD4 EN IN1 IN2 OUT ENO MD10 Q 4.0 =
A signal state of 1 at input I0.0 activates the ADD_R box. The result of the addition MD0 + MD4 is entered in memory double word MD10. If either of the inputs or the result is not a floating-point number and if the signal state of I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
87
8.3.2
Symbol
SUB_R EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Minuend (from which the second value is subtracted) Subtrahend (that is subtracted from the first value) Result of subtraction Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Subtract Real instruction. This instruction subtracts input IN2 from IN1. The result can be scanned at output OUT. If either of the inputs or the result is not a floating-point number, the OV bit and the OS bit are set to 1 and ENO is set to 0. See also Evaluating the Bits of the Status Word with Floating Point Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
SUB_R
I 0.0 MD0 MD4 EN IN1 IN2 OUT ENO MD10 Q 4.0 =
A signal state of 1 at input I0.0 activates the SUB_R box. The result of the subtraction MD0 - MD4 is entered in memory double word MD10. If either of the inputs or the result is not a floating-point number and if the signal state of I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
88
8.3.3
Symbol
MUL_R EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Multiplicand (value to be multiplied) Multiplier (value by which first value is multiplied) Result of multiplication Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Multiply Real instruction. This instruction multiplies input IN1 by IN2. The result can be scanned at output OUT. If either of the inputs or the result is not a floating-point number, the OV bit and the OS bit are set to 1 and ENO is set to 0. See also Evaluating the Bits of the Status Word with Floating Point Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
MUL_R
I 0.0 MD0 MD4 EN IN1 IN2 OUT ENO MD10 Q 4.0 =
A signal state of 1 at input I0.0 activates the MUL_R box. The result of the multiplication MD0 x MD4 is entered in memory double word MD10. If either of the inputs or the result is not a floating-point number and if the signal state of I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
89
8.3.4
Symbol
DIV_R EN IN1 IN2 OUT ENO
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Dividend (value to be divided by second value) Divisor (value by which first value is divided) Result of division Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Divide Real instruction. This instruction divides input IN1 by IN2. The result can be scanned at output OUT. If either of the inputs or the result is not a floating-point number, the OV bit and the OS bit are set to 1 and ENO is set to 0. See also Evaluating the Bits of the Status Word with Floating Point Instructions.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
DIV_R
I 0.0 MD0 MD4 EN IN1 IN2 OUT ENO MD10 Q 4.0 =
A signal state of 1 at input I0.0 activates the DIV_R box. The result of dividing MD0 by MD4 is entered in memory double word MD10. If either of the inputs or the result is not a floating-point number and if the signal state of I0.0 is 0, output Q4.0 is set to 0 and the instruction is not executed.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
90
8.3.5
Symbol
ABS EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Enable input Input value: floating-point number Output value: absolute value of the floating-point number Enable output
Description
With the Form the Absolute Value of a Floating-Point Number instruction, you can form the absolute value of floating-point number.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
ABS
I 0.0 MD8 EN OUT IN ENO MD10 Q 4.0
If I0.0 = 1, the absolute value of MD8 is output at MD12. MD8 = +6.234 results in MD12 = 6.234 x 1. Output Q4.0 is 0 if the conversion is not executed (ENO = EN = 0).
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
91
8.4
8.4.1
Extended Instructions
SQR : Forming the Square of a Floating-Point Number
Symbol
SQR EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
With the Form the Square of a Floating-Point Number instruction, you can square a floating-point number. If either of the inputs or the result is not a floating-point number, the OV bit and OS bit are set to 1 and ENO is set to 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
SQR
I 0.0 MD0 EN OUT IN ENO MD10 Q 4.0
A signal state of 1 at input I0.0 activates the SQR box. The result of SQR (MD0) is entered in the memory double word MD10. If MD0 is less than 0 or if either of the inputs or the result is not a floating-point number and if the signal state of I0.0 is 0, output Q4.0 is set to 0.
92
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
8.4.2
Symbol
SQRT EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
With the Form the Square Root of a Floating-Point Number instruction, you can extract the square root of a floating-point number. This instruction returns a positive result, if the value at the address is greater than 0". If either of the inputs or the result is not a floating-point number, the OV bit and OS bit are set to 1 and ENO is set to 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
SQRT
I 0.0 MD0 EN OUT IN ENO MD10 Q 4.0
A signal state of 1 at input I0.0 activates the SQRT box. The result of SQRT (MD0) is entered in memory double word MD10. If MD0 is less than 0 or if either of the inputs or the result is not a floating-point number and if the signal state of I0.0 is 0, output Q4.0 is set to 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
93
8.4.3
Symbol
EXP EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
With the Form the Exponential Value of a Floating-Point Number instruction, you can form the exponential value of a floating-point number to base e (= 2.71828...). If either of the inputs or the result is not a floating-point number, the OV bit and OS bit are set to 1 and ENO is set to 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
EXP
I 0.0 MD0 EN OUT IN ENO MD10 Q 4.0
A signal state of 1 at input I0.0 activates the EXP box. The result of EXP (MD0) is entered in memory double word MD10. If either of the inputs or the result is not a floating-point number and if the signal state of I 0.0 is 0, output Q4.0 is set to 0.
94
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
8.4.4
Symbol
LN EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
With the Form the Natural Logarithm of a Floating-Point Number instruction, you can form the natural logarithm of a floating-point number. If either of the inputs or the result is not a floating-point number, the OV bit and OS bit are set to 1 and ENO is set to 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
LN
EI MD0 EN OUT IN ENO MD10 Q 4.0
A signal state of 1 at input I0.0 activates the LN box. The result of LN (MD0) is entered in memory double word MD10. If MD0 is less than 0 or if either of the inputs or the result is not a floating-point number and if the signal state of I0.0 is 0, output Q4.0 is set to 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
95
8.4.5
Description
With the following instructions, you can form trigonometric functions of angles represented as 32-bit IEEE floating-point numbers.
Instruction Meaning
Form the sine of a floating-point number of an angle specified in radians. Form the cosine of a floating-point number of an angle specified in radians. Form the tangent of a floating-point number of an angle specified in radians. Form the arc sine of a floating-point number. The result is an angle specified in radians. The value is in the following range: - / 2 <= arc sine <= + / 2, where = 3.14... Form the arc cosine of a floating-point number. The result is an angle specified in radians. The value is in the following range: 0 <= arc cosine <= + , where = 3.14... Form the arc tangent of a floating-point number. The result is an angle specified in radians. The value is in the following range: - / 2 <= arc tangent <= + / 2, where = 3.14...
ACOS
ATAN
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
SIN
EI 0.0 MD0 EN OUT IN ENO MD10 Q 4.0
A signal state of 1 at input I0.0 activates the SIN box. The result of SIN (MD0) is entered in memory double word MD10. If either of the inputs or the result is not a floating-point number and if the signal state of I0.0 is 0, output Q4.0 is set to 0.
96
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Symbol
SIN EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Symbol
ASIN EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Symbol
COS EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
97
Symbol
ACOS EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Symbol
TAN EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Symbol
ATAN EN OUT IN ENO
Parameter
Data Type
Memory Area
Description
EN IN OUT ENO
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
98
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
9
9.1
Symbol
Move Instructions
MOVE : Assign Value
MOVE
EN IN OUT ENO
Parameter
Data Type
Memory Area
Description
EN IN
BOOL
I, Q, M, D, L, T, C
I, Q, M, D, L or All elementary data types with a length of constant 8, 16 or 32 bits I, Q, M, D, L All elementary data types with a length of 8, 16 or 32 bits BOOL I, Q, M, D, L
OUT
Destination address
ENO
Enable output
Description
With the Assign Value instruction, you can assign specific values to variables. The value specified at the IN input is copied to the address specified at the OUT output. ENO has the same signal state as EN. With the MOVE box, the Assign Value instruction can copy all elementary data types with lengths of 8, 16, or 32 bits. Userdefined data types such as arrays or structures must be copied with the system function SFC 20 BLKMOV". The Assign Value instruction is affected by the Master Control Relay (MCR). For more information on how the MCR functions, see Master Control Relay On/Off.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
99
Note
When moving a value to a data type of a different length, higher-value bytes are truncated as necessary or filled up with zeros:
Example: Double Word Move 1111 1111 Result 0000 1111 1111 0000 0101 0101
1111 1111
0000 1111
Result
to a byte: to a word: to a double word: 0000 0000 0000 0000 0000 0000 0000 0000
Example
MOVE
I 0.0 MW10 EN IN OUT ENO DBW12 Q 4.0 =
The instruction is executed, when input I0.0 is 1. The content of MW10 is copied to data word 12 of the open DB. If the instruction is executed, Q4.0 is set to 1.
100
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
10
10.1
Description
The following instructions are available for performing program control operations: CALL: Calling an FC/SFC without Parameters CALL_FB : Call FB as Box CALL_FC : Call FC as Box CALL_SFB : Call System FB as Box CALL_SFC : Call System FC as Box Calling Multiple Instances Calling a Block from a Library Master Control Relay Instructions Important Notes on Using MCR Functions MCR< MCR> MCRA MCRD Master Control Relay On Master Control Relay Off Master Control Relay Activate Master Control Relay Deactivate
RET Return
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
101
10.2
Symbol
<FC-/SFC number>
CALL
Parameter
Data Type
Memory Area
Description
Number
BLOCK_FC
Number of the FC or SFC (for example FC10 or SFC59). The SFCs that are available depend on your CPU. A conditional call with a parameter of the data type BLOCK_FC as the address is only possible in an FB and not in an FC.
Description
With the Call FC/SFC without Parameters instruction, you can call a function (FC) or a system function (SFC) that has no parameters. The call is conditional or unconditional depending on the preceding logic operation (see the example). In the code section of a function (FC), you cannot specify any parameter of the type BLOCK_FC as the address for a conditional call. You can, however, specify a parameter of the type BLOCK_FC as the address in a function block (FB). A conditional call is executed only if the RLO is 1. If a conditional call is not executed, the RLO after the call instruction is 0. If the instruction is executed, the following functions are performed: The address required to return to the calling block is saved. The data block registers are saved (data block and instance data block). The MA bit (active MCR bit) is written to the block stack (BSTACK). The new local data area is created for the called FC or SFC. Program execution is then continued in the called block.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes writes
0 0
0 0
1 1
1 -
0 0
102
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Example
DB 10 OPN MCRA FC 10 CALL Q 4.0 I 0.0 = MCRD FC 11 I 0.1 CALL
If the unconditional call for FC10 is executed, the CALL instruction performs the following functions: Saves the address required to return to the current FB. Saves the selectors for DB10 and for the instance data block of the FB. Pushes the MA bit, set to 1 in the MCRA instruction, to the block stack (BSTACK) and resets this bit to 0 for the called FC10 Program execution continues in FC10. If you want to use the MCR function in FC10, you must reactivate it there. When FC10 is completed, program execution returns to the calling FB. The MA bit is restored. DB10 and the instance data block of the user-defined FB are the current DBs again, regardless of which DBs were used by FC10. After the return jump from FC10, the signal state of input I0.0 is assigned to output Q4.0. The call for FC11 is a conditional call. It is executed only if the signal state of input I0.1 is 1. If the call is executed, the function is the same as for calling FC10.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
103
10.3
Symbol
The symbol depends on the function block (whether and how many parameters exist). EN, ENO and the name or number of the FB must exist.
Parameter Data Type Memory Area Description
I, Q, M, L, D I, Q, M, L, D -
Enable input Enable output Number of the FB/DB, range depends on the CPU
Description
CALL_FB (call FB as box) is executed when the signal state of EN is 1. If the CALL_FB instruction call is executed: The return address of the calling block is saved, The selection data for the two currently open data blocks (DB and instance DB) are saved, A new local data area is created for the called function block. The MA bit (active MCR bit) is pushed to the BSTACK,
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes writes
X -
0 0
0 0
X X
X X
X X
104
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Example
Network 1
DB 10 OPN
Network 2
MCRA
Network 3
DB 11 FB11
EN ENO
Q 4.0
Network 4
DB 10 OPN
The networks shown above are program sections of a function block created by the user. DB10 is opened in this block and the MCR activated. If the unconditional FB11 call is executed, the following happens: The return address of the calling function block and the selection data for DB10 and the instance data block of the calling function block are saved. The MA bit that was set to 1 by the MCRA instruction is pushed to the BSTACK and then set to 0 for the called function block FB11. The program is continued in FB11. If FB11 requires the MCR, the MCR must be reactivated in the function block. The signal state of the RLO must be saved in the BR bit by the [SAVE] instruction to allow error evaluation in the calling FB. When FB11 has been executed, the program returns to the calling function block. The MA bit is restored and the instance data block of the function block written by the user once again becomes the open data block. If FB11 is executed correctly, the signal state of ENO is 1 and the state of Q4.0 is therefore also 1. Note With FB/SFB calls, the number of the previously open data block is lost. The required DB must be opened again.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
105
10.4
Symbol
FC no.
EN ENO
The symbol depends on the function (whether and how many parameters exist). EN, ENO and the name or number of the FC must exist.
Parameter Data Type Memory Area Description
EN ENO FC no.
I, Q, M, L, D I, Q, M, L, D -
Enable input Enable output Number of the FC, range depends on the CPU
Description
CALL_FC (call FC as box) calls a function (FC). The call is executed when EN has a signal state of 1. If the CALL_FC instruction is executed: The return address of the calling block is saved, A new local data area is created for the called function. The MA bit (active MCR bit) is pushed to the BSTACK, Finally, program execution is resumed in the called function. The BR bit is checked to determine the ENO. The user must assign the required signal state (error evaluation) to the BR bit in the called block [SAVE]. If you call a function and the variable declaration table of the called block has IN, OUT, and IN_OUT declarations, these variables are added in the program for the calling block as a list of formal parameters. When calling the function, you must assign actual parameters to the formal parameters at the call location. Any initial values in the function declaration have no significance.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes writes
X -
0 0
0 0
X X
X X
X X
106
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Example
Network 1
DB 10 OPN
Network 2
MCRA
Network 3
FC 10
EN ENO
FC 11
EN ENO
Q 4.0 =
The networks shown above are program sections of a function block created by the user. DB10 is opened in this block and the MCR activated. If the unconditional FC10 call is executed, the following happens: The return address of the calling function block and the selection data for DB10 and the instance data block of the calling function block are saved. The MA bit that was set to 1 by the MCRA instruction is pushed to the BSTACK and then set to 0 for the called block FC10. The program is continued in FC10. If FC10 requires the MCR, the MCR must be reactivated in FC10. The signal state of the RLO must be saved in the BR bit by the [SAVE] instruction to allow error evaluation in the calling FB. When FC10 has been executed, the program returns to the calling function block. The MA bit is restored. After FC10 has been executed, the program is resumed in the calling FB depending on the signal state of ENO, as follows: ENO = 1 ENO = 0 FC11 is executed The program starts in the next network
If FC11 was correctly executed, ENO is set to 1 and Q4.0 is therefore also set to 1. Note After the program returns to the calling block, it is not always guaranteed that the previously open DB is opened again. Please refer to the note in the readme file.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
107
10.5
Symbol
The symbol depends on the system function block (whether and how many parameters exist). EN, ENO and the name or number of the SFB must exist.
Parameter Data Type Memory Area Description
I, Q, M, L, D I, Q, M, L, D -
Enable input Enable output Number of the SFB/DB, range depends on the CPU
Description
CALL_SFB (call SFB as box) is executed when the signal state of EN is 1. If the CALL_SFB instruction is executed: The return address of the calling block is saved, The selection data for the two currently open data blocks (DB and instance DB) are saved, A new local data area is created for the called system function block. The MA bit (active MCR bit) is pushed to the BSTACK, Finally, program execution is resumed in the called system function block. ENO is 1 if the function was called and no errors occurred.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes writes
X -
0 0
0 0
X X
X X
X X
108
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Example
Network 1
DB 10 OPN
Network 2
MCRA
Network 3
DB 8 SFB 8 EN . . . . . . .
. . .
Q 4.0
ENO
Network 4
DB 10 OPN
The networks shown above are program sections of a function block created by the user. DB10 is opened in this block and the MCR activated. If the unconditional SFB8 call is executed, the following happens: The return address of the calling function block and the selection data for DB10 and the instance data block of the calling function block are saved. The MA bit that was set to 1 by the MCRA instruction is pushed to the BSTACK and then set to 0 for the called system function block SFB8. The program is continued in SFB8. When SFB8 has been executed, the program returns to the calling function block. The MA bit is restored and the instance data block of the function block written by the user once again becomes the current data block. If SFB8 is executed correctly, the signal state of ENO is 1 and the state of Q4.0 is therefore also 1. Note With FB/SFB calls, the number of the previously open data block is lost. The required DB must be opened again.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
109
10.6
Symbol
The symbol depends on whether and how many parameters exist). EN, ENO and the name or number of the SFC must exist.
Parameter Data Type Memory Area Description
I, Q, M, L, D I, Q, M, L, D -
Enable input Enable output Number of the SFC, range depends on the CPU
Description
CALL_SFC (call system FC as box) calls a system function. The call is executed when the signal state of EN is 1. If the CALL_SFC instruction is executed: The return address of the calling block is saved, A new local data area is created for the called system function. The MA bit (active MCR bit) is pushed to the BSTACK, Finally, program execution is resumed in the called system function. ENO is 1 if the function was called and no errors occurred.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes writes
X -
0 0
0 0
X X
X X
X X
110
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Example
Network 1
DB 10 OPN
Network 2
MCRA
Network 3
SFC 20
EN DBDW12 SCRBLK RET_VAL DSTBLK ENO MW10 MOTOR.SPEED Q 4.0
The networks shown above are program sections of a function block created by the user. DB10 is opened in this block and the MCR activated. If the unconditional SFC20 call is executed, the following happens: The return address of the calling function block and the selection data for DB10 and the instance data block of the calling function block are saved. The MA bit that was set to 1 by the MCRA instruction is pushed to the BSTACK and then set to 0 for the called block SFC20. The program is continued in SFC20. When SFC20 has been executed, the program returns to the calling function block. The MA bit is restored. After SFC20 has been executed, the program is resumed in the calling FB depending on the signal state of ENO, as follows: ENO = 1 ENO = 0 Q4.0 = 1 Q4.0 = 0
Note After the program returns to the calling block, it is not always guaranteed that the previously open DB is opened again. Please refer to the note in the readme file.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
111
10.7
Symbol
EN IN
#Variable name
OUT ENO
IN/OUT
Parameter
Data Type
Memory Area
Description
I, Q, M, D, L, T, C I, Q, M, D, L -
Description
You create a multiple instance by declaring a static variable of the type function block. Only multiple instances that have already been declared are listed in the program element catalog. The symbol of a multiple instance changes depending on whether and how many parameters exist. EN, ENO and the variable name are always present.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
10.8
112
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
10.9
Instructions dependent on MCR and their reactions to the signal state of the MCR
Signal State of MCR 0 ("OFF") Assign, Midline Output Set or Reset Output Move
Writes 0. (Imitates a relay that falls to its quiet state when voltage is removed.)
Does not write. (Imitates a relay that remains in its current state when voltage is removed.) Normal processing
Writes 0. (Imitates a component that produces a value of 0 when voltage is removed.) Normal processing
1 ("ON")
Normal processing
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
113
10.10
If the MCR is deactivated, the value 0 is written by all assignments in program segments between Master Control Relay On and Master Control Relay Off. This is valid for all boxes which contain an assignment, including the parameter transfer to blocks. The MCR is deactivated if the RLO was = 0 before a Master Control Relay On instruction.
Access to components of complex FC parameters of the type STRUCT, UDT, ARRAY, STRING Access to components of complex FB parameters of the type STRUCT, UDT, ARRAY, STRING from the IN_OUT area in a block with multiple instance capability (version 2 block). Access to parameters of a function block with multiple instance capability (version 2 block) if its address is greater than 8180.0. Access in a function block with multiple instance capability (version 2 block) to a parameter of the type BLOCK_DB opens DB0. Any subsequent data access sets the CPU to STOP. T 0, C 0, FC0, or FB0 are also always used for TIMER, COUNTER, BLOCK_FC, and BLOCK_FB. Calls in which parameters are transferred. T branches and midline outputs in Ladder or FBD starting with RLO = 0.
Parameter passing
LAD/FBD
Remedy Free the above commands from their dependence on the MCR:
1st Deactivate the Master Control Relay using the Master Control Relay Deactivate instruction before the statement or network in question. 2nd Activate the Master Control Relay again using the Master Control Relay Activate instruction after the statement or network in question.
114
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
10.11
Symbol
MCR<
MCR On
The Master Control Relay On (MCR<) instruction triggers an operation that saves the RLO in the MCR stack and opens an MCR zone. The instructions shown in MCR Instructions are influenced by this RLO that is saved in the MCR stack when the MCR zone is opened. The MCR stack works like a LIFO (Last In, First Out) buffer. Only eight entries are possible. If the stack is already full, the Master Control Relay On instruction produces an MCR stack error (MCRF).
Symbol
MCR>
MCR Off
The Master Control Relay Off (MCR>) instruction closes the MCR zone that was opened last. The instruction does this by removing the RLO entry from the MCR stack. The RLO was saved there by the Master Control Relay On instruction. The entry released at the other end of the LIFO (Last In, First Out) MCR stack is set to 1. If the stack is already empty, the Master Control Relay Off instruction produces an MCR stack error (MCRF).
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
115
MCR-Stack
The MCR is controlled by a stack which is one bit wide and eight entries deep. The MCR is activated as long as all eight entries in the stack are equal to 1. The MCR< instruction copies the RLO to the MCR stack. The MCR> instruction removes the last entry from the stack and sets the released stack address to 1. If an error occurs, for example, if there are more than eight MCR> instructions in succession, or you attempt to execute the instruction MCR> when the stack is empty, the MCRF error message is activated. The monitoring of the MCR stack is based on the stack pointer (MSP: 0 = empty, 1 = one entry, 2 = two entries, ..., 8 = eight entries).
RLO
Shifted Bit 1 2 3 4 5 6 7 8
MSP
Shifted Bit 1
MA MCRA 1 0 MCRD
The MCR< instruction adopts the signal state of the RLO and copies it to the MCR bit. The MCR> instruction sets the MCR bit to 1 unconditionally. Because of this characteristic, every other instruction between the instructions MCRA and MCRD operates independent of the MCR bit.
116
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
MCRA I 0.0 I 0.1 MCR< MCR< Q 4.0 I 0.3
S
MCR> Q 4.1
I 0.4
=
MCR> MCRD
When the MCRA instruction activates the MCR function, you can create up to eight nested MCR zones. In the example, there are two MCR zones. The first MCR> instruction works together with the second MCR< instruction. All instructions between the second set of MCR brackets (MCR<MCR>) belong to the second MCR zone. The operations are executed as follows If I0.0 = 1: the signal state of input I0.4 is assigned to output Q4.1. If I0.0 = 0: the signal state of output Q4.1 is 0 regardless of the signal state of input I0.4. Output Q4.0 remains unchanged regardless of the signal state of input I0.3. If I0.0 and I0.1 = 1: output Q4.0 is set to 1 if I0.3 = 1 and Q4.1 = I0.4. If I0.1 = 0: output Q4.0 remains unchanged regardless of the signal state of input I0.3 and input I0.0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
117
10.12
Symbol
MCRA
MCR Activate
With the Activate Master Control Relay, instruction, you make subsequent commands dependent on the MCR. After entering this command, you can program the MCR zones with these instructions (see Master Control Relay On/Off). When your program activates an MCR area, all MCR actions depend on the content of the MCR stack.
Symbol
MCRD
MCR Deactivate
With the Deactivate Master Control Relay instruction, subsequent commands are no longer dependent on the MCR. After this instruction, you cannot program any more MCR zones. When your program deactivates an MCR area, the MCR is always energized irrespective of the entries in the MCR stack. The MCR stack and the bit that controls its dependency (the MA bit) relate to individual levels and must be saved and fetched every time you change the sequence level. They are preset at the beginning of every sequence level (MCR input bits 1 to 8 are set to 1, the MCR stack pointer is set to 0 and the MA bit is set to 0). The MCR stack is transferred from block to block and the MA bit is saved and set to 0 every time a block is called. It is fetched back at the end of the block. The MCR can be implemented in such a way that it optimizes the run time of code-generating CPUs. The reason for this is that the dependency of the MCR is not passed on by the block; it must be explicitly activated by an MCR instruction. A code-generating CPU recognizes this instruction and generates the additional code necessary for the evaluation of the MCR stack until it recognizes an MCR instruction or reaches the end of the block. With instructions outside the MCRA/MCRD range, there is no increase of the run time. The instructions MCRA and MCRD must always be used in pairs within your program.
118
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
OB1
FBx
FCy
BEU
Instructions not dependent on the MCR bit Instructions dependent on the MCR bit BEU is an STL statement
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
119
Example
MCRA I 0.0 MCR< Q 4.0 I 0.3
S
Q 4.1
I 0.4
=
MCR> MCRD
The MCRA instruction activates the MCR function until the next MCRD. The instructions between MCR< and MCR> are processed dependent on the MA bit (here I0.0): If the signal state of input I0.0 is 1: Output Q4.0 is set to 1 if the signal state of input I0.3 is 1. Output Q4.0 remains unchanged if the signal state of input I0.3 is 0. The signal state of input I0.4 is assigned to output Q4.1. Output Q4.0 remains unchanged regardless of the signal state of input I0.3. Output Q4.1 is 0 regardless of the signal state of input I0.4.
You must program the dependency of the functions (FCs) and function blocks (FBs) in the blocks yourself. If this function or function block is called from an MCRA/MCRD sequence, not all instructions within this sequence are automatically dependent on the MCR bit. To achieve this, use the instruction MCRA of the block called.
120
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
10.13
Symbol
RET : Return
RET
Description
You can use the Return instruction to exit blocks. You can exit a block conditionally.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
* The operation RET is shown internally in the sequence "SAVE; BEC, ". This also affects the BR bit
Example
E 0.0 RET
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
121
122
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
11
11.1
11.1.1
Description
You can use the Shift instructions to move the contents of input IN bit by bit to the left or the right (see also CPU Registers). Shifting n bits to the left multiplies the contents of input IN by 2 to the power n (2 n); shifting n bits to the right divides the contents of input IN by 2 to the power n (2 n). For example, if you shift the binary equivalent of the decimal value 3 to the left by 3 bits, you obtain the binary equivalent of the decimal value 24. If you shift the binary equivalent of the decimal value 16 to the right by 2 bits, you obtain the binary equivalent of the decimal value 4. The number that you supply for input parameter N indicates the number of bits by which the value is shifted. The bit places that are vacated by the Shift instruction are either padded with zeros or with the signal state of the sign bit (0 stands for positive and 1 stands for negative). The signal state of the bit that is shifted last is loaded into the CC1 bit of the status word, see also CPU Registers. The CC0 and OV bits of the status word are reset to 0. You can use jump instructions to evaluate the CC1 bit. The following Shift instructions are available: SHR_I : Shift Right Integer SHR_DI : Shift Right Double Integer SHL_W : Shift Left Word SHR_W : Shift Right Word SHL_DW : Shift Left Double Word SHR_DW : Shift Right Double Word
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
123
11.1.2
Symbol
SHR_I EN IN N OUT ENO
Parameter
Data Type
Memory Area
Description
EN IN N OUT ENO
I, Q, M, L, D, T, C I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D
Enable input Value to be shifted Number of bit positions by which the value will be shifted Result of the shift instruction Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Shift Right Integer instruction. This instruction shifts bits 0 to 15 of input IN bit by bit to the right. Input N specifies the number of bits by which the value will be shifted. If N is higher than 16, the command behaves as if N were 16. The bit positions at the left are padded according to the signal state of bit 15 (the sign of an integer number). They are filled with zeros if the number is positive, and with ones if it is negative. The result of the shift operation can be scanned at output OUT. The operation triggered by this instruction always resets the CC0 and OV bits of the status word to 0 if N is not equal to zero. ENO has the same signal state as EN.
124
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Status Word
IN N 15... 1 0 1 0 Sign bit ...8 7... 1 1 1 1 0 0 0 0 4 places ...0 1 0 1 0
OUT
1 1 1 1
1 0 1 0
1 0 0 0 0
The vacated places are filled with the signal state of the sign bit.
BR
CC1
CC0
OV
OS
OR
STA
RLO
FC
writes
Example
SHR_I I 0.0 MW0 MW2 EN IN N OUT ENO MW4 Q 4.0 S
The instruction is activated if the signal state of I0.0 is 1. Memory word MW0 is shifted to the right by the number of bits specified in memory word MW2. The result is entered in memory word MW4. Output Q4.0 is set to 1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
125
11.1.3
Symbol
Parameter
Data Type
Memory Area
Description
EN IN N OUT ENO
I, Q, M, L, D, T, C I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D
Enable input Value to be shifted Number of bit positions by which the value will be shifted Result of the shift instruction Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Shift Right Double Integer instruction. This instruction shifts the entire contents of input IN bit by bit to the right. Input N specifies the number of bits by which the value will be shifted. If N is higher than 32, the command behaves as if N were 32. The bit positions at the left are padded according to the signal state of bit 31 (the sign of a double integer number). They are filled with zeros if the number is positive, and with ones if it is negative. The result of the shift operation can be scanned at output OUT. The operation triggered by this instruction always resets the CC0 and OV bits of the status word to 0 if N is not equal to zero. ENO has the same signal state as EN.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
SHR_DI I 0.0 MD0 MW4 EN IN N OUT ENO MD10 Q 4.0 S
The instruction is activated if the signal state of I0.0 is 1. Memory double word MD0 is shifted to the right by the number of bits specified in memory word MW4. The result is entered in memory double word MD10. Output Q4.0 is set to 1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
126
11.1.4
Symbol
SHL_W EN IN N OUT ENO
Parameter
Data Type
Memory Area
Description
EN IN N OUT ENO
I, Q, M, L, D, T, C I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D
Enable input Value to be shifted Number of bit positions by which the value will be shifted Result of the shift instruction Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Shift Left Word instruction. This instruction shifts bits 0 to 15 of input IN bit by bit to the left. Input N specifies the number of bits by which to shift the value. If N is higher than 16, the command writes 0 to output OUT and sets the CC0 and OV bits of the status word to 0. The bit positions at the right are padded with zeros. The result of the shift operation can be scanned at output OUT. The operation triggered by this instruction always resets the CC0 and OV bits of the status word to 0 if the value of N is not equal to 0. ENO has the same signal state as EN.
15... 0 0 0 0 ...8 7... 1 1 1 1 0 1 0 1 6 places ...0 0 1 0 1
IN N
OUT
0 1 0 1
0 1 0 0
0 0 0 0
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
127
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
SHL_W I 0.0 MW0 MW2 EN IN N OUT ENO MW4 Q 4.0 S
The instruction is activated if the signal state of I0.0 is 1. Memory word MW0 is shifted to the left by the number of bits specified in memory word MW2 The result is entered in memory word MW4. Output Q4.0 is set to 1.
128
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
11.1.5
Symbol
Parameter
Data Type
Memory Area
Description
EN IN N OUT ENO
I, Q, M, L, D, T, C I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D
Enable input Value to be shifted Number of bit positions by which the value will be shifted Result of the shift instruction Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Shift Right Word instruction. This instruction shifts bits 0 to 15 of input IN bit by bit to the right. Bits 16 to 31 are not affected. Input N specifies the number of bits by which the value will be shifted. If N is greater than 16, the command writes 0 to output OUT and resets the CC0 and OV bits of the status word to 0. The vacated bit positions at the left are padded with zeros. The result of the shift operation can be scanned at output OUT. The operation triggered by this instruction always resets the CC0 and OV bits of the status word to 0 if N is not equal to zero. ENO has the same signal state as EN.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
SHR_W I 0.0 MW0 MW2 EN IN N OUT ENO MW4 Q 4.0 S
The instruction is activated if the signal state of I0.0 is 1. Memory word MW0 is shifted to the right by the number of bits specified in memory word MW2. The result is entered in memory word MW4. Output Q4.0 is set to 1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
129
11.1.6
Symbol
Parameter
Data Type
Memory Area
Description
EN IN N OUT ENO
I, Q, M, L, D, T, C I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D
Enable input Value to be shifted Number of bit positions by which the value will be shifted Result of the shift instruction Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Shift Left Double Word instruction. This instruction shifts bits 0 to 31 of input IN bit by bit to the left. Input N specifies the number of bits by which the value will be shifted. If N is greater than 32, the command writes 0 to output OUT and sets the CC0 and OV bits of the status word to 0. The vacated bit positions at the right are padded with zeros. The result of the shift operation can be scanned at output OUT. The operation triggered by this instruction always resets the CC0 and OV bits of the status word to 0 if the value of N is not equal to 0. ENO has the same signal state as EN.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
SHL_DW I 0.0 MD0 MW4 EN IN N OUT ENO MD10 Q 4.0 S
The instruction is activated if the signal state of I0.0 is 1. Memory double word MD0 is shifted to the left by the number of bits specified in memory word MW4. The result is entered in memory double word MD10. Output Q4.0 is set to 1.
130
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
11.1.7
Symbol
SHR_DW EN IN N OUT ENO
Parameter
Data Type
Memory Area
Description
EN IN N OUT ENO
I, Q, M, L, D, T, C I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D
Enable input Value to be shifted Number of bit positions by which the value will be shifted Result of the shift instruction Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Shift Right Double Word instruction. This instruction shifts bits 0 to 31 of input IN bit by bit to the right. Input N specifies the number of bits by which the value will be shifted. If N is higher than 32, the command writes 0 to output OUT and resets the CC0 and OV bits of the status word to 0. The vacated bit positions at the left are padded with zeros. The result of the shift operation can be scanned at output OUT. The operation triggered by this instruction always resets the CC1 and OV bits of the status word to 0 if N is not equal to zero. ENO has the same signal state as EN.
31... ...16 15... ...0 1111 1111 0101 0101 1010 1010 1111 1111 3 places
IN N
OUT
0001 1111 1110 1010 1011 0101 0101 1111 The vacated places are filled with zeros.
111
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
131
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
SHR_DW I 0.0 MD0 MW4 EN IN N OUT ENO MD10 Q 4.0 S
The instruction is activated if the signal state of I0.0 is 1. Memory double word MD0 is shifted to the right by the number of bits specified in memory word MW4. The result is entered in MD10. Output Q4.0 is set to 1.
132
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
11.2
11.2.1
Rotate Instructions
Overview of Rotate Instructions
Description
You can use the Rotate instructions to rotate the entire contents of input IN bit by bit to the left or to the right (see also CPU Registers). The vacated bit positions are filled with the signal states of the bits that are shifted out of input IN. The number that you specify for input parameter N is the number of bits by which the value will be rotated. Depending on the instruction, rotation uses the CC1 bit of the status word. The CC0 bit of the status word is reset to 0. The following Rotate instructions are available: ROL_DW : Rotate Left Double Word ROR_DW : Rotate Right Double Word
11.2.2
Symbol
ROL_DW EN IN N OUT ENO
Parameter
Data Type
Memory Area
Description
EN IN N OUT ENO
I, Q, M, L, D, T, C I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D
Enable input Value to be rotated Number of bit positions by which the value will be rotated Result of the rotate instruction Enable output
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
133
Description
A signal state of 1 at the Enable input (EN) activates the Rotate Left Double Word instruction. This instruction rotates the entire contents of input IN bit by bit to the left. Input N specifies the number of bits by which to rotate. If N is higher than 32, the double word is rotated ((N-1) modulo 32) +1) places. The bit positions at the right are filled with the signal states of the bits rotated. The result of the rotate operation can be scanned at output OUT. The operation triggered by this instruction always resets the CC0 and OV bits of the status word to 0 if N is not equal to zero. ENO has the same signal state as EN.
31... ...16 15... ...0 1111 0000 1010 1010 0000 1111 0000 1111 3 places
IN N
OUT
111
1000 0101 0101 0000 0111 1000 0111 1111 These three bits are lost.
The signal states of the three bits that are shifted out are inserted in the vacated places.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
ROL_DW I 0.0 MD0 MW4 EN IN N OUT ENO MD10 Q 4.0 S
The instruction is activated if the signal state of I0.0 is 1.Memory double word MD0 is rotated to the left by the number of bits specified in memory word MW4. The result is entered in memory double word MD10. Output Q4.0 is set to 1.
134
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
11.2.3
Symbol
ROR_DW EN IN N OUT ENO
Parameter
Data Type
Memory Area
Description
EN IN N OUT ENO
I, Q, M, L, D, T, C I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D I, Q, M, L, D
Enable input Value to be rotated Number of bit positions by which the value will be rotated Result of the rotate instruction Enable output
Description
A signal state of 1 at the Enable input (EN) activates the Rotate Right Double Word instruction. This instruction rotates the entire contents of input IN bit by bit to the right. Input N specifies the number of bits by which the value will be rotated. If N is higher than 32, the double word is rotated ((N-1) modulo 32) +1) places. The value of N can be between 0 and 31. The bit positions at the left are filled with the signal states of the bits rotated. The result of the rotate operation can be scanned at output OUT. The operation triggered by this instruction always resets the CC0 and OV bits of the status word to 0 if N is not equal to zero. ENO has the same signal state as EN.
31... ...16 15... ...0 1010 1010 0000 1111 0000 1111 0101 0101 3 places
IN N
OUT
1011 0101 0100 0001 1110 0001 1110 1010 The signal states of the three bits that are shifted out are inserted in the vacated places.
101
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
135
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
ROR_DW I 0.0 MD0 MW4 EN IN N OUT ENO MD10 Q 4.0 S
The instruction is activated if the signal state of I0.0 is 1.Memory double word MD0 is rotated to the right by the number of bits specified in memory word MW4. The result is entered in memory double word MD10. Output Q4.0 is set to 1.
136
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
12
12.1
Description
The status bit instructions are bit logic instructions that work with the bits of the status word (see CPU Registers). Each of these instructions reacts to one of the following conditions that is indicated by one or more bits of the status word: The binary result bit (BR) is set (has a signal state of 1). The result of a math function is relative to 0 in one of the following ways: == 0, <> 0, > 0, < 0, >= 0, <= 0. The result of a math function is unordered (UO). A math function produced an overflow (OV) or a or a stored overflow (OS). When a status bit instruction is connected in series, it combines the result of its signal state check with the previous result of logic operation according to the And truth table. When a status bit instruction is connected in parallel, it combines its result with the previous RLO according to the Or truth table.
Status word
The status word is a Register in the memory of your CPU that contains bits that you can reference in the address of bit and word logic instructions. Structure of the status word:
2 ...
15
...2
BR
CC1
CC0
OV
OS
OR
STA
RLO
/FC
You can evaluate the bits in the status word by Integer Math Functions by Floating-Point Functions
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
137
12.2
Symbol
OV
Description
You can use the Exception Bit Overflow instruction to detect an overflow (OV) in the last math function. If, after the system executes a math function, the result is outside the permitted negative range or outside the permitted positive range, the OV bit in the status word (see also CPU Registers) is set. The instruction checks the signal state of this bit. This bit is reset if the math functions were free of errors
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
Network 1
SUB_I
I 0.0 IW0 IW2 EN IN1 IN2 OUT ENO MW10
Network 2
I 0.1 I 0.2 I 0.3 & >=1 M 3.3
138
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Network 3
OV Q 4.0 S
If the signal state at input I0.0 is 1, the SUB_I box is activated. If the result of the math function input word IW0 minus input word IW2 is outside the permitted range for an integer, the OV bit in the status word is set. The result of a signal state check at OV is 1. Output Q4.0 is set if the check at OV is 1 and the RLO of network 2 is 1 (if the RLO prior to output Q4.0 is 1). If the signal state of input I0.0 is 0 (not activated), the signal state of both EN and ENO is 0. If the signal state of EN is 1 (activated) and the result of the math function is out of range, the signal state of ENO is 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
139
12.3
Symbol
OS
Description
In an AND operation, this instruction combines the result of its check with the previous result of logic operation according to the AND truth table. In an OR operation, the OR truth table is used. You can use the Exception Bit Overflow Stored instruction to recognize a previous overflow (overflow stored, OS) in a math function. If, after the system executes a math function, the result is outside the permitted negative range or outside the permitted positive range, the OS bit in the status word (see also CPU Registers) is set. The instruction checks the signal state of this bit. Unlike the OV (overflow) bit, the OS bit remains set even if later math functions were executed free of errors (see also Exception Bit Overflow).
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
Network 1
MUL_I
I 0.0 IW0 IW2 EN IN1 IN2 OUT ENO MD8
Network 2
ADD_I
I 0.1 IW0 IW2 EN IN1 IN2 OUT ENO MW12
140
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Network 3
OS Q 4.0 S
If the signal state at input I0.0 is 1, the MUL_I box is activated. If the signal state at input I0.1 is 1, the ADD_I box is activated. If the result of one of the math functions is outside the permissible range for an integer, the OS bit in the status word is set. The result of a signal state check at OS is 1 and output Q4.0 is set. Network 1: if the signal state of input I0.0 is 0 (not activated), the signal state of both EN and ENO is 0. If the signal state of EN is 1 (activated) and the result of the math function is out of range, the signal state of ENO is 0. Network 2: if the signal state of input I0.1 is 0 (not activated), the signal state of both EN and ENO is 0. If the signal state of EN is 1 (activated) and the result of the math function is out of range, the signal state of ENO is 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
141
12.4
Symbol
UO
Description
You can use the Exception Bit Unordered instruction to check whether or not the result of a floating-point math function is unordered (in other words, whether one of the values in the math function is not a valid floating-point number). The condition code bits of the status word (CC 1 and CC 0, see CPU Registers) are evaluated. If the result of the math function is unordered (UO) the signal state check produces a result of 1. If the combination in CC 1 and CC 0 does not indicate unordered, the result of the signal state check is 0.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
Network 1
DIV_R
I 0.0 ID0 ID4 EN IN1 IN2 OUT ENO MD10 Q 4.1 S
Network 2
UO Q 4.0 S
If the signal state at input I0.0 is 1, the DIV_R box is activated. If the value of either input double word ID0 or ID4 is not a valid floating-point number, the floating-point math function is unordered. If the signal state of EN is 1 (activated) and an error occurs while the instruction is being executed, the signal state of ENO is 0. Output Q4.0 is set if the function DIV_R is executed, but one of the values in the math function is not a valid floating-point number. If the signal state of input I0.0 is 0 (not activated), the signal state of both EN and ENO is 0.
142
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
12.5
Symbol
English
German
BR
BIE
Description
You can use the Exception Bit BR Memory instruction to check the signal state of the BR bit (Binary Result) of the status word (see CPU Registers).
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
I 0.0 I 0.2 BR >=1 & Q 4.0 S
Output Q4.0 is set if the signal state at input I0.0 is 1 OR the signal state at input I0.2 is 0, and, in addition to this RLO, the signal state of the BR bit is 1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
143
12.6
Symbols
The Result Bit instruction for equal to 0 determines whether or not the result of a math instruction is equal to 0. The Result Bit instruction for not equal to 0 determines whether or not the result of a math instruction is not equal to 0. The Result Bit instruction for greater than 0 determines whether or not the result of a math instruction is greater than 0 The Result Bit instruction for less than 0 determines whether or not the result of a math instruction is less than 0. The Result Bit instruction for greater than or equal to 0 determines whether or not the result of a math instruction greater than or equal to 0. The Result Bit instruction for less than or equal to 0 determines whether or not the result of a math instruction is less than or equal to 0.
Description
You can use the Result Bit instructions to determine the relationship of the result of a math function to zero, in other words, whether the result is ==0, <>0; >0, <0, >=0 OR <=0. The condition code bits of the status word (CC 1 and CC 0, see CPU Registers) are evaluated. If the comparison condition indicated in the address is fulfilled, the result of this signal state check is 1. In an AND operation, this instruction combines the result of its check with the previous result of logic operation (RLO) according to the AND truth table. In an OR operation, this instruction combines the result of its check with the previous RLO according to the OR truth table.
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
144
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Example
1) SUB_I
I 0.0 IW0 IW2 EN IN1 OUT IN2 ENO >0 MW10 & Q 4.0 S
2) SUB_I
I 0.0 IW0 IW2 EN IN1 OUT IN2 ENO <=0 MW10 & Q 4.0 S
If the signal state at input I0.0 is 1, the SUB_I box is activated. If the value of input word IW0 is greater than the value of input word IW2, the result of the math function IW0 - IW2 is greater than 0. If the signal state of EN is 1 (activated) and an error occurs while the instruction is being executed, the signal state of ENO is 0. 1. Output Q4.0 is set if the function is executed correctly and the result is less than or equal to 0. If the signal state of input I0.0 is 0 (not activated), the signal state of both EN and ENO is 0. 2. Output Q4.0 is set if the function is executed correctly and the result is less than or equal to 0. If the signal state of input I0.0 is 0 (not activated), the signal state of both EN and ENO is 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
145
146
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
13
13.1
Timer Instructions
Overview of Timer Instructions
Description
You can find information for setting and selecting the correct time under "Location of a Timer in Memory and Components of a Timer". The following timer instructions are available: S_PULSE : Assign Pulse Timer Parameters and Start S_PEXT : Assign Extended Pulse Timer Parameters and Start S_ODT : Assign On-Delay Timer Parameters and Start S_ODTS : Assign Retentive On-Delay Timer Parameters and Start S_OFFDT : Assign Off-Delay Timer Parameters and Start SP : Start Pulse Timer SE : Start Extended Pulse Timer SD : Start On-Delay Timer SS : Start Retentive On-Delay Timer SF : Start Off-Delay Timer
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
147
13.2
Memory Area
Times have an area reserved for them in the memory of your CPU. This memory area reserves one 16-bit word for each timer address. When you program in FBD, 256 timers are supported. Please refer to your CPU's technical information to check the number of timer words available. The following functions access the timer memory area: Timer instructions Updating of timer words by the clock timing. In the RUN mode, this CPU function decrements a given time value by one unit at the interval specified by the time base until the time value is zero.
Time Value
Bits 0 through 9 of the timer word contain the time value in binary code. The time value specifies a number of units. When the timer is updated, the time value is decremented by one unit at intervals specified by the time base. The time value is decremented until it is equal to zero. You can pre-load a time value using either of the following formats: S5T#aH_bM_cS_dMS Where H = hours, M = minutes, S = seconds, and MS = milliseconds; a, b, c, d are defined by the user. The time base is selected automatically, and the value is rounded to the next lower number with that time base.
The maximum time value that you can enter is 9,990 seconds, or 2H_46M_30S. S5TIME#4S = 4 seconds s5t#2h_15m = 2 hours and 15 minutes S5T#1H_12M_18S = 1 hour, 12 minutes, and 18 seconds
148
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Time Base
Bits 12 and 13 of the timer word contain the time base in binary code. The time base defines the interval at which the time value is decremented by one unit. The smallest time base is 10 ms; the largest is 10 s.
Time Base Binary Code for the Time Base
10 ms 100 ms 1s 10 s
00 01 10 11
Because time values are saved at only one time interval, values that are not exact multiples of a time interval are truncated. Values with a resolution too high for the required range are rounded down to within the required range but not to the desired resolution. The following table shows the possible resolutions and the corresponding ranges.
Resolution Time Base
15... x x
0 0
0 1
...8 7... 1 0 0 2
0 0
1 7
...0 1
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
149
Q 4.0 S_PULSE t
Q 4.0 S_PEXT t
Q 4.0 S_ODT t
Q 4.0 S_ODTS t
Q 4.0 S_OFFDT t
150
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Timer S_PULSE Pulse timer S_PEXT Extended pulse timer S_ODT On-delay timer S_ODTS Retentive on-delay timer S_OFFDT Off-delay timer
Description
The maximum time that the output signal remains at 1 is the same as the programmed time value t. The output signal stays at 1 for a shorter period if the input signal changes to 0. The output signal remains at 1 for the programmed length of time, regardless of how long the input signal stays at 1. The output signal changes to 1 only when the programmed time has elapsed and the input signal is still 1. The output signal changes from 0 to 1 only when the programmed time has elapsed, regardless of how long the input signal stays at 1. The output signal changes to 1 when the input signal changes to 1 or while the timer is running. The time is started when the input signal changes from 1 to 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
151
Timer Instructions 13.3 S_PULSE : Assign Pulse Timer Parameters and Start
13.3
Symbol
Parameter English
Parameter German
Data Type
Memory Area
Description
no. S TV R BI BCD Q
T I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L, T, C I, Q, M, D, L I, Q, M, D, L I, Q, M, D, L
Timer identification number. The range depends on the CPU. Start input Preset time value (range 0-9999) Reset input Time remaining (value in integer format) Time remaining (value in BCD format) Status of the timer
Description
The Assign Pulse Timer Parameters and Start instruction starts a specified timer if there is a rising edge (a change in signal state from 0 to 1) at the Start (S) input. A signal change is always necessary to start a timer. The timer continues to run for the time specified at the Time Value (TV) input until the programmed time elapses, as long as the signal state at input TV is 1. While the timer is running, a signal state check for 1 at output Q produces a result of 1. If there is a change from 1 to 0 at the S input before the time has elapsed, the timer is stopped. Then a signal state check for 1 at output Q produces a result of 0. While the timer is running, a change from 0 to 1 at the Reset (R) input of the timer resets the timer. This change also resets the time and the time base to zero. A signal state of 1 at the R input of the timer has no effect if the timer is not running. The current time value can be scanned at outputs BI and BCD. The time value at BI is in binary format; at BCD it is in binary coded decimal format.
152
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Timer Instructions 13.3 S_PULSE : Assign Pulse Timer Parameters and Start
Timing Diagram
Pulse timer characteristics:
t RLO at S input t t
RLO at R input
Timer running
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
T5 S_PULSE I 0.0 S5T#2s I 0.1 S TV R BI BCD Q Q 4.0 =
If the signal state of input I0.0 changes from 0 to 1 (if there is a rising edge in the RLO), timer T5 is started. The timer continues to run with the specified time of two seconds (2s) as long as input I0.0 is 1. If the signal state of input I0.0 changes from 1 to 0 before the time elapses, the timer is stopped. If the signal state of input I0.1 changes from 0 to 1 while the timer is running, the timer is reset. The signal state of output Q4.0 is 1 as long as the timer is running.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
153
Timer Instructions 13.4 S_PEXT : Assign Extended Pulse Timer Parameters and Start
13.4
Symbol
S_PEXT :
Parameter English
Parameter German
Data Type
Memory Area
Description
no. S TV R BI BCD Q
T I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L, T, C I, Q, M, D, L I, Q, M, D, L I, Q, M, D, L
Timer identification number. The range depends on the CPU. Start input Preset time value (range 0-9999) Reset input Time remaining (value in integer format) Time remaining (value in BCD format) Status of the timer
Description
The Assign Extended Pulse Timer Parameters and Start instruction starts a specified timer if there is a rising edge (change in signal state from 0 to 1) at the Start (S) input. A signal change is always necessary to start a timer. The timer continues to run for the time specified at the Time Value (TV) input, even if the signal state at the S input changes to 0 before the time has elapsed. A signal state check for 1 at output Q produces a result of 1 as long as the timer is running. The timer is restarted with the specified time if the signal state at input S changes from 0 to 1 while the timer is running. A change from 0 to 1 at the Reset (R) input of the timer while the timer is running resets the timer. This change also resets the time and the time base to zero. The current time value can be scanned at the outputs BI and BCD. The time value at BI is in binary format; at BCD it is in binary coded decimal format.
154
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Timer Instructions 13.4 S_PEXT : Assign Extended Pulse Timer Parameters and Start
Timing Diagram
Extended pulse timer characteristics:
t RLO at S input t t t
RLO at R input
Timer running
Status Word
BR CC1 CC0 OV OS OR STA RLO FC
writes
Example
T5 S_PEXT I 0.0 S5T#2s I 0.1 S TV R BI BCD Q Q 4.0 =
If the signal state of input I0.0 changes from 0 to 1 (rising edge in the RLO), timer T5 is started. The timer continues to run for the specified time of two seconds (2s) regardless of a falling edge at input S. If the signal state of input I0.0 changes from 0 to 1 before the time has elapsed, the timer is restarted. If the signal state of input I0.1 changes from 0 to 1 while the timer is running, the timer is reset. The signal state of output Q4.0 is 1 as long as the timer is running.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
155
Timer Instructions 13.5 S_ODT : Assign On-Delay Timer Parameters and Start
13.5
Symbol
Parameter English
no. S TV R BI BCD Q
Parameter German
Nr. S TW R DUAL DEZ Q
Data Type
TIMER BOOL S5TIME BOOL WORD WORD BOOL
Memory Area
T I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L, T, C I, Q, M, D, L I, Q, M, D, L I, Q, M, D, L
Description
Timer identification number. The range depends on the CPU. Start input Preset time value (range 0-9999) Reset input Time remaining (value in integer format) Time remaining (value in BCD format) Status of the timer
Description
The Assign On-Delay Timer Parameters and Start instruction starts a specified timer if there is a rising edge (change in signal state from 0 to 1) at the Start (S) input. A signal change is always necessary to start a timer. The timer continues to run for the time specified at the Time Value (TV) input as long as the signal state at input S is 1. A signal state check for 1 at output Q produces a result of 1 when the time has elapsed without error and when the signal state at input S is still 1. When the signal state at input S changes from 1 to 0 while the timer is running, the timer is stopped. In this case, a signal state check for 1 at output Q always produces the result 0. A change from 0 to 1 at the Reset (R) input of the timer while the timer is running resets the timer. This change also resets the time and the time base to zero. The timer is also reset if the signal state is 1 at the R input while the timer is not running. The current time value can be scanned at the outputs BI and BCD. The time value at BI is in binary format; at BCD it is in binary coded decimal format.
156
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Timer Instructions 13.5 S_ODT : Assign On-Delay Timer Parameters and Start
Timing Diagram
On-Delay timer characteristics:
t RLO at S input t t
RLO at R input
Timer running
Status Word
BR
writes -
CC1
-
CC0
-
OV
-
OS
-
OR
X
STA
X
RLO
X
FC
1
Example
T5 S_ODT I 0.0 S5T#2s I 0.1 S TV R BI BCD Q Q 4.0 =
If the signal state of input I0.0 changes from 0 to 1 (rising edge in the RLO), timer T5 is started. If the specified time of two seconds (2s) elapses and the signal state of input I0.0 is still 1, the signal state of output Q4.0 is 1. If the signal state of input I0.0 changes from 1 to 0, the timer is stopped and output Q4.0 is 0. If the signal state of input I0.1 changes from 0 to 1 while the timer is running, the timer is restarted.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
157
Timer Instructions 13.6 S_ODTS : Assign Retentive On-Delay Timer Parameters and Start
13.6
S_ODTS Start
Symbol
English T no. S_ODTS S TV R BI BCD Q German T-Nr. S_SEVERZ S TW R DUAL DEZ Q
Parameter English
no. S TV R BI BCD Q
Parameter German
Nr. S TW R DUAL DEZ Q
Data Type
TIMER BOOL S5TIME BOOL WORD WORD BOOL
Memory Area
T I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L, T, C I, Q, M, D, L I, Q, M, D, L I, Q, M, D, L
Description
Timer identification number. The range depends on the CPU. Start input Preset time value (range 0-9999) Reset input Time remaining (value in integer format) Time remaining (value in BCD format) Status of the timer
Description
The Assign Retentive On-Delay Timer Parameters and Start instruction starts a specified timer if there is a rising edge (change in signal state from 0 to 1) at the Start (S) input. A signal change is always necessary to start a timer. The timer continues to run for the time specified at the Time Value (TV) input, even if the signal state at input S changes to 0 before the timer has expired. A signal state check for 1 at output Q produces a result of 1 when the time has elapsed, regardless of the signal state at input S when the reset input (R) remains at 0. The timer is restarted with the specified time if the signal state at input S changes from 0 to 1 while the timer is running. A change from 0 to 1 at the Reset (R) input of the timer resets the timer regardless of the RLO at the S input. The current time value can be scanned at the outputs BI and BCD. The time value at BI is in binary format; at BCD it is in binary coded decimal format.
158
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Timer Instructions 13.6 S_ODTS : Assign Retentive On-Delay Timer Parameters and Start
Timing Diagram
Retentive On-Delay timer characteristics:
t RLO at S input t t t
RLO at R input
Timer running
Status word
BR
writes: -
CC 1
-
CC 0
-
OV
-
OS
-
OR
x
STA
x
RLO
x
/FC
1
Example
T5 S_ODTS I 0.0 S5T#2s I 0.1 S TV R BI BCD Q Q 4.0 =
If the signal state of input I0.0 changes from 0 to 1 (rising edge in the RLO), timer T5 is started. The timer continues to run regardless of a signal change at input I0.0 from1 to 0. If the signal state of input I0.0 changes from 0 to 1 before the time has elapsed, the timer is restarted. If the signal state of input I0.1 changes from 0 to 1 while the timer is running, the timer is restarted. The signal state of output Q4.0 is 1 if the time has elapsed and the signal state at I0.1 remains 0.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
159
Timer Instructions 13.7 S_OFFDT : Assign Off-Delay Timer Parameters and Start
13.7
Symbol
Parameter English
no. S TV R BI BCD Q
Parameter German
Nr. S TW R DUAL DEZ Q
Data Type
TIMER BOOL S5TIME BOOL WORD WORD BOOL
Memory Area
T I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L, T, C I, Q, M, D, L I, Q, M, D, L I, Q, M, D, L
Description
Timer identification number. The range depends on the CPU. Start input Preset time value (range 0-9999) Reset input Time remaining (value in integer format) Time remaining (value in BCD format) Status of the timer
Description
The Assign Off-Delay Timer Parameters and Start instruction starts a specified timer if there is a falling edge (change in signal state from 1 to 0) at the Start (S) input. A signal change is always necessary to start a timer. The result of a signal state check for 1 at output Q is 1 when the signal state at the S input is 1 or when the timer is running. The timer is reset when the signal state at input S changes from 0 to 1 while the timer is running. The timer is not restarted until the signal state at input S changes again from 1 to 0. A change from 0 to 1 at the Reset (R) input of the timer while the timer is running resets the timer. The actual time value can be scanned at the outputs BI and BCD. The time value at BI is in binary format; at BCD it is in binary coded decimal format.
160
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Timer Instructions 13.7 S_OFFDT : Assign Off-Delay Timer Parameters and Start
Timing Diagram
Off-Delay timer characteristics:
t RLO at S input t t t
RLO at R input
Timer running
Status Word
BR
writes -
CC1
-
CC0
-
OV
-
OS
-
OR
x
STA
x
RLO
x
FC
1
Example
T5 S_OFFDT I 0.0 S5T#2s I 0.1 S TV R BI BCD Q Q 4.0 =
If the signal state at input I0.0 changes from 1 to 0, the timer is started. Output Q4.0 is 1 when I0.0 is 1 or the timer is running. If the signal state at I0.1 changes from 0 to 1 while the timer is running, the timer is reset.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
161
13.8
Symbol
English
<address> SP <time value> TV
German
<address> SI <time value> TW
Parameter English
Timer no. TV
Parameter German
Timer no. TW
Data Type
TIMER S5TIME
Description
The Start Pulse Timer instruction starts the specified timer if there is a rising edge (change in signal state from 0 to 1) in the RLO. As long as the RLO is positive, the timer continues running with the specified value. The result of a signal state check for 1 is 1 when the timer is running. If the RLO changes from 1 to 0 before the timer has elapsed, the timer is stopped. In this case the result of the signal state check for 1 is 0. You will find more information about memory areas and components of a timer in Memory Areas. You can only place the box Start Pulse Timer at the right-hand end of a logic string. You can use a number of Start Pulse Timer boxes.
Status Word
BR
writes -
CC1
-
CC0
-
OV
-
OS
-
OR
0
STA
-
RLO
-
FC
0
162
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Example
Network 1
T5 I 0.0 S5T#2s TV SP
Network 2
Q 4.0 =
T5
If the signal state at input I0.0 changes from 0 to 1 (rising edge in the RLO), the timer T5 is started. As long as the signal state is 1, the timer continues to run with the specified value of 2 seconds. If the signal state at I0.0 changes from 1 to 0 while the timer is running, the timer is stopped. Output Q4.0 is 1 when the timer is running.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
163
13.9
Symbol
English
<address> SE <time value> TV
German
<address> SV <time value> TW
Parameter English
Timer no. TV
Parameter German
Timer no. TW
Data Type
TIMER S5TIME
Description
The Start Extended Pulse Timer instruction starts the specified timer if there is a rising edge (change in signal state from 0 to 1) in the RLO. The timer continues running with the specified value if the RLO changes to 0 before the timer elapses. The result of a signal state check for 1 is 1 when the timer is running. If the RLO changes from 0 to 1 while the timer is running, the timer is restarted with the specified time. You will find more information about memory areas and components of a timer in Memory Areas. You can only place the box Start Extended Pulse Timer at the right-hand end of a logic string. You can use a number of Start Extended Pulse Timer boxes.
Status Word
BR
writes -
CC1
-
CC0
-
OV
-
OS
-
OR
0
STA
-
RLO
-
FC
0
164
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Example
Network 1
T5 I 0.0 S5T#2s TV SE
Network 2
Q 4.0 =
T5
If the signal state at input I0.0 changes from 0 to 1 (rising edge in the RLO), the timer T5 is started. The timer continues to run without being influenced by a falling edge in the RLO. If the signal state at I0.0 changes from 0 to 1 before the specified time has elapsed, the timer is restarted. Output Q4.0 is 1 when the timer is running.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
165
13.10
Symbol
English
<address> SD <time value> TV
German
<address> SE <time value> TW
Parameter English
Timer no. TV
Parameter German
Timer no. TW
Data Type
TIMER S5TIME
Description
The Start On-Delay Timer instruction starts the specified timer if there is a rising edge (change in signal state from 0 to 1) in the RLO. The result of a signal state check for 1 is 1 if the specified time has elapsed without error and the RLO still has the value 1. If the RLO changes from 1 to 0 while the timer is running, the timer is stopped. In this case the result of the signal state check for 1 is always 0. You will find more information about memory areas and components of a timer in Memory Areas. You can only place the box Start On-Delay Timer at the right-hand end of a logic string. You can use a number of Start On-Delay Timer boxes.
Status Word
BR
writes -
CC1
-
CC0
-
OV
-
OS
-
OR
0
STA
-
RLO
-
FC
0
166
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Example
Network 1
T5 I 0.0 S5T#2s TV SD
Network 2
Q 4.0 =
T5
If the signal state at input I0.0 changes from 0 to 1 (rising edge in the RLO), the timer T5 is started. If the signal state at I0.0 is still 1 when the timer elapses, the output Q4.0 is 1. If the signal state changes from 1 to 0, the timer is stopped.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
167
13.11
Symbol
English
<address> SS <time value> TV
German
<address> SS <time value> TW
Parameter English
Timer no. TV
Parameter German
Timer no. TW
Data Type
TIMER S5TIME
Description
The Start Retentive On-Delay Timer instruction starts the specified timer if there is a rising edge (change in signal state from 0 to 1) in the RLO. The timer continues running with the specified value if the RLO changes to 0 before the timer elapses. The result of a signal state check for 1 is 1 if the timer has elapsed independent of the RLO. If the RLO changes from 0 to 1 while the timer is running, the timer is restarted with the specified time. You will find more information about memory areas and components of a timer in Memory Areas. You can only place the box Start Retentive On-Delay Timer at the right-hand end of a logic string. You can use a number of Start Retentive On-Delay Timer boxes.
Status Word
BR
writes -
CC1
-
CC0
-
OV
-
OS
-
OR
0
STA
-
RLO
-
FC
0
168
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Example
Network 1
T5 I 0.0 S5T#2s TV SS
Network 2
Q 4.0 =
T5
If the signal state at input I0.0 changes from 0 to 1 (rising edge in the RLO), the timer T5 is started. The timer continues to run independent of whether the signal state at input I0.0 changes from 1 to 0. If the signal state changes from 0 to 1 before the specified time has elapsed, the timer is restarted. Output Q4.0 is 1 when the timer has elapsed.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
169
13.12
Symbol
SF
English
<address> SF <time value> TV
German
<address> SA <time value> TW
Parameter English
Timer no. TV
Parameter German
Timer no. TW
Data Type
TIMER S5TIME
Description
The Start Off-Delay Timer instruction starts the specified timer if there is a falling edge (change in signal state from 1 to 0) in the RLO. The result of a signal state check for 1 is 1 if the RLO is 1 or if the timer is running. If the RLO changes from 0 to 1 while the timer is running, the timer is reset. The timer is then restarted when the RLO changes from 1 to 0. You will find more information about memory areas and components of a timer in Memory Areas. You can only place the box Start Off-Delay Timer at the right-hand end of a logic string. You can use a number of Start Off-Delay Timer boxes.
Status Word
BR
writes -
CC1
-
CC0
-
OV
-
OS
-
OR
0
STA
-
RLO
-
FC
0
170
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
13.12 SF
Example
Network 1
T5 I 0.0 S5T#2s TV SF
Network 2
Q 4.0 =
T5
If the signal state at input I0.0 changes from 1 to 0, the timer is started. If the signal state changes from 0 to 1, the timer is reset. The signal state at output Q4.0 is 1 if the signal state at input I0.0 is 1 or the timer is running.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
171
172
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
14
14.1
Description
Word logic instructions compare pairs of words (16 bits) and double words (32 bits) bit by bit, according to Boolean logic. The value of the result at output OUT relative to 0 affects the CC1 bit in the status word as follows: If the result at output OUT is not equal to 0, the CC1 bit in the status word is set to 1. If the result at output OUT is 0, the CC1 bit in the status word is set to 0. The following instructions are available for performing word logic operations: WAND_W : AND Word (Word) WOR_W : OR Word (Word) WXOR_W : Exclusive OR Word (Word) WAND_DW : AND Double Word (Word) WOR_DW : OR Double Word (Word) WXOR_DW : Exclusive OR Double Word (Word)
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
173
14.2
Symbol
Parameter
EN IN1 IN2 OUT ENO
Data Type
BOOL WORD WORD WORD BOOL
Memory Area
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
Enable input First value of the logic operation Second value of the logic operation Result of the logic operation Enable output
Description
The (Word) AND Word instruction is activated by signal state 1 at the Enable input (EN) and combines the two digital values at inputs IN1 and IN2 bit by bit according to the AND truth table. The values are interpreted as pure bit patterns. The result can be scanned at output OUT. ENO has the same signal state as EN.
Status Word
BR
writes 1
CC1
X
CC0
0
OV
0
OS
-
OR
X
STA
1
RLO
1
FC
1
Example
WAND_W I 0.0 MW0 2#0000000000001111 EN IN1 IN2 OUT ENO MW2 Q 4.0
The instruction is activated when the signal state of I0.0 is 1. Only bits 0 to 3 are relevant, all other bits of MW0 are masked. IN1 IN2 OUT = = = 0101010101010101 0000000000001111 0000000000000101
174
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
14.3
Symbol
Parameter
EN IN1 IN2 OUT ENO
Data Type
BOOL WORD WORD WORD BOOL
Memory Area
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
Enable input First value of the logic operation Second value of the logic operation Result of the logic operation Enable output
Description
The (Word) OR Word instruction is activated by signal state 1 at the Enable input (EN) and combines the two digital values at inputs IN1 and IN2 bit by bit according to the OR truth table. The values are interpreted as pure bit patterns. The result can be scanned at output OUT. ENO has the same signal state as EN.
Status Word
BR
writes 1
CC1
X
CC0
0
OV
0
OS
-
OR
X
STA
1
RLO
1
FC
1
Example
WOR_W I 0.0 MW0 2#0000000000001111 EN IN1 IN2 OUT ENO MW2 Q 4.0
The instruction is activated when I0.0 is 1. The bits in MW0 and in the constant are ORed and bits 0 to 3 set to 1, all other bits of MW0 are entered unchanged in MW2 IN1 IN2 OUT = = = 0101010101010101 0000000000001111 0101010101011111
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
175
14.4
Symbol
Parameter
EN IN1 IN2 OUT ENO
Data Type
BOOL WORD WORD WORD BOOL
Memory Area
I, Q, M, D, L I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
Enable input First value of the logic operation Second value of the logic operation Result of the logic operation Enable output
Description
The (Word) OR Word instruction is activated by signal state 1 at the Enable input (EN) and combines the two digital values at inputs IN1 and IN2 bit by bit according to the OR truth table. The values are interpreted as pure bit patterns. The result can be scanned at output OUT. ENO has the same signal state as EN.
Status Word
BR
writes 1
CC1
X
CC0
0
OV
0
OS
-
OR
X
STA
1
RLO
1
FC
1
Example
WXOR_W I 0.0 MW0 2#0000000000001111 EN IN1 IN2 OUT ENO MW2 Q 4.0
The instruction is activated when input I0.0 is 1. IN1 IN2 OUT = = = 0101010101010101 0000000000001111 0101010101011010
176
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
14.5
Symbol
Parameter
EN IN1 IN2 OUT ENO
Data Type
BOOL DWORD DWORD DWORD BOOL
Memory Area
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
Enable input First value of the logic operation Second value of the logic operation Result of the logic operation Enable output
Description
The (Word) AND Double Word instruction is activated by signal state 1 at the Enable input (EN) and combines the two digital values at inputs IN1 and IN2 bit by bit according to the AND truth table. The values are interpreted as pure bit patterns. The result can be scanned at output OUT. ENO has the same signal state as EN.
Status Word
BR
writes 1
CC1
X
CC0
0
OV
0
OS
-
OR
X
STA
1
RLO
1
FC
1
Example
WAND_DW I 0.0 MD0 DW#16#FFF EN IN1 IN2 OUT ENO MD4 Q 4.0
The instruction is activated when I0.0 is 1. Only bits 0 to 11 are relevant, all other bits of MD4 are masked. IN1 IN2 OUT = = = 0101010101010101 0000000000000000 0000000000000000 0101010101010101 0000111111111111 0000010101010101
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
177
14.6
Symbol
Parameter
EN IN1 IN2 OUT ENO
Data Type
BOOL DWORD DWORD DWORD BOOL
Memory Area
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
Enable input First value of the logic operation Second value of the logic operation Result of the logic operation Enable output
Description
The (Word) OR Double Word instruction is activated by signal state 1 at the Enable input (EN) and combines the two digital values at inputs IN1 and IN2 bit by bit according to the OR truth table. The values are interpreted as pure bit patterns. The result can be scanned at output OUT. ENO has the same signal state as EN.
Status Word
BR
writes 1
CC1
X
CC0
0
OV
0
OS
-
OR
X
STA
1
RLO
1
FC
1
Example
WOR_DW I 0.0 MD0 DW#16#FFF EN IN1 IN2 OUT ENO MD4 Q 4.0
The instruction is activated when I0.0 is 1. The bits in MD0 and in the constant are ORed and bits 0 to 11 set to 1, all other bits of MD0 are entered unchanged in MD4. IN1 IN2 OUT = = = 0101010101010101 0000000000000000 0101010101010101 0101010101010101 0000111111111111 0101111111111111
178
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
14.7
Symbol
Parameter
EN IN1 IN2 OUT ENO
Data Type
BOOL DWORD DWORD DWORD BOOL
Memory Area
I, Q, M, D, L, T, C I, Q, M, D, L or constant I, Q, M, D, L or constant I, Q, M, D, L I, Q, M, D, L
Description
Enable input First value of the logic operation Second value of the logic operation Result of the logic operation Enable output
Description
The (Word) Exclusive OR Double Word instruction is activated by signal state 1 at the Enable input (EN) and combines the two digital values at inputs IN1 and IN2 bit by bit according to the EXCLUSIVE OR truth table. The values are interpreted as pure bit patterns. The result can be scanned at output OUT. ENO has the same signal state as EN.
Status Word
BR
writes 1
CC1
X
CC0
0
OV
0
OS
-
OR
X
STA
1
RLO
1
FC
1
Example
WXOR_DW I 0.0 MD0 DW#16#FFF EN IN1 IN2 OUT ENO MD4 Q 4.0
The instruction is activated when input I0.0 is 1. IN1 IN2 OUT = = = 0101010101010101 0000000000000000 0101010101010101 0101010101010101 0000111111111111 0101101010101010
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
179
180
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
A
A.1
English Mnemonics
& >=1 = # ---| ---o| ==0 >0 >=0 <0 <=0 <>0 ABS ACOS ADD_DI ADD_I ADD_R ASIN ATAN BCD_DI BCD_I BR CALL CALL_FB CALL_FC CALL_SFB CALL_SFC CEIL CMP ? D CMP ? I CMP ? R
Description
AND Logic Operation OR Logic Operation Assign Midline Output Insert Binary Input Negate Binary Input Result Bits Result Bits Result Bits Result Bits Result Bits Result Bits Forming the Absolute Value of a Floating-Point Number Forming Trigonometric Functions of Angles as Floating-Point Numbers Add Double Integer Add Integer Add Real Forming Trigonometric Functions of Angles as Floating-Point Numbers Forming Trigonometric Functions of Angles as Floating-Point Numbers BCD to Double Integer BCD to Integer Exception Bit BR Memory Calling an FC/SFC without Parameters CALL_FB (Call FB as Box) CALL_FC (Call FC as Box) CALL_SFB (Call System FB as Box) CALL_SFC (Call System FC as Box) Ceiling Compare Double Integer Compare Integer Compare Real
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
181
Overview of All FBD Instructions A.1 FBD Instructions Sorted According to German Mnemonics (SIMATIC)
German Mnemonics
COS DI_BCD DI_R DIV_DI DIV_I DIV_R EXP FLOOR I_BCD I_DI INV_I INV_DI JMP JMP JMPN LABEL LN MCR> MCR< MCRA MCRD MOD_DI MOVE MUL_DI MUL_I MUL_R N NEG NEG_DI NEG_I NEG_R OPN OS OV P POS R RET ROL_DW ROUND ROR_DW RS S SA
English Mnemonics
COS DI_BCD DI_R DIV_DI DIV_I DIV_R EXP FLOOR I_BCD I_DI INV_I INV_DI JMP JMP JMPN LABEL LN MCR> MCR< MCRA MCRD MOD_DI MOVE MUL_DI MUL_I MUL_R N NEG NEG_DI NEG_I NEG_R OPN OS OV P POS R RET ROL_DW ROUND ROR_DW RS S SF
Description
Forming Trigonometric Functions of Angles as Floating-Point Numbers Double Integer to BCD Double Integer to Real Divide Double Integer Divide Integer Divide Real Forming the Exponential Value of a Floating-Point Number Floor Integer to BCD Integer to Double Integer Ones Complement Integer Ones Complement Double Integer Unconditional Jump in a Block Conditional Jump in a Block Jump-If-Not Jump Label Forming the Natural Logarithm of a Floating-Point Number Master Control Relay On/Off Master Control Relay On/Off Master Control Relay Activate/Deactivate Master Control Relay Activate/Deactivate Return Fraction Double Integer Assign Value Multiply Double Integer Multiply Integer Multiply Real Negative RLO Edge Detection Address Negative Edge Detection Twos Complement Double Integer Twos Complement Integer Negate Real Number Open Data Block Exception Bit Overflow Stored Exception Bit Overflow Positive RLO Edge Detection Address Positive Edge Detection Reset Output Return Rotate Left Double Word Round to Double Integer Rotate Right Double Word Reset_Set Flip Flop Set Output Start Off-Delay Timer
182
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Overview of All FBD Instructions A.1 FBD Instructions Sorted According to German Mnemonics (SIMATIC)
German Mnemonics
SAVE S_AVERZ SE S_EVERZ SHL_DW SHL_W SHR_DI SHR_DW SHR_I SHR_W SI S_IMPULS SIN SQR SQRT SR SS S_SEVERZ SUB_DI SUB_I SUB_R SV S_VIMP SZ TAN TRUNC UO WAND_DW WAND_W WOR_DW WOR_W WXOR_DW WXOR_W XOR ZAEHLER ZR Z_RUECK ZV Z_VORW
English Mnemonics
SAVE S_OFFDT SD S_ODT SHL_DW SHL_W SHR_DI SHR_DW SHR_I SHR_W SP S_PULSE SIN SQR SQRT SR SS S_ODTS SUB_DI SUB_I SUB_R SE S_PEXT SC TAN TRUNC UO WAND_DW WAND_W WOR_DW WOR_W WXOR_DW WXOR_W XOR S_CUD CD S_CD CU S_CU
Description
Save RLO to BR Memory Assign Off-Delay Timer Parameters and Start Assign On-Delay Timer Parameters and Start Assign On-Delay Timer Parameters and Start Shift Left Double Word Shift Left Word Shift Right Double Integer Shift Right Double Word Shift Right Integer Shift Right Word Start Pulse Timer Assign Pulse Timer Parameters and Start Forming Trigonometric Functions of Angles as Floating-Point Numbers Forming the Square (SQR) of a Floating-Point Number Forming the Square Root (SQRT) of a Floating-Point Number Set_Reset Flip Flop Start Retentive On-Delay Timer Assign Retentive On-Delay Timer Parameters and Start Subtract Double Integer Subtract Integer Subtract Real Start Extended Pulse Timer Assign Extended Pulse Timer Parameters and Start Set Counter Value Forming Trigonometric Functions of Angles as Floating-Point Numbers Truncate Double Integer Part Exception Bit Unordered AND Double Word (Word) AND Word (Word) OR Double Word (Word) OR Word (Word) Exclusive OR Double Word (Word) Exclusive OR Word (Word) Exclusive OR Logic Operation Assign Parameters and Count Up/Down Down Counter Assign Parameters and Count Down Up Counter Assign Parameters and Count Up
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
183
Overview of All FBD Instructions A.2 FBD Instructions Sorted According to English Mnemonics (International)
A.2
German Mnemonics
& >=1 = # ---| ---o| ==0 >0 >=0 <0 <=0 <>0 ABS ACOS ADD_DI ADD_I ADD_R ASIN ATAN BCD_DI BCD_I BIE CALL CALL_FB CALL_FC CALL_SFB CALL_SFC ZR CEIL CMP ? D CMP ? I CMP ? R COS ZV DI_BCD DI_R
Description
AND Logic Operation OR Logic Operation Assign Midline Output Insert Binary Input Negate Binary Input Result Bits Result Bits Result Bits Result Bits Result Bits Result Bits Forming the Absolute Value of a Floating-Point Number Forming Trigonometric Functions of Angles as Floating-Point Numbers Add Double Integer Add Double Integer Add Real Forming Trigonometric Functions of Angles as Floating-Point Numbers Forming Trigonometric Functions of Angles as Floating-Point Numbers BCD to Double Integer BCD to Integer Exception Bit BR Memory Calling an FC/SFC without Parameters CALL_FB (Call FB as Box) CALL_FC (Call FC as Box) CALL_SFB (Call System FB as Box) CALL_SFC (Call System FC as Box) Down Counter Ceiling Compare Double Integer Compare Integer Compare Real Forming Trigonometric Functions of Angles as Floating-Point Numbers Up Counter Double Integer to BCD Double Integer to Real
184
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Overview of All FBD Instructions A.2 FBD Instructions Sorted According to English Mnemonics (International)
English Mnemonics
DIV_DI DIV_I DIV_R EXP FLOOR I_BCD I_DI INV_I INV_DI JMP JMP JMPN LABEL LN MCR> MCR< MCRA MCRD MOD_DI MOVE MUL_DI MUL_I MUL_R N NEG NEG_DI NEG_I NEG_R OPN OS OV P POS R RET ROL_DW ROUND ROR_DW RS S SAVE SC
German Mnemonics
DIV_DI DIV_I DIV_R EXP FLOOR I_BCD I_DI INV_I INV_DI JMP JMP JMPN LABEL LN MCR> MCR< MCRA MCRD MOD_DI MOVE MUL_DI MUL_I MUL_R N NEG NEG_DI NEG_I NEG_R OPN OS OV P POS R RET ROL_DW ROUND ROR_DW RS S SAVE SZ
Description
Divide Double Integer Divide Integer Divide Real Forming the Exponential Value of a Floating-Point Number Floor Integer to BCD Integer to Double Integer Ones Complement Integer Ones Complement Double Integer Unconditional Jump in a Block Conditional Jump in a Block Jump-If-Not Jump Label Forming the Natural Logarithm of a Floating-Point Number Master Control Relay On/Off Master Control Relay On/Off Master Control Relay Activate/Deactivate Master Control Relay Activate/Deactivate Return Fraction Double Integer Assign Value Multiply Double Integer Multiply Integer Multiply Real Negative RLO Edge Detection Address Negative Edge Detection Twos Complement Double Integer Twos Complement Integer Negate Real Number Open Data Block Exception Bit Overflow Stored Exception Bit Overflow Positive RLO Edge Detection Address Positive Edge Detection Reset Output Return Rotate Left Double Word Round to Double Integer Rotate Right Double Word Reset_Set Flip Flop Set Output Save RLO to BR Memory Set Counter Value
Jumps
Floating point instruction Program control Program control Program control Program control Integer math instruction Move Integer math instruction Integer math instruction Floating point instruction Bit logic instruction Bit logic instruction Convert Convert Convert DB call Status bits Status bits Bit logic instruction Bit logic instruction Bit logic instruction Program control Shift/Rotate Convert Shift/Rotate Bit logic instruction Bit logic instruction Bit logic instruction Counters
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
185
Overview of All FBD Instructions A.2 FBD Instructions Sorted According to English Mnemonics (International)
English Mnemonics
S_CD S_CU S_CUD SD SE SF SHL_DW SHL_W SHR_DI SHR_DW SHR_I SHR_W SIN S_ODT S_ODTS S_OFFDT SP S_PEXT S_PULSE SQR SQRT SR SS SUB_DI SUB_I SUB_R TAN TRUNC UO WAND_DW WAND_W WOR_DW WOR_W WXOR_DW WXOR_W XOR
German Mnemonics
Z_RUECK Z_VORW ZAEHLER SE SV SA SHL_DW SHL_W SHR_DI SHR_DW SHR_I SHR_W SIN S_EVERZ S_SEVERZ S_AVERZ SI S_VIMP S_IMPULS SQR SQRT SR SS SUB_DI SUB_I SUB_R TAN TRUNC UO WAND_DW WAND_W WOR_DW WOR_W WXOR_DW WXOR_W XOR
Description
Assign Parameters and Count Down Assign Parameters and Count Up Assign Parameters and Count Up/Down Start On-Delay Timer Start Extended Pulse Timer Start Off-Delay Timer Shift Left Double Word Shift Left Word Shift Right Double Integer Shift Right Double Word Shift Right Integer Shift Right Word Forming Trigonometric Functions of Angles as Floating-Point Numbers Assign On-Delay Timer Parameters and Start Assign Retentive On-Delay Timer Parameters and Start Assign Off-Delay Timer Parameters and Start Start Pulse Timer Assign Extended Pulse Timer Parameters and Start Assign Pulse Timer Parameters and Start Forming the Square (SQR) of a Floating-Point Number Forming the Square Root (SQRT) of a Floating-Point Number Set_Reset Flip Flop Start Retentive On-Delay Timer Subtract Double Integer Subtract Integer Subtract Real Forming Trigonometric Functions of Angles as Floating-Point Numbers Truncate Double Integer Part Exception Bit Unordered AND Double Word (Word) AND Word (Word) OR Double Word (Word) OR Word (Word) Exclusive OR Double Word (Word) Exclusive OR Word (Word) Exclusive OR Logic Operation
Counters
Timers Timers Timers Shift/Rotate Shift/Rotate Shift/Rotate Shift/Rotate Shift/Rotate Shift/Rotate Floating point-instruction Timers Timers Timers Timers Timers Timers Floating point-instruction Floating point-instruction Bit logic instruction Timers Integer math-instruction Integer math-instruction Floating point-instruction Floating point-instruction Convert Status bits Word logic instruction Word logic instruction Word logic instruction Word logic instruction Word logic instruction Word logic instruction Bit logic instruction
186
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
B
B.1
Programming Examples
Overview of Programming Examples
Practical Applications
Each FBD instruction triggers a specific operation. When you combine these instructions into a program, you can accomplish a wide variety of automation tasks. This chapter provides the following examples of practical applications of the FBD instructions: Controlling a conveyor belt using bit logic instructions Detecting direction of movement on a conveyor belt using bit logic instructions Generating a clock pulse using timer instructions Keeping track of storage space using counter and comparison instructions Solving a problem using integer math instructions Setting the length of time for heating an oven
Instructions Used
Mnemonik
WAND_W WOR_W S_CD S_CU R S P ADD_I DIV_I MUL_I CMP >=I, CMP <=I & >=1 = JMPN RET MOVE SE
Description
(Word) And Word (Word) Or Word Down Counter Up Counter Reset Output Set Output Positive RLO Edge Detection Add Integer Divide Integer Multiply Integer Compare Integer AND OR Assign Jump-If-Not Return Assign a Value Extended Pulse Timer
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
187
B.2
Sensor S5
MOTOR_ON
S1 S2
O Start O Stop
S3 S4
O Start O Stop
Absolute Address
I 1.1 I 1.2 I 1.3 I 1.4 I 1.5 Q 4.0
Symbol
S1 S2 S3 S4 S5 MOTOR_ON
Symbol Table
I 1.1 I 1.2 I 1.3 I 1.4 I 1.5 Q 4.0 S1 S2 S3 S4 S5 MOTOR_ON
188
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Network 2: Pressing either stop switch or the sensor at the end of the belt turns the motor off.
I 1.2 I 1.4 I 1.5 >=1 Q 4.0 R
Q 4.0
PEB2
PEB1
Q 4.1
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
189
Absolute Address
I 0.0 I 0.1 Q 4.0 Q 4.1 M 0.0 M 0.1
Symbol
PEB1 PEB2 RIGHT LEFT PMB1 PMB2
Symbol Table
I 0.0 I 0.1 Q 4.0 Q 4.1 M 0.0 M 0.1 PEB1 PEB2 RIGHT LEFT PMB1 PMB2
Network 2: If there is a transition in signal state from 0 to 1 (positive edge) at input I 0.1 and, at the same time, the signal state at input I 0.0 is 0, then the package on the belt is moving to the right.
M 0.1 I 0.1 P I 0.0 & Q 4.0 S
Network 3: If one of the photoelectric barriers is interrupted, this means that there is a package between the barriers. The direction pointer shuts off.
&
I 0.0 I 0.1
Q 4.0 R Q 4.1 R
190
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
B.3
Packages in
I 12.0
I 12.1
Packages out
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
191
Function Block Diagram that Activates the Indicator Lamps on the Display Panel
Network 1: Counter C1 counts up at each signal change from 0 to 1 at input CU and counts down at each signal change from 0 to 1 at input CD. With a signal change from 0 to 1 at input S, the counter value is set to the value PV. A signal change from 0 to 1 at input R resets the counter value to 0. MW200 contains the current counter value of C1. Q12.1 indicates storage area not empty.
C1 S_CUD I 12.0 I 12.1 I 12.2 C#10 I 12.3 CU CD S CV MW210 MW200 Q 12.1 =
PVCV_BCD R Q
Network 3: If 50 is less than or equal to the counter value (in other words if the current counter value is greater than or equal to 50), the indicator lamp for storage area 50% full is lit.
CMP <= I 50 MW210 IN1 IN2 Q 15.2 =
Network 4: Network 4: If the counter value is greater than or equal to 90, the indicator lamp for storage area 90% full is lit.
CMP >= I MW210 90 IN1 IN2 Q 15.3 =
192
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Network 5: If the counter value is greater than or equal to 100, the indicator lamp for storage area full is lit.
CMP >= I MW210 100 IN1 IN2 Q 15.4 =
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
193
B.4
Function Block Diagram to Generate a Clock Pulse (pulse duty factor 1:1)
Network 1: If the signal state of timer T1 is 0, load the time value 250 ms into T1 and start T1 as an extended-pulse timer.
T1 M0.2 & T SE
S5T#250MS
Network 2: The state of the timer is saved temporarily in an auxiliary memory marker.
M0.2 T1 & =
Network 4: When the timer T1 expires, the memory word 100 is incremented by 1.
ADD_I ??.? MW100 1 EN IN1 IN2 OUT ENO MW100
194
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Network 5: The MOVE instruction allows you to output the different clock frequencies at outputs Q12.0 through Q13.7.
??.? MW100
QW12
Signal Check
A signal check of timer T1 produces the following result of logic operation (RLO) for the negated input parameter of the AND logic operation (M0.2) in the clock pulse example:
1 0 250 ms
As soon as the time runs out, the timer is restarted. Because of this, the signal produces a signal state of 1 only briefly. The negated (inverted) RLO:
1 0 250 ms
Every 250 ms the RLO bit is 0. The jump is ignored and the contents of memory word MW100 is incremented by 1.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
195
M 101.0 M 101.1 M 101.2 M 101.3 M 101.4 M 101.5 M 101.6 M 101.7 M 100.0 M 100.1 M 100.2 M 100.3 M 100.4 M 100.5 M 100.6 M 100.7
2.0 1.0 0.5 0.25 0.125 0.0625 0.03125 0.015625 0.0078125 0.0039062 0.0019531 0.0009765 0.0004882 0.0002441 0.000122 0.000061
(250 ms on / 250 ms off) (0.5 s on / 0.5 s off) (1 s on / 1 s off) (2 s on / 2 s off) (4 s on / 4 s off) (8 s on / 8 s off) (16 s on / 16 s off) (32 s on / 32 s off) (64 s on / 64 s off) (128 s on / 128 s off) (256 s on / 256 s off) (512 s on / 512 s off) (1024 s on / 1024 s off) (2048 s on / 2048 s off) (4096 s on / 4096 s off)
0 1 2 3 4 5 6 7 8 9 10 11 12
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1
0 0 0 0 1 1 1 1 0 0 0 0 1
0 1 0 1 0 1 0 1 0 1 0 1 0
250 250 250 250 250 250 250 250 250 250 250 250 250
1 1
0 0
1 1
0 0
1 1
0
196
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
M 101.1
1 0
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
197
B.5
Network 2: Input word IW0 is added to shared data word DBW3 (data block must be defined and opened) and the sum is loaded into memory word MW100. MW100 is then multiplied by 15 and the answer stored in memory word MW102. MW102 is divided by MW0 with the result stored in MW4.
ADD_I EN IN1 IN2 OUT ENO MW100 15 MW100 MUL_I EN IN1 IN2 OUT ENO MW102 MW0 MW102 DIV_I EN IN1 IN2 OUT ENO MW4
198
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
B.6
Heating an Oven
The operator of the oven starts the oven heating by pushing the start push button. The operator can set the length of time for heating by using the thumbwheel switches shown in the figure. The value that the operator sets indicates seconds in binary coded decimal (BCD) format.
Oven
4 Heat Q 4.0 7.... XXXX IB0 Start push button I 0.7 ...0 0001 7... 1001
IB1
System Component
Absolute Address
Start Push Button Thumbwheel for ones Thumbwheel for tes Thumbwheel for hundreds Heating starts
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
199
Network 2: If the timer is running, the Return instruction ends the processing here.
T1
&
RET
Network 3: Mask input bits I 0.4 through I 0.7 (that is, reset them to 0). These bits of the thumbwheel inputs are not used. The 16 bits of the thumbwheel inputs are combined with W#16#0FFF according to the (Word) And Word instruction. The result is loaded into memory word MW1. In order to set the time base of seconds, the preset value is combined with W#16#2000 according to the (Word) Or Word instruction, setting bit 13 to 1 and resetting bit 12 to 0.
WAND_W ??.? IW0 W#16#FFF EN IN1 IN2 OUT ENO MW1 W#16#2000 MW1 WOR_W EN IN1 IN2 OUT ENO MW2
Network 4: Start timer T1 as an extended pulse timer if the start push button is pressed, loading as a preset value memory word MW2 (derived from the logic above).
T1 I 0.7 & MW2 SE TV
200
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
C
C.1
Around the actual instructions in the box, additional STL instructions are generated for the EN/ENO mechanism with dependency on the existing preceding and subsequent logic operations. The four possible cases are shown using the example of an adder: 1. Adder with EN and with ENO Connected 2. Adder with EN and without ENO Connected 3. Adder without EN and with ENO Connected 4. Adder without EN and without ENO Connected
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
201
Ensure that this network is processed in every case, which means you must not use BEC within the block and skip this network.
202
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
C.1.1
Following line 1 the RLO contains the result of the preceding logic operation. The JNB instruction copies the RLO into the BR bit and sets the first check bit. If the RLO = 0, the program jumps to line 10 and resumes with A BR. The addition is not executed. In line 10 the BR is copied into the RLO again and 0 is thus assigned to the output. If the RLO = 1, the program does not jump, meaning the addition is executed. In line 7 the program evaluates whether an error occurred during addition, this is then stored in BR in line 8. Line 9 sets the first check bit. Now the BR bit is copied back into the RLO in line 10 and thus the output shows whether the addition was successful or not. The BR bit is not changed by lines 10 and 11, so it also shows whether the addition was successful.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
203
C.1.2
Following line 1 the RLO contains the result of the preceding logic operation. The JNB instruction copies the RLO into the BR bit and sets the first check bit. If the RLO = 0, the program jumps to line 7 and the addition is not executed. The RLO and BR are 0. If RLO was 1, the program does not jump, meaning the addition is executed. The program does not evaluate whether an error occurred during addition. The RLO and BR are 1.
C.1.3
The addition is executed in every case. In line 5 the program evaluates whether an error occurred during addition, this is then stored in BR in line 6. Line 7 sets the first check bit. Now the BR bit is copied back into the RLO in line 8 and thus the output shows whether the addition was successful or not. The BR bit is not changed by lines 8 and 9, so it also shows whether the addition was successful.
204
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
C.1.4
The addition is executed. The RLO and the BR bit remain unchanged.
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
205
C.2
Parameter Transfer
The parameters of a block are transferred as a value. With function blocks a copy of the actual parameter value in the instance data block is used in the called block. With functions a copy of the actual value lies in the local data stack. Pointers are not copied. Prior to the call the INPUT values are copied into the instance DB or to the L stack. After the call the OUTPUT values are copied back into the variables. Within the called block you can only work on a copy. The STL instructions required for this are in the calling block and remain hidden from the user.
Note If memory bits, inputs, outputs or peripheral I/Os are used as actual address of a function they are treated in a different way than the other addresses. Here, updates are carried out directly, not via L-Stack. Exception: If the corresponding formal parameter is an input parameter of the data type BOOL, the current parameters are updated via the L stack.
CAUTION When programming the called block, ensure that the parameters declared as OUTPUT are also written. Otherwise the values output are random! With function blocks the value will be the value from the instance DB noted by the last call, with functions the value will be the value which happens to be in the L stack. Note the following points:
Initialize all OUTPUT parameters if possible. Try not to use any Set and Reset instructions. These instructions are dependent on the RLO. If the RLO has the value 0, the random value will be retained. If you jump within the block, ensure that you do not skip any locations where OUTPUT parameters are written. Do not forget BEC and the effect of the MCR instructions.
206
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
Index
A
Add Double Integer 79 Add Integer 75 Add Real 87 Adder with EN and with ENO Connected 203 Adder with EN and without ENO Connected 204 Adder without EN and with ENO Connected 204 Adder without EN and without ENO Connected 205 Address Negative Edge Detection 31 Address Positive Edge Detection 32 AND Double Word (Word) 177 AND Logic Operation 13 AND Word (Word) 174 AND-before-OR Logic Operation and OR-before-AND Logic Operation 14 Assign 19 Assign Extended Pulse Timer Parameters and Start 154 Assign Off-Delay Timer Parameters and Start 160 Assign On-Delay Timer Parameters and Start 156 Assign Parameters and Count Down 59 Assign Parameters and Count Up 57 Assign Parameters and Count Up/Down 55 Assign Pulse Timer Parameters and Start 152 Assign Retentive On-Delay Timer Parameters and Start 158 Assign Value 99
D
DIV_DI 82 DIV_I 78 Divide Double Integer 82 Divide Integer 78 Divide Real 90 Double Integer to BCD 42 Double Integer to Real 43 Down Counter 64
E
EN/ENO Mechanism 201, 202 Evaluating the Bits of the Status Word with Floating-Point Instructions 86 Evaluating the Bits of the Status Word with Integer Math Instructions 74 Example Bit Logic Instructions 188 Counter and Comparison Instructions 191 Integer Math Instructions 198 Timer Instructions 194 Word Logic Instructions 199 Examples 187 Exception Bit BR Memory 143 Exception Bit Overflow 138 Exception Bit Overflow Stored 140 Exception Bit Unordered 142 Exclusive OR Double Word (Word) 179 Exclusive OR Logic Operation 16 Exclusive OR Word (Word) 176
B
BCD to Double Integer 40 BCD to Integer 38
C
CALL_FB (Call FB as Box) 104 CALL_FC (Call FC as Box) 106 CALL_SFB (Call System FB as Box) 108 CALL_SFC (Call System FC as Box) 110 Calling a Block from a Library 112 Calling an FC/SFC without Parameters 102 Calling Multiple Instances 112 Ceiling 51 CMP ? D 35 CMP ? I 34 CMP ? R 36 Compare Double Integer 35 Compare Integer 34 Compare Real 36 Conditional Jump in a Block 69
F
FBD Instructions Sorted According to English Mnemonics (International) 184 FBD Instructions Sorted According to German Mnemonics (SIMATIC) 181 Floor 52 Forming the Absolute Value of a Floating-Point Number 91 Forming the Exponential Value of a Floating-Point Number 94 Forming the Natural Logarithm of a Floating-Point Number 95 Forming the Square (SQR) of a Floating-Point Number 92 Forming the Square Root (SQRT) of a Floating-Point Number 93 Forming Trigonometric Functions of Angles as Floating-Point Numbers 96
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01
207
Index
I
Important Notes on Using MCR Functions Insert Binary Input 17 Integer to BCD 39 Integer to Double Integer 41 114
173
P
Parameter Transfer 206 Positive RLO Edge Detection Practical Applications 187 29
J
Jump Label 71 Jump-If-Not 70
R
Reset Output 23 Reset_Set Flip Flop 25 Result Bits 144 Return 121 Return Fraction Double Integer 83 Rotate Instructions - Overview 133 Rotate Left Double Word 133 Rotate Right Double Word 135 Round to Double Integer 49
M
Master Control Relay Activate/Deactivate 118 Master Control Relay Instructions 113 Master Control Relay On/Off 115 Memory Areas and Components of a Timer 148 Midline Output 21 Mnemonics English (International) 184 German (SIMATIC) 181 MOD_DI 83 MUL_DI 81 MUL_I 77 Multiply Double Integer 81 Multiply Integer 77 Multiply Real 89
S
Save RLO to BR Memory 30 Set Counter Value 61 Set Output 24 Set_Reset Flip Flop 27 Shift Instructions - Overview 123 Shift Left Double Word 130 Shift Left Word 127 Shift Right Double Integer 126 Shift Right Double Word 131 Shift Right Integer 124 Shift Right Word 129 Start Extended Pulse Timer 164 Start Off-Delay Timer 170 Start On-Delay Timer 166 Start Pulse Timer 162 Start Retentive On-Delay Timer 168 SUB_DI 80 SUB_I 76 Subtract Double Integer 80 Subtract Integer 76 Subtract Real 88
N
Negate Binary Input 18 Negate Real Number 48 Negative RLO Edge Detection 28
O
Ones Complement Double Integer 45 Ones Complement Integer 44 Online-Hilfe 5 Open Data Block 65 OR Double Word (Word) 178 OR Logic Operation 12 OR Word (Word) 175 Overview of Bit Logic Instructions 11 Overview of Comparison Instructions 33 Overview of Conversion Instructions 37 Overview of Counter Instructions 53 Overview of Floating-Point Math 85 Overview of Integer Math Instructions 73 Overview of Jump Instructions 67 Overview of Program Control Instructions 101 Overview of Programming Examples 187 Overview of Status Bit Instructions 137 Overview of Timer Instructions 147
T
Truncate Double Integer Part 50 Twos Complement Double Integer 47 Twos Complement Integer 46
U
Unconditional Jump in a Block 68 Up Counter 63
208
Function Block Diagram (FBD) for S7-300 and S7-400 Programming Reference Manual, 05/2010, A5E02790131-01