Jump to content

How to search array


Recommended Posts

Guest Need_help
Posted
Hello, I'm trying to search through an array of BOOL, for each element I need to see if it 1 or 0, if it is 1 one thing should happend and if it's 0 another thing should happen. It won't work, I have tried 100 ways, Is there anyone out there who have any good tips about this so please answer!?

Posted
I hope the "one thing" and the "another thing" are similar for each bit in the array. In this case all you need is the indexed condition bit within FOR-NEXT loop. Unfortunately, Mitsubishi does not support indexed bit contacts. There is, however, a trick. After performing the instruction MOV K1M0Z K1M100, the contact M100 becomes an equivalent of contact M0Z (not supported by Mitsubishi PLC). The number 100 is for example only, your number will vary. Note, that the instruction above will affect 4 consecutive bits started from M100.
Posted
Another way is to use the BON (bit on) instruction. Example: (This will check 100 bits starting at M0) LD M8000 RST Z ;initialize Z index to 0. FOR K100 ;number of bits to check. LD M8000 BON K1M0Z M100 K0 ;current bit being checked is moved into M100. INC Z LD M100 ;Do whatever you wish if M0 plus index is true. LDI M100 ;Do whatever you wish if M0 plus index is false. NEXT The advantage is that only 1 destination bit is affected rather than the 4 used by Sergei's method. The disadvantage is that BON is slowwwww.... Personally, I'd opt for Sergei's MOV suggestion. Jim Rowell
Posted (edited)
Jim, I actually offered a way acceptable for any Mitsu PLC, even FX0 and FX1. These ones do not support BON instruction. Concerning 4 bits affected- this is not a problem, since these are the same 4 bits for each comparison. Navillusi, For which PLC this example is written? Edited by Sergei Troizky
Posted
Sergei, I agree with you 100%. Actually, 110%. As I said in my post, I'd use your suggestion of MOV myself. I was simply mentioning the BON method as an alternative more out of interest than anything else. It could prove useful in the odd situation such as if you were stuck with a section of memory where you couldn't spare 4 bits. I admit that's about as likely as world peace, or me retiring before the next millenium. I suspect that Mitsubishi's designers intended the BON instruction to be the one used in this situation (otherwise why even put it in) but MOV is just as effective and much faster. And as you mention, it works on all models. Jim Rowell

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...