Dumb question on PLC program operation.

Yes, you can use ANDB to check if certain flag position is set, then use XORB to toggle that bit.

If you only wanted to ensure the bit is on (or off) you don't need to test anything, just ANDB (to turn off) or ORB (to turn on). No test required.
 
It is not easy or hard for C compiler to do. To the user, it is how easy to be present in PLC logic and how much trouble can be reduced for users.
I am trying to understand what you try to accomplish that new method you proposed would help. Sorry for being slow.

OK, A small fragment of real-world code.
Because I don't have enough *registers*, I most registers store more than one thing. Here, VAR5 holds my "desired" position in the upper-4 digits, and the "actual" position in the lower 4 digits. (so xx,xxy,yyy where 'x' is desired, and 'y' is actual).
I need to jump through hoops to extract or adjust either:

Code:
	    div var5 10000 ram1	 # extract "desired" position
	    mul ram1 10000 ram3	 # Need actual position shortly, so save for later
	    sub var5 ram3 ram2	  # ram3 has desired position, ram2 has actual position.

							    # now check limit switches
	    tsteq ip3 1			 # East limit active?
	    set ram2 0			  # we are now fully east
	    tsteq ip4 1			 # West limit active?
	    set ram2 var2		   # Fully west
	    add ram3 ram2 var5	  # update desired and actual positions

   (do various stuff here)

	    tstlt ram1 ram2 op1	 # is required position LESS than actual? If so turn ON east
	    dec var5			    # and adjust actual postition counter

	    tstgt ram1 ram2 op2	 # is required position MORE than actual?  If so turn ON west
	    inc var5			    # and adjust actual position counter

Or here, all I want to do is set the "required" position to be mid-travel... (full travel is stored in VAR2)
Code:
	    div var5 10000 ram2	 # get actual position
	    mul ram2 10000 ram2
	    sub var5 ram2 var5	  # removed all except current actual position
	    mul var2 5000 ram2	  # get half total travel time, and shift left 4 decades  (divide by 2, multiply by 10000)
	    add var5 ram2 var5	  # Leave actual position as is.
 
could all be replaced with

	   div var2 2 word9    # set required position to midpoint


Out of context, that probably looks unnecessarily convoluted, but it IS necessary!
 
If you are not using decimal, but binary/hex then it may be faster, with the new ANDB/ORB/XORB functions.
ANDB 255 will directly get last 8 bits,
DIV 255 then ANDB 255 will get 2nd 8 bits
DIV 65535 then ANDB 255 will get 3rd 8 bits.
...
Internally, each VAR has its associated timer value. RAM does not have timer value. To get to those bytes, we will need to introduce four additional variable names for each RAM, so that it will introduce 32 additional variables. Then internally declear internal variables and copy contents for operation. That is probably not much faster than above ANDB 255 method.

In few versions back, we added UROM1...4 read only variable, that is only settable through web GUI. Have you tried to use those to reduce some of your desireable value calculation? We did not make them to be PLC settable, because the EEPROM chip spec has very limited write cycles - easily worn out within a day, if there was a mistake in the PLC code. Those could be helpful, if you have a system need to be fine tuned during setup.
 
Another dumb question
Code:
TSTEQ TS1 1 
BZ  TEMPERR
Where will the code take me if the temp sensor has failed? As it stands with fail clearly displayed, it skips and goes to the next line. If I change it to a BNZ and test for 0 it works as intended. ???????? I'm missing or not correctly understanding something here.
 
TSx is temperature sensor status. It should have value 1 when it is okay, or zero when it is failed. If it is failed, TS1 is 0, so that it should skip next instruction. My understanding is that any TSTxy when result is false, it will skip next line.
 
True, however the instructions state that the BZ and BNZ can be used after it. If in fact the result is a zero and the next line is skipped, when do I get to use a BZ?
Example 6.4.6

START
BNZ IP1 start
l1:
TSTEQ IP1 1
BZ l1
SET OP1 1
SET OP4 0
So if the next line is skipped if the result is a 0 then in the example above BZ 11 and NOP would actually amount to the same thing?
I do know with ANDB ORB etc the BZ will work as advertised.
 
Back
Top