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,991
I have a project to automate four generator sets. The system will monitor and store the load demand of the factory. Once there's Power outage, the...
Replies
0
Views
64
Adding ethernet equipment to an existing panel that has none. We have some solid ethernet cables coming from other remote cabinets that I plan to...
Replies
3
Views
124
I'm trying to control a device via MODBUS RTU and the ModbusRtuMasterV2_PcCOM in Twincat 3. I've configured a device with the right com port and...
Replies
7
Views
222
Hi, I'm trying to use the IO Device Library (Product Versions) which is configured to work with the 1756-EN4TR & 1756-EN2TR but my system uses...
Replies
0
Views
60
Back
Top Bottom