[?]: problem when I use AR2 inside function block

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
Dr.Acrobat
Posts: 66
Joined: Sat Mar 10, 2007 8:11 am
Location: Spain

[?]: problem when I use AR2 inside function block

Post by Dr.Acrobat »

Hello everybody.
I have some problem when I use AR2 inside function block,
Siemens technician explain me is better do not use AR2 in FB.
Is true???
Thanks.
:roll:
Tomekk
Posts: 15
Joined: Sat Feb 23, 2008 11:59 am
Location: Europe

Post by Tomekk »

Yeah, it's true. AR2 is used in FBs for addressing global variables.
However, it's possible to use it as long as you do not read or write these global variables. At first you have to back it up in a local variable and after use to restore it before you use any global variable or leave the FB...
komatic
Posts: 79
Joined: Thu Mar 15, 2007 12:59 pm
Location: Ukraine

Post by komatic »

You can free use AR2 inside in FB
but only use save/restore tehnik
Dr.Acrobat
Posts: 66
Joined: Sat Mar 10, 2007 8:11 am
Location: Spain

AR2

Post by Dr.Acrobat »

Hi komatic could you send a example???
Thanks advance.
Bye.
:arrow:
Tomekk
Posts: 15
Joined: Sat Feb 23, 2008 11:59 am
Location: Europe

Post by Tomekk »

me too, please !
komatic
Posts: 79
Joined: Thu Mar 15, 2007 12:59 pm
Location: Ukraine

Post by komatic »

its simple

Code: Select all

----------------------------------------
// save address register
TAR1 #SAVE_AR1  // type DWORD
TAR2 #SAVE_AR2

... use AR1,2 as you wont

// restore
LAR1 #SAVE_AR1  // type DWORD
LAR2 #SAVE_AR2
----------------------------------------
more ihfo from help
Notes on Changing the Contents of Registers
If you use the programming options below together with the registers and accumulators listed, you must make sure you restore the contents of the registers or accumulators yourself, otherwise errors may occur.



Using the following higher-language constructions may cause the contents of the DB register and address register AR1 to be modified:

Fully-qualified DB access (for example, DB20.DBW10) as an actual parameter for a function (FC)

Function block (FB) and multiple-instance calls

Structure components of a formal parameter as an address within an FC or FB

Structure components of a formal parameter as an actual parameter for an FC or FB

With FB, FC, and multiple-instance calls, you should not use the RLO or accumulator 1 or 2 as additional (implicit) parameters.

The DI register and address register AR2 are used on the system side for the FB and multiple-instance calls and should not therefore be modified within FBs.

Address register AR1 is used by some of the loadable standard blocks.

The command "L P#parameter_name" loads the address offset of the specified parameter within an FB, relative to address register AR2. In order to determine the absolute offset in the instance data block in multiple-instance type FBs, you must also add the area-internal pointer (address only) of the AR2 register to this value.

You can find further information on the CPU registers in the help on the programming language (LAD/FBD/STL).
have a nice day :)
Tomekk
Posts: 15
Joined: Sat Feb 23, 2008 11:59 am
Location: Europe

Post by Tomekk »

Of course you can use AR2 in FBs and FCs as you will. But if you change the contain of AR2 in FBs (and only in FBs) and try to read or write a IN/OUT-parameter you'll get the error message "Access Error" cos the CPU tries to read or write a variable with a non-existant address and that may cause the CPU to stop...
komatic
Posts: 79
Joined: Thu Mar 15, 2007 12:59 pm
Location: Ukraine

Post by komatic »

of course i agree
beetwen save and restore you must not use variabe like #var1 in FB
but you can pass it via TEMP variable i think

Good luck :D
sania
Site Admin
Posts: 1387
Joined: Sat Aug 13, 2005 6:15 am

Post by sania »

i use ar2 in fb without problem - see my sample keb on profibus
azeem_javaid
Posts: 23
Joined: Wed Oct 24, 2007 8:49 am
Location: Saudi Arabia

Re: [?]: problem when I use AR2 inside function block

Post by azeem_javaid »

How can we use "8 byte Process Inputs & 8 Byte Process Outputs".
All applications are related to parameterization through "Parameterizing channel".
I have worked on Control Technique which is quite easy.
I want to Take Status word & Encoder pulses through "Process INPUT" & Want to control inverter through Control Word & Speed Setpoint through "Process Outputs"

Some body can help me by sending me example program or some tips?


Thanks & Regards.