Programming options
5.2 Structuring your user program is easy
Easy Book
Manual, 05/2009, A5E02486774-01
55
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.
'%
'%
'%
)%'%
)%'%
)%'%
2%
)%
5.2.3
Data blocks provide easy storage for program data
You create data blocks (DB) in your user program to store data for the code blocks. All of the
program blocks in the user program can access the data in a global DB, but an instance DB
stores data for a specific function block (FB).
Your user program can store data in the specialized memory areas of the CPU, such as for
the inputs (I), outputs (Q), and bit memory (M). In addition, you can use a data block (DB) for
fast access to data stored within the program itself. You can define a DB as being read-only.
The data stored in a DB is not deleted when the data block is closed or the execution of the
associated code block comes to an end. There are two types of DBs:
●
A global DB stores data for the code blocks in your program. Any OB, FB, or FC can
access the data in a global DB.
●
An instance DB stores the data for a specific FB. The structure of the data in an instance
DB reflects the parameters (Input, Output, and InOut) and the static data for the FB. The
Temp memory for the FB is not stored in the instance DB.
Although the instance DB reflects the data for a specific FB, any code block can access the
data in an instance DB.