Mike the puzzled

Join Date
Jul 2015
Location
newton aycliffe
Posts
8
Anyone out there that can help?
I need to be able to sort 54 numbers in ascending order along with a name which is associated with each of these numbers. i.e. 507 would be the name and 2354 the number could be one pairing, 504 and 216 could be another. then 511 and 67 could be a third. These would need to be organised so that 511 and 67 are at the top of the list and 507 ,2354 are at the bottom. I am using RS logix 5000. Does anyone know how to do this in ladder logic?
 
Is this what you mean?

Before
507,2354
504,216
511,67

After sorting
511,67
504,216
507,2354

How are you storing the data?
A UDT (User Defined Type) is recommended then you create an array of that UDT
 
I would start with getting the data into two arrays, one for the number and one for the text.

My first stab would be to use a Bubble Sort (https://en.wikipedia.org/wiki/Bubble_sort) on the number array with the simple addition of making sure I swap the text items every time I swap the number items. Bubble sorts are not the most efficient but they are generally easy to understand. Check out the Pseudocode implementation section in the Wikipedia link; it looks similar to ST code.

I'm not an AB guy but if I was doing this in CoDeSys I would make sure it was in a task that had a long enough watch dog timer that it wouldn't fault out the processor. I would also only call the sort routine when I knew that new information was added that needed sorting.
 
RSLogix5000 has a sort command in ladder logic (SRT). If you use ST, everyone who needs access to the logic will need that language package in$talled.

EDIT: I am not sure the SRT function can be made to sort an array in multiple dimensions (keep the name and data together), so writing your own may be a better option. I have not used the SRT myself and don't have a way to test it.
 
Last edited:
RSLogix5000 has a sort command in ladder logic (SRT).

Didn't know that. Will it work to let the secondary (text) array be sorted based on the primary array sorting?

If you use ST, everyone who needs access to the logic will need that language package in$talled.
I thought everyone could at least look at it but on the sight is says "Upload/
Download Included, Editor Available Separately" for Standard, Mini and Maintenance versions. Not having the software I don't know if Upload/Download means you can see it or not.

Still, from a purely engineering standpoint, I believe ST would be best for creating your own sort routine and I believe I could explain it to a maintenance guy better than what it would take to roll my own customized sort routine in ladder.

viva 'la CoDeSys :p
 
Attached is a ladder implementation with Mike's criteria.

Edit - You will have to populate the array with data, move 54 - the array length - into 'Array_Length' then turn 'Begin_Sort' on.
 
Last edited:
bernie_carlton said:
Attached is a ladder implementation with Mike's criteria...

Good stuff Bernie (y)

ndzied1 said:
This problem SCREAMS for a solution in Structured Text (ST) language.

For anyone interested...

521953 - Sample code in structured text for a bubble sort
Access Level: TechConnect

Regards,
George
 
If you feel the sort takes too long then I can add the test to end it early if it detects that the array has been fully sorted (a pass through the array yields no swaps).

As it is it takes (N^2 + N)/2 ladder scans to complete the sort. (N = 54 in this particular application.)
 
Last edited:
The Sort function is limited to a small number isn't it? Not sure, but I don't have access to CLX instruction right now either.
 
Attached is a ladder implementation with Mike's criteria.

Edit - You will have to populate the array with data, move 54 - the array length - into 'Array_Length' then turn 'Begin_Sort' on.

This just worked years. Time doesn't define you Bernie. Thank you very much. Props on 14 years!!! 🍻
 

Similar Topics

Anyone else having issues loading mikeholt forums?
Replies
5
Views
2,021
To Mike Granby I wanted to take the time to wish fair weathers and safe travels as he leaves Red Lion. I know whatever he does going forward...
Replies
7
Views
3,939
http://reason.com/reasontv/2013/12/13/dirty-jobs-mike-rowe-on-the-high-cost-of Interesting actual interview about college vs. blue collar...
Replies
34
Views
16,963
Hello We have a S7-414 2DP CPU and we are trying to read diameter of a cable via Beta LaserMike AS5010 P Diameter Sensor. The sensor is alive on...
Replies
8
Views
4,653
I am looking for an old Lasermike "Smarbox" serial converter for a Lasermike gaging laser. The one I have is a model 800-01. I'd be willing to...
Replies
6
Views
2,170
Back
Top Bottom