s7 pointers p#

darren.s

Member
Join Date
Apr 2005
Posts
46
in s7 i know p# represents a pointer but i dont really know what one is and why or where you would use it.

could anyone please explain.

thanks in advance
 
A pointer is a variable that contains an address. It is a quick and easy way of passing large amounts of data to a function. Lets say you had a function that delt with a data block of 100 words. Normally, this will need to be allocated on the stack, but such a large amount of data could cause a stack overflow, so instead the start address of the data (pointer) is passed instead. The function then knows where to look for the data it is processing.

So Far I have only used these pointers when a pre-written function requires it. I haven't yet needed to actually write a pointer based function.
 
thanks for that !
one more question i know i should look it up in a book really but
do you know what the "AR1" instruction does or means .

thanks
 
You may find this worddocument usefull. I've downloaded it from the siemens website. Mind you, this still is a 'difficult' topic.
 
Thanks for the document ivo.maenen,

your right it is a difficult topic. well for me it is anyway. ill keep reading hopefully some of it will stick.
 
Darren, below is the source code for FC397 which shows an example of using any pointers as well as AR1 (address register 1). FC397 extracts the bit number, byte number and area type for an I, Q or M. It returns "?" if the area is not one of the above. (Other areas can be extracted, I've just not included them in this example). Also included is the source code for FC398 which calls FC397 with four different areas. If you cut/paste this into a source code file and then compile, it should generate these two blocks in your blocks folder. Call FC398 from OB1 and then monitor FC398.


FUNCTION FC 397 : VOID
TITLE =Find byte and bit address of I, Q, or M
VAR_INPUT
pIOAddress : ANY ;
END_VAR
VAR_OUTPUT
iByteAddress : INT ;
iBitAddress : INT ;
cAreaIQorM : CHAR ; //area I,Q or M or ?
END_VAR
BEGIN
NETWORK
TITLE
=decode input pointer type and get byte/bit address
L P##pIOAddress; //point to input parameter
LAR1 ;
L B [AR1,P#6.0]; //get address area
L W#16#81; // I area ?
==I ;
JC inpu;
TAK ;
L W#16#82; // Q area ?
==I ;
JC outp;
TAK ;
L W#16#83; // M area ?
==I ;
JC mflg;
L '?'; // not any of the above
T #cAreaIQorM;
JU nof;
inpu: L 'I';
T #cAreaIQorM;
JU nof;
outp: L 'Q';
T #cAreaIQorM;
JU nof;
mflg: L 'M';
T #cAreaIQorM;
JU nof;
nof: L B [AR1,P#9.0]; //lower 3 bits of byte 9 of area is bit address
AW W#16#7;
T #iBitAddress; //bit address
L D [AR1,P#6.0];
AD DW#16#3FFFF; //mask off operand area
SRD 3; //and shift to get byte address
T #iByteAddress;
SET ; //ENO = 1
SAVE ; END_FUNCTION

FUNCTION FC 398 : VOID
TITLE =test FC397
VERSION : 0.1

VAR_TEMP
iByteAddress : INT ;
iBitAddress : INT ;
cArea : CHAR ;
END_VAR

BEGIN
NETWORK
TITLE
=call FC397 with 4 different pointers
CALL FC 397 (
pIOAddress := I 9.3,
iByteAddress := #iByteAddress,
iBitAddress := #iBitAddress,
cAreaIQorM := #cArea);
CALL FC 397 (
pIOAddress := "IntAutoLoad",
iByteAddress := #iByteAddress,
iBitAddress := #iBitAddress,
cAreaIQorM := #cArea);
CALL FC 397 (
pIOAddress := "bBowedRollReverseQ",
iByteAddress := #iByteAddress,
iBitAddress := #iBitAddress,
cAreaIQorM := #cArea);
CALL FC 397 (
pIOAddress := DB100.DBX 30.6,
iByteAddress := #iByteAddress,
iBitAddress := #iBitAddress,
cAreaIQorM := #cArea);
END_FUNCTION
 
AR1 is not an instruction. It's name of an address register.
No, but one of the things that causes newcomers some confusion is that +AR1 (and +AR2) are instructions, which add the current value of AKKU1 to the register. It's one of the less intuitive instructions in the S7 instruction set.
 
In the S7 world you can count bits from the beginning of the memory f.e. DB. The pointer is the bit number from the beginning of memory area.
Usually from 0 to 65000 times 8 bits, thats why 16-bit integer is not enough for the pointer variable.
 
RMA said:
No, but one of the things that causes newcomers some confusion is that +AR1 (and +AR2) are instructions, which add the current value of AKKU1 to the register. It's one of the less intuitive instructions in the S7 instruction set.

RMA,
thats one of the things that was confusing me i saw the instruction +AR1 but did not know what "AR1" was.
so if it adds the value of AKKU1 to the register. by "register" do you mean the data that the pointer points to.
 
Oops, I think I may be guilty of imprecise formulation here!:oops:

I'm not in the office now, so it'll have to wait until tomorrow for verification, but I believe the instruction +AR1 (or +AR2) actually loads the value in AKKU1 into the address register (which, of course, is what AR stands for). Either way, it is the address register contents, or the pointer if you prefer, which is modified, not the data it's pointing to.

Come to think of it that's another bit of unintuitive mnemonic naming, if I'm correct!

I'll check up tomorrow and get back, unless S7Guy can confirm it in the meantime, since I notice he was online when I came in.
 
Roy, you've got it a little mixed up. "+AR1" adds ACCU1 to AR1.

For instance, this loads 10.0 into AR1:

L P#10.0
LAR1

This adds 8.0 to AR1, so AR1 is now pointing to P#18.0:
+AR1 P#8.0

Alternatively, I could do it this way:
L P#8.0
+AR1
 
Thanks for clearing that up S7Guy, I would have got it sorted out tomorrow, but I had one of these sudden moments where I wasn't sure either way.

Anyway, Darren will at least have the correct answer waiting for him tomorrow!
 
hi everybody,
i want to use indirect addressing as follow:
there is a byte with the name "index" in a DB say db9.
i want to use this "index" byte to write desired values in some addresses in the same db, which are started from a specific address and indexed by the "index" byte .
can you please guide me about this problem?
also please tell me that is it possible to use arrays for indirect addresing i.e. can i use these instructions:
L 5
T #index
L Array[#index]


thanks very much.
 

Similar Topics

Hello, I've just came out of a call where a program that was modified two weeks ago threw the processor into fault. The program has been done...
Replies
9
Views
3,462
I'm trying to get a 5069-L306er to talk to a Automation Direct ProSence Controller by using RA's AOI for modbus client but its stuck not getting a...
Replies
9
Views
1,873
The last time I did anything with Wonderware was just after the dot com bust. Boy, I feel old. Anyway, it looks like I will get the chance to...
Replies
3
Views
1,506
Hi guys, Some pointers needed: Having PC with WIN7 pro X64 and Amsamotion clone of 6ES7 972-0CB20-0XA0 cable and need to backup VIPA cpu...
Replies
14
Views
3,107
Is there any form of Reference Type or Pointer Type like Codesys has? I am aware that you can nut a tag in the index of an array reference. but...
Replies
7
Views
1,880
Back
Top Bottom