Sign in to follow this  
Followers 0
Guest Need_help

How to search array

7 posts in this topic

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!?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
An array of Bools can be indexed and compared individually using a data register as the index. Please see the attached example bit_index.pdf

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
The BON function is unfortunately limited to FX Cpu's. For the other PLC's Q, QnA, A etc, and indexed compare must be used.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

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