Step7 CPU300 question

Dear PeterW.

I think I understand a part of it.

Let me try to explain how I understand, what You wrote:

L MW8 Here I load MW8
L 2 (or 4) Here I load the integer value 2 (or 4)
+I Here the values in MW8 and the value 2 (or 4) are added
T MW8 And here they are transferred to MW8
SLD 3 This means that above values are going to the BYTE-part
of the POINTER. What is a POINTER ??
T MD10 This I dont know what means.


Have I understood some of it correctly ??

Thank You for helping me alot
 
Hello Laura;
What is a POINTER ??
DB1.DBD[MD10], where MD10 will be added with the value 4 before every move

We are building our examples here based on your original example. MD10 will point to an address where you want to go to in the next operation. In Siemens' world, it must then be in pointer format; it is not an integer value.
You can go on online help or in the manual to understand the pointer format, I highly recommend you do. But for the moment, please accept that by doing the SLD 3 operations, and transfering this value to MD10 (that is what the T MD10 instruction does), then DB1.DBD[MD10] will point to an address 2 or 4 bytes further than the preceding loop, which is what you want.
First, DB1.DBD[MD10] = DB1.DBD0
then DB1.DBD[MD10] = DB1.DBD4
then DB1.DBD[MD10] = DB1.DBD8 ...

Hope this helps,
Daniel Chartier
 
Basically in this example MW8 would be used as a 'pointer' to the Dataword address you will store the next PIW read value into.

The pointer is not where you will store the value, it is merely acting as an indication to where the data will be stored, like the address on an envelope tells the postman which house to deliver the letter to.

As Siemens works in bytes and not words, the value you are reading is from PIW752, which uses bytes 752 and 753. The same way when stored in the dataword will occupy two bytes.

The first read would go into DBW0, which is bytes 0 and byte 1, the second cannot go into DBW1, as this is bytes 1 and 2, byte 1 is already used as part of DBW0.

DBW 0 = High Byte (0) and Low byte (1) - DBB0 and DBB1.
DBW 1 = High Byte (1) and Low byte (2) - DBB1 and DBB2.

Your second read would corrupt your first, theerfore the next available whole word would be DBW2 (DBB2 and DBB3).

That is why the 'pointer' would increment by 2, to point to the next available word. In your case you specified 4 in your first post, I don't know your application so I don't know what the 3rd and 4th bytes are reserved for.

The pointer itself is MD10, this is a double word, 32 bits (or 4 bytes) or long. Pointers have to be 32 bits to comply with Siemens pointer format.

Pointer Format:

pointer.JPG


The only reason to use MW8 really, is because its easier to add 2 to it and show what is happening. there is another way using P#2.0.

As you can see from the bit pattern of bytes 2 to 5, the far right 3 bits make up the bit address 000 = 0 to 111 = 7. The byte address overflows into the preceding word.

If MW8 = 200 and the addition changed it to 202, then the code after SLD 3 and transferring into MD10 would do the following:

T DB1.DBD[MD10] would in fact be DB1.DBD[202.0] or to you and me DB1.DBD202.

MD10 was the pointer to DW202, next time it will point to DW204, etc..
 
Thank You so very much friends, You are fantastic.


I think I understand it now.

Although when I write T DB1.DBD[MD10] in STL in my FC, it will not be accepted. The code changes color to red.

Why is this ?
 
It need to be a formatted as a DWORD, rather than using MD10, maybe better to create a TEMP in DWORD format in the declarations at the top of the block.
 
laura said:
Although when I write T DB1.DBD[MD10] in STL in my FC, it will not be accepted. The code changes color to red.
Why is this ?
Because you have mixed direct and indirect addressing in this statement. Correct form:
OPN DB1 // DB1 opening
T DBD[MD10] // Transfer to DB1.DBD10
 
OK I'm guilty of reproducing the example in the original request without thinking about it.

Just wondered why Gambrinus repeated the same thing as Simon, I bet its to rub it in...šŸ™ƒ :sick:
 
Thank You so much, You are super !!


I will try this then:

L MW8
L2
+I
T MW8
SLD3
OPN DB1
T DBW [MW8]

If I understand You correctly, this moves the saving-destination 2 bytes for each scan.

But how about the actual saving of values from my PIW752 ?

Will it then be like this:

L MW8
L2
+I
T MW8
SLD3
OPN DB1
T DBW [MW8]

L PIW752
OPN DB1
T DBW [MW8]

Or am I still missing it ?

laura
 
Not quite

You still need MD10, but better would be, in The TEMP Area in the declarations create a new variable

'DW_Address' and make it a 'DWORD'

at some point you would ensure MW8 = 0 at the start (on a one shot or when you want to restart from the beginning)then do this code.

L MW 8
SLD3
T #DW_Address <-- This replaces MD10, no need to store in memory

L PIW752
OPN DB1
T DBW [#DW_Address]

L MW8
L2
+I
T MW8 <-- add to MW8 ready for next time.




Of course there are the other concerns raised about the maximum size of the DB so what do you do when its full etc
 
Last edited:
Thanks again PeterW.


I believe I now understand it all, except why I do need MD10.

PIW752 is only 2 bytes.

I know I started this topic mensioning MD10, but this was a fault.

When the datablock is full, I was thinking about saving in DB2 then DB3 etc. etc.

laura
 
MD10 is a double word, a double word is needed for the pointer as the pointer is 32 bits.

In the above example I replaced MD10 with a DWORD TEMP flag instead, so you don't need MD10, just a temporary double word into which to place the pointer address which needs a double word, otherwise it would turn RED when programming it.

L PIW752 <== Single word
OPN DB1
T DBW [DW_Address] <== DBW = single word, DW_Address is a double word in pointer format which tells the instruction which DBW word to place the contents of the accumulator, which is the value held in PIW752.
 
Last edited:

Similar Topics

This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
162
When you download a DB, the values get overwritten by what is in the "actual" column in offline DB. Does this happen at the start of the PLC...
Replies
6
Views
156
Hello Inside a FB, IĀ“m trying to transfer a string from a DB to a IN_OUT var that was define as a UDT. The problem is that i canĀ“t determine the...
Replies
4
Views
146
Hi all, I am trying to convert RSLogix 5000 program to Step7. I need to bit shift left my array of double integers for tracking the product on...
Replies
2
Views
529
I have a word in some DB which I want to load to AR1 and use as a pointer. In order to do this I need to write L DBxy.DBW xy SLD 3 LAR1 I...
Replies
3
Views
550
Back
Top Bottom