dynamic Array indexing - SIEMENS PLC

naturephoenix

Member
Join Date
Jan 2015
Location
Vienn
Posts
181
Hi guys! Imagine you got taks someting like this:
You got 6 motors and under some conditions you have to start one of them. That "one of them" has to be choiced by user on HMI device. So if user enter number 5 then he wants that motor number 5 starts. All all motors have same conditions for start.

Here is not the problem how to resolve this task, problem is that I want to resolve it on this way...SO here is how my data looks like.

Motors.Start[1] //- motor 1 - DB4.DBX0.0
Motors.Start[2] //- motor 2 - DB4.DBX0.1
Motors.Start[3] //Start motor 3 - DB4.DBX0.2
Motors.Start[4] //- motor 4 -DB4.DBX0.3
Motors.Start[5] // '- motor 5 -DB4.DBX0.4
Motors.Start[6] //- motor 6 - DB4.DBX0.5

If user enter number 5 via HMI for example in variable n(n is INT data type) this wont work
Motors.Start[n]. This is what i am looking for, how to address my array dynamicly. I have read something about pointers ,but I
still dont know how to use them here.
YES i know how to resolve this in SCL but that's not an option.
STL and/or FBD are the options.

A condition1
A condition2
S Motors.Start[n]
 
https://www.automation.siemens.com/doconweb/pdf/SINUMERIK_SINAMICS_03_2013_E/S7200SH.pdf?p=1
Not sure which PLC you are using. I'll guess an say a S7 200.
I would try a table instruction for this with a First-In-First-Out.

Another thought would be 'Using Pointers for Indirect Addressing of the S7-200 Memory Areas'. There is a good overview in the manual reference above. In your case you would have pointers for inputting the data and a pointer for the current values being worked on.

Regards,
Garry
http://www.accautomation.ca
 
As you have so few array elements, the JL (case statement) instruction could be used:

Code:
      A     #bCondition1
      A     #bCondition2
      L     #iNumber
      JL    MOT
      JU    ex
      JU    M1
      JU    M2
      JU    M3
      JU    M4
      JU    M5
      JU    M6
MOT:  JU    ex

M1:   S     #Motor.Start[1]
      JU    ex

M2:   S     #Motor.Start[2]
      JU    ex

M3:   S     #Motor.Start[3]
      JU    ex

M4:   S     #Motor.Start[4]
      JU    ex

M5:   S     #Motor.Start[5]
      JU    ex

M6:   S     #Motor.Start[6]
      JU    ex

ex:   NOP   0
 
SO here is how my data looks like.

Motors.Start[1] //- motor 1 - DB4.DBX0.0
Motors.Start[2] //- motor 2 - DB4.DBX0.1
Motors.Start[3] //Start motor 3 - DB4.DBX0.2
Motors.Start[4] //- motor 4 -DB4.DBX0.3
Motors.Start[5] // '- motor 5 -DB4.DBX0.4
Motors.Start[6] //- motor 6 - DB4.DBX0.5

Is DB4 a global shared DB or an instance DB?
 
Thx on replay L D[AR2,P#0.0] but your solution is not what i am looking for, actually what i am looking for is hidden in ur forum username :)
I dont want to spam case statements for a such stuff. This is not actually my task but this easy task represents what i really need to solve on more better way some complicated stuffs.

Yes DB is sharedDB
 
Last edited:
Code:
      L     #iNumber
      +     -1                          //make address zero based
      LAR1                              //directly to AR1 as we are accessing bits
      OPN   DB     4                    //global db to use
      A     #bCondition1
      A     #bCondition2
      S     DBX [AR1,P#0.0]
 
Also one more question but maybe is out of topic:
is it possible to set whole array to some value for example 0
I know it is in some higher programming language.
for example array Motors.Motor[1..5]
something like : Motors.Motor[1..5]:={0}
or i have to make loop or literally
R Motors.Motor[1]
R Motors.Motor[2]
R Motors.Motor[3]
R Motors.Motor[4]
R Motors.Motor[5]
 
you are using continuous dbx addresses, so if you move 0 to db4.dbb0 address, it will also reset dbx0.0 - 0.7 addresses on Siemens.


You can also use dbw0 address, then it will reset bits 0.0-0.7 and 1.0-1.7

You need take care of byte order when using word adressing. Bytes are in different order at word than you maybe expect.

Dbw0's high byte is dbb0 and low byte dbb1.
So if you write value 1 to dbw0 address then bit dbx1.0 have value "1" not dbx0.0.

Same also for memory marker bits and words. (M and MW adressing)
 
Loop example for clearing your array elements:

Code:
      OPN   DB     4                    //array db
      LAR1  P#0.0                       //start of array
      L     6                           //no of elements to clear
ALL:  T     #iCount
      SET                               //ensure RLO=1
      R     DBX [AR1,P#0.0]             //reset element
      +AR1  P#0.1                       //inc to next element
      L     #iCount                     //loop to do them all
      LOOP  ALL
 
In SCL this is not working, I need help to go throught this:

WORD_TO_BLOCK_DB(DB_Num).DD[DB_Address]:= ref*X[1];

DB_Num is byte
DB_Address is int
ref and X[..] are real

I am writting into DB_Num = 25, DB_ADdresss=6
so for example
DB25.DBD6 := ref*X[1];

When I do like this
DWORD_TO_REAL(WORD_TO_BLOCK_DB(DB_Num).DD[DB_Address]):=ref*X[1];
I am getting error
but this is working
ref:=DWORD_TO_REAL(WORD_TO_BLOCK_DB(DB_Num).DD[DB_Address]);
 
You are missing the real to dword conversion (the dword to real is present in the working line of code)

Code:
WORD_TO_BLOCK_DB(DB_Num).DD[DB_Address]:= REAL_TO_DWORD(ref*X[1]);
 

Similar Topics

Hello All, Needing some help with finding Min max values in an array that can have a dynamic element count. The Sort function in Logix 5K only...
Replies
9
Views
5,677
Hi, I want to create a block that takes a dynamic number of inputs like the AND, OR or MUX blocks in Unity Pro for Schneider Quantum PLC. You...
Replies
4
Views
5,995
Rockwell Tech Support seemed to have hit a wall with this question. Already updated the version to 5.00.13 per their suggestio but am still...
Replies
1
Views
69
Maybe this is just not possible, or maybe I am doing something wrong. Background; I have a data array of over 1500 products. For sorting I...
Replies
6
Views
727
HEllo, still satruggling with the curse WinCC Unified. See attached picture. I just want to change the fill colour from turqoise to grey and then...
Replies
5
Views
410
Back
Top Bottom