You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old November 25th, 2017, 10:32 PM   #1
anthony.v3a
Member
United States

anthony.v3a is offline
 
Join Date: May 2016
Location: Bakersfield
Posts: 16
Array searching and inserting data to first available space

How would I search an array of 52 SINTs for an available space (0) then move a (1) into the first available space?
  Reply With Quote
Old November 25th, 2017, 10:48 PM   #2
Bullzi
Lifetime Supporting Member
United States

Bullzi is offline
 
Join Date: Jun 2012
Location: Colorado
Posts: 1,235
What PLC are you using? Very important detail.
__________________
There is never enough money to do it right but there is always enough money to do it again.
  Reply With Quote
Old November 25th, 2017, 10:59 PM   #3
anthony.v3a
Member
United States

anthony.v3a is offline
 
Join Date: May 2016
Location: Bakersfield
Posts: 16
AB 1756-L72 Version 21. Studio 5000. Haven't found the right combination of anything in the Instruction Reference Manual.
  Reply With Quote
Old November 25th, 2017, 11:09 PM   #4
Bullzi
Lifetime Supporting Member
United States

Bullzi is offline
 
Join Date: Jun 2012
Location: Colorado
Posts: 1,235
Look at the File Search and Compare (FSC) Instruction.
You can have that instruction search your array for a 0 (or just about anything). It will return the fist location that it finds that meets your search criteria. You can then write something into that location.
__________________
There is never enough money to do it right but there is always enough money to do it again.

Last edited by Bullzi; November 25th, 2017 at 11:15 PM.
  Reply With Quote
Old December 4th, 2017, 09:42 PM   #5
anthony.v3a
Member
United States

anthony.v3a is offline
 
Join Date: May 2016
Location: Bakersfield
Posts: 16
This seems to work, although I am having some difficulty setting it up properly, everything says that I need to RES the FD or IN bits but when I write the CONTROL.IN bit in the RES instruction I get an ERROR, invalid data type. The only resetting in the RES instruction that doesn't cause an ERROR is just the CONTROL data type. How do I just reset the .DN or .IN bits?
  Reply With Quote
Old December 4th, 2017, 10:01 PM   #6
ASF
Lifetime Supporting Member
Australia

ASF is offline
 
Join Date: Jun 2012
Location: Australia
Posts: 2,550
If you reset the FSC instruction (by addressing a RES command to the Control tag of the FSC instruction), it will reset the .FD and .DN bits as a part of the reset.

You can also turn off the .FD and .IN bits with an OTU instruction, if you wish - an example of where you might do this is if your FSC finds a match, but you want it to continue searching the array for more matches. In that case you'd unlatch the .FD bit, and next time around it would continue from where it left off.

Last edited by ASF; December 4th, 2017 at 10:09 PM.
  Reply With Quote
Old December 4th, 2017, 10:03 PM   #7
Bullzi
Lifetime Supporting Member
United States

Bullzi is offline
 
Join Date: Jun 2012
Location: Colorado
Posts: 1,235
Try using the unlatch OTU instruction (U)? (RES) will clear out the .POS memory but wont reset the .IN bit.
If you want to post your code you can just make sure to zip it first.

EDIT: ASF is a faster than me
__________________
There is never enough money to do it right but there is always enough money to do it again.
  Reply With Quote
Old December 4th, 2017, 11:20 PM   #8
anthony.v3a
Member
United States

anthony.v3a is offline
 
Join Date: May 2016
Location: Bakersfield
Posts: 16
Ok, that makes sense. I would try the unlatch if I needed it to continue to search. What I'm trying to do is have it find the first available space in the array then MOV a 1 into it. After, RES the CONTROL tag for the next search. The problem I'm coming across is that it will fill the first two available places in the array but will then take 3 or 4 search attempts to fill in the next place. I'm wondering if it has to do with my ONS's. Also, I have it set to INCREMENTAL. Not sure if I should be using the ALL mode. I may attempt to upload the code.

Thanks guys
  Reply With Quote
Old December 5th, 2017, 01:52 AM   #9
anthony.v3a
Member
United States

anthony.v3a is offline
 
