Guest Need_help Posted April 19, 2004 Report Posted April 19, 2004 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!? Quote
Sergei Troizky Posted April 19, 2004 Report Posted April 19, 2004 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. Quote
navillusi Posted April 20, 2004 Report Posted April 20, 2004 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 Quote
JimRowell Posted April 21, 2004 Report Posted April 21, 2004 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 Quote
navillusi Posted April 21, 2004 Report Posted April 21, 2004 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. Quote
Sergei Troizky Posted April 21, 2004 Report Posted April 21, 2004 (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 April 21, 2004 by Sergei Troizky Quote
JimRowell Posted April 22, 2004 Report Posted April 22, 2004 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 Quote
Recommended Posts
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.