Data Block Addressing

Jieve

Member
Join Date
Feb 2012
Location
USA
Posts
274
Hello,

Couple of quick questions regarding use of data blocks when programming Siemens PLCs with TIA Portal in LAD/FBD:

1) When I was taught to program Siemens PLC's, I was told to avoid using memory bits and only use data blocks with no explanation. What are the advantages of using data blocks over using memory bits/bytes/words? From what I can tell, I cannot define certain data types using memory bits (structs, arrays, etc.) and there seems to be no way to set an initial value for memory bits in the tag table. These would be a couple disadvantages of memory. Are there any others?

2) A nice thing (it seems) about TIA portal is that when you use data block bits with symbolic addressing in the program and you add a bit in the data block before the program bit, the program continues to associate the bit used in the program with its symbolic name, and not with the absolute address. This way, the bit doesn't change even when the address changes when the data block is recompiled (I think I remember in older versions having to go through and change every bit address that came after the modified bit).

Is there a way to symbolically address a byte, say absolute address DB6.DBB8, symbolically called "Machine Mode", and use the bits individually without using absolute addressing?

An example I was playing around with, was transferring a byte into the data block byte "Machine Mode", where each of the 8 bits represents a different mode, and then using those bits symbolically individually later in the program. Is there a way to symbolically name each of the bits within a byte, as well as the byte itself, so that both can be used in the program? Or just a way to use a single bit within the byte symbolically rather than with the absolute address?

I'm not necessarily interested in finding a solution to the specific application mentioned, just more curious if data block bits can be used in this way.

Thanks!
 
The last question. You can make an array of bools. At least that way you have the symbolic tag as the first part then your array pointer in brackets.
mydb.machinestatus[2]. Problem is is getting the data into it in byte form. You might need to create a simple function that takes your byte, breaks it down and inserts the relevant bits into your array tag as an inout.
 
Last edited:
Hjtrbo,

Thanks for that response. Yeah, i tried that after i posted, made an array of 8 Bools and tried to move the byte into the array with no luck, just as you said. The data type difference stopped it from happening. A function could work, but it would be nice if there were some way to simply access the bits symbolically from the byte, something like DB1.Machine Mode.1 or something.
 
Is there a way to symbolically address a byte, say absolute address DB6.DBB8, symbolically called "Machine Mode", and use the bits individually without using absolute addressing?

In Simatic manager, No. (I assume it is the same in TIA)

An example I was playing around with, was transferring a byte into the data block byte "Machine Mode", where each of the 8 bits represents a different mode, and then using those bits symbolically individually later in the program. Is there a way to symbolically name each of the bits within a byte, as well as the byte itself, so that both can be used in the program? Or just a way to use a single bit within the byte symbolically rather than with the absolute address?

If you want to use DBs for your global data don't mess about with a byte in this way. Use bits for the modes and process only the bits - that way everything will hang together symbolically.

I would personally use M flags for machine modes. Declare them as bits in the symbol table and set them in stone.

e.g. If you want to know if any machine mode is active, OR the machine mode bits together into another M flag called "bAnyModeActive" or the like.
 
Guys, thanks for the responses.

Kalle, I also tried this method with the struct, and that's more along the lines I was looking for, that I can actually name each bit and manipulate the byte. I was trying to do it all in FBD but it seems using STL is really the only way to manipulate the bits on that level. I am familiar with basic STL but have never used the address registers or pointers, only accumulators and math, so I'm not exactly familiar with how they work. I will have to do a forum search on those.

LD, the reason I was doing it this way was really just to test out the method, not because it's the best way to solve the problem. Using the byte method means when programming that I don't have to worry about network/rung order since the machine can never be in two states at once, then beyond that just using the bits I don't have the overhead of using ints and compare functions continuously. There were a couple other applications where I wanted to declare a byte and just use the individual bits as well. Thanks for the tips and info though, TIA portal is probably no different than older step 7 versions in that sense.

Anyone have any comments about the first question, why I would use data blocks over memory besides the examples I gave?

Thanks!
 
