![]() |
||
|
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. |
||
| ||
New Here? Please read this important info!!!
|
|
#1 |
|
Member
|
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 |
|
|
|
#2 |
|
Member
|
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. |
|
|
|
#3 |
|
Member
|
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 |
|
|
|
#4 |
|
Member
|
You may find this worddocument usefull. I've downloaded it from the siemens website. Mind you, this still is a 'difficult' topic.
|
|
|
|
#5 |
|
Member
|
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. |
|
|
|
#6 |
|
Member
|
AR1 is not an instruction. It's name of an address register.
__________________
jacekd |
|
|
|
#7 |
|
Member
|
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 |
|
|
|
#8 | |
|
Member
|
Quote:
|
|
|
|
|
#9 |
|
Member
|
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. |
|
|
|
#10 | |
|
Member
|
Quote:
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. |
|
|
|
|
#11 |
|
Member
|
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. |
|
|
|
#12 |
|
Member
![]() 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 |
|
|
|
#13 |
|
Member
|
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! |
|
|
|
#14 |
|
Member
|
once again guys you always have the answers
cheers !............... |
|
|
|
#15 |
|
Member
|
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. |
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |