Sorting Numbers in Numerical Order

Chris84948

Member
Join Date
Jul 2010
Location
Minneapolis
Posts
4
Hi there,

I'm really new to PLC programming, but I do have experience with other languages. Currently I'm learning to use on an logix 5562 using RSLogix 5000 language.

What I'm trying to do is take 5 numbers, entered by the user, and sort them into numerical order so I can check them. Is there any simple way of doing this? I've read a little bit about the sequencer, but I don't think that's what's best in this situation.

Any help would be great.

Thanks
Chris
 
Sort routines aren't hard, but first, what PLC, brand & model, are you using? Also, what programming software, incl. version, are you using?
 
Thanks a lot. I've actually been looking around and it looks as though you're right, a bubblesort would be the best idea. I have the option of writing in structured text, so that seems like a reasonable idea.

Thanks again.
 
Hi I'm back again.

I've given it a shot at writing a bubblesort in structured text, but the syntax is a funny guy so I wanted to throw this up here and see what you guys think of it.

WHILE SWAPPED DO
SWAPPED := 0;
FOR COUNT := 1 TO 4 DO
IF DICE_IN_ORDER[COUNT] > DICE_IN_ORDER[COUNT+1] THEN
TEMP := DICE_IN_ORDER[COUNT];
DICE_IN_ORDER[COUNT] := DICE_IN_ORDER[COUNT+1];
DICE_IN_ORDER[COUNT+1] := TEMP;
SWAPPED := 1;
END_IF;
END_FOR;
END_WHILE;

where dice_in_order is my array of 5 dice numbering from 1-6. I've chosen the count to be from 1 to 4 because dice_in_order[0] is a spare to make things more readable, so my array goes from 1 to 5.

I've given it a shot and it appears to not work. Any ideas.

Thanks
Chris
 
I think the way the WHILE/END_WHILE works is the input WHILE condition needs to be true in order to pass. If it is not true the code moved to the END_WHILE line and continues.

So you will either need to invert your WHILE and END_WHILE lines (if the plc will let you) or seed SWAPPED with a 1 before you get to the sort routine.

Keith
 
Thanks again guys, the repeat..until loop worked perfectly. I just needed to do that. The swapped bit wasn't true before it started and that was the problem.

Thanks
Chris
 

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
315
Hi, I have just started with WinCC unified (v17) and there are alot of things I used on Comfort but now are not available. Currently I am finding...
Replies
3
Views
2,830
I'm trying to be smart about naming my tags so things automatically group together alphabetically, but for some reason it doesn't work like I...
Replies
15
Views
3,635
Hello friends. There is an int type, number that I got from the DataBlock. For example, the DataBlock address is Db1.dbw0. Here's what I want to...
Replies
32
Views
10,437
Good afternoon all, I am working on a college project where we have to sort 3 different color legos. Orange, Black, and Tan. I am using a color...
Replies
30
Views
6,763
Back
Top Bottom