Anyone have any comments about the first question, why I would use data blocks over memory besides the examples I gave?


- If you have developed some kind of a complex function, f.x. a communication interpreter, you would like to have all the data 'private' for your system - in a DB. Then you can load your function into an already running system with much less collision points (only FB and DB numbers, not nty M/MBs).

- Back in the (good?,) old Step5 times, the Marker area was quite narrow (64/128/ 256 bytes). So we had to use the Ms carefully and preferably only for the main process/machine logics.


BTW, I'm not a TIA user, but I mean I read somewhere that this expression from your earlier post: "DB1.Machine Mode.1" is legal (in TIA). Perhaps it was only for the S71200? I'll see if I can dig it up.



Kalle
 
Kalle, thanks for those examples.

- Back in the (good?,) old Step5 times, the Marker area was quite narrow (64/128/ 256 bytes). So we had to use the Ms carefully and preferably only for the main process/machine logics.

I figured that this might be the case. The guy I learned from originally programmed (and learned on) S5 PLC's before switching to S7, so I figured some things he said were a carryover from an older time.

Uploading program changes without memory collisions is a good reason though.

BTW, I'm not a TIA user, but I mean I read somewhere that this expression from your earlier post: "DB1.Machine Mode.1" is legal (in TIA). Perhaps it was only for the S71200? I'll see if I can dig it up.

I tried the example using an S7-300 in TIA, and couldn't get it to work. However, it might work with the 1200. I'll see if I can give it a shot, or if you can find where you came across that, even better.

Thanks!
 
Finally, here I found it! It is a cutout from the S71200 Easy book, 04/2012 (never tried it myself ):

Kalle



4.4.3 Accessing a "slice" of a tagged data type
PLC tags and data block tags can be accessed at the bit, byte, or word level depending on
their size. The syntax for accessing such a data slice is as follows:
● "<PLC tag name>".xn (bit access)
● "<PLC tag name>".bn (byte access)
● "<PLC tag name>".wn (word access)
● "<Data block name>".<tag name>.xn (bit access)
● "<Data block name>".<tag name>.bn (byte access)
● "<Data block name>".<tag name>.wn (word access)
A double word-sized tag can be accessed by bits 0 - 31, bytes 0 - 3, or word 0 - 1. A wordsized
tag can be accessed by bits 0 - 15, bytes 0 - 2, or word 0. A byte-sized tag can be
accessed by bits 0 - 8, or byte 0. Bit, byte, and word slices can be used anywhere that bits,
bytes, or words are expected operands.
 
Last edited:
Kalle, thanks for that info. It works fine using an S7-1200, just tested it in TIA Portal. When trying to use that method with the S7-300 I get the error message "addressing with .x1 is not supported by the CPU used".

L D, thanks, that method will be my next test.

Thanks again guys.
 
using the above example:

L LW0
T MW46

or

L LW0
T DB24.BDW46

any contiguous array of bools can be easily moved with a simple MOV as a word.

Of course there will will be those who caution against ever addressing the L stack directly. It is a common method I have seen used quite a bit. I agree it can be tricky, but in a FC that is used without being edited frequently, it is a quick way to move data around.
 

Similar Topics

Afternoon, I have a DB in TIA Portal V16 that is optimised. I cannot change this. There is an array inside that block which consists of 3000...
Replies
9
Views
1,118
Hello all, PLC-programming noob here. I have multiple clients accessing some data on my Siemens S7 1211C PLC; some OPC clients and some direct...
Replies
30
Views
8,287
Hey people, I have been using GET_NAME , GET_IM_DATA and ModuleStatus FB to get an info from Modules inside my program, but ever since and...
Replies
4
Views
2,536
Hi, just wondering if I could get some advice when setting up function blocks (Currently using Siemens S7) using a STRUCT data format. Say I was...
Replies
11
Views
2,985
Hi, Ok bear with me, I have an Array of Real in a DB ranging from 0 to 10. In ladder I want when count pulse = 100 move count into Array 0...
Replies
1
Views
2,076
Back
Top Bottom