You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old May 7th, 2005, 12:55 PM   #1
darren.s
Member
United Kingdom

darren.s is offline
 
darren.s's Avatar
 
Join Date: Apr 2005
Posts: 46
s7 pointers p#

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
  Reply With Quote
Old May 7th, 2005, 06:17 PM   #2
Doug_Adam
Member
Australia

Doug_Adam is offline
 
Doug_Adam's Avatar
 
Join Date: Sep 2002
Location: Perth
Posts: 946
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.
  Reply With Quote
Old May 8th, 2005, 07:01 AM   #3
darren.s
Member
United Kingdom

darren.s is offline
 
darren.s's Avatar
 
Join Date: Apr 2005
Posts: 46
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
  Reply With Quote
Old May 8th, 2005, 08:22 AM   #4
ivo.maenen
Member
Belgium

ivo.maenen is offline
 
ivo.maenen's Avatar
 
Join Date: Nov 2003
Posts: 491
You may find this worddocument usefull. I've downloaded it from the siemens website. Mind you, this still is a 'difficult' topic.
Attached Files
File Type: doc indirecte adressering S7.doc (166.0 KB, 481 views)
  Reply With Quote
Old May 8th, 2005, 11:12 AM   #5
darren.s
Member
United Kingdom

darren.s is offline
 
darren.s's Avatar
 
Join Date: Apr 2005
Posts: 46
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.
  Reply With Quote
Old May 9th, 2005, 01:20 AM   #6
jacekd
Member
Poland

jacekd is offline
 
jacekd's Avatar
 
Join Date: Jan 2004
Location: Radom/Poland
Posts: 262
AR1 is not an instruction. It's name of an address register.
__________________
jacekd
  Reply With Quote
Old May 9th, 2005, 01:27 AM   #7
SimonGoldsworthy
Member
United Kingdom

SimonGoldsworthy is offline
 
SimonGoldsworthy's Avatar
 
Join Date: Mar 2005
Location: England
Posts: 1,079
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.


FUNCTIONFC 397 : VOID
TITLE =Find byte and bit address ofI, 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 pointertype and get byte/bit address
L P##pIOAddress; //point to input parameter
LAR1 ;
LB [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: LB [AR1,P#9.0]; //lower 3 bits of byte 9 of area is bit address
AW W#16#7;
T #iBitAddress; //bit address
LD [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

FUNCTIONFC 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
CALLFC 397 (
pIOAddress :=I 9.3,
iByteAddress := #iByteAddress,
iBitAddress := #iBitAddress,
cAreaIQorM := #cArea);
CALLFC 397 (
pIOAddress :="IntAutoLoad",
iByteAddress := #iByteAddress,
iBitAddress := #iBitAddress,
cAreaIQorM := #cArea);
CALLFC 397 (
pIOAddress :="bBowedRollReverseQ",
iByteAddress := #iByteAddress,
iBitAddress := #iBitAddress,
cAreaIQorM := #cArea);
CALLFC 397 (
pIOAddress := DB100.DBX 30.6,
iByteAddress := #iByteAddress,
iBitAddress := #iBitAddress,
cAreaIQorM := #cArea);
END_FUNCTION
  Reply With Quote
Old May 9th, 2005, 03:26 AM   #8
RMA
Member
Scotland

RMA is offline
 
RMA's Avatar
 
Join Date: Sep 2004
Location: North of Hamburg, Germany
Posts: 2,039
Quote:
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.
  Reply With Quote
Old May 9th, 2005, 09:03 AM   #9
seppoalanen
Member
Finland

seppoalanen is offline
 
seppoalanen's Avatar
 
Join Date: Jan 2003
Location: Finland
Posts: 1,024
Smile

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.
  Reply With Quote
Old May 9th, 2005, 12:43 PM   #10
darren.s
Member
United Kingdom

darren.s is offline
 
darren.s's Avatar
 
Join Date: Apr 2005
Posts: 46
Quote:
Originally Posted by RMA
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.
  Reply With Quote
Old May 9th, 2005, 02:28 PM   #11
RMA
Member
Scotland

RMA is offline
 
RMA's Avatar
 
Join Date: Sep 2004
Location: North of Hamburg, Germany
Posts: 2,039
Oops, I think I may be guilty of imprecise formulation here!

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.
  Reply With Quote
Old May 9th, 2005, 02:47 PM   #12
S7Guy
Member
United States

S7Guy is offline
 
Join Date: Nov 2003
Location: Dayton, Ohio
Posts: 1,242
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
  Reply With Quote
Old May 9th, 2005, 02:56 PM   #13
RMA
Member
Scotland

RMA is offline
 
RMA's Avatar
 
Join Date: Sep 2004
Location: North of Hamburg, Germany
Posts: 2,039
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!
  Reply With Quote
Old May 10th, 2005, 12:19 PM   #14
darren.s
Member
United Kingdom

darren.s is offline
 
darren.s's Avatar
 
Join Date: Apr 2005
Posts: 46
once again guys you always have the answers

cheers !...............
  Reply With Quote
Old May 30th, 2009, 12:50 AM   #15
is_razi
Member
Azerbaijan

is_razi is offline
 
is_razi's Avatar
 
Join Date: Aug 2003
Location: tabriz
Posts: 4
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.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
COnverting S5 Real (KG) to S7 Real smersh LIVE PLC Questions And Answers 9 August 8th, 2011 09:53 AM
SCADA with S7 PLC by means siemens S7 PC/MPI cable Andoni LIVE PLC Questions And Answers 4 December 15th, 2008 07:04 PM
MPI comunication Manuel Raposo LIVE PLC Questions And Answers 22 July 16th, 2007 06:24 AM
S7 IEC timer - RESET functionality. JesperMP LIVE PLC Questions And Answers 6 May 28th, 2004 03:26 AM
Siemens S7 ethernet protocol fzhang LIVE PLC Questions And Answers 3 May 19th, 2004 12:06 PM


All times are GMT -5. The time now is 08:04 PM.


.