FSC with COP causes corrupted strings - Logix5K

scarince

Lifetime Supporting Member
Join Date
Jan 2009
Location
Dayton, OH
Posts
153
In a 1769-L16ER-BB1B, ver24:

I'm probably trying to do something impossible with FSC, but I can't explain this behavior:

I have a string array [500] elements long and I sort part numbers with a normal bubble sort. It takes a long time of course.

I had an idea that maybe instead of iterating through and doing one operation per scan, that maybe I could use the FSC instruction to do the comparison of the data in the two array positions.

In the attached logic I use FSC with an expression that says "MyArray[control_2.POS] > MyArray[control_2.POS + 1]". That's not that actual syntax...I'm simplifying.

If it finds that the two values need to be swapped then I copy each value out and copy them back in with the array positions swapped. Then I clear the .IN bit.

So, it works. The code attached will work.....but it will only work if I put in debugging bits and then manually execute one rung at a time. What I mean by that is that if I let the FSC run until it finds two values to be swapped, it will run and stop correctly at a point in the array where the string in position X is larger than the string X+1. Once the FSC stops (.FD is set) then I manually trigger rung 8 and the COP instructions execute correctly. Finally, I manually trigger run 9 and I clear the .IN bit to allow the FSC to run.

If this code runs "normally" (as displayed in the attachments) then what happens is that when I enter a new part number into the first null position of the array then the COP instruction in rung 8 will garble the data. For example, if the number to be moved in the array is "999555" then when it copies it to the temp storage tag, it becomes "999$00$00$00$00" or something like that. There are other strange things related to where in the array the data gets copied back to, as if the .POS value was still changing even though .IN is set. I can confirm POS is not moving when I do this manually.

I even tried delaying the clearing of the .IN bit to see if copy needed more that one scan to complete. I delayed it 10 scans but the results were the same.

I'm not asking how I can sort this better, or even how to get this to work. What I'm really asking is if one of you experts can explain how the function of FSC is related to the normal scan, and if there is any explanation for why (at least in this context) logic would work when executed one step at a time but not when allowed to run at the normal scan rate.

If nobody can or wants to answer this, then can someone just explain how in FSC the .POS value is incremented and how that value is changed relative to the normal logic scan.

The two attached files are the same. The .zip is the .L5X file.

Thx.
 
I think the issue with your logic is that you are continuously restarting the search. I added a condition to start the FSC and then unlatch the condition when the search is complete (DN bit) and it seems to work. It does take 499 scans though.

I may all wet though as I have had a glass or two of the red!

Sort.jpg
 

Attachments

  • Rungs0to4_from_MainRoutine.zip
    3.8 KB · Views: 9
Last edited:
You were right Mike, that worked, but I'm still not clear on *why* it works, or rather why it won't work without it. What does stopping the FSC do that makes it work without garbling the string data in the COP instructions?
 
Scarince,
Attached is a version of your sort without the FSC if you are interested.
I think the garbling of your strings relates to moving the data while you are doing the search?
Perhaps someone who uses the FSC more than I can explain?

Cheers
 
Scarince,
Attached is a version of your sort without the FSC if you are interested.

That's exactly how my "working" version of the program is running. I know there are a lot of ways to skin this cat, but I wanted to try to use FSC because I thought it might be faster. A worst-case sort would be if a newly-added part number is added near the end of the array and also has a "small" value. It takes about 40 seconds for such a number to bubble up to the top. I thought maybe FSC would be faster since I don't have to wait an entire scan to increment to the next value in the array. Hopefully I can try this out in another day or so just to see how it works. I think what I'm going to end up doing is to not allow other file operations while the sort is in progress. I'll let the operator add and remove part numbers and then I'll either trigger the sort after some period of activity or maybe provide a "Sort" PB and a progress indicator so they know why the HMI is "stuck".

I think the garbling of your strings relates to moving the data while you are doing the search?

I think so too, but I also don't know why. I agree that the answer is inside an explanation of how FSC works.

I really appreciate your help Mike...thanks!
 
Just curious, why not use the built-in SRT instruction?

That's a fair question.......my example was a little simplified. I have part numbers and I have recipes. The actual recipes are stored in a UDT that is 50 elements long and has several DINTS and STRINGs per element. The recipe number is it's element number (recipe #1 is in Recipe[1]).

The part numbers are stored in a UDT that is 500 elements long. The UDT is a STRING with a DINT. The string is the part number (they can be alpha-numeric) and the DINT stores the corresponding recipe number. I'd love to use SRT but then I lose the link between the part number and it's related recipe number.
 

Similar Topics

Maybe this is just not possible, or maybe I am doing something wrong. Background; I have a data array of over 1500 products. For sorting I...
Replies
6
Views
802
I am trying to use the FSC to count how many numbers in my real array are less than a certain value but not sure why I cant for the life of me get...
Replies
11
Views
403
I have a FSC instruction that won't enable. I check tags and data type and can't find the problem. I'm trying to pull index numbers for data...
Replies
4
Views
750
I received the following message via PM, and am posting here publicly to help others. ============================================ I had a...
Replies
10
Views
1,072
Good Morning, New poster here, i'm looking to get my FSC working for some reason it is only looking at the data in the 0 dint instead of the full...
Replies
10
Views
2,543
Back
Top Bottom