terça-feira, 24 de junho de 2025

PROGRAMMING A PLC SIEMENS / BASICS OF BLOCK ACCESS

Basics of block access 

Introduction 


STEP 7 offers data blocks with different access options: 


Data blocks with optimized access (S7-1200/S7-1500)


Data blocks with standard access (S7-300 / S7-400 / S7-1200 / S7-1500)


Within one program you can combine the two types of blocks. 


Data blocks with optimized access


Data blocks with optimized access have no fixed defined structure. In the declaration, the data elements are assigned only a symbolic name and no fixed address within the block. The elements are saved automatically in the available memory area of the block so that there are no gaps in the memory. This makes for optimal use of the memory capacity. 


Tags are identified by their symbolic names in these data blocks. To address the tag, enter its symbolic name. For example, you access the "Fill Level" tag in the "Data" DB as follows: 


"Data".Fill Level


Blocks with optimized access offers the following advantages:


You can create data blocks with any structure without paying attention to the physical arrangement of the individual data elements.


Quick access to the optimized data is always available because the data storage is optimized and managed by the system.


Access errors, as with indirect addressing or from the HMI, for example, are not possible. 


You can define specific individual tags as retentive.


Optimized blocks are equipped with a memory reserve by default which lets you expand the interfaces of function blocks or data blocks during operation. You can download the modified blocks without setting the CPU to STOP and without affecting the values of already loaded tags. 


Note 


The "Optimized block access" attribute is always enabled for the following blocks and cannot be deselected.


GRAPH blocks


CEM blocks


ARRAY data blocks

 



Data blocks with standard access


Data blocks with standard access have a fixed structure. In the declaration, the data elements are assigned both a symbolic name and a fixed address within the block. The address is shown in the "Offset" column.


Tags in these data blocks can be addressed in both symbolic and absolute form. 


"Data".Fill Level


DB1.DBW2


Setting Retentivity for Optimized Access or Standard Access


If you define data as retentive, its values are retained even after a power failure or a network off. A retentive tag is not initialized after the hot restart but retains the value it had prior to the power failure. If a DB tag is defined as retentive, it is stored in the retentive memory area of the data block. 


The options for setting the retentivity depend on the access type of the block.


In data blocks with standard access, you cannot set the retentive behavior of individual tags. The retentivity setting is valid for all tags of the data block.


In data blocks with optimized access you can define the retentive behavior of individual tags. 


For structured data type tags, the retentivity setting always applies to the entire structure. You cannot make any individual retentivity setting for separate elements within the data type. 


Setting Addressing Options for Optimized Access or Standard Access


Blocks with optimized access permit only "type-safe" access. Type-safe access addresses tags by their symbolic name only. This means even changes to the block or the block interface will not result in inconsistencies in the program or access errors.


The following table shows the permitted addressing options for optimized data:


Fazendo upload: 14095 de 14095 bytes.



Addressing

 Block with standard access

 Block with optimized access

 

Symbolic addressing

 x

 x

 

Indexed addressing of ARRAYs

 -

 x

 

Slice access

 x

 x

 

Overlapping with AT

 x

 -

 

Absolute addressing

 x

 -

 

Indirect addressing via ANY

 x

 -

 

Indirect addressing via POINTER and VARIANT

 x

 with symbolic notation only

 

Indirect addressing via references

 -

 x

 




--------------------------------------------------------------------------------


See also 


Setting up block access 

Addressing variables in data blocks 

Retentive memory areas (S7-1200) 

Creating blocks 

EMERSON EDUARDO RODRIGUES

Programming a PLC Siemens - Multi-Instances

 Multi-instances 

Definition 


When a function block (FB) calls another FB, its instance data can also be stored in the instance DB of the calling FB. This type of block call is referred to as a multi-instance.


Advantages


The use of multi-instances provides the following advantages: 


Good structuring options for complex blocks 


Lower number of instance DBs 


Easy programming of local subprograms, for example for local timers or edge evaluations.


How multi-instances work


The following figure shows an FB that uses another FB ("Valve"). "Valve" is called as a multi-instance, i.e. it stores its data in the instance DB of the calling FB. Multi-instance data is located in the "Static" section of the calling block. In CPUs of the S7-1200/S7-1500 series, the instance can also be located in the instance DB of another function block.


Creating multi-instances


You have the following options for creating a multi-instance:


When you call an FB in the program, the "Call options" dialog appears. Here, you can specify whether you want to call the FB as a single instance, multi-instance or parameter instance.


You declare the multi-instance directly in the interface of the calling block.


You declare the multi-instance in the interface of another function block (S7-1200/S7-1500).


See also: Declaring multi-instances


ARRAYs of multi-instances


Multi-instances can also be created as an ARRAY. You can address the individual ARRAY elements using a variable index, for example when processing program loops. 





 



You declare ARRAYs of multi-instances directly in the interface of a function block.


Calling multi-instances 


When a multi-instance is called, the assigned instance is indicated. The following figures show the call of the "Block" block as a multi-instance in LAD. 


In the following example, the instance is located locally in the instance DB of the calling block:


 



In the following example, the instance is located in the instance DB "MyOtherFB" (S7-1200/S7-1500):


 



In the following example, the instance is located in an ARRAY of multi-instances in instance DB "MyOtherFB" (S7-1200/S7-1500):


 




Note 


Calling and addressing blocks in namespaces


Blocks located in namespaces are represented in the program code in IEC-compliant notation:


The block name is not in quotation marks.


The namespace precedes the block name, separated by a dot.


You can find detailed information on the notation of namespaces under: Introduction to namespaces

 




--------------------------------------------------------------------------------


See also 


Instance data blocks 

Basics of instances 

Single instances 

Example of using parameter instances in an ARRAY of multi-instances 

EMERSON EDUARDO RODRIGUES


Programming a PLC SIEMENS - Single Instances

Single instances 

Definition 


An instance of a function block (FB) that is located in its own instance DB is referred to as a single instance. The instance DB thus contains the working data for an individual block call.


Advantages


The use of single instances provides the following advantages: 


Reusability of the function blocks 


Good structuring options for simple programs


How single instances work


The following figure shows the FB "Caller" that uses another FB ("Valve"). "Valve" is called as a single instance, i.e. it stores its data in its own instance DB. 





The structure of the instance data block is defined by the interface of the corresponding FB and can only be changed there. The instance DB contains the following data: 


Block parameters 


The block parameters in the "Input", "Output" and "InOut" sections form the interface of the block for the call in the program. 


Static local data


Static local data in the "Static" section is used for permanently storing intermediate results beyond the current program cycle, for example for storing the signal state for an edge evaluation.


Creating single instances


You have the following options for creating a single instance:


When you call an FB in the program, the "Call options" dialog appears. Here, you can specify whether you want to call the FB as a single instance, multi-instance or parameter instance.


When you create a new data block, the "Add new block" dialog opens. Here, you can select a function block that you want to create an instance data block for under "Type". 


Calling single instances


When a single instance is called, the assigned instance data block is indicated.


The following figure shows the call of the "Block" block as a single instance in LAD. The instance data block "BlockData" is above the call.


Note 


Calling and addressing blocks in namespaces


Blocks located in namespaces are represented in the program code in IEC-compliant notation:


The block name is not in quotation marks.


The namespace precedes the block name, separated by a dot.


You can find detailed information on the notation of namespaces under: Introduction to namespaces

 




--------------------------------------------------------------------------------


See also 


Basics of instances 

Multi-instances