ElectronGuru

Sorting Data Arrays in CLX

11 posts in this topic

I have a customer who wants to put counters on 35 alarms, and make the 5 top-most occurring alarms available for display on an HMI. I've put a branch rung under each alarm condition with a counter and move instruction. The MOV moves the accumulators' values to designated, corresponding spots in a newly created array of 35 DINTS. The problem is in sorting the data from lowest highest. I believe the SRT instruction sorts data within the array, but not the array tags themselves. This would lead to the wrong data being placed on each alarm accumulator tag in the array. Writing compare instructions or expressions that analyze 35 pieces of data against each other, either in FactoryTalk or ControlLogix, seems impractical, if not impossible. 

We're using 1769-L30ER controllers and PanelView 6 & 7 HMIs.

Any ideas? Please tell me there's a simple instruction or two I don't know about that will accomplish this.

Edited by ElectronGuru

Share this post


Link to post
Share on other sites

Wow! The SRT is pretty much useless.

Wondering if the way to attack it is outside the PLC.  Say using an excel spreadsheet that does the sorting to another array tag that is read back into the PLC and therefore the HMI?

1 person likes this

Share this post


Link to post
Share on other sites

I'm basing my thoughts on you having an array of 35 DINTS {ALARM_COUNT[36]} and an array of 35 Alarm  Message Strings {ALARM_MESSAGE[36]}.

You'd need 5 passes through the DINT Array looking for the Maximum Value.  

The loop or subroutine acts like this.

Place the Value 0 into Pointer_to_Alarm DINT and Value of 0 into Maximum_Value DINT.

Loop through ALARM_COUNT[1] to ALARM_COUNT[35] .

If the ALARM_COUNT[#] value is bigger than Maximum_Value update Maximum_Value and Location into Pointer_to_Alarm.

At end of loop - Zero Out the value in ALARM_COUNT[Pointer_to_Alarm] and move Pointer_to_Alarm to Top_Alarm_1.

Repeat the loop and load Top_Alarm_2

Once you've loaded Top_Alarm_3, 4 & 5 you can use those pointers to load the messages that the PV will display.

Quite doable, but you'll learn pointers and in directs tom make it work.

 

2 people like this

Share this post


Link to post
Share on other sites

Pcmaccartney1, I had thought about this. I have exported tag sets and they slide easily into most spreadsheet programs. We'd need another, external processor (like a cheap laptop) on each machine for the sole purpose of handing the conversions, OR have to write the data arrays (probably via MSG instructions) to a server for multiple machines. In the first scenario it's just not practical or financial feasible. In the second, we'd likely eat up too much band width on the network to make it worth the while. 

BobLfoot, I appreciate you taking the time to lay that out. I'll start working on banging out some code.

Thanks, guys!

Share this post


Link to post
Share on other sites

Another option is to have an array of UDT with two elements:

AlarmCount & AlarmID

Then do a bubble sort on the AlarmCount (and move AlarmID at the same time when sorting)

Share this post


Link to post
Share on other sites

destination unknown, I'm not sure how I'd code a bubble sort in ladder logic. 

Share this post


Link to post
Share on other sites

In Ladder you could use "For" like this:

Main -> For i -> For J -> Sort Logic 

 

Main

Lad2.png.e1b57258b561f0e09362dbb963ced70

i_Routine

Lad3.png.3747d2d9bd1b33d76ba25f650944664

 

J_Routine

 

Lad1.png

Edited by destination unknown
2 people like this

Share this post


Link to post
Share on other sites

Destination Unknown - 30+ years and I never gave coding a bubble sort in ladder much thought, but you've nailed it beautifully.

Share this post


Link to post
Share on other sites

destination unknown, I hate to ask but could you please post your tags and UDTs? The code itself makes sense to me but I'm fighting with the array subscripts, and think maybe I'm missing something simple but critical in the one of my temp arrays or UDTs.

Share this post


Link to post
Share on other sites

destination unknown, never mind, I got it! This is crazy brilliant and I appreciate the help. It would never have occurred to me to try to bubble up data in ladder. Truly appreciate the insight.

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