Author Topic: Programming help  (Read 12097 times)

StefanA

  • Newbie
  • *
  • Posts: 29
  • I'm a llama!
    • View Profile
Programming help
« 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?

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Programming help
« Reply #1 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.

StefanA

  • Newbie
  • *
  • Posts: 29
  • I'm a llama!
    • View Profile
Re:Programming help
« Reply #2 on: September 06, 2013, 09:20:40 AM »
Thank you very much Gary.