Simple program to switch on relays

Should that only to bitwise operator or to all AND/OR/XOR?
Also, after change, if user just want to store a bit to a variable, they must add
NOP
if the bit was zero. Otherwise, it will be skipped. 
In case the bit is changing and programmer does not know the bit value before hand, then it will need always add
NOP
to prevent skip next logic.
 
Maybe the better way is to add additional PLC command that can skip.
We can add more PLC commands, since that does not require using additional RAM.
Please let us know how many commands would be helpful and suggestion of their unique names.
 
Yes that is what he suggested.  Leave the bitwise commands alone and add:
 
TANDB
TORB
TXORB
TOR
TAND
TXOR
 
and make ZB or ZBIT a variable referencing the zero bit
 
CAI_Support said:
Thanks for your suggestion.  What the 'T' stand for?  just for easier to document.
 
This is what I meant.  Leave the current bitwise operations alone.  Add new ones.
 
TSTANDB
TSTORB
TSTXORB
 
or, 
 
TANDB
TORB
TXORB
 
The "T" or "TST" stand for "test".  They would function the same as TSTEQ, TSTGT, etc.  where a true result executes the next line and a false result skips.
 
az1324 said:
Also, it would be potentially useful to have the zero bit as an operand
 
ANDB RAM1 RAM2
SET RAM3 ZB
 
Tell me if I am wrong, since I have never used the "logical AND", etc.
 
But, wouldn't this give you the same result
 
AND RAM1 RAM2 RAM3
 
?
 
Say you had RAM1=1 and RAM2=2.  ANDB would give 0.  AND would give 1.  ZB from ANDB would be 0.
 
Say you had RAM1=1 and RAM2=3.  ANDB would give 2.  AND would give 1.  ZB from ANDB would be 1.
 
So having ZB as a variable allows you to use the logical result of a bitwise function.  Can be useful.
 
Lou Apo said:
Let me think about this.  I would rather have it switch at the 15 minute mark.  
 
Also, try deleting the middle line (ANDB RAM1 3).  I think the zero bit should not need to be set again.
 
CZ RESET                            * if neither flag set (zero bit 0), shuts off relays
ANDB RAM1 3                      * tests if either of above flags set, might not be needed, depends if "x10" changes 0 bit
CNZ RELAY                          * if either flag set (zero bit not 0), runs the relay sub
Hi,
I removed line ANDB RAM1 3 and the OP1 and OP2 are switching more or less 15min 15sec after the hour..
 
laodice said:
Hi,
I removed line ANDB RAM1 3 and the OP1 and OP2 are switching more or less 15min 15sec after the hour..
 
OK, well then setting x10 devices does not affect the zero bit.  But this shouldn't have anything to do with the timing of the relays switching.  There is basically a 60 second timer that only lets the code that switches the relays run once per minute.  The timer starts when the unit first boots, so if you boot it 15 seconds after the minute, then it will stay on that schedule.
 
I think this will make it always run on the minute by adding 2 lines.
 
START
TSTLT CYEAR 2013             * waits for clock to bet set before proceeding
GOTO START
TSTNE CS 0              *** add this line       
GOTO START          ***  add this line
SET RAM2 CTS
 
az1324 said:
Say you had RAM1=1 and RAM2=2.  ANDB would give 0.  AND would give 1.  ZB from ANDB would be 0.
 
Say you had RAM1=1 and RAM2=3.  ANDB would give 2.  AND would give 1.  ZB from ANDB would be 1.
 
So having ZB as a variable allows you to use the logical result of a bitwise function.  Can be useful.
 
So, tell me if I am correct.
 
Logical AND, OR, XOR looks at a 0 as false and non-zero as true?  The result of any of the three would be either true or false (1 or 0) and that would be the only two possibilities for the result?
 
using the symbols
NZ for non-zero number (I assume this includes negative numbers)
Z for zero
 
Where you use the following format
operator RAM1 RAM2 RAM3
 
AND
results
RAM1=NZ RAM2=NZ RAM3 = 1
RAM1=Z   RAM2=Z   RAM3 = 1
RAM1=NZ RAM2=Z  RAM3 = 0
RAM1=Z  RAM2=NZ RAM3 = 0
 
OR
results
RAM1=NZ RAM2=NZ RAM3 = 1
RAM1=Z RAM2=Z RAM3 = 0
RAM1=NZ RAM2=Z  RAM3 =1
RAM1=Z RAM2=NZ RAM3 = 1
 
XOR
results
RAM1=NZ RAM2=NZ RAM3 = 0
RAM1=Z RAM2=Z RAM3 = 0
RAM1=NZ RAM2=Z RAM3 = 1
RAM1=Z RAM2=NZ RAM3 = 1
 
AND
results
RAM1=NZ RAM2=NZ RAM3 = 1
RAM1=Z   RAM2=Z   RAM3 = 0
RAM1=NZ RAM2=Z  RAM3 = 0
RAM1=Z  RAM2=NZ RAM3 = 0
 
Hi,
 
I tried to understand the codes and adapted them to:
-Check day and night  if the door is open (IP=0) and if so send an email and set OP3 high (siren) for about 45 sec: this works but not always between 21h and 22h
 
-Between 21h and 22h switch OP1 and OP2 on and off every 20 minutes: this works fine
 
-Between 22h and 23h switch on and of two X10 devices every 15 minutes this works but not restricted to this period
 
