S7 300 indirect addressing help

JOLTRON

Lifetime Supporting Member
Join Date
Aug 2006
Location
MI
Posts
692
Hello all,

I'm new to indirect addressing in siemens controller.
I know the basic idea but I'm having issues with coding it.

I basicly have 50 some part numbers that I want to be able to move around and i don't want to have a network for everyone one.

The information I am moving is in a DB and all part numbers are 18 characters long.

Ex: P#DB99.DBX0.0 byte 18

So I was wondering if someone could help me out and give me a basic idea of what the code would look like to the DBX0.0 by 18 or 20.

Thanks,
Joel
 
Sorry my replies were just re-directions, I was just leaving the office. I'm supprised no-one else has come in and given an overview.

To move data around you need to call SFC20 from the Siemens library, this uses the ANY pointer as source and destination. That last link in my second post includes a cut and paste of the siemens help for the ANY format.

To use it as a variable pointer, you would need to create two ANY variables in the TEMP declaration field, plus a TEMP INT for the SFC20 result.

To modify the data in the TEMP ANY area, you would have to point the address register to the start address of the variable and use it to offset to all the fields.

for example, a TEMP variable SOURCE is named and set as an ANY.

The STL code would be:

Code:
LAR1 P##SOURCE // point AR1 to the start address of the TEMP SOURCE
 