Join Date: May 2016
Location: Bakersfield
Posts: 16
I attached two pictures of what I have. When I toggle either BMB(1 or 2)_eye I'd like for the FSC to find the first available place in the SPACE[52] array, up to 12 places, with a 0 then MOV a 1 to the space and so on when the next BMB(1 or 2)_eye is toggled.
Attached Images
File Type: jpg FSC.jpg (27.9 KB, 23 views)
File Type: png SPACE_ARRAY.PNG (28.9 KB, 17 views)
  Reply With Quote
Old December 5th, 2017, 04:22 AM   #10
daba
Lifetime Supporting Member + Moderator
United Kingdom

daba is offline
 
daba's Avatar
 
Join Date: Jul 2004
Location: uk
Posts: 4,341
Quote:
Originally Posted by anthony.v3a View Post
I attached two pictures of what I have. When I toggle either BMB(1 or 2)_eye I'd like for the FSC to find the first available place in the SPACE[52] array, up to 12 places, with a 0 then MOV a 1 to the space and so on when the next BMB(1 or 2)_eye is toggled.
Looks ok to me.....

Any reason you are using a SINT array ?

Are you assuming it is more "efficient" because you only need to store 0 and 1 values ?

The controller has a 32-bit architecture, so works most efficiently with DINTs. I'll try to set up a test to see how much using SINT arrays knocks the performance.

Talking about efficiency, OTL SPACE[FIND_AVAILABLE_SPACE.POS].0 will be more efficient than the MOV 1, but is less transparent to a casual observer of the code. Properly documented should be OK.

I presume something else is "unloading" the 1's in the array.... Have you thought about what would need to happen if one of the cells was triggered and there ware no spaces available in the array ?
__________________
___________________________
ControlLogix & SLC Training
a-b train ltd.
abtrain@tiscali.co.uk
www.abtrain.co.uk
tel: 07506 73 9999
nil illegitimi carborundem


  Reply With Quote
Old December 5th, 2017, 06:10 AM   #11
cwal61
Member
United States

cwal61 is offline
 
Join Date: Jan 2011
Location: NC
Posts: 946
Quote:
Originally Posted by Bullzi View Post
Try using the unlatch OTU instruction (U)? (RES) will clear out the .POS memory but wont reset the .IN bit.
This is not a true statement the (RES) instruction resets all bits of the instruction.
  Reply With Quote
Old December 5th, 2017, 07:51 AM   #12
cwal61
Member
United States

cwal61 is offline
 
Join Date: Jan 2011
Location: NC
Posts: 946
Quote:
Originally Posted by anthony.v3a View Post
When I toggle either BMB(1 or 2)_eye I'd like for the FSC to find the first available place in the SPACE[52] array, up to 12 places, with a 0 then MOV a 1 to the space and so on when the next BMB(1 or 2)_eye is toggled.
If I understand your task then you need something like this. I have included an exported subroutine of the logic. This is uses indirect addressing with an equation to find and write to the correct locations. Good Luck with your project.

FSC FIND.jpg
Attached Files
File Type: zip FSC_FIND.zip (1.5 KB, 1 views)
  Reply With Quote
Old December 5th, 2017, 08:54 AM   #13
cwal61
Member
United States

cwal61 is offline
 
Join Date: Jan 2011
Location: NC
Posts: 946
If you need to Fill all 52 SINT then you could do this to manage the overflow.
Attached Images
File Type: jpg FSC Fill 52.jpg (34.1 KB, 105 views)
  Reply With Quote
Old December 5th, 2017, 09:19 AM   #14
Doug-P
Member
United States

Doug-P is offline
 
Doug-P's Avatar
 
Join Date: Jun 2003
Location: Pa
Posts: 1,243
Quote:
Originally Posted by anthony.v3a View Post
How would I search an array of 52 SINTs for an available space (0) then move a (1) into the first available space?
A question from left field. If you're only dealing with '1' and '0' would a bit array not work as well?
__________________
Let's eat Grandma!

Let's eat, Grandma!

Words are very important, but punctuation saves lives...
  Reply With Quote
Old December 5th, 2017, 10:08 AM   #15
Bullzi
Lifetime Supporting Member
United States

Bullzi is offline
 
Join Date: Jun 2012
Location: Colorado
Posts: 1,235
Quote:
Originally Posted by cwal61 View Post
This is not a true statement the (RES) instruction resets all bits of the instruction.
Yea I should have been more clear and said that the RES will not reset the .in bit by itself, it resets the whole control word.
__________________
There is never enough money to do it right but there is always enough money to do it again.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:45 PM.


.