S7 indirect

Thim

Member
Join Date
Mar 2008
Location
Belgium
Posts
392
First, i would like to wish everyone a happy new year!!

could someone explain me what this code is doing??
I will try to put as much info after the code what i think/assume it is doing, can someone correct me??


Thx


FUNCTION_BLOCK FB 1
TITLE =
VERSION : 0.1

VAR
iCount : INT ;
bFlasher : BOOL ;
bFlashEdge : BOOL ;
dwData : DWORD ;
END_VAR
VAR_TEMP
bFlash : BOOL ;
END_VAR
BEGIN
NETWORK
TITLE =
OPN DB 2; // opn DB2
L #iCount; // Load value Count "Integer"
+ 1; // Add 1
T #iCount; // transfer the sum of iCounter +1 to iCounter
TAR2 ; // Load the adress of iCounter to AR2 "0.0"
T #dwData; // transfer the adress of AR2 to dwData "0.0"
LAR1 P##iCount; // L iCount to AR1 or say LAR1 P#DIX0.0 WORD 1
A [AR1,P#1.3]; // And AR1+1.3 or 0.0+1.3 so makes A DIX1.3
FP #bFlashEdge; //Positief flank
JCN nofl; // Jump condition not to nofl
SET ; // set but what i don't know
S DIX 4.1; //Set Dix 4.3, so that would be second bit of dwData
R DIX 4.2; // reset dix 4.2, would be the 3 bit of dwData,
L #dwData; // Load the value of dwData, but what is in there exactly??
LAR1 ; // transfer the adress to AR1, Is this adress 4.0??
CAR ; // change ar1 and AR2, But what exactly is in AR1 and AR2??
CDB ; // change DI and shared db, so i think DB1 and DB2
AN #bFlasher; // Andnot bFlasher
= #bFlasher; // is bflasher
CDB ; // change DI and shared db, so i think DB1 and DB2

SET ; //??
R DIX 4.1; // reset bit 4.1, so again i think it is dwData second bit is reseted
S DIX 4.2; // 3th bit is set
L #dwData; // Load dwData, but what is exactly in there
LAR1 ; // transfer the adress to Dwdata
CAR ; // change AR1 and AR2, but what is in there?
nofl: NOP 0;
END_FUNCTION_BLOCK
 
Have you run this code in the simulator and monitored the contents of the accu's and AR1,AR2 ? This will clear a lot of the mist for you.
 
Some hints..

When you call a FB, AR2 = the pointer to Instance DB start of Data.

LAR1 = loads the pointer AR1 from the accumulator.

TAR1 = Load the accumulator with the contents of the pointer AR1.

LAR2/TAR2 are the same for AR2.
 
Here's the source code for the block with a full explanation:


Thank you both for the explaination, it is really appreciated

I still have some questions

1.
TAR2 ;
// .
// TAR2 transfers the contects of AR2 (currently dw#16#84000000 = DBX0.0)
// into the accumulator
//.
T #dwData;
//.
// The contents of the accu (i.e. AR2 = DBX0.0) are now stored in
// static data dwData. dwData is located at DIX4.0

What is really in dwData "0.0" being hex 84 or DIX0.0??

2.

SET ;
S DIX 4.1;
R DIX 4.2;
//.
// The SET instruction ensures the RLO is true, thus ensuring
// following S and R instructions are active.
// DIX4.0 is the start location of the variable dwData which
// currently contains DBX0.0 = dw#16#84000000
// S DIX4.1 and R DIX4.2 modifies dwData to now contain
// Q0.0 = dw#16#82000000

So dwData is in reallity DB1.DBW4 So it has byte 4 and 5
You modify byte 4 to change the memory area from DBX0.0 to Q0.0 when you load it again in AR (hex 84 to 82)
But what can you do with byte 5??
I assumed it was to point to the adress Like hex 8201 would be Q0.1 but this isn't correct when i tested it it was Q8192.0

Sorry my mistake It is really DB1DBD4 so it has byte 4, 5, 6, 7. after modifing Dix7.0 i had Q0.1

3.
AN #bFlasher;
= #bFlasher;
//.
// All static variable accesses in FB's use indirect addressing
// AN #bFlasher is executed as A DIX[AR2,p#2.0]
// But as the DB2 register (instance DB) is --, these two
// instructions both generate calls to OB121
What do you mean with both instructions
AN bflasher // 1ste instruction
= bflasher // 2nd instruction
???

// Even though AR2 contains Q0.0, the DIX in the instruction
// overrides the Q0.0. This is provided as miss-direction.
What do you mean with overrides?? Do you mean that the code actually is doing something or just calls OB121 and continues?
If it does something, then what is it doing? i do understand it does not set Q0.0


4. In the end all that the code does is load in Q0.0 to AR1???
for every time interval depending from the bit you select
 
Last edited:
1. Please take a look at the following post http://www.plctalk.net/qanda/showpost.php?p=222839&postcount=6

The address registers contain 32bit area pointers. When referring to an address register,

dw#16#84000000 and DBX0.0 are one and the same thing but displayed in different formats.

2. resolved

3. The code does nothing but call OB121 twice

4. In the end all the code in this FB is designed to do is call OB121 three times. Any reference to Q0.0 inside this block is designed to cause confusion and mislead.
 
Last edited:
1. Please take a look at the following post http://www.plctalk.net/qanda/showpost.php?p=222839&postcount=6

The address registers contain 32bit area pointers. When referring to an address register,

dw#16#84000000 and DBX0.0 are one and the same thing but displayed in different formats.

1. In the example at the link you say
L P#I0.0

If i understand it well the you can write pointers hex like following:

L DW#16#81000000 // Configure the Input
L B#16#1 // configure the byte so it makes 0.1 could also be
//L dw#16#1
+D //add so makes last bit 1 (81000001)where 81 is Input
//and 1=0.1
LAR1

would be the same like
L P#I0.1
LAR1



2.Could you tell me little more about following?
110=L (temp local data)
111=V (temp local data of the preceding block)
 
Here's an example of the L area and V area access:

Ok little more difficult

How i understand it

A FC doesnt have adresses like a fb so if you would like to point to a adress (declaration) you have to look how they where configured in the block where they where called.
In this case OB1 calls FC 1 with Input Temp(adres 20.0)
So if i would like to question the input of that FC i could do it by indirect V20.0 what actually is the input of the FC??
Where V20.0 acctually is declaration Adres 20.0 from the block where FC1 is called.
But lets say FC1 is called in a FB and the fb would have declaration adress 20.0 at inputs and STATS and temps, how do you know which it is?
The L0.0 is to adres to the Temperay variables in the FC

One more thing
Lets say i would have dwData(declaration adress 22.0) in OB1 where dwdata=hex 83000000 (M0.0), and dwdata would be the input of the fc.
If i would adress in the fc to the input i assume S7 will load V22.0 in ar1, then i would say L [AR1,P0.1] is this then M0.1???

Total program will look like this

OB1

Call FC1
input: dwdata //(temp value declaration adress 22.0
// and contains value hex 83000000 or M0.0)

FC1

L P##inputdwdata // so load the input what would be hex 870000B0
LAR1 // transfer to AR1 what would be V22.0

A [AR1,P#0.1] ///is this then M0.1???
 
As already stated FC parameters are passed as 32 bit area pointers. This means you cannot specify a global DB or instance DB variable as a parameter because the 32 bit area pointer tells you where in the area the variable is - it does not specify the DB number.

So, if you want to call FC1 and pass a temp variable from an FB it will work the same as the previous OB1 example.

If you want to pass a stat variable to FC1 it cannot be done by simply passing the DIW address of the variable, instead the editor generates instructions that copy the stat value to the temp area and then a pointer to that area is passed instead. This means thqt when you examine the address of the variable you will see it as the V area, even though it is a stat variable being passed.

See example below: (Note I did not update the comment text in FC1)

fblv009.jpg
 
One more thing
Lets say i would have dwData(declaration adress 22.0) in OB1 where dwdata=hex 83000000 (M0.0), and dwdata would be the input of the fc.
If i would adress in the fc to the input i assume S7 will load V22.0 in ar1, then i would say L [AR1,P0.1] is this then M0.1???

Total program will look like this

OB1

Call FC1
input: dwdata //(temp value declaration adress 22.0
// and contains value hex 83000000 or M0.0)

FC1

L P##inputdwdata // so load the input what would be hex 870000B0
LAR1 // transfer to AR1 what would be V22.0

A [AR1,P#0.1] ///is this then M0.1 - no, V22.1

Code:
L inputdwdata
LAR1
A [AR1,p#0.1] //this would be M0.1
 

Similar Topics

Howdy folks, I am an Allen Bradley guy currently living in an Emerson world. Working with Rx3i on PacSystems Machine Edition v. 9.6? i think...
Replies
3
Views
637
Hey, I'm trying to do the following, I have some experience with Citect but can't seem to figure this out. I/O Tag: BoxPos1_ProdNum (Data Type...
Replies
0
Views
588
Hello, I'm very new to programming with absolutely zero schooling in this field and pretty hands off training in my new role, it's been fun...
Replies
4
Views
675
Hi, I have this code: LAR1 P##structy L 0 T LW [AR1,P#0.0] which resets all the bits in this struct called structy...
Replies
1
Views
643
I have upgraded an old RS500 project to Studio 5000, it has thrown multiple errors which I am currently working through. I have looked through...
Replies
8
Views
1,731
Back
Top Bottom