FUnction Block for finding the second highest value

mthompson6782

Member
Join Date
Mar 2014
Location
houton
Posts
2
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) in a Triconex PLC. Does anyone have a canned version of this they would like to share?
 
why don't you think about the problem and suggest your solution then someone may help you

Declare Highest /2nd Highest

If IN1 > IN2 then
Highest=IN1
2nd Highest =IN2
end if

etc
 
No need to sort into order, e.g

Code:
FUNCTION_BLOCK FB97
VAR_INPUT
T:ARRAY[1..16] OF REAL;
END_VAR
VAR_OUTPUT
SecondHighest:REAL;
END_VAR
VAR
i,j:INT;
END_VAR
BEGIN
j:=1;
//find highest and make it very low
FOR i:=1 TO 16 DO 
 IF T[i] >= T[j] THEN j:=i; END_IF;
END_FOR;
T[j]:=-99999.0;

//find highest again, this will be the second highest
j:=1;
FOR i:=1 TO 16 DO 
 IF T[i] >= T[j] THEN j:=i; END_IF;
END_FOR;
SecondHighest:=T[j];
END_FUNCTION_BLOCK
 
No need to sort into order, e.g

Code:
FUNCTION_BLOCK FB97
VAR_INPUT
T:ARRAY[1..16] OF REAL;
END_VAR
VAR_OUTPUT
SecondHighest:REAL;
END_VAR
VAR
i,j:INT;
END_VAR
BEGIN
j:=1;
//find highest and make it very low
FOR i:=1 TO 16 DO 
 IF T[i] >= T[j] THEN j:=i; END_IF;
END_FOR;
T[j]:=-99999.0;

//find highest again, this will be the second highest
j:=1;
FOR i:=1 TO 16 DO 
 IF T[i] >= T[j] THEN j:=i; END_IF;
END_FOR;
SecondHighest:=T[j];
END_FUNCTION_BLOCK

I really appreciate your response. I think this is exactly what I was trying to do. I have been fiddling around with this and have decided that using structured text is the way to go. I was able to find the second highest using all function blocks but the method i used had problems when the second highest value was the same as the first.

Using function blocks I used the MAX of the 16 inputs then subtracted the max from the original tag values if the value was Not EQUAL to zero it outputted a 1 which I then multiplied again by the original tag values and sent to a MAX block which yielded the second highest. My way is bulky, labor intensive, and clumsy.

I want it so that if the second highest value is equal to the highest value it displays that value twice.

I have read that ST is very much like PASCAL and I have decided to try to sharpen my ST programming skills in this area. Thank you very much.
 

Similar Topics

Hi, I have attached herewith one image which our programmer has been used in S7 1500 PLC. Now we need to use the same instructions in S7 1200 PLC...
Replies
4
Views
137
Please see attached file. I need this program in Function Block form but I am totally lost on this. Any help would be appreciated. Thanks!
Replies
8
Views
308
Hi! I am using a TM200CE40T PLC from Schneider to write data over Modbus. I have used Memory words (%MW) before using the Write variable...
Replies
1
Views
548
Hi folks. New to the forum, but been working with PLCs for several years now. Would like some advice on whether you would keep this logic, or...
Replies
9
Views
1,077
Hi Yes, I'm stuck again. Trying to define a Function Block. What I've put in there so far has been a straight copy/paste from the code (and that...
Replies
22
Views
2,951
Back
Top Bottom