get the highest value

alennamo

Member
Join Date
Mar 2022
Location
modesto
Posts
7
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 Dint[104]

how can i do that please
 
so is there is any instruction does that for me or do i need to write program for that i need some help please i have RSlogix 5000
 
Well, you can populate and index a B-tree with the values, then the highest can be found fairly quickly.

Others might not agree. Sometimes you want fast list insertions with something like a doubly-linked list. But you’ll need to iterate the nodes to find the highest.

Also the possibility of copying it all to another array, bubble sorting, then using the first or last array element (depending on whether you sorted in ascending or descending order).

On the back of my napkin here, I’ve come up with yet another approach: look the list over, write the biggest number you find on a Post-It, then stick that to the PanelView.
 
Last edited:
Welcome to the PLCTalk forum community !

Are you familiar with Structured Text, or only Relay Ladder logic ?

Presumably because this is an hour meter, the speed of the function is not critical.

The Sort (SRT) instruction can find the maximum value.

Once you know the maximum value, you can find its location with the File Search Compare (FSC) instruction.

Or, you can DIY a simple index search in a few rungs.
 
Because I seldom use the FSC instruction I spent a few minutes taking a look. Having a 1756-L61 for a desk toy is great !

The SRT instruction in ControlLogix has no ascending/descending options: it always places the largest value in the last index.

FSC is really a little embedded FOR loop with a comparison expression. The function of the .IN bit can trip you up if you have not used it before.

This should do what OP wants:

SRT_Example.PNG
 
Last edited:
And yes, you can find the maximum using only the FSC with a greater-than expression. I will leave that as an exercise for the reader.
 
Assuming the data is in an array in the plc
A simple for loop will the simplest way to what you want
about 3 rungs of code
maybe if I get time, I will set it up and post it here
 
Something like this (I like to use structured text for loops):

Code:
// reset our highest value
highest_value := 0;

// iterate our value you array, looking for the highest
// value
For i:= 0 To 103 Do
	If value_array[i] > highest_value Then
		// found a higher value
		highest_value := value_array[i];
	End_if;
End_For;
 
How do the values get written to the array in the first place? That is where looking for the largest value should take place.


Or [MOV -2148483648 maxval_dint], then run a FAL with this expression:

(maxval_dint * (maxval_dint >= array104[control.POS])) + (array104[control.POS] * (maxval_dint < array104[control.POS]))


 
Last edited:
Here is a fairly concise scan based ladder logic solution
It will update the answer every 104 scans

It can be done in 1 scan with a For Next ladder loop if you want

I try to save processing for the important tasks that require high speed

Lamp.jpg
 

Similar Topics

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,488
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,422
Plc: RX3i Cpu: CPE305 I want to search a range of real registers for highest value. The range is R1050 to R1525. I thought it would be an array...
Replies
4
Views
1,613
I am trying to find a function block to determine the second highest value ( i need the second highest value out of 16 thermocouple temperatures)...
Replies
6
Views
2,562
Is there a way to record the highest value in a certain time frame? For example an analog input card.
Replies
32
Views
6,278
Back
Top Bottom