Indirect address Int Variable siemens step7

gabc

Member
Join Date
Jun 2016
Location
Monterrey
Posts
4
Hi everyone, I hope you can help me. Im working with get the production parts of all hours-day using STL. My idea is to use an array [0..23] of Integer variable. I want to use inderect address to get every variable, i mean, i want to use the integer variable Index [/B]as indirect address, this variable depends of the clock hour i was trying but i can´t get what i need.



this is what i write as code in stl
Hour[Index]

can anyone help me to solve this?.

Thanks in advance.
 
Welcome to forum

Siemens indirect addressing consist of bit and word field. First three digitis point to bit address and rest to word. Indirect address is (double) integer.

That is why you need before indirect addressing shift word three times to left SLD 3 (or multiple with eight) to pointing to word values

STL coding is also little bit different than with SCL, on STL you need to code with real addresses.

If you have your 24 different hour values in one db-block, then it would be something like this (there can be typing errors).
I assume that hour value is one word long, so dbwxx.dbw0, dbw2, dbw4...



L MD0 //Load value 0..23
L L#2
*I
T MD4 // multiple with 2 -> dbw0,2,4,6...46

L MD4
SLD 3 //make pointer value (*8)
T MD8 // save pointer to MD4
OPD DBx // open datablock DBxx
L DBW [MD8] //open DBxx.DBWxx with pointer
T MD20 //save result

...

http://www.plcdev.com/siemens_s7_indirect_addressing
http://www.plctalk.com/qanda/showthread.php?p=19321
 
Why not use SCL?

I made a project in TIA portal doing what I assume you need.

Code:
IF #iCalculate = TRUE
THEN
    #qnDaily := 0;
    FOR #stanHourloop := 0 TO 23 BY 1 DO
        #qnDaily := #qnDaily + #anHourly[#stanHourloop];
    END_FOR;
    
END_IF;

If you hit a switch #iCalculate (for example %I0.0) it will calculate what is in the array from #anHourly[0] up until #anHourly[23] and store the result in #qnDaily

Let me know if you want any more help.

http://i.imgur.com/YWCGeTJ.png

DailyCounter.jpg
 
thank you, i already did whta you recommend me. but it got fail. I think the error is in the type of data.
i6awc9.jpg
[/IMG]
 
Why not use SCL?

I made a project in TIA portal doing what I assume you need.

Code:
IF #iCalculate = TRUE
THEN
    #qnDaily := 0;
    FOR #stanHourloop := 0 TO 23 BY 1 DO
        #qnDaily := #qnDaily + #anHourly[#stanHourloop];
    END_FOR;
    
END_IF;

If you hit a switch #iCalculate (for example %I0.0) it will calculate what is in the array from #anHourly[0] up until #anHourly[23] and store the result in #qnDaily

Let me know if you want any more help.

http://i.imgur.com/YWCGeTJ.png

unfortunately im working with sinumerik 840d and it doesn´t work with TIA Portal.

Thank for your recommendation.
 
unfortunately im working with sinumerik 840d and it doesn´t work with TIA Portal.

Thank for your recommendation.


You should still be able to use SCL with 840D. SCL isn't Portal only.
 
Last edited:
I don't see how you try to load values after OPN command.

Is values in consistently words at db-block.

Anyway, if you have SCL pack on step7 (step 7 pro) then go to SCL with UDT-data. It is much easier than STL and uses symbols.
 
These code snippets might help guide you in the right direction:

Code for Doubles or Reals:

Code:
      OPN #myDB
      L     #iIndex                     // table Index
      SLD   2                           // *4 for bytes
       
      L     #iOffset                   // Offset to start of table in Bytes
      +D    
      SLD   3                           // Make it a pointer
      T     #pPointer1
      L     DBD [#pPointer1]            // Value from Table
      T     #rValue

Code for Integers or Words:

Code:
      OPN #myDB
      L     #iIndex                     // table Index
      SLD   1                            // *2 for bytes
       
      L     #iOffset                    // Offset to start of table in Bytes
      +D    
      SLD   3                            // Make it a pointer
      T     #pPointer1
      L     DBW [#pPointer1]       // Value from Table
      T     #iValue

The code would be easier to write in SCL and SCL compiles to STL for S7-300.

#iIndex (Int) is the table entry you require,
#iOffset (Int) offset from start of DB to beginning of table in bytes
#pPointer1 (Dword) Byte pointer (bottom three bits are bit part 0-7)
#?value Wherev er you wanted to put the result.

N.B. For integers: Each shift left multiplies by two, Each shift right divides by
two

Nick
 
Thanks to all of you for your help. I already found a solution. I really appreciate your recommendations.

This is what i did.

oka9kz.jpg
[/IMG]
 
why times by 2 then by 8,? do it all together. (I am assuming you are using DB100 to illustrate the code)

Code:
L DB100.Hour_Int
SLD 4   //convert to pointer to ints
LAR1

Note that accessing a global DB will force an open of that DB so in your example the OPN DB100 is redundant.

Code:
OPN DB100
L DB100.Hour_Int

If you were using a different DB for the loads/transfers then you would have to open the correct DB before each indirect transfer.
 

Similar Topics

Hi, I have a DB in my program with all the alarms of a machine, but the machine is divided in stations. So I want to check if any station is with...
Replies
2
Views
2,078
I have an indirect PLC5 code conversion I can not figure out how to convert to CLX Anyone have a solution Thanks
Replies
11
Views
4,144
In an old PLC5 I see an output like this B37 -()- [N19:21] If I remember correctly that says to set the bit of word 37 thats equal to the value...
Replies
13
Views
6,936
Good day all. I have an alarm that has been triggered and I can't figure out what is triggering it. When I go to the alarm table it shows an...
Replies
4
Views
2,153
Back
Top Bottom