Sign in to follow this  
Followers 0
Gazzr

Data sorting in S7-200

7 posts in this topic

I have been scratching my head trying to sort data into a descending list. What I want to do is measure the length of time that an input is active (in minutes). Then when it becomes inactive (Switched off) - take the time it has been on. Say 2.5 minutes, and insert the value into a list of ten values in descending order. IE create a "top 10" list of activations. The system should insert the value at the correct location in the list. If the value is so short that it doesn't make the list, it is just disregarded. Rather than come and ask the question earlier, I have persevered and managed to make a program that does what I want... (I think) But would like some input on how it could have been done (Probably) much simpler. Also, I have metric minutes - 1 min 30s becomes 1.50 minutes, could this be worked around to keep things looking better? Please see attached attempt, comments welcomed. Data_sort.rar

Share this post


Link to post
Share on other sites
Whats the min and max time range ? I would have used seconds as that would be tidier than 1 min 30 becoming 1.5 etc Ill look at your program later this evening Edited by 504bloke

Share this post


Link to post
Share on other sites
This would be monitoring how long a rejection device is active on a line. Minimum time active could be less than 30 seconds. Max realistically could be a couple of hours if a trial is being done and run straight into scrap. I am monitoring over an 8 hour shift, then resetting all and starting again. I suppose I should cater for minimum of 1 second, max of 8 hours. Bit wide open i know, but I suppose I should cover for "worst case". When this is comnplete I will also be recording a timestamp. So the list of the ten would be: 1) 09.20am - 25m 30s 2) 08.36am - 22m 14s 3) 12.04pm - 15m 04s etc........ (Or thats the aim anyway) Also worth mentioning that I was trying to get the table addresses into the subroutine as variables. But couldn't manage it. Due to the confusion of IN IN/OUT OUT etc.... I will get the hang of that one day. Edited by Gazzr

Share this post


Link to post
Share on other sites
After a moments thought...... I could just work in whole minutes. On a "normal" day the top of the list may be 15mins, working down to 5mins. If the whole list consisted of times less than a minute then the list is worthless anyway, it has been a great day. On a worst case scenario of 8 hours rejecting, it would read 480mins which ain't hard to work out. So the resolution could be whole minutes.

Share this post


Link to post
Share on other sites
Yes whole minutes would be neater or even just seconds. Have a look at Bubble sort and using a For/Next loop, that would be another way of doing the sort http://en.wikipedia.org/wiki/Bubble_sort Edited by 504bloke

Share this post


Link to post
Share on other sites
Thanks for the info, had a look at the link. Very simple idea, more straight forward than my method of finding the slot - making the hole - inserting the data. Cheers.

Share this post


Link to post
Share on other sites
Your way will work fine, its just another way of doing it. There are other ways to sort as well but bubble is simple for small sorts. The bubble sort will work over progessive scans so you need to make sure your scan time isnt slower than the sample you are taking which in a 1 sec sample i dont think will be a problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0