S7 - Address Registers from Multi Instance

JayD

Member
Join Date
Aug 2009
Location
Australia
Posts
53
Hey guys,

I am looking for advice on the use of AR1 or AR2 from a multi instance FB (defined as static memory within another FB).

I don't understand the limitations/requirements when using multi-instances. I have noticed in some code samples there is a need to save AR2.

Sorry for the vague question.

Cheers
JD
 
I was trying to copy a UDT from a shared DB to a static memory within a multi instance FB.

I became frustrated as I couldn't understand how the ARs were behaving. So I converted my FB to an FC and used the code you helped me with a couple of weeks ago. I don't have a specific example that I am working on now. Was just asking for background knowledge..

Again super vague - Sorry. Next time I'll post the code I am struggling with.

Maybe I could ask what circumstances should you save AR2?
 
Here's the start of the story.....

Code:
FUNCTION_BLOCK FB 2
TITLE =
VERSION : 0.1

VAR_INPUT
  iInstanceNumber : INT ; 
END_VAR
VAR
  iCopyOfInstanceNumber : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =accessing FB variables
//When you access a variable from instance data, that is
// variables in the IN,OUT,IN_OUT and STAT area (not the TEMP area),
// the editor displays this nicely for you as below
//..
      L     #iInstanceNumber; 
      T     #iCopyOfInstanceNumber; 
//..
//however, behind the scenes, the instructions actually stored are
//as in the comments below
//..
      L     #iInstanceNumber; // same as L DIW[AR2,P#0.0]
      T     #iCopyOfInstanceNumber; // same as T DIW[AR2,P#2.0]
//..
//If you type L DIW[AR2,P#0.0] and then save the block, the editor
//will automatically convert the instruction to the nice display format
// if it is possible.
//(as this block has been saved it cannot be shown other than in a comment!)
//Try it using the block editor and see for yourself.
//..
//      L     DIW [AR2,P#0.0]
//..
//If you use an instruction that does not convert to the nice display format, 
//it will not convert. For example referencing a byte of the integer.
//Instructions with AR1 will also not convert.
//..
      L     DIB [AR2,P#0.0]; 
      TAR2  ; 
      LAR1  ; 
      L     DIW [AR1,P#0.0]; 
//..
//The editor works out all the correct P# offsets for every variable.
//If you insert another variable, the editor re-adjusts all the P# values
//..
//When an FB is called, the calling block will set AR2 to point to the base
//address of the instance data.
//For an FB with it's own instance DB, AR2 will point to the start of the instance DB
//For a multiple instance FB, AR2 will point to the relevant point in the instance DB
//..
//If you modify AR2 inside an FB, all instance data variable access will be relative
//to the modifed AR2
//For example, if we increment AR2 by two bytes, 
//..
      +AR2  P#2.0; 
      L     #iInstanceNumber; //is actually accessing iCopyOfInstanceNumber
//..
//
//
 
END_FUNCTION_BLOCK
 
Here's the rest of the story shown in FB2 in the attached archived library. I've shown four different methods of copying the contents of a UDT in a global DB to the stat area of an FB using multiple instances(3). To make things easy to monitor, you can enable each instance via M0.0, M0.1 and M0.2 (which I did via PLCSIM).
 

Similar Topics

Hello everyone, I can't seem to find the answer to this one. I have a micrologix 1100 with integrated ethernet port. I have it setup to my IP...
Replies
8
Views
3,396
Hi, I’m having problems using an UDP connection, especially regarding how to put in registers Nx:4 and Nx:5 IP address to write my message...
Replies
7
Views
2,120
How to increment the address of the 'D' data registers in MX-400 plc using MX-Builder software which is merely same as Omron Plc and there...
Replies
0
Views
1,308
Can someone define the address registers for me, as in the ones manipulated with LAR1, LAR2. Are there only 2 in the S7-300? How are they...
Replies
2
Views
5,539
Hello everyone, I've had this issue for the last 2 days where I try to assign the profisafe address to an IO block (6ES7 146-6FF00-0AB0) but when...
Replies
5
Views
205
Back
Top Bottom