Using Databse Arrays Dynamically

andyhill

Member
Join Date
Sep 2003
Location
Aberdeen
Posts
5
How can I itterate through a array defined in a DB so that I can write/read to it.

::: DB1. Pressure Defined as Array of [0..1,1..8]

--------------------------------------------------------
// !!! This doesn't WORK
L 1 // Start
T #a // Load Start to a temp variable
L MW288 // Read Data
NEx: T Db1.pressure[1,#a] // store data to array
inc #a // increment array pointer
L 8 // Load Loop Limit
<> I // compare
JC Nex // Jump if loop limit is not reached.


--------------------------------------------------------

This should fill
DB1.pressure [1,1] with value of MW288
DB1.pressure [1,2] with value of MW288
DB1.pressure [1,3] with value of MW288
DB1.pressure [1,4] with value of MW288
DB1.pressure [1,5] with value of MW288
DB1.pressure [1,6] with value of MW288
DB1.pressure [1,7] with value of MW288
DB1.pressure [1,8] with value of MW288


Thanks is Advance
 
I don't know who's mnemonics are these, but by looking at your code
at some places your are moving the data from right to left (which is normal in an assy languages) and in other places you are moving it from left to right. I don't think that you can have it both ways.
I don't see how you can move the data at the NEx: label?
By the way if your compiler is case sensitive in terms of labels, then you should make your label either Nex: or NEx: in both places to be consistent.
For example the line L 8 obviously loads acc with 8 right to left??
At the NEx: label you are moving it from left to right?

Also why do you need the L 8 line within the loop?
Load the loop limit before the Nex: label.
 
Firstly this is s7 code.

These lines;

L Mw 28
T Db1.preesure[1,0]

The L load Memory word 28 to accum1
the T Transfers accum1 to db1.pressure [1,0]

I wanted to use an int to define the index of the array rather than a hard coded number.

Hope this helps.
 
I feel your pain.

I just modified code in a thread below. I haven't test this but it worked as a copy before I modified it.

You may be able to get by with changing the loading of LAR1 to LAR1 P##PRESSURE. My example below was from a FB so it had to be more general.


Code:
      L     #_nS7DB                     // Need to do this as OPN DB does not
      T     #_wTemp                     // work with STAT data.
      OPN   DB [#_wTemp]

      L     #_pS7                       // Load area crossing pointer dw#8400000
      LAR1  

      L     16                          // copy 2 x 8 elements.
L31:  T     #_nI
      L     0
      T     DBW [AR1,P#0.0]             // Store in the S7 somewhere
      +AR1  P#2.0                       // increment pDst
      L     #_nI
      LOOP  L31
 
Andy-
To the best of my knowledge the S7-300 doesn't natively support multi-dimensional arrays. The brackets you see in Step7 are not array index definitions, they are pointer designators. You will need to infer the array structure yourself.
For example, you say that you want to set up 2 X 8 array with indeces rangine from [0,1] to [1,8]. You only have one pointer to work with so the pointer value needs to be a manual combination of the two array indeces. So use Peter's code as shown. However, determine your pointer offset as:
8 * (((Upper_Index * 10) + Lower_Index) * Bytes_Per_Element)
and add this to your base pointer value, which is presumably 0.0
The '8 *' thing shifts the offest up by three bits to account for the bit location part of the pointer. The Byte_Per_Element value depends on what the data type of your array is; 1 for bytes, 2 for integers or words, 4 for doubles and reals.

I hope this helps.
Keith
 
Simplify, FILL 8-word only (even 100 is the same)

L MW 288
T DB1.pressure[1,1]
T DB1.pressure[1,2]
T DB1.pressure[1,3]
T DB1.pressure[1,4]
T DB1.pressure[1,5]
T DB1.pressure[1,6]
T DB1.pressure[1,7]
T DB1.pressure[1,8]


After this, we have correct X-ref for DB1.pressure[1,5] or what ever.
This code is much more fast than looped and indirect pointed code !
Read, Kameges comment.
 
Last edited:
You must be kidding

Seppo, would you really hard code filling an 100 elemet array?
Isn't there a Siemens user group that has FCs such as FILL_I, FIll_DW, FILL_W, FILL_DW and FILL_R?

Keith, Step7 allows one to declare a 2 dimensional array, but it doesn't really support array indexing. Your technique of indexing into arrays is required for random access into an array. However, for filling an array with a constants then my code will work. I would just replace the L 16 in my code to be a more generic L _count.
 
Re: You must be kidding

Peter Nachtwey said:
Seppo, would you really hard code filling an 100 elemet array?
Peter, I have done it many times, particularly in S5-world for the speed.

Last, on last week I spoke ugly words for x-ref problems.
Someone was used FC82 (RSET) and x-ref naturally can show those resettings.

Ps. With C++ or Basic code I'm using subroutines for that kind of things.
 
Last edited:

Similar Topics

Hello everyone, I'm working on a project that involves controlling an array of nozzles within a CNC environment, where the nozzles travel along a...
Replies
5
Views
128
Hi, I was noticing that Profibus connectors have 2 ports on them that can house 2 separate cables. Can I use 2 cables with Profibus signals...
Replies
4
Views
132
Hi, Seeking consultation on an implementation matter, and have a question about Modicon Compact 984 communication through RS485: Three Modicon...
Replies
3
Views
94
Dear all, I don't know why setup of password became challenging and weird. After setting up the password and try to upload the ladder from the plc...
Replies
3
Views
93
Dear All, I need a sample PLC program to count the output pulse of a mass flow meter so that a specific amount of mass (for example 100gm)can be...
Replies
2
Views
82
Back
Top Bottom