Let's take the simple lines of code to test non-equality of two items and the results of the conditional branch
TSTNE A B
GOTO NOTSAME
SAME:
do some stuff...
NOTSAME:
do some other stuff...
Now the TSTNE usually performs the usual mental, behind the scenes, subtraction of the two quantities like this:
A - B = ?
If equal, then A-B = 0, and the zero bit should be set, from the result, indicating that, right?
Right! But it is inverted to what we need and the test is for NOT equality so we have to invert the zero bit..
Our zero bit for each case becomes:
A == B , zero bit = 0 (false)
A =/= B, zero bit = 1 (true)
Like all TSTxx PLC code lines, the zero bit indicates "the result of the expression tested is true" and if true executes the next line:
GOTO NOTSAME
resulting in a branch of execution in the PLC code. in this case.
Similarly if the result of doing the NOT (A - B = 0) mental math is false (They happen to be equal) then the ELSE condition happens with the Zero bit 0. All that means is the PLC code skips the next TRUE line after the TSTNE and executes:
SAME:
do some stuff.....
TSTEQ
----------
You may have guessed by now that the TSTEQ performs exactly the same mental subtraction of the two operands except without the Zero Bit result being inverted.
TSTNE A B
GOTO NOTSAME
SAME:
do some stuff...
NOTSAME:
do some other stuff...
Now the TSTNE usually performs the usual mental, behind the scenes, subtraction of the two quantities like this:
A - B = ?
If equal, then A-B = 0, and the zero bit should be set, from the result, indicating that, right?
Right! But it is inverted to what we need and the test is for NOT equality so we have to invert the zero bit..
Our zero bit for each case becomes:
A == B , zero bit = 0 (false)
A =/= B, zero bit = 1 (true)
Like all TSTxx PLC code lines, the zero bit indicates "the result of the expression tested is true" and if true executes the next line:
GOTO NOTSAME
resulting in a branch of execution in the PLC code. in this case.
Similarly if the result of doing the NOT (A - B = 0) mental math is false (They happen to be equal) then the ELSE condition happens with the Zero bit 0. All that means is the PLC code skips the next TRUE line after the TSTNE and executes:
SAME:
do some stuff.....
TSTEQ
----------
You may have guessed by now that the TSTEQ performs exactly the same mental subtraction of the two operands except without the Zero Bit result being inverted.