S7 STL indirect addressing

K

Thread Starter

kevin glaser

<p>This code runs fine from 0-2047 but when 'DB1.DBD 176' goes over 2047 the cpu stops because it tried to access address 61440. I don't know how this number is derived... Why would the 16384 bit cause this?
<pre>
LAR1 P#DBX 0.0 //Area-crossing DBX pointer
L DB1.DBD 176 //Selected Dword byte location of data
SLD 3 //Word in pointer format
+AR1
</pre>
<p>All I need is AR1 to address byte 0 to 10348 in DB126.

<p>[email protected]
 
D

Dobrowolski, Jacek

Hi,

I can think of two reasons:
1st - the DB126 is not long enough,
2nd - well, show me first how content of the DB1.DBD176 is created and how you access the DB, maybe I could help you more then.

Regards,

Jacek Dobrowolski
 
The problem is caused by the way Siemens have defined the area pointer.

If you consider the pointer as a double word with Bits 0 - 31 going from right to left (LSB -> MSB) then Bits 0 - 2 are the Bit address, Bits 3 - 18 are the Byte address, Bits 19 - 23 are "0" Bits 24 - 26 define the area in Memory (0 = Peripheral devices, 1 = Inputs, 2 = Outputs etc.), 27 - 30 are again "0" and Bit 31 is always "1" (presumably to differentiate the are-crossing pointer from the area-internal pointer, where all the Bits 19 - 31 are always "0").

This means that the highest address you can address this ways has offset 2047.

I must admit I don't see any easy solution other than to break your DB down into 2048 Byte chunks and access them sequentially.

At least you now know why it doesn't work! :)

Oops, too quick off the mark there - I've miscounted my Bits and the maximum Byte address is indeed 7FFF not 7FF as I mistakenly calculated. This should indeed be able to access the full 32767 Bytes (although only forwards).

The only other thought that occurs to me is that it may be processor dependant, since some of the smaller 300 series CPUs have a maximum DB size of 8 or 16 kB. Which CPU are you using?
 
Top