L W#16#1002 // The 10 part is always there, the 02 refers to BYTE format (see the help of ANY for the others)
T LW[AR1,P#0.0] // Transfer into the SOURCE local flag area (first two bytes)
 
L 18 // Length of Data
T LW[AR1, P#2.0] // notice the P# is acting as a byte offset.
 
L 99 // Data Block No.
T LW[AR1, P#4.0]
 
L 6 // In this example it is DW6
SLD 3 // The 3 right most bits of Byte 9 make up the bit address (0-7)
T LD[AR1, P#6.0] // Byte address is in Bytes 7, 8 and 9
 
L B#16#84 // 84=Data Area (see help to find other areas, like flags etc)
T LB[AR1, P#6.0] // Byte 6 = data type

The TEMP ANY is now set up as DB99.DBX6.0 BYTE 18.
 
So then is the P#0.0 and P#2.0 pointing to a specific part of the AR1???
LW[AR1,P#0.0]
LW[AR1, P#2.0]

And how would I go about having the pointer shift according to what part I have selected.
Part 1 db99.dbx20.0
part 2 db99.dbx40.0
part 3 db99.dbx60.0
etc....

I've gone thru quite a few other threads. the idea in my head is so simple it seems like alot of work to get it done.

thanks for your help so far.
 
If you look in post#2 above, the second link will take you to a block that I wrote (FC200) that allows you to copy any area of a db to any area of another db. All you would need to do is manipulate the iSourceByteOffset to select the part number you want as the source.
 
Instruction
T LW[AR1, P#0.0] transfers contents of ACCU1 to local data word whitch adress is stored in AR1,
T LW[AR1, P#2.0] tranfers contents of ACCU1 to local data word with adress stored in AR1 + 2bytes,
so if AR1 contains adress of LW10 then
T LW[AR1,P#0.0] - writes to LW10
T LW[AR1,P#2.0] - writes to LW12.
 
JOLTRON said:
So then is the P#0.0 and P#2.0 pointing to a specific part of the AR1???
LW[AR1,P#0.0]
LW[AR1, P#2.0]

And how would I go about having the pointer shift according to what part I have selected.
Part 1 db99.dbx20.0
part 2 db99.dbx40.0
part 3 db99.dbx60.0
etc....

I've gone thru quite a few other threads. the idea in my head is so simple it seems like alot of work to get it done.

thanks for your help so far.

AR1 is one of two address registers.

In the instruction

LAR1 #SOURCE

if SOURCE was the first TEMP declaration it would be in the first local flag area, i.e. Local Byte 0. As it has been declared as an ANY data type, it will take up 10 Bytes, so in total it will be local byte 0 to local byte 9.

local byte 0 = Step 7 format = w#16#10
local byte 1 = Data Format = w#16#01 = BIT, w#16#02 = BYTE, etc
local word 2 = Length
local word 4 = Data Block number (0 if not a DB)
local byte 6 = Data Type = w#16#83 = Marker flag, w#16#84 = DB data, etc
local byte 7 and local word 8 = BYTE,BIT address.

The T LW[AR1,P#x.0]instruction is filling these words and bytes to point to your DB, DW address. As AR1 was loaded with the starting point of the parameter SOURCE, it is pointing to L 0.0, the P# part is offsetting from the address AR1 pointes to, where P#x.y where x=byte and y=bit.

To point to a different area, for example to change to db99.dbx40.0, you would repeat the part

L 6 // In this example it is DW6
SLD 3 // The 3 right most bits of Byte 9 make up the bit address (0-7)
T LD[AR1, P#6.0] // Byte address is in Bytes 7, 8 and 9

L B#16#84 // 84=Data Area (see help to find other areas, like flags etc)
T LB[AR1, P#6.0] // Byte 6 = data type

but change 6 to 40.

For a block move, you would set up two TEMP ANY parameters, one for the source address and one for the destination address. When using SFC20, these cannot cross.

In the past I have used SFC20 to control a shift register, I had to call it twice, the first to move from source to a temporary store area, the second to move it from the temp store to the destination as the source and destinations overlapped.
 
Last edited:
an example, the input parameters are where you specify the DB's and Data Bytes and length.

Code:
FUNCTION FC 80 : VOID
TITLE =
//The Block is called and the parameters Source Data Block and Data Byte is 
//passed 
//together with Destination Data Block and Data Byte with the Length of the block 
//move.
VERSION : 0.1

VAR_INPUT
  i_S_DB_Address : INT ; 
  i_S_DBB_Address : INT ; 
  i_Length : INT ; 
  i_D_DB_Address : INT ; 
  i_D_DBB_Address : INT ; 
END_VAR
VAR_TEMP
  t_SOURCE_ANY : ANY ; 
  t_DEST_ANY : ANY ; 
  t_RESULT : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =

// Set up Source Address
	  LAR1  P##t_SOURCE_ANY; // Point the Address Register to the SOURCE_ANY Temp flag
	  L	 W#16#1002; // 10 = STEP 7, 02 = BYTE Format
	  T	 LW [AR1,P#0.0]; // Transfer into the start address for t_SOURCE_ANY, offset by 0 Bytes
	  L	 #i_Length; // Length of Block Move (in Bytes)
	  T	 LW [AR1,P#2.0]; // Transfer into the start address for t_SOURCE_ANY, offset by 2 Bytes
	  L	 #i_S_DB_Address; // Data Block Address
	  T	 LW [AR1,P#4.0]; // Transfer into the start address for t_SOURCE_ANY, offset by 4 Bytes
	  L	 #i_S_DBB_Address; // Data Byte Address, shift left 3 to change to pointer foremat
	  SLD   3; 
	  T	 LD [AR1,P#6.0]; // Transfer into the start address for t_SOURCE_ANY, offset by 6 Bytes
	  L	 B#16#84; // Data Type = 84Hex = Data 
	  T	 LB [AR1,P#6.0]; // Transfer into the start address for t_SOURCE_ANY, offset by 6 Bytes

//Set up Destination Address
	  LAR1  P##t_DEST_ANY; // Point the Address Register to the DEST_ANY Temp flag
	  L	 W#16#1002; // 10 = STEP 7, 02 = BYTE Format
	  T	 LW [AR1,P#0.0]; // Transfer into the start address for t_DEST_ANY, offset by 0 Bytes
	  L	 #i_Length; // Length of Block Move (in Bytes)
	  T	 LW [AR1,P#2.0]; // Transfer into the start address for t_DEST_ANY, offset by 2 Bytes
	  L	 #i_D_DB_Address; // Data Block Address
	  T	 LW [AR1,P#4.0]; // Transfer into the start address for t_DEST_ANY, offset by 4 Bytes
	  L	 #i_D_DBB_Address; // Data Byte Address, shift left 3 to change to pointer foremat
	  SLD   3; 
	  T	 LD [AR1,P#6.0]; // Transfer into the start address for t_DEST_ANY, offset by 6 Bytes
	  L	 B#16#84; // Data Type = 84Hex = Data 
	  T	 LB [AR1,P#6.0]; // Transfer into the start address for t_DEST_ANY, offset by 6 Bytes
	  CALL SFC   20 (
		   SRCBLK				   := #t_SOURCE_ANY,
		   RET_VAL				  := #t_RESULT,
		   DSTBLK				   := #t_DEST_ANY);
END_FUNCTION
 

Similar Topics

Hi All, As i am new to STL programming I am facing a problem with the code below OPN DB 103 A M [DBD 140] = M 206.0 A M [DBD...
Replies
14
Views
2,362
I have spent a couple of weeks now hunting around for information to step7 indirect addressing. There are many, many discussions relating to this...
Replies
5
Views
10,354
So far all the code i've written for PLC's has been simple ladder logic and I'm sure this will be simple once i know how. I have an s7-300 setup...
Replies
9
Views
13,841
Sorry if that has been posted before, but I cannot find an answer to my problem. I am trying to access a Flag Byte MBXX in a Function call. My...
Replies
5
Views
4,329
Hello, I would like to know if there is and equivalent to the follow AB indirect addressing technique available with S7-300 N19:[N7:91]/15 I use...
Replies
1
Views
8,094
Back
Top Bottom