Nickr6

CompactLogix function to find the highest DINT ?

6 posts in this topic

hello!

I create many DINT[13] data to memorize the recipe data.

As the value can change (the operator will change the value of the recipe) how can I code to find the highest value in this 13 value ?

I need to be sure to move the highest value to a timer.pre every scan.

Thanks for looking :-)

compactlogix.jpg

Share this post


Link to post
Share on other sites

MAX_Index = 0

DINT_MAX = ARR[MAX_Index]

FOR n=1 to 12

   IF ARR[n]>DINT_MAX THEN

         MAX_Index = n

         DINT_MAX = ARR[MAX_Index]

    ENDIF

ENDFOR

1 person likes this

Share this post


Link to post
Share on other sites

Thanks panic mode, I will add the structured text editor to my Studio 5000 mini edition then I will try this!

Share this post


Link to post
Share on other sites

you don't have to, this is just pseudo code. implementation can be in any language. 

Share this post


Link to post
Share on other sites

:doh:

thanks, problem resolved! 

Edited by Nickr6

Share this post


Link to post
Share on other sites

Another option, if you can rearrange the data (or copy it into an array that can be rearranged), is the SRT instruction. You give it an array and it sorts in ascending order so the largest value will end up at the bottom of the array.

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now