A couple of different methods
If you are using a Logix-class PLC, go with the SRT (sort) instruction.
It will rearrange an array of values (one-dimension) in ascending order. NOTE: If your setpoints are in an array, and the order needs to remain unchanged, then you will have to copy the array to a buffer array prior to sorting.
Once your values are arranged, you can compare each value against the array, and the position where the match is found + 1 is the priority. For example, if Controller A has a SP of 300, B is 250, and C is 500, then after a SRT, a FSC would find A at My_Sort[1], which is actually 2nd position, so A would be 2nd priority...
Attached is a sample program I worked up for RS5k which contains 3 different Sort routines. The first is done in ladder, without using the built-in SRT instruction, to give an idea of how to implement the function on another processor lacking a built-in sort instruction. Use at your own discretion
.
The second routine is performing the same function as the first, only with the SRT instruction.
The third routine is basically the same as the first, but done in ST.
Hope this helps. Happy coding!