Hi LD
I am feeding the DB with different values, I have a DB with DINT where a fix't part is filled with different values.
Out of these values I need a Minimum, Maximum and Average,
I have found a way to sort the values so I have minimum and the first address and Maximum at the last address, (my first day with STL, so I have to cheat where ever i can
)
And i found a code for generating an Average of the data area, so in theory a am able to put my project together, the last part I am working on is combining the two codes to safe a loop, maybe I am going to deep in my surge for scan time
Here are the codes I am trying to combine:
//Average
L P##values_to_average
LAR1
L W [AR1,P#2.0]
T #elem_count
L W [AR1,P#4.0]
T #db_num
OPN DB [#db_num]
L D [AR1,P#6.0]
LAR1
L 0
T #sum
L #elem_count
_loo: T #loop_temp
L W [AR1,P#0.0]
L #sum
+I
T #sum
L 16
+AR1
L #loop_temp
LOOP _loo
L #sum
L #elem_count
/I
T #RET_VAL
//Sorting
OPN #Data_DB //Open Data Block
M002: LAR1 P#DBX 0.0
SET //LET #Sort_done = TRUE
S #Sort_done
L #DB_Length
L 1
-I
Loop: T #Count //FOR INDEX = Count TO DB_length
L W [AR1,P#0.0]
L #Average // load sum of all previous elements
+D // add these two together !!!
T #Average // store it in the sum
L W [AR1,P#0.0] //IF M(INDEX) > M(INDEX+1) THEN
L W [AR1,P#2.0]
<=I
JC M003
// change M(INDEX+1) for M(INDEX)
L W [AR1,P#0.0] //LET TEMP = M(INDEX)
T #Temp
L W [AR1,P#2.0] //LET M(INDEX) = M(INDEX+1)
T W [AR1,P#0.0]
L #Temp //LET M(INDEX+1) = TEMP
T W [AR1,P#2.0]
SET
R #Sort_done //LET #Sort_done = FALSE
M003: TAR1
L 16 //NEXT INDEX
+D
LAR1
L #Count
LOOP Loop //End of sorting pass
AN #Sort_done //If sorting is not done
JC M002 //Jump Conditionally to M002
L #Average
L #DB_Length
/D
T #Average
BE