Internet PLC Forum

General => Technical support => Topic started by: StefanA on September 05, 2013, 10:20:36 AM

Title: Programming help
Post by: StefanA on September 05, 2013, 10:20:36 AM
Need some help with a programming problem.

We assumes that DM1-48 contains various reading from a ADC. I want to identify the highest and lowest of the readings. Any good suggestions?
Title: Re:Programming help
Post by: garysdickinson on September 05, 2013, 07:48:29 PM
Scan through DM[1..48].  The following code scans through DM and records the maximum value in A and the index to this value in B:

A = -1    ' start with a value that is less than minimum data value
B = 0     ' illegal index into DM[]

for I = 1 to 48
  if DM > A
    ' value in DM is greater than previous maximum value
    '   Remember it...
    A = DM
    B = I
  endif
next

Not much to it!  You can easily add another test to check for minimal values within the same for/next loop

Gary d.
Title: Re:Programming help
Post by: StefanA on September 06, 2013, 09:20:40 AM
Thank you very much Gary.