S7-300 Average Array Values inside of instance fb

I think my problem is that I'm using an FB instead of an FC... I can't do something like T DBW [#ADDRESS], where #address is a pointer value. Because I can't define a pointer in the local symbol table. That data type is not available.
 
If you wish to access My_Array then you have first determine where in memory My_Array exists. A DBpointer specifies where in memory a variable exists. A DBpointer consists of a 16 bit DB number and a 32 bit area pointer. If the DB number is zero, then the variable does not exist in a DB (it will be in the M/I/Q etc. area). The area pointer contains the address of the variable (to the bit level) and the area in which it exists. To access My_Array you have to calculate the offset in bits that needs to be added to the area pointer to give you the address of My_array. For an array of integers for example, i will have to be multiplied by 16 to calculate the offset - this is normally coded as SLD 4
 
If you wish to access My_Array then you have first determine where in memory My_Array exists.


I am creating an FB, which will have several instances within my main program. So, I've defined an array within that FB. So, at this point its not tied to any Datablock. Since I have multiple instances, it doesn't make since to specify specific DB's in the programming.

The only way I know how direct access the data is something like...

T LW 272

But that still leaves me with the problem... How Do I tell it to transfer to 274, 276, and so on, based on a count value?
 
[sorry for the break in posts but this connection is unreliable.]

A DBpointer (called a pointer to confuse matters) can only be specified as a IN/IN_OUT/OUT/RET_VAL to an FC/FB - you cannot declare one in your stat/temp area.

When you call an FC/FB with a pointer parameter, the editor automatically inserts code that determines the DB number and the area pointer for the variable you have entered. This data is passed to the FC/FB and again to confuse matters, you can only access the DBnumber and area pointer values in the called FC/FB by using indirect addressing......
 
I think my problem is that I'm using an FB instead of an FC... I can't do something like T DBW [#ADDRESS], where #address is a pointer value. Because I can't define a pointer in the local symbol table. That data type is not available.

You are almost there.

Define ADDRESS as a TEMP doubleword. This value must contain the bit number of the first bit in your DBW. It means DBW10 will need the value 10*8=80 in your ADDRESS pointer.

In coding:
L 10 // My DBW number (eg. the first byte no), coming from wherever, whoever...
SLD 3 // Multiply with 8; calculate the bit address
T #ADDRESS

L DBW[#ADDESS] // Here's your value from DBW10


Kalle
 
[sorry for the break in posts but this connection is unreliable.]

A DBpointer (called a pointer to confuse matters) can only be specified as a IN/IN_OUT/OUT/RET_VAL to an FC/FB - you cannot declare one in your stat/temp area.

When you call an FC/FB with a pointer parameter, the editor automatically inserts code that determines the DB number and the area pointer for the variable you have entered. This data is passed to the FC/FB and again to confuse matters, you can only access the DBnumber and area pointer values in the called FC/FB by using indirect addressing......

This does not seem very helpful. I do not want the user of the block to have to input a pointer variable to the address. I want the pointer to change locations, as the block executes, based on timers, internal to the block.

This is not possible?
 
Refer to my example in post 5 which initialises an array of 50 ints with the numbers 1 through 50 and then calculates the average. It is written in ladder. It should be easy to modify to insert values into the array every second.
 
You are almost there.

Define ADDRESS as a TEMP doubleword. This value must contain the bit number of the first bit in your DBW. It means DBW10 will need the value 10*8=80 in your ADDRESS pointer.

In coding:
L 10 // My DBW number (eg. the first byte no), coming from wherever, whoever...
SLD 3 // Multiply with 8; calculate the bit address
T #ADDRESS

L DBW[#ADDESS] // Here's your value from DBW10


Kalle

Hey, this kind of makes sense to me... But, I tried a form of what you said and it didn't seem to work. I made #S_Count_Array_Pos a STAT DWord (since I want the value to carry over on the next FB execution)

Code:
L     #S_Count_Array_Pos
      SLD   3
      T     #S_Count_Array_Pos
      L     #S_Counter
[COLOR="Red"]T LW[#S_Count_Array_Pos][/COLOR]
// (Also tried T DBW[#S_Count_Array_Pos] and was still an invalid statement.)
 
Hey, this kind of makes sense to me... But, I tried a form of what you said and it didn't seem to work. I made #S_Count_Array_Pos a STAT DWord (since I want the value to carry over on the next FB execution)

Code:
L     #S_Count_Array_Pos
      SLD   3
      T     #S_Count_Array_Pos
      L     #S_Counter
[COLOR=Red]T LW[#S_Count_Array_Pos][/COLOR]
// (Also tried T DBW[#S_Count_Array_Pos] and was still an invalid statement.)

You must copy the value to an LD (TEMP) or (heaven forbid) an MD to make it a legal pointer.


Clarifying:
L #S_Count_Array_Pos
T LD0 // Better give this TEMP a proper name
T DBW[LD0]


You must also check the formats regarding byte/word.

If the S_Count_Array_Pos is writing to a Word (INT) it should increase by 2 each call, OR you should SLD 4 instead of 3.
 
Last edited:
You must copy the value to an LD (TEMP) or (heaven forbid) an MD to make it a legal pointer

...and boom goes the dynamite! :ROFLMAO:

I'm not going to try to understand the logic behind why things are the way they are, but it works!

Thank you all for having the patience to help me. I think I'm good.
 
Sorry, but you are not. I'll let Kalle continue with the multiple instance hurdle.

This does not account for multiple instances of the fb?

Code:
L     #S_Count_Array_Pos
      SLD   3
      T     #Temp_Pointer
      L     #S_Counter
      T     LW [#Temp_Pointer]


It seems like everything above accesses the local symbol table. I will insert this FB and assign a separate DB for each one that I insert? I don't see how there is any conflicts?
 

Similar Topics

Hello, I'd like to obtain average of my analog input value which will be displayed on SCADA. For examplle, analog value should be sampled avery...
Replies
2
Views
2,123
Does anyone know if there is a standard block to perform Moving Average in S7-300? I can't see one in the library, even though Siemens suggest...
Replies
13
Views
8,429
Hi everyone. I'm relative inexperienced with plc's but very curious. I'm starting to use an s7-300 siemens plc, and I'm starting to program with...
Replies
7
Views
14,211
Hi i using Kinetik 300 2097 driver control by EIP with using move absolute and incremental for motion , but i want to add same driver and motor as...
Replies
0
Views
27
Hey all, first time poster here. I am wondering if anyone has tried using a Keyence SR-X300 barcode scanner to a Micrologix 1400. Keyence sent...
Replies
0
Views
37
Back
Top Bottom