finding the maximum of 16 values

jvreys

Member
Join Date
Mar 2009
Location
belgium
Posts
2
Hello, I need a function like the FC25 but then with 16 values as input, how could i do this?

I am only a beginner in PLC.
Can someone help me with this?
 
first of all you need to specify PLC (presumably some siemens..) then language.
some plcs may have function for this but other way is to assume that first value IS the maximum.

then you compare that with second value. if second is greater, make that the maximum.

then you compare that with third value. if third is greater, make that the maximum.

then you compare that with fourth value. if fourth is greater, make that the maximum. etc.

this can be done in a loop too...
 
Here's the simple version for 16 ints. If you want dint or real it's a simple edit to change this block.

Code:
FUNCTION FC 4 : INT
TITLE =
VERSION : 0.1

VAR_INPUT
  iV1 : INT ; 
  iV2 : INT ; 
  iV3 : INT ; 
  iV4 : INT ; 
  iV5 : INT ; 
  iV6 : INT ; 
  iV7 : INT ; 
  iV8 : INT ; 
  iV9 : INT ; 
  iV10 : INT ; 
  iV11 : INT ; 
  iV12 : INT ; 
  iV13 : INT ; 
  iV14 : INT ; 
  iV15 : INT ; 
  iV16 : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =
      L     #iV1; 
      L     #iV2; 
      <I    ; 
      JC    x3; 
      TAK   ; 
x3:   L     #iV3; 
      <I    ; 
      JC    x4; 
      TAK   ; 
x4:   L     #iV4; 
      <I    ; 
      JC    x5; 
      TAK   ; 
x5:   L     #iV5; 
      <I    ; 
      JC    x6; 
      TAK   ; 
x6:   L     #iV6; 
      <I    ; 
      JC    x7; 
      TAK   ; 
x7:   L     #iV7; 
      <I    ; 
      JC    x8; 
      TAK   ; 
x8:   L     #iV8; 
      <I    ; 
      JC    x9; 
      TAK   ; 
x9:   L     #iV9; 
      <I    ; 
      JC    x10; 
      TAK   ; 
x10:  L     #iV10; 
      <I    ; 
      JC    x11; 
      TAK   ; 
x11:  L     #iV11; 
      <I    ; 
      JC    x12; 
      TAK   ; 
x12:  L     #iV12; 
      <I    ; 
      JC    x13; 
      TAK   ; 
x13:  L     #iV13; 
      <I    ; 
      JC    x14; 
      TAK   ; 
x14:  L     #iV14; 
      <I    ; 
      JC    x15; 
      TAK   ; 
x15:  L     #iV15; 
      <I    ; 
      JC    x16; 
      TAK   ; 
x16:  L     #iV16; 
      <I    ; 
      JC    x; 
      TAK   ; 
x:    T     #RET_VAL; 
      SET   ; 
      SAVE  ; 
END_FUNCTION
 
Here's a more compact but more complex version that you pass an array of 16 ints instead of 16 individual parameters.

Code:
FUNCTION FC 5 : INT
TITLE =
VERSION : 0.1

VAR_INPUT
  aiData : ARRAY  [1 .. 16 ] OF INT ; 
END_VAR
VAR_TEMP
  idb : INT ; 
  iLoopCount : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =return max value of aiData[1..16]
      L     P##aiData; 
      LAR1  ; 
      L     W [AR1,P#0.0]; 
      T     #idb; 
      OPN   DB [#idb]; 
      L     D [AR1,P#2.0]; 
      LAR1  ; 
      L     W [AR1,P#0.0]; 
      L     15; 
LOOP: T     #iLoopCount; 
      TAK   ; 
      L     W [AR1,P#2.0]; 
      <I    ; 
      JC    ns; 
      TAK   ; 
ns:   +AR1  P#2.0; 
      L     #iLoopCount; 
      LOOP  LOOP; 
      TAK   ; 
      T     #RET_VAL; 
      SET   ; 
      SAVE  ; 
END_FUNCTION
 

Similar Topics

Hi all, I'm in the process of upgrading a PanelView1200 HMI program to be developed in FactroyTalk View Studio. The filetype for PanelView 1200...
Replies
7
Views
238
Hey all, pretty new to PLC and got a question regarding finding the MSB or the last non-zero bit in a SINT array in studio5000... I am reading...
Replies
2
Views
813
Having an issue connecting to my Micro820 PLC. I don't have an IP Explorer and I know its MAC Address is 5C:88:16:D8:E6:65. I'm connected to the...
Replies
5
Views
809
I have reached a dead end trying to find an EDS file. Manufacturer says to contact third party tech support. Clueless. RSLINX can see it, just...
Replies
9
Views
1,754
Hello, I have an array of 300 of UDT. In each UDT is an array of 3 DINT and another array of 3 REAL. I have 10 controllers that pull data from...
Replies
7
Views
1,132
Back
Top Bottom