Simple program to switch on relays

Lou Apo said:
This should swap the relays every 15 minutes.  This is a very generic program in that you could very easily swap out the numbers in the 3 lines with ** to make the program work on different times and intervals.  It also can't get messed up by changes to the clock or someone manually changing things.  It will immediately correct itself.  Again, I haven't tested, so no promises.
 
START
TSTGE CH 20              **  first 4 lines set the first and second bits to 1 if they are true
ORB RAM1 1 RAM1
TSTLT CH 6                 **
ORB RAM1 2 RAM1
TSTNE RAM1 3               first and second bits both true is 3
CALLSUB RESET
TSTEQ RAM1 3
CALLSUB RELAY
SET RAM1 0
END
 
RELAY:
DIV CTS 900 RAM1    **  substitute for 900 how many seconds you want between relay swaps.  900 for 15 minutes
ANDB RAM1 1        
BZ RELAY1        
SET OP1 0
SET OP2 1
RET
 
RELAY1:
SET OP1 1
SET OP2 0
RET
 
RESET:
SET OP1 0
SET OP2 0
RET
Hi,
I have just uploaded this program in the CAI controller and OP1 and OP2 stay 0.
I can’t even change them manually in the output control
 
laodice said:
Hi,
I have just uploaded this program in the CAI controller and OP1 and OP2 stay 0.
I can’t even change them manually in the output control
 
Two possibilities
 
1) You copied in the program before I did the edit on line 2 and 4 changing ORB RAM1 1   to   ORB RAM1 1 RAM1  and ORB RAM1 2  to ORB RAM1 2 RAM1
2) It is not between the hours of 20 and 6.  From 20 to 6, it shuts them off.
 
START
TSTLT CYEAR 2013
GOTO START
TSTLT CH 20
TSTGE CH 6
SET RAM1 0
CZ GETSCH
CALLSUB XTEN
END
 
GETSCH:
DIV CM 15 RAM1    //swap every 15 min
AND RAM1 1 RAM1
ROTL 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
X10 2 0 RAM2
AND RAM1 2 RAM2
X10 2 1 RAM2
ORB VAR1 1 VAR1
DONE:
RET
 
az1324 said:
START
TSTLT CYEAR 2013
GOTO START
TSTLT CH 20
TSTGE CH 6
SET RAM1 0
CZ GETSCH
CALLSUB XTEN
END
 
GETSCH:
DIV CM 15 RAM1    //swap every 15 min
AND RAM1 1 RAM1
ROTL 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
X10 2 0 RAM2
AND RAM1 2 RAM2
X10 2 1 RAM2
ORB VAR1 1 VAR1
DONE:
RET
Thanks,
Got a reply from the CAI controller that ROTL is an  invalid opcode
 
Lou Apo said:
Two possibilities
 
1) You copied in the program before I did the edit on line 2 and 4 changing ORB RAM1 1   to   ORB RAM1 1 RAM1  and ORB RAM1 2  to ORB RAM1 2 RAM1
2) It is not between the hours of 20 and 6.  From 20 to 6, it shuts them off.
Both conditions were fulfilled.
I changed the hour into 13 and tried it again this afternoon ( in Belgium) and again both outputs 1 and 2 stay low and can't be changed by the ttl output control. Output 3 can be set high  by the controller.
When I remove the PLC routine I'm able again to put the outputs manually high by means of the controller
 
laodice said:
Both conditions were fulfilled.
I changed the hour into 13 and tried it again this afternoon ( in Belgium) and again both outputs 1 and 2 stay low and can't be changed by the ttl output control. Output 3 can be set high  by the controller.
When I remove the PLC routine I'm able again to put the outputs manually high by means of the controller
 
I see what I did wrong.  
 
START
TSTGE CH 20              **  first 4 lines set the first and second bits to 1 if they are true
CALLSUB RELAY
TSTLT CH 6                 **
CALLSUB RELAY
TSTGE CH 6                **  sends you to subroutine that shuts relays off after 6
CALLSUB RESET
END
 
RELAY:
DIV CTS 900 RAM1    **  substitute for 900 how many seconds you want between relay swaps.  900 for 15 minutes
ANDB RAM1 1        
BZ RELAY1        
SET OP1 0
SET OP2 1
RET
 
RELAY1:
SET OP1 1
SET OP2 0
RET
 
RESET:
TSTGE CH 20                **  aborts the reset if it is after 20
RET
SET OP1 0
SET OP2 0
RET
 
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
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
TSTEQ 0 RAM2
X10 2 0 OFF
TSTEQ 1 RAM2
X10 2 0 ON
ANDB RAM1 2 RAM2
TSTEQ 0 RAM2
X10 2 1 OFF
TSTEQ 1 RAM2
X10 2 1 ON
ORB VAR1 1 VAR1
DONE:
RET
 
The problem is we did checking for house ID and device ID for valid range.  That limited the parameters must be numeric. If we allow passing RAM or VAR as X10 parameter, we will have to remove that checking in the PLC logic.  I think that is probably okay.  This is in the GUI library, so that we could remotely update even for the older board, if we can remotely connect to the port 80 of the board.  Since each version firmware having its match GUI, we have to know exact version firmware to make change so that you can test.
 
Laodice, what is your firmware version number?
 
house id and device ID check to make sure in the range
0-15
The 3rd parameter in X10 commands can be:
0 == off
1 == on
2 == bright
3 == dim
 
If we removed those checking, the parameters can be RAM or VAR.
 
It's not a huge issue and only requires a few lines of code for a workaround in this case so don't worry too much about it I was just mentioning it so that you could fix it for future firmwares.  If it only requires bypassing those checks it could also be worked around by using a javascript debugger.
 
It will be a good test for making sure the change will work.  Right now we wait for being able to reach to his board.
 
Back
Top