Sorting in Plc from smallest to largest

dear parky You are a perfect man. Thank you so much. (y)

Here is a quick bit of code that does what I think you need.
When Memory bit M10.0 is set to true, it runs through FC4 & finds the lowest number in the Container words, providing it is above 0 & it is enabled per the DW associated with them i.e. DW12-30 are the containers DW32-50 are the status words, currently the status words re either 0 or 1 (you could add other values for some purpose).
When M10.0 is set, it first places the first container value in a temp word, it then cycles through each container & if the value is > 0 and < than the stored one and it's associated enable is 1 then it writes that over the previous one.
Loops through to the end to check the rest, then resets M10.0 so only processes the code on a oneshot. So providing the container is above 0, the container is enabled and it is the lowest value it is stored in the robot word DW0, have left a few spares, you may need to shift the data about if you have already got some sort of formant, I did not effectively use a 2 dimentional array (although it is sort of), thought it was cleaner & it was quick to code but I'm sure someone will post if they have a better way of doing it, my last experience on S7 was probably about 12 years ago & with that & using my experience of S5 some 22 years ago I cobbled it up, well if you do it like this.....
There is a caveat, if no valid container is availlable then the robot word will stay as is so you will need to deal with this.
Anyway, it should give you some ideas.
 
The one problem I can see if this code is what you want is what do you do when the robot finishes using DBW0, do you reset it to 0 ? as if for some reason the containers have either all 0 or disabled, you need some way of telling the robot that any data in DBW0 is new.
 
The one problem I can see if this code is what you want is what do you do when the robot finishes using DBW0, do you reset it to 0 ? as if for some reason the containers have either all 0 or disabled, you need some way of telling the robot that any data in DBW0 is new.


Yes, you are correct. Can we add a command such that if there is no number greater than 0, the DB value to be sent to the Robot should be "0"?
 

Similar Topics

I have worked on small projects using AB Micrologix but now we want to take a photo, process it online, and sort based on returned variables...
Replies
5
Views
323
First off, I am new to the whole PLC world and was tasked with a project at work. I was given a Click C0-11dre-D, Honeywell 310G barcode scanner...
Replies
4
Views
2,307
I am trying to make an object sorting system using PLCs for university. The system uses the shape of incoming objects to figure out if they need...
Replies
9
Views
3,745
Hello all, I am currently reseaching the best way to create a simple sorting system. My challange is that all sorting decisions are made by...
Replies
2
Views
6,057
I am a user of Siemens PLCS. I am not a regular visitor of this site, but whenever I am here, I click mostly * Postings that are related to...
Replies
14
Views
3,244
Back
Top Bottom