Highest And Lowest From Array

mattdotnet

Member
Join Date
Mar 2018
Location
North Carolina
Posts
1
I am working with Allen-Bradley RSLogix 5000. I would like to track the highest and lowest values in an array set by a FFL instruction. Is there an instruction which will constantly move track the highest and lowest values?
 
There's no single instruction that I know of, but you could use indirect addressing and a counter to examine each array entry and compare it with a "current lowest" value, replacing if the examined value is lower than the compared value.

So, whenever you want to initiate an update to the highest/lowest, reset the counter to zero and use it's accumulator as the indirect variable.

IF Array[counter.ACC] < CurrentLowestValue THEN MOV Array[counter.ACC] TO CurrentLowestValue

IF Array[counter.ACC] > CurrentHighestValue THEN MOV Array[coutner.ACC] TO CurrentHighestValue

Then increment the counter and do it again. Make the counter preset equal to the length of your array, and when the counter DN bit turns on, reset the counter. Will be ready to compare again whenever you flag it again.
 
If you're using structured text, you could use a for loop to run through the array elements and identify the highest and lowest value, and also location in the array.
 
The loop is easy and it can be done in ladder also with the JMP and LBL instructions. This example provides the greatest and least value out of an array of 200.

Loop_Array.png
 
The loop is easy and it can be done in ladder also with the JMP and LBL instructions. This example provides the greatest and least value out of an array of 200.

That is overkill if you just want largest and smallest values.

COP (or CPS) the array to another, SRT it, then array[0] will have smallest, array[nn] will have largest (nn = array size - 1).

I dislike looping using JMP and LBL, there's always a potential for the loop to become indefinite = Major Fault
 
Looping is common in many forms of programming. Faults are caused by mishandling the index pointer. It's good practice to clear it before AND after the loop.

The loop may be overkill for greater and less than comparisons, but it is consistently effective and does not require additional tag usage. Especially strings. It can also compare different tag types embedded within user defined structures that are arrayed.
 

Similar Topics

PLC is a SLC 5/04 I can one write logic to see how high or how low a value got? Example their is a 0-10v scaled signal coming into my analog...
Replies
4
Views
2,490
folks i have 104 lamps that record their hours on the panelview, so i need to get the highest hour value of these lamps data data type is...
Replies
26
Views
5,494
Hello Currently have a project in which I have to find the highest value in a dint array. Once the highest value is found I will have to move...
Replies
20
Views
11,316
This is a Citect SCADA question I have Six variables of type REAL (Float) to compare and determine (identify) which variable has the highest...
Replies
4
Views
1,390
Hey. (AB CLX) I have an application where I am recording faults into an array of 15 DINTS. The Members of the array represent different faults...
Replies
2
Views
1,418
Back
Top Bottom