-IP8 controls the on and off of the whole system
 
 
START   
            CALLSUB INIT_OUT  
 
            SET RAM2 CTS                   
 
LOOP:
            TSTEQ CH 21 
            CALLSUB RELAY  
            TSTLE CH 20 
            CALLSUB RESET  
            TSTGE CH 22 
            CALLSUB RESET  
 
 
TSTLT CTS RAM2              
GOTO LOOP
ADD RAM2 60 RAM2           
SET RAM3 0                        
TSTGE CH 22              
ORB RAM2 3 RAM3            
TSTLT CH 23                
ORB RAM1 2 RAM3            
ANDB RAM3 3                     
CZ RESET1                           
ANDB RAM3 3                     
CNZ RELAY2                         
 
 
 
 
            CALLSUB CHECK_DIS  
            TSTEQ VAR1 0 
            CALLSUB DOORS  
            TSTEQ OP3 1 
            CALLSUB DISAB_ALM  
            GOTO LOOP  
            END   
 
INIT_OUT:
            SET OP3 0 
            SET OP1 0 
            SET OP2 0 
            SET VAR1 0 
            RET   
 
CHECK_DIS:
            TSTEQ IP8 0 
            DELAY 50  
            TSTEQ IP8 0 
            SET VAR1 1 
            TSTEQ IP8 1 
            SET VAR1 0 
            RET   
 
DISAB_ALM:
            DELAY 60000  
            SET OP3 0 
            DELAY 100  
            RET   
 
DOORS:
            TSTEQ IP1[100] 0 
            CALLSUB ALARM  
            RET   
 
ALARM:
            SET OP3 1 
            EMAIL EM1  
            RET   
 
RELAY:
            DIV CTS 1200 RAM1
            ANDB RAM1 1 
            BZ  RELAY1 
            SET OP1 0 
            DELAY 5000  
            SET OP2 1 
            RET   
 
RELAY1:
            SET OP2 0 
            DELAY 5000  
            SET OP1 1 
            RET   
 
RESET:
            SET OP1 0 
            SET OP2 0 
            RET
 
RELAY2:
DIV CTS 900 RAM2         
ANDB RAM2 1                 
BZ RELAY3                      
X10 2 0 0             
X10 1 0 1               
RET
RELAY3:
X10 2 0 1
X10 1 0 0
RET
 
RESET1:
X10 2 0 0
X10 1 0 0
RET
 
After looking at this a bit, I found some problems.  I really didn't follow the logic all the way to conclusion however.
 
Code:
START   
CALLSUB INIT_OUT       $$$ this subroutine is not needed.  OP’s are 0 at boot unless you manually click “save state”
SET RAM2 CTS                   
 
LOOP:
TSTEQ CH 21 
CALLSUB RELAY  
TSTLE CH 20             $$$ change to TSTNE CH 21
CALLSUB RESET  
TSTGE CH 22            $$$ delete
CALLSUB RESET      $$$ delete
TSTLT CTS RAM2              
GOTO LOOP
ADD RAM2 60 RAM2           
SET RAM3 0                        
TSTGE CH 22              
ORB RAM2 3 RAM3         $$$RAM2 is CTS plus 60, did you mean ORB RAM3 1 RAM3?
TSTLT CH 23                
ORB RAM1 2 RAM3         $$$ Did you mean ORB RAM3 2 RAM3?  All of this could be replaced with TSTEQ CH 22
ANDB RAM3 3                     
CZ RESET1                           
ANDB RAM3 3                     
CNZ RELAY2                         
CALLSUB CHECK_DIS  
TSTEQ VAR1 0 
CALLSUB DOORS  
TSTEQ OP3 1 
CALLSUB DISAB_ALM  
GOTO LOOP  
END   
 
INIT_OUT:		Delete this.  Move set VAR1 0 up where the subroutine call is
SET OP3 0
SET OP1 0 
SET OP2 0 
SET VAR1 0 
RET   
 
CHECK_DIS:
TSTEQ IP8 0 
DELAY 50             
TSTEQ IP8 0 
SET VAR1 1 
TSTEQ IP8 1 
SET VAR1 0 
RET   
 
DISAB_ALM:
DELAY 60000      $$$this is going to lock up the program for 60 seconds
SET OP3 0 
DELAY 100  
RET   
 
DOORS:
TSTEQ IP1[100] 0 
CALLSUB ALARM  
RET   
 
ALARM:
SET OP3 1 
EMAIL EM1  
RET   
 
RELAY:
DIV CTS 1200 RAM1
ANDB RAM1 1 
BZ  RELAY1 
SET OP1 0 
DELAY 5000       $$$ why do you need this, this locks up the program for 5 seconds
SET OP2 1 
RET   
 
RELAY1:
SET OP2 0 
DELAY 5000     $$$ why do you need
SET OP1 1 
RET   
 
RESET:
SET OP1 0 
SET OP2 0 
RET
 
RELAY2:
DIV CTS 900 RAM2         
ANDB RAM2 1                 
BZ RELAY3                      
X10 2 0 0             
X10 1 0 1               
RET
RELAY3:
X10 2 0 1
X10 1 0 0
RET
 
RESET1:
X10 2 0 0
X10 1 0 0
RET
 
I used the DELAY code to keep the siren working for one minute.
Would it be better to use “SET OP3[60000] 1” instead of DELAY60000
 
Back
Top