Siemens 6AV6651-7KA01-3AA4 - S7-1200 + KTP400 Basic Starter Kit 6AV6651-7KA01-3AA4 Manuel D’Utilisation

Codes de produits
6AV6651-7KA01-3AA4
Page de 364
 
Programming made easy 
 
6.1 Easy to design your user program 
Easy Book 
Manual, 03/2014, A5E02486774-AF 
91
 
A function block (FB) is like a subroutine with memory. An FB is a code block whose calls 
can be programmed with block parameters. The FB stores the input (IN), output (OUT), and 
in/out (IN_OUT) parameters in variable memory that is located in a data block (DB), or 
"instance" DB. The instance DB provides a block of memory that is associated with that 
instance (or call) of the FB and stores data after the FB finishes.  
You typically use an FB to control the operation for tasks or devices that do not finish their 
operation within one scan cycle. To store the operating parameters so that they can be 
quickly accessed from one scan to the next, each FB in your user program has one or more 
instance DBs. When you call an FB, you also open an instance DB that stores the values of 
the block parameters and the static local data for that call or "instance" of the FB. These 
values are stored in the instance DB after the FB finishes.  
You can assign start values to the parameters in the FB interface. These values are 
transferred to the associated instance DB. If you do not assign parameters, the values 
currently stored in the instance DB will be used. In some cases, you must assign 
parameters. 
You can associate different instance DBs with different calls of the FB. The instance DBs 
allow you to use one generic FB to control multiple devices. You structure your program by 
having one code block make a call to an FB and an instance DB. The CPU then executes 
the program code in that FB and stores the block parameters and the static local data in the 
instance DB. When the execution of the FB finishes, the CPU returns to the code block that 
called the FB. The instance DB retains the values for that instance of the FB. By designing 
the FB for generic control tasks, you can reuse the FB for multiple devices by selecting 
different instance DBs for different calls of the FB. 
The following figure shows an OB that calls one FB three times, using a different data block 
for each call. This structure allows one generic FB to control several similar devices, such as 
motors, by assigning a different instance data block for each call for the different devices.  
 
Each instance DB stores the data (such as speed, ramp-up time, and total operating time) 
for an individual device. In this example, FB 22 controls three separate devices, with DB 201 
storing the operational data for the first device, DB 202 storing the operational data for the 
second device, and DB 203 storing the operational data for the third device.