Simple program to switch on relays

az1324 said:
Oh that's unfortunate you cannot pass a reference to the X10 function.  CAI please fix.
 
 
START
TSTLT CYEAR 2013
GOTO START
TSTLT CH 20
TSTGE CH 6
SET RAM1 0
CZ GETSCH
CALLSUB XTEN
AND 1 RAM1 OP1  //optionally set OP1
AND 2 RAM1 OP2  //optionally set OP2
END
 
GETSCH:
DIV CM 15 RAM1    //swap every 15 min
AND RAM1 1 RAM1
ADD 1 RAM1 RAM1
RET
 
XTEN:
MOD CM 5    //send every 5 minutes
BZ XTENTX
ANDB 0xFFFFFFF7 VAR1 VAR1
RET
XTENTX:
AND 1 VAR1
BNZ DONE
AND RAM1 1 RAM2
TSTEQ 0 RAM2
X10 2 0 OFF
TSTEQ 1 RAM2
X10 2 0 ON
AND RAM1 2 RAM2
TSTEQ 0 RAM2
X10 2 1 OFF
TSTEQ 1 RAM2
X10 2 1 ON
ORB VAR1 1 VAR1
DONE:
RET
Still a problem:
Both OP1 and OP2 stay high
Both X10 2 0 and X10 2 1 stay high too
 
TST and SET all update the zero bit.  If user need to jump in next instruction if based on value, then it will only need to check zero bit.
 
In the manual it does not mention that SET updates the zero bit even though all the other instructions that do explicitly state so.

It really should not be updating the zero bit because

SET a b
BZ

with the zero bit is the same as

SET a b
BZ b

but you lose the ability to carry over the zero bit from the previous operation which would be quite useful.
 
Then BZ will require to have two parameters.  If anyone had already written PLC code, BZ, BNZ, CZ and CNZ will all need to have two parameters.
That is easy to change in our firmware, simply not set zero bit.
 
That is understandable, however since it is not documented and it is somewhat obscure from a logical perspective I don't think there will be many cases where it is being used.  Just something to consider for the next update.
 
az1324 said:
That is understandable, however since it is not documented and it is somewhat obscure from a logical perspective I don't think there will be many cases where it is being used.  Just something to consider for the next update.
 
I agree.  I did not know that "SET" sets the zero bit.  I just read this and changed the order of 2 lines so a "SET" command would not alter my zero bit for a second consecutive zero bit command.
 
The below is not tested, but the logic seems good.  It will only allow the x10 setting subroutines to happen once per minute (can be altered in line 6).  This prevents flooding the house wire with x10 signals but still give you plenty of repeats just in case an x10 signal is lost.  It will always put the relays into the same on/off status at any given 15 minute block no matter when the unit is powered on.  CTS divided by 15 minutes will always be even at the top of every hour and stay even (with a remainder which is ignored) until 15 minutes past the hour.  The same holds true at the bottom of the hour.
 
 
START
TSTLT CYEAR 2013             * waits for clock to bet set before proceeding
GOTO START
SET RAM2 CTS                    * sets ram2 to current total seconds at startup
LOOP:
TSTLT CTS RAM2               * program loops until cts catches up to ram2 (60 seconds here)
GOTO LOOP
ADD RAM2 60 RAM2            * pushes ram2 60 seconds into future
SET RAM1 0                         *  clears ram1 so first 2 bits can be flags
TSTGE CH 20              
ORB RAM1 1 RAM1              * sets first flag if after 20 hours
TSTLT CH 6                
ORB RAM1 2 RAM1             * sets second flag if before 6 hours
ANDB RAM1 3                      * tests if either of above flags set
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
GOTO LOOP
END
 
RELAY:
DIV CTS 900 RAM1           *divides cts by 15 minutes (60 seconds time 15)
ANDB RAM1 1                   * checks if above is even or odd
BZ RELAY1                        * if even, branches, if odd it finishes this subroutine
X10 0 0 OFF              * sets x10 A1 off
X10 0 1 ON                * sets x10 A2 on
RET
 
RELAY1:
X10 0 0 ON
X10 0 1 OFF
RET
 
RESET:
X10 0 0 OFF
X10 0 1 OFF
RET
 
We uploaded a test gui library on his board that removed X10 parameter checking. Theoretically, he could use variables for X10 command in PLC on his board now.  We will see how that test out.
 
Hi Lou Apo,
 
Thans for all your research
 
Tried to upload the routine but got an error: PLC error line20: invalid number of operands for opcode SET
 
Meanwhile my gui is uploaded so that the X10 commands accept variables  as VAR1
 
Code:
START
TSTLT CYEAR 2013
GOTO START
TSTLT CH 20
TSTLT CH 6
GOTO GETSCH
SET RAM1 0
RESUME:
CALLSUB XTEN
ANDB 1 RAM1 OP1  //optionally set OP1
DIV RAM1 2 RAM1 //optionally set OP2
ANDB 1 RAM1 OP2  //optionally set OP2
END
 
GETSCH:
DIV CM 15 RAM1    //swap every 15 min
ANDB RAM1 1 RAM1
ADD 1 RAM1 RAM1
GOTO RESUME
 
XTEN:
MOD CM 5    //send every 5 minutes
BZ XTENTX
ANDB 0xFFFFFFF7 VAR1 VAR1
RET
XTENTX:
ANDB 1 VAR1
BNZ DONE
ANDB RAM1 1 RAM2
X10 2 0 RAM2
ANDB RAM1 2 RAM2
DIV RAM1 2
X10 2 1 RAM2
ORB VAR1 1 VAR1
DONE:
RET
 
laodice said:
Hi Lou Apo,
 
Thans for all your research
 
Tried to upload the routine but got an error: PLC error line20: invalid number of operands for opcode SET
 
Meanwhile my gui is uploaded so that the X10 commands accept variables  as VAR1
 
Try copying and pasting again.  There are no "set" commands anywhere in that region of the program.
 
laodice,
 
Please make sure the PLC code you pasted into WebControl PLC window exactly match what it displayed when you refresh the PLC window. If not, please let us know where the differences.  Since we put a test GUI library on your board yesterday, I want to make sure there is no mismatch between your firmware and GUI library version.
 
I uploaded the test PLC code of Lou Apo.
The controller refused the ON and OFF command in X10 line.
When I changed it in 1 and 0 the code got accepted.
For the moment I have only one X10 receiver listening to house code 2 and  device code 0 (not one with device code 1)
I understand the controller  should swap from device 0 to 1 and my receiver (listening to houscode2 device code0) should be on for 15 minutes and then off for 15 minutes but he stays all the time on.
 
Okay, so you don't have the SET error any more?
When we updated your GUI library, your computer may still cached older version.  When you reload the screen, the new one will work.
Your new library does not check the X10 parameter, nor substitute ON and OFF to 1 and 0, because it takes VAR and RAM now.
 
 
The problem now you describing is the PLC logic.  Are you using the last post by Dr. Lou?
 
Back
Top