S7 Array to DB

YoungWint

Member
Join Date
Dec 2012
Location
East Midlands
Posts
77
Hi All

Bit puzzled.

I have wrote a bit of code to take the 8 channels from an analogue card and store them in an array.

The array data (8 Ints/ Words) is then moved to a Datablock where each card is stored with an index move to step to each card.

I have the code working but am a bit lost as to why or how its working. Could anyone explain, code for setting pointer as below:

L #CH0_Raw
T #RAW_AIN[0] // This is repeated for each channel

L W#16#10002
T LW [AR1,P#0.0]

L 16
T LW [AR1,P#2.0]

L #Dst_block
T #LW [AR1,P#4.0]

L #Dst_Index // Channel Number
L 64
*I
T #Result

L #Result
+I
SLD
L P#DBX0.0
OD
T LD [AR1,P#6.0]

I then use SFC20 to move the array contents to the DB.

It works but how? Particularly puzzled by the 64.

Any one can shed any light on this would appreciate it.

Young Wint
 
Please post the code by copying and pasting it from the Step 7 editor. There is at least one typo in the code you have posted, so there may be more.

Which CPU have you had this runing in or have you been using PLCSIM?
 
Last edited:
As there are 16bytes/card and 8 bits per byte, you need to multiply the Dst_Index by 128 to get the correct pointer. Your code multiplies by 64 and then doubles it before then performing a shift left using accu-2-L-L to specify the number of bits to shift. In PLCSIM (or a 400 series CPU) this will result in no change as PLCSIM uses 4 accumulators, however, in a 300 series CPU (except the 318) the result will be somewhat different.

Re-coded to work in either CPU

Code:
      L     #CH0_Raw
      T     #RAW_AIN[0]

      L     W#16#1002
      T     LW [AR1,P#0.0]

      L     16
      T     LW [AR1,P#2.0]

      L     #dst_Block
      T     LW [AR1,P#4.0]

      L     #Dst_index                  // Card Number
      SLD   7                           // sld 4 for 16bytes/card + sld 3 for 8bits/byte 
      L     P#DBX 0.0
      OD    
      LAR2  
      T     LD [AR1,P#6.0]
 
In PLCSIM (or a 400 series CPU) this will result in no change as PLCSIM uses 4 accumulators, however, in a 300 series CPU (except the 318) the result will be somewhat different.

[/code]

LD, what is different about the 318's? I have not used them before. I was told once that the 319 series had 4 accumulators, so I am assuming they would have the same issue as the 400's.
 
Solved

Guys

Following the posting had another look at it and realized the error of my ways.

In the actual code I had neglected to SLD 3 bits, thus moving my data as expected, I was trying to move 16 bytes and ended with 64 coincidentally working and doing the SLD.

SLD 3 code now works with 16 and thus indexes in bytes of 16.

It was a puzzler but the the grey matter kicked in eventually.
 
LD, what is different about the 318's? I have not used them before. I was told once that the 319 series had 4 accumulators, so I am assuming they would have the same issue as the 400's.

318 has 4 accumulators. 319 has two.
 

Similar Topics

Hi, I'm having an issue in crimson 3.0 when I create a programme using a case statement referencing a fault word that each bit needs to change the...
Replies
4
Views
177
I am trying to copy an array of real numbers into a UDT with a real data type element. I have attached a snip below showing my COP instruction...
Replies
4
Views
203
I have an array of 55 REAL values. Is there a way to multiply based on the array location ? I have 55 transfer belts that are equally spaced...
Replies
3
Views
152
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
176
Hi. I'm using a Modbus ProSoft where I basically map data to a big INT array. Example, where GX_I_63HPU is a REAL, MNETC.DATA.WriteData[200] an...
Replies
21
Views
425
Back
Top Bottom