Simple program to switch on relays

laodice

Member
I’m experimenting with my cai webcontroller.
But I’m rather new on plc.
I would like to switch on alternating two relays every hour for one hour from 20.00h until 6.00h in the morning (20.00h relay1 21.00h relay2…)
If possible through X10.
Could anyone give me a basic code to start with and experiment on and learn the basics.
Any help will be appreciated.
 
If using X-10, what are you switching (current and voltage requirements)?  I don't know if the CAI supports generation of an X-10 signal (power line or wireless), but you can rig something in place (see how to hack a palm pad remote).
 
You might want to glance at these How-to's:
 
http://cocoontech.com/forums/page/articles/_/tutorials/home-automation-tutorials/how-to-build-an-x-10-broadcast-car-monitor-r36
 
http://cocoontech.com/forums/page/articles/_/reviews/home-automation-reviews/review-wgl-designs-relay-8-r66
 
http://cocoontech.com/forums/page/articles/_/tutorials/home-automation-tutorials/how-to-control-your-sprinklers-using-x-10-r42
 
Hard to give any more advice without additional information.
 
laodice said:
I’m experimenting with my cai webcontroller.
But I’m rather new on plc.
I would like to switch on alternating two relays every hour for one hour from 20.00h until 6.00h in the morning (20.00h relay1 21.00h relay2…)
If possible through X10.
Could anyone give me a basic code to start with and experiment on and learn the basics.
Any help will be appreciated.
You can generate X10 RF signals through WebControl.  If those two relays on two different switches, you will need to send X10 RF command On for first switch, wait for a hour, send another command to turn the first switch OFF, then send command to turn the 2nd switch ON.
They can be done in the PLC logic by having a line like:
 
X10 1 15 ON
X10 1 15 OFF
in above 1 is house number, 15 is device number
Please check the user guide for more details, or post your question here.
 
I connected a 433 transmitter to TTL7 and TTL8 and I’m able to switch on an X10 transceiver (220V) module.
But I would like to write a PLC program to trigger (time based) a X10 receiver module or two relays (arduino based) on TTL output port 1 and 2 
 
I connected a 433 transmitter to TTL7 and TTL8 and I’m able to switch on an X10 transceiver (220V) module.
But I would like to write a PLC program to trigger (time based) a X10 receiver module or two relays (arduino based) on TTL output port 1 and 2 
 
START
TSTEQ CH 20
CALLSUB RELAY1
TSTEQ CH 21
CALLSUB RELAY2
TSTEQ CH 22
CALLSUB RELAY1
TSTEQ CH 23
CALLSUB RELAY2
TSTEQ CH 0
CALLSUB RELAY1
TSTEQ CH 1
CALLSUB RELAY2
TSTEQ CH 2
CALLSUB RELAY1
TSTEQ CH 3
CALLSUB RELAY2
TSTEQ CH 4
CALLSUB RELAY1
TSTEQ CH 5
CALLSUB RELAY2
TSTEQ CH 6
SET OP2 0
END
 
RELAY1:
SET OP1 1
SET OP2 0
RET
 
RELAY2:
SET OP1 0
SET OP2 1
RET
 
Here is what I think is a slicker way to do it.  I haven't tested it however.
 
START
TSTGE CH 20              first four lines call the subroutine if current hour from 20 to 6
CALLSUB RELAY
TSTLT CH 6
CALLSUB RELAY
TSTEQ CH 6               at 6 am, it shuts off output 2 which would be the one on when the clock goes from 5 to 6am.
SET OP2 0
END
 
RELAY:
ANDB CH 1         tests for even/odd (zero bit 0 if even)
BZ RELAY1        branches if current hour even (zero bit 0)
SET OP1 0
SET OP2 1
RET
 
RELAY1:
SET OP1 1
SET OP2 0
RET
 
Lou Apo said:
START
TSTEQ CH 20
CALLSUB RELAY1
TSTEQ CH 21
CALLSUB RELAY2
TSTEQ CH 22
CALLSUB RELAY1
TSTEQ CH 23
CALLSUB RELAY2
TSTEQ CH 0
CALLSUB RELAY1
TSTEQ CH 1
CALLSUB RELAY2
TSTEQ CH 2
CALLSUB RELAY1
TSTEQ CH 3
CALLSUB RELAY2
TSTEQ CH 4
CALLSUB RELAY1
TSTEQ CH 5
CALLSUB RELAY2
TSTEQ CH 6
SET OP2 0
END
 
RELAY1:
SET OP1 1
SET OP2 0
RET
 
RELAY2:
SET OP1 0
SET OP2 1
RET
Thanks,
I tested it and it works.
Seems quite simple.
I changed RELAY1 into
 
RELAY1
X10 2 0 1
RET
 
and it triggers my X10 transceiver!
And if I want to trigger my relay at 20:15?
 
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
 
az1324 said:
On 15 minute intervals MOD CM 15 is zero
 
The trouble with using the remainder function is that it is only a trigger on the 15 minute mark.  If you have a power failure or a clock change the unit won't get back to the proper state until the next 15 minute mark, and then only with a 50:50 chance.  It may end up being in the opposite state from expected when it resumes.
 
That is a fair point.  How about:
 
MOD CM 30 RAM1
TSTLT RAM1 15
 
Plus you want to use a bit flag for when you have sent the x10 command so you don't keep sending it.
 
Yes, I assume you can't keep hammering out x10 commands.  Output commands on the other hand are fine.
 
x10 in general is not the best situation.  You have no way of knowing if your x10 command actually executed or what state they are in at any time.  You might consider having it send the x10 command every 5 minutes or so to give yourself the best chance of it actually being the way you want.
 
Would it be possible to get a confirmation via hardware (current Xducer, DPDT relay with one of the poles going to a digital input, etc...)?
 
Back
Top