ST help

scottmurphy

Member
Join Date
Oct 2004
Posts
363
I am new to ST, I want to sum the average of an Array.

The array length is 26 variables.

I actually need the average, but there is another 3 variables
that are not part of this array that need to be included.

Instead of calculating the total as below, can I do this
in one command?

total := range[0] + range[1] + range[2];

Will save 26 repeat '+' instructions, and give me something else to use, that is more readable than doing it in ladder.
 
scottmurphy said:
I am new to ST, I want to sum the average of an Array.

Do you mean you want to summate all 26 array values + your three other non-array variables and then find the average of that value ?

What platform are you using ?
 
Assuming you are using RSL5K see below for array math function


ADD.jpg
 
Do you mean you want to summate all 26 array values + your three other non-array variables and then find the average of that value ?


Yes,this is exactly what I want to do. I am using Omron ST Function Block. I think that not all ST instructions are included, even though it complies with IEC...

I can do this in Ladder easy enough, in only a few instructions also, but wanted to try and implement in ST.
 
Hello Scott,

You could try a FOR / NEXT loop to get the total value of the array elements, then just add the 3 others and divide...

ArrayResult := 0 ; 'Set an initial value of zero
FOR Index := 1 TO 26 DO 'Index is a variable of type INT
ArrayResult := ArrayResult + YourArray[Index] ;
END_FOR ;

Total := (ArrayResult + Other1 + Other2 + Other3) / 4 ;

Hope this helps
 
L D[AR2 said:
You need to divide by 29 instead of 4 :)

Hello L D[AR2,P#0.0] (that's some moniker!)
Whoops, good call!
However, your post has led me to realise that the value of ArrayResult could well be huge o_O , therefore Scott will need to ascertain what the potential total value may be, and take action accordingly.
Depending on the potential value, my proposal may well prove to be impossible :eek: , unless 'ArrayResult' is type LREAL.

One of those days!
 
Why? Good ladder is a hell of a lot easier to trouble shoot quite frankly.

Just something else that I wanted to be more competent with. I prefer doing math calcs this way, as one can express the actual formula. I did this in ladder with the SUM instruction, then a couple of + inst, & finally a divide ( conveted to FLT for this though ).

You could try a FOR / NEXT loop to get the total value of the array elements, then just add the 3 others and divide...

ArrayResult := 0 ; 'Set an initial value of zero
FOR Index := 1 TO 26 DO 'Index is a variable of type INT
ArrayResult := ArrayResult + YourArray[Index] ;
END_FOR ;

Total := (ArrayResult + Other1 + Other2 + Other3) / 4 ;

This is new to be, but will experiment, not sure if I will use yet as is not as easy to follow.

However, your post has led me to realise that the value of ArrayResult could well be huge o_O , therefore Scott will need to ascertain what the potential total value may be, and take action accordingly.

Not likely, as the values are 0-100%, so maximum value will be 100 * No.of variables.


Thanks for your help.

Scott
 

Similar Topics

Hello, doing switch from FBD to ST. First task is converting my old work. How do you sum variables? For example, Interlock1, interlocl2 and...
Replies
5
Views
86
Hi guys, I need help with position control using a Veichi AC Servo Drive model SD600A1-T2-2R2. How do I know how many pulses for it to rotary 1...
Replies
1
Views
36
Hi friends, i need a help to know the procedure and steps to connect Lenze i700 to PC for parameterize. i tried with lenze easy-starter using LAN...
Replies
0
Views
43
HI everyone, i am new to Siemens plc programming and i am in need of some help. yesterday we had an S7-1200 CPU 1214C fail to turn on an output to...
Replies
11
Views
339
I have an old Sentry Palletizer (S/O Number 3007 / Serial Number 1172) that has lost its program as the backup battery died years ago. I can...
Replies
0
Views
125
Back
Top Bottom