Using XOR's or OR's or AND's to simplify Logic

dbh6

Lifetime Supporting Member
Join Date
Jan 2013
Location
Central, NJ
Posts
552
Hello All,

Recently while trouble shooting some systems i came across some alarm words bits (0 through 16) and and XOR instruction used with another alarm word. Here is the XOR truth table as most of you know:

A B Output
0 0 0
0 1 1
1 0 1
1 1 0

So as an example to make an XOR useful we can use it to compare to alarm words, and if the output is set, we can declare that an alarm is present, however if you noticed on the truth table A is set to 1 and B is set to 1, but the output of that XOR is 0, so how can we make that info useful if say A & B alarms are set but the output is 0? maybe im not using this correctly so feel free to demonstrate how it can be used correctly.

Also same way a XOR can be used to simplify Logic, what others methods can be used in the same manner to simplify logic not just for alarms but anything else in general ex. OR, & AND instructions that you may have used for something specific in logic that proved useful???
 
I sometimes use an XOR to toggle the state of a bit. It's a nice clean way to do it but since it works at the word level, it can be difficult to troubleshoot. If you want to toggle O:0/3, for example, you have to XOR word O:0 with 1000b which will show up in the instruction as 8 decimal (confusing). Plus, unless you're using O:0/3 elsewhere in the program, it won't be located with a Find All search. For these reasons I use it sparingly and well-documented.
 
@koylyur if your are XORing O:0 with 1000b, the "1000b" do you mean the binary equivalent of 1000 in binary, if so when you XOR are the two variables your XORing O:0 and 8 decimal??
 
@ Tconnolly thanks, once again if their are shortcuts that you may have used to simplify logic please feel free to add.
 
@koylyur if your are XORing O:0 with 1000b, the "1000b" do you mean the binary equivalent of 1000 in binary, if so when you XOR are the two variables your XORing O:0 and 8 decimal??
Yes, the 'b' suffix denotes binary and you can enter it that way in the instruction.

Source A: O:0.0
Source B: 1000b
Destination: O:0.0

This will toggle O:0.0/3.
 
Hello All,

Recently while trouble shooting some systems i came across some alarm words bits (0 through 16) and and XOR instruction used with another alarm word. Here is the XOR truth table as most of you know:

A B Output
0 0 0
0 1 1
1 0 1
1 1 0

So as an example to make an XOR useful we can use it to compare to alarm words, and if the output is set, we can declare that an alarm is present, however if you noticed on the truth table A is set to 1 and B is set to 1, but the output of that XOR is 0, so how can we make that info useful if say A & B alarms are set but the output is 0? maybe im not using this correctly so feel free to demonstrate how it can be used correctly.

Also same way a XOR can be used to simplify Logic, what others methods can be used in the same manner to simplify logic not just for alarms but anything else in general ex. OR, & AND instructions that you may have used for something specific in logic that proved useful???

This is a really useful instruction, used alone it can work with 8, 16, or 32 alarms at a time (depending on whether the word is an SINT, and INT, or a DINT). However, use it in a FAL expression and it can work with all of the alarms in the file in one go.

You know the truth-table of XOR, you posted it, so how is it relevant to alarms ?

Let's assume your column A represent actual alarms (bits set when something is in alarm).

Let's assume column B represents a copy of the alarms (made after all the alarm processing is done by the logic).

The result column, A XOR B, tells us that the alarm conditions are different - i.e. new alarms that have just occurred, or an existing alarm condition that has gone "normal".

However, most alarm handling code would "latch" the alarm occurring, (column A in the truth table), so the XOR would not normally report alarm conditions going "OK", so the XOR is a means to tell us what NEW alarms exist. An "Alarm Reset" would clear both A and B, and the next execution of the XOR would "collect" the alarm bits that still exist.
 
Last edited:
@daba thanks , just one thing though the FAL is that a file type instruction in Allen Bradley processors?
 
@daba thanks , just one thing though the FAL is that a file type instruction in Allen Bradley processors?

Yes, FAL - File Arithmetic/Logical. Can do the same arithmetic or logical operation to all the elements in arrays.
 

Similar Topics

Going to a free training class on Tuesday. Just wondering if anyone is using this. Pros? Cons?
Replies
8
Views
2,909
Hello everyone, I'm working on a project that involves controlling an array of nozzles within a CNC environment, where the nozzles travel along a...
Replies
5
Views
128
Hi, I was noticing that Profibus connectors have 2 ports on them that can house 2 separate cables. Can I use 2 cables with Profibus signals...
Replies
4
Views
132
Hi, Seeking consultation on an implementation matter, and have a question about Modicon Compact 984 communication through RS485: Three Modicon...
Replies
3
Views
94
Dear all, I don't know why setup of password became challenging and weird. After setting up the password and try to upload the ladder from the plc...
Replies
3
Views
93
Back
Top Bottom