Sign in to follow this  
Followers 0
Sleepy Wombat

How to use XOR

9 posts in this topic

XOR = 0 0 = 0, 1 0 = 1, 0 1 = 1, 1 1 = 0 SO in code simple program the following...assuming inputs on 000.00 and 000.01 and output on 010.00 000.00 000.01 010.00 -----[ ]----------[/]-----+----( ) 000.00 000.01 | -----[/]----------[ ]-----+

Share this post


Link to post
Share on other sites
Am new to PLC. Currently working on a simple project that need to use XOR logic with OMRON CPM2A (sinking output) PLC. My intention is to directly use two inputs and 1 ouput. I have found the closest match - XORW. Tried to do it myself by directly entering 2 input port and 1 output port. What I got was a red-word XORW which means it was wrong. I was wondering probably I cannot use the I/O ports directly. Can you give me a hand? Thank you.

Share this post


Link to post
Share on other sites
Can you be more specific what you are trying to accomplish !? You can use IO words directly in the XORW instruction. Perrhaps you can post a snapshot of the instruction in your ladder? Otherwise have a look at the instruction use in the PDF. [ Logical_and_Exclusive_OR_CPM2A.pdf

Share this post


Link to post
Share on other sites
Hi kokiong, My understanding is that XORW operates on WORD, not BIT data. That is why you get error. You do not need special function to realize “Exclusive OR”. For two inputs XOR should give TRUE when one input but not both is TRUE. Make the rung logic as follows: (X1 AND NOT X2) OR (NOT X1 AND X2) = Q1 Where X1, X2 are the inputs Q1 is the output For more than two inputs XOR should give TRUE when odd number of inputs are TRUE. It is doable dough a little more complicated but I believe that is not your case since you tried to use a function that takes two input parameters. Just a tip: for every function if you look in the help there is a list with the acceptable types of the parameters Hope this helps a little

Share this post


Link to post
Share on other sites
So what was wrong with the code i posted ? Surely thats an XOR....

Share this post


Link to post
Share on other sites
It is doable, yes, but not very fun beyond 3 inputs (already there we're at 10 instructions to code the XOR). For larger XORs, I would make sure all the relevant bits are in one consecutive area of words (and all other bits in that area are reset), and then use the instruction BCNT on that range, thereafter checking if the answer is ODD (output = true) or even (output = false). Basically, I'll output the LSB from the result och BCNT'ing all the inputs.

Share this post


Link to post
Share on other sites
Hi guys, thanks for the reply. Wombat, I was thinking to use the method that you posted. There was a bit not quite right, because the inputs are not turned on at the same time. The sequence is about like this case, input 1 ON -> input 2 ON -> both OFF together after few miliseconds. Then input 2 ON -> input 1 ON -> both OFF together after few miliseconds. The output only turned ON according to eXclusive OR conditions. Probably I can add a timer, Wombat, the only problem is I have to get the 'miliseconds' accurately. Therefore, XORW function is the most convenient way. I have attached the screenshot of how I do it. Apparently I did wrong. Anatas, you are right. That was what I think of. Any idea to convert the input into words?

Share this post


Link to post
Share on other sites
Why do you think that the XWOR would work any differently to the simle logic i coded...? The main diff is that it works on a whole word or channel if you like.... I sure hope that you are not using an relay output model....

Share this post


Link to post
Share on other sites
This should work. Note that you cannot use any of the other bits of channels 40 and 41. And BTW, you haven't declared the contact to fire the instruction. If it has to be always on, use the system flag 253.13.

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