Main page
PLC functions
Small tools
Technical links
Other links
Some information
Back to home
 Reactions: E-mail

Working people make mistakes, some people do never make mistakes! Working people
I work to live, my boss thinks I live to work!

Here are the functions who can be usefull if you want to use DB's in a plc.
These functions are made for Siemens Step7® plc's.
a DB (DataBase) is a lists of data in the memory of the plc. Mostly its a STRUCT (Record) or a combination of several STRUCTS.
There are several types of DB's, if you don't now the difference between them you have to watch out with these functions.

download awl source (all DB-functions.)

Symbol table:
DB copy RAM 2 RAM FC 1050FC 1050DB copy RAM 2 RAM using SFC 20 (DB may not be unlinked!)
DB copy RAM 2 FlashFC 1051FC 1051DB copy RAM 2 Flash using SFC 84 (DB can be unlinked)
DB copy Flash 2 RAMFC 1052FC 1052DB copy Flash 2 RAM using SFC 83 (DB can be unlinked)
DB byteswap FC 1053FC 1053DB copy RAM 2 RAM with byteswap (DB may not be unlinked!)

First some tips:

Instance DB functions:
// Determ instance DB number (only in STL)
L DINO
T #InstanceDB

// Direct adressing in an instance DB (only in STL)
OPN DI x // (x=instand DB)-> Open DB as instance DB. The second data block is opened with the OPN DIx instruction and addressed as an instance data block of an FB call by DIX, DIB, DIW, and DID.
A DIXx.x // bit x.x out of instance DB
L DIx (x= B,W or D) // load out of instance DB (Byte, Word or Dword)

// Example with normal DB: (from help file)
OPN DB10 // Open data block DB10 as a shared data block.
L DBW35 // Load data word 35 of the opened data block into ACCU 1-L.
T MW22 // Transfer the content of ACCU 1-L into MW22.
// Example with instance DB:
OPN DI20 // Open data block DB20 as an instance data block.
L DIB12 // Load data byte 12 of the opened instance data block into ACCU 1-L.
T DBB37 // Transfer the content of ACCU 1-L to data byte 37 of the opened shared data block.
// Example with pointer:
L P#8.7 // Load ACCU 1 with pointer value.
T MD 2 // Transfer pointer into MD2.
A DIX [MD 2] // Scan state of bit 8.7, and assign it.
= Q [MD 2] // signal state to output bit Q 8.7.

top

Make copy and/or swap the content of a DB easy:

Network 3: FC 1053: Byte swap
Input: EN Condition for copy data. May be an AND/OR logic or another combination of functions. Mostly not used.
SourceDB DB were the data has to be loaded from.
TargetDB DB were the data has to be saved to.
NumberOfByte The number of bytes to be swapped or copied. (starting with word 0.)
Swap If high then during the copy process the byte's will be swapped in every word.
Watch out: There is no control if the DB exists or if the DB has the correct size! The PLC will stop or may overwrite data in the memory!
Easy for the communication between Siemens S7 PLC and Siemens OP.

The cause of this problem is the method of writing to the memory of the internal CPU.
Motorola based processors write Highbyte, Lowbyte to a Word in the memory.
Intel based processors write Lowbyte, Highbyte in a Word in the memory.
I guess a S5 PLC and the OP's from Siemens have a Motorola based processors, and the Siemens S7 PLC's have intel based processors. The same problem occurs when communicating between different brands of controllers!!)
top

Make copy of a part of a DB or copy a complete DB easy:
DB copy
Network 4: FC 1050: DB copy RAM 2 RAM
Input: EN Condition for copy data. May be an AND/OR logic or another combination of functions. Function uses SFC20.
SourceDB DB number were the data has to be loaded from.
TargetDB DB number were the data has to be saved to.
NumberOfByte The number of bytes to be copied.
StartAdrSource The byte address in the Source DB were to start reading the data.
StartAdrTarget The byte address in the Target DB were to start saving the data.
Watch out: There is no control if the DB exists or if the DB has the correct size! The PLC will stop or may overwrite data in the memory!
top


Unlinked DB: (Step 7)
You can only read a DB that is loaded in the RAM memory of the PLC. But the internal memory is not expandable! You have to buy a bigger PLC just for more memory. If you only need the memory for recipes or other setting you can write this data only in the flash memory. You can't read this memory directly and there is a limit of writing actions for this type of memory. (somewhere around the 1 million times writing! Even with your digital camera there is this limit!!! For more information, see the reference manual "SIMATIC S7-300 Programmable Controller CPU Data: CPU 31xC and CPU 31x".)
You have to say to your software (step 7) that you want to load the DB only in the Flash memory. You do that by opening the "Properties" of a DB in the Simatic manager, go to Section "General - Part 2". Click the Unlinked and click OK. (see above picture.) Now the manager only loads the DB in the Flash memory. It may not exist in the RAM memory!!!
top


Network 6: FC 1052: DB copy FLASH 2 RAM
Input: EN Condition for copy data. May be an AND/OR logic or another combination of functions. Function uses SFC 83 "READ_DBL".
Function SFC 83 is an Asynchronous function! That means the function perform its task in the background. The data is not copied directly! SFC 83 is not suitable for frequent (or cyclical) reading of variables!! Use a One shot function!
SourceDB DB number were the data has to be loaded from. DB must be a unlinked DB
TargetDB DB number were the data has to be saved to. DB may not be a unlinked DB
NumberOfByte The number of bytes to be copied.
StartAdrSource The byte address in the Source DB were to start reading the data.
StartAdrTarget The byte address in the Target DB were to start saving the data.
Watch out: There is no control if the DB exists or if the DB has the correct size! The PLC will stop or may overwrite data in the memory!
top

Network 7: FC 1051: DB copy RAM 2 FLASH
Input: EN Condition for copy data. May be an AND/OR logic or another combination of functions. Function uses SFC 84 "WRIT_DBL".
Function SFC 84 is an Asynchronous function! That means the function perform its task in the background. The data is not copied directly!
SFC 84 is not suitable for frequent (or cyclical) writing of variables to the load memory writing. This is because the technology of Micro Memory Cards means that only a certain number of write accesses can be made to a Micro Memory Card!! Use a One shot function!
SourceDB DB number were the data has to be loaded from. DB may not be a unlinked DB
TargetDB DB number were the data has to be saved to.DB must be a unlinked DB
NumberOfByte The number of bytes to be copied.
StartAdrSource The byte address in the Source DB were to start reading the data.
StartAdrTarget The byte address in the Target DB were to start saving the data.
Watch out: There is no control if the DB exists or if the DB has the correct size!
top