meta data for this page
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| automation:db [2026/01/06 15:01] – created - external edit 127.0.0.1 | automation:db [2026/01/06 23:18] (current) – vamsan | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ==== Data block (DB) ==== | ==== Data block (DB) ==== | ||
| {{anchor: | {{anchor: | ||
| - | “DB” | + | “DB” |
| The image below shows the contents of a DB, along with some settings: | The image below shows the contents of a DB, along with some settings: | ||
| Line 19: | Line 19: | ||
| |**Setpoint**|This allows you to initialize values in a data block (DB) online while the CPU is in RUN mode.| | |**Setpoint**|This allows you to initialize values in a data block (DB) online while the CPU is in RUN mode.| | ||
| |**Comment**|Description of the function of the field.| | |**Comment**|Description of the function of the field.| | ||
| + | |||
| + | === DB Limits === | ||
| + | |||
| + | * You can define up to 252 structures within a single data block for S7-1200/ | ||
| + | * Maximum DB Number: The total number of data blocks is generally capped at 65,535, due to the common use of a 16-bit address range. | ||
| + | * Maximum DB Size (Standard - not optimized - Access): For older PLC models like S7-300/400 and for standard access DBs in newer models, each DB's size typically does not exceed 64 KB (65,534 bytes). | ||
| + | * Maximum DB Size (Optimized Access): In contrast, S7-1200/ | ||
| + | |||
| + | === Instant vs global DB === | ||
| + | |||
| + | A **global DB** is a data block that programmers can freely create and populate with variables. These variables may include default Simatic types (INT, REAL, etc.), structures, arrays, or UDTs. | ||
| + | |||
| + | **Instant DB**s are implicitly created when FBs are called for the first time. This call is primarily through the instant DB. When an FB is deleted, the TIA Portal also issues a separate warning about removing the instant DB. The contents of the instant DB automatically update with changes to the FB's variable list. It can include default Simatic variables like INT, REAL, structures, arrays, and UDTs. If the FB calls other embedded FBs (e.g., TON, TOF), their instant DBs are also stored here, resulting in a **multi-instant DB**. | ||
| + | |||
| === DB Properties === | === DB Properties === | ||
| Line 28: | Line 42: | ||
| ^Name the attribut^Description| | ^Name the attribut^Description| | ||
| |**Only store in load memory**|This attribute is stored on the PLC's Micro Memory Card (MMC) or similar non-volatile storage, not in the CPU's working RAM, making it ideal for large, infrequently used data such as recipes or logs. \\ It's accessed using special instructions like READ_DBL or WRIT_DBL to transfer data to/from working memory. This preserves precious working memory, but requires explicit programming to move data for active processing. The data survives power cycles but can be lost with a factory reset.| | |**Only store in load memory**|This attribute is stored on the PLC's Micro Memory Card (MMC) or similar non-volatile storage, not in the CPU's working RAM, making it ideal for large, infrequently used data such as recipes or logs. \\ It's accessed using special instructions like READ_DBL or WRIT_DBL to transfer data to/from working memory. This preserves precious working memory, but requires explicit programming to move data for active processing. The data survives power cycles but can be lost with a factory reset.| | ||
| - | |Data block write-protected in the device|Make the entire data block read-only.| | + | |**Data block write-protected in the device**|Make the entire data block read-only.| |
| - | |Optimized block access|Optimized variable order within the DB. See below: [[# | + | |**Optimized block access**|Optimized variable order within the DB. See below: [[# |
| - | |Data block accessible from OPC UA|The data block can be accessed and published by OPC UA. See: [[# | + | |**Data block accessible from OPC UA**|The data block can be accessed and published by OPC UA. See: [[# |
| - | == Optimized DB == | + | === Optimized DB === |
| {{anchor: | {{anchor: | ||
| Simatic groups variables in the optimized DB so they occupy as little storage space as possible. This means that it is "not visible from the outside" | Simatic groups variables in the optimized DB so they occupy as little storage space as possible. This means that it is "not visible from the outside" | ||
| Line 39: | Line 53: | ||
| On the one hand, this helps better utilize the PLC's storage space. Still, on the other hand, it makes operations that require direct addressing (communication modules - Modbus, direct addressing, etc.) impossible. In such cases, this option must be disabled in the settings (// | On the one hand, this helps better utilize the PLC's storage space. Still, on the other hand, it makes operations that require direct addressing (communication modules - Modbus, direct addressing, etc.) impossible. In such cases, this option must be disabled in the settings (// | ||
| + | |||
| + | === Tags vs DB data === | ||
| + | |||
| + | There are two basic methods for storing data in PLCs (in a simplified view). One involves placing variables in a global memory table alongside input and output variables, while the other uses data blocks (DBs). From my experience, storing data in DBs tends to be simpler and more straightforward for several reasons. | ||
| + | |||
| + | * Function-specific data can be stored in DBs. For example, the “motor1” DB contains only data for the 1st motor, but all of them (speed, load, temperature, | ||
| + | * If someone wants to define a “motor2” as well, identical to “motor1” in terms of its parameters, they just need to copy the previous DB | ||
| + | * Cross-reference management of data immediately points to the given DB, from which we can immediately deduce their function | ||
| + | * If the data is already in the instant DBs assigned to the FBs, it is easy to embed them in a calling FB to use them as multi-instants. | ||
| + | |||
| + | Typically, I don't bother defining variables within the Tags; creating them directly in the databases suffices—though this is just my personal preference. | ||
| + | |||
| + | === Storing DB records in the load memory === | ||
| + | In PLCs, working memory is PLC-dependent and often very limited. We may have a lot of information that does not need to be read and written cyclically. Examples include recipe data (a list of technological components), | ||
| + | |||
| + | In these cases, one option is to store the data not in working memory but on the SD card and in load memory, and to transfer them only when needed using the " | ||
| + | |||
| + | {{: | ||
| <WRAP center round info 80%> | <WRAP center round info 80%> | ||