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

Hi all, hope you are having a great day, I am in need of your help to create a AOI or program that does this kind of job: I have a IO Link...
Replies
0
Views
18
please help me . I have to make this ladder diagram and I can’t figure it out :(
Replies
12
Views
270
Hi Everyone, i was hoping for a little help with this module. i have data that needs to be read from a different plc through the Modbus plus...
Replies
11
Views
188
Hello, I am trying to replicate a piece of logic on the PLC5 onto an SEL RTAC. I am using ladder on SEL and FBD. I am having issue on the ladder...
Replies
13
Views
207
Back
Top Bottom