How to find Largest of 4-integers Via Logic

skyfox

Lifetime Supporting Member
Join Date
Nov 2006
Location
CA
Posts
279
Hello all,

I need some help to figure this out with least amount of logic. What I am trying to do is to find the laragest value from group of 4 numbers and use it as my input for logic to be added later. In real life, these numbers will be varying dynamically (RPM values from 4 motors) and I need to pick the highest value for my needs. This is the logic I cameup with so far and it seems to work (unless I missed something). However, the more I look at it, I can't help but feel there has got to be a a simpler way way of doing this (with much less code). But can't seem to put my finger on it. May be one of you super WIZ bang PLC guru's who do stuff like this in their sleep could give me some pointers. That is, w/o using pointers :)

Thanks

Value.JPG
 
If this is a PLC5/?? enhanced Controller then see pic below. ( some of your other posts where about PLC5's.
SLC's do not have this instruction.

sort.jpg
 
Last edited:
Thanks Mickey,

You are correct it is a PLC-5. I am unfamiliar with the SRT function and a bit scared of using it because of,(A) Terrified of not clearly understanding or not having a good grasp of S:24 registers functionality. Several other subroutines (not written by me) uses indexed as well as indirect addressing and not sure or have a clear understanding of how this may affect the rest of the logic. Since this instruction is using a control structure, I am assuming it takes 4-scans to sort 4 numbers. I prefer that this be done in a single scan but I am always willing to learn. I read thru the instruction reference but still in the dark as to how this functions. For example, looking at the instruction example you posted; if I interpret it correctly, it sorts 123 values starting at N7:0 and takes 123 scans to complete the sorting. Where will the sorted values be stored? N7:0 to N7:122? If that is the case then I am guessing that I need to move/copy my sensor values in to a temporary buffer and then use the buffer as the File source for SRT instruction. Since this instruction requires a false to true tansition to trigger, can I use the Not enable bit of this same instruction to trigger it (EN -[/]-)?

Thanks again.
 
Last edited:
skyfox said:
Thanks Mickey,

You are correct it is a PLC-5. I am unfamiliar with the SRT function and a bit scared of using it because of,(A) Terrified of not clearly understanding or not having a good grasp of S:24 registers functionality. Several other subroutines (not written by me) uses indexed as well as indirect addressing and not sure or have a clear understanding of how this may affect the rest of the logic. Since this instruction is using a control structure, I am assuming it takes 4-scans to sort 4 numbers. I prefer that this be done in a single scan but I am always willing to learn. I read thru the instruction reference but still in the dark as to how this functions. For example, looking at the instruction example you posted; if I interpret it correctly, it sorts 123 values starting at N7:0 and takes 123 scans to complete the sorting. Where will the sorted values be stored? N7:0 to N7:122? If that is the case then I am guessing that I need to move/copy my sensor values in to a temporary buffer and then use the buffer as the File source for SRT instruction. Since this instruction requires a false to true tansition to trigger, can I use the Not enable bit of this same instruction to trigger it (EN -[/]-)?

Thanks again.

The instruction executes the sort ( the whole thing) when the rung goes false to true. It does not take multiple scans.
The sort rearranges the values in in N7:0 to N7:122 or whatever length you use. ( uses the same registers.)
Your concern about the S:24 word is valid depending on the rest of your program. But it can be worked around.
I would use a self a resseting timer to execute the instruction ( lets say every 1 sec, you decide)

But if you are going to lose sleep over this just use Peter's
example and be done with it. Peter's ex. just selects the highest ( which was your orginal request) the sort sorts them all.
 
Last edited:
Mickey/Peter,

Thanks for your help. I want to figure out the SRT function, but because of time constraints, will have to revisit it on another day.

Once again, Thanks for all the HELP!
 
Here is a very quick 16-rung RSLogix500 program that will sort up to 255 numbers from smallest to largest, putting the numbers back into the same memory area. It uses Indirect Addressing and runs on the SLC 5/03, 5/04, and Micrologix 1200 & 1500. It could be converted to use Indexed Addressing and would then run on the SLC 5/02. Anyone up for the challenge?
 
Last edited:
skyfox said:
Thanks Mickey,

You are correct it is a PLC-5. I am unfamiliar with the SRT function and a bit scared of using it because of,(A) Terrified of not clearly understanding or not having a good grasp of S:24 registers functionality.
skyfox, the SRT instruction does use indexed addressing (indicated by the "#"), but it is done internally to the instruction. Operation is similar to the FAL and the like. Used as depicted, you need not concern yourself with S:24 unless the value it contains at the time the sort is executed will be needed elsewhere. If this is the case it's easily cured with a MOV S:24 Nx:y and reload with MOV Nx:y S:24 later.

A little gotcha - the instruction will sort everything in the file specified. If the file is ten words long and contains '0 5 3 0 0 2 0 1 4 0' before sorting, it will be arranged as '0 0 0 0 0 1 2 3 4 5' after sorting.
 

Similar Topics

Hi , Where i can find Mitsubishi PLC Card end of line & replacement model details. i am looking for Q02CPU replacement model. Please advice. thanks
Replies
2
Views
126
I have tested every screen and no single screen individually has this fault pop up, but when I compile and send to the PanelView it comes up. If I...
Replies
4
Views
176
Hi, One of my customers has an old fabric tensile testing machine. The IC # AD7501KN of its controller has malfunctioned. This IC is related to...
Replies
1
Views
80
Hello everyone, I am a student and would like to take the next step and learn FactoryTalk (Batch preferably) and how to create HMIs etc. Would...
Replies
4
Views
493
Hi, Have a look at this picture... How can I find out the memory address of this tag? It was created by adding it to DB "Data_block_1", but I...
Replies
6
Views
1,063
Back
Top Bottom