Hi, My knowledge of electronics is pretty basic and hope someone can help.
I need to build a device that has 2 relays. Each time the device is powered up I need the alternate relay to be switched on.
ie
Power on - Relay 1 turns on
Power off
Power on - Relay 2 turns on
Power off
Power on - Relay 1 turns on
etc etc.
I can program microcontrollers and would normally just use one of them to do what I want, but it needs to remember the previous state and the only way I know to do that is write to eeprom. This is OK but the eeprom only has 100,000 read/write cycle and this thing will be switching a lot. Any suggestions or ideas how I can do this?
I believe EEPROMs have 100K write/erase cycles per memory location. I don't think there are any limits to the number of times you can read the EEPROM.
One way to maximize the life of the EEPROM would be to use more than one memory location. Initialize the EEPROM with 0's. On power up, increment the first location that has the smallest value in it. Doing this scan will also tell you how many times you've powered up since initialization.
For instance, your EEPROM contents will look like:
initially: 0 0 0 0 ...
then: 1 0 0 0 ...
then: 1 1 0 0 ...
etc.
eventually you'll wrap around to: 2 1 1 1 ...
This will distribute the writes across many EEPROM cells.
Another idea is to use a latching relay to store the parity of the number of times you've powered up.
I believe EEPROMs have 100K write/erase cycles per memory location. I don't think there are any limits to the number of times you can read the EEPROM.
One way to maximize the life of the EEPROM would be to use more than one memory location. Initialize the EEPROM with 0's. On power up, increment the first location that has the smallest value in it. Doing this scan will also tell you how many times you've powered up since initialization.
This will distribute the writes across many EEPROM cells.
Another idea is to use a latching relay to store the parity of the number of times you've powered up.
Thanks pc88, I already have a heap of relays so I don't want to buy any more if I don't have to. I was wondering if there may be some type of logic gate that might hold it's previous state? Otherwise I'll do as you suggest with the eeprom.
As you are concerned about using the eeprom, an alternative idea could be to keep the pic operating in sleep mode when the relay power is off.
Powering the pic from a supercap or lithium battery would mean that you could then wake-up the pic when full power is applied and turn-on the appropriate relay.
Thanks for all the suggestions, they all sound pretty good. The time between on and off is only around 30 seconds to a minute.
I do like the circuit that Eric has attached. That seems to be exactly what I need. If you do have time to check it out Eric, I would greatly appreciate it.
If that's the case a large capacitor would do, especially if you put the PIC to sleep in between cycles. For example a 47,000:mu:F capacitor will last 47 seconds if the voltage drops by 1V and the current is 1mA.
I already have a heap of non-latching relays so I don't want to have to buy any others if I don't have to. I have never used latching relays before. How do they work?
Also there are magnetic latching relays which (I presume) use a permanent magnet to keep the contacts closed. Another pulse (perhaps using reversed current) through the coil is used to break the contacts free.
Also there are magnetic latching relays which (I presume) use a permanent magnet to keep the contacts closed. Another pulse (perhaps using reversed current) through the coil is used to break the contacts free.
Thanks, I should have looked it up myself. I don't think a latching relay will help me. I didn't really explain properly, I don't want the relay to stay on after the power goes off to my device. I only want a relay on when the device is on, when the power is off I want the relay off, but I want alternate relays to switch each time the device is turned on.
Maybe the latching relay might be what you want, since they do hold state without power, and with a bit of circuitry you can get it to switch state the first thing whenever power is applied. (though perhaps that initial connection to the old device might not be acceptable, but maybe that can be worked around with a secondary relay + RC?
Thanks, I should have looked it up myself. I don't think a latching relay will help me. I didn't really explain properly, I don't want the relay to stay on after the power goes off to my device. I only want a relay on when the device is on, when the power is off I want the relay off, but I want alternate relays to switch each time the device is turned on.
A latching relay will stay in it's last state without power, it's like a mechanical 1bit EEPROM. As posted in this thread it can be used to control another relay.
It is for a friend of mine. He owns a hydroponics shop and has developed a new aeroponic system using compressed air. I haven't actually seen it so I am not sure how it works, but he needs to add a second spray nozzle without increasing the compressor size. He wants alternate nozzles to spray each time the timer turns it on. The relays will switch solenoid valves from the compressor ... something like that anyway.
It is for a friend of mine. He owns a hydroponics shop and has developed a new aeroponic system using compressed air. I haven't actually seen it so I am not sure how it works, but he needs to add a second spray nozzle without increasing the compressor size. He wants alternate nozzles to spray each time the timer turns it on. The relays will switch solenoid valves from the compressor ... something like that anyway.
hi Chris,
I would suggest that you get a mains powered 'ac' motorised cam.
Set up the cams so that it operates the cam microswitch lever.
Connect the common pole of the microswitch to sprinkler supply input.
Use the n/o and n/c contacts of the microswitch to select alternate sprinklers.
By setting the cams it should be possible to set the sprinkler #1 and #2 times
so that both beds get watered one after the other, then it waits for the next sprinkle period.
You can get a decent S/H cam timer from an old washing machine.
and you could buy a simple 7 day timer to control the cam motor on time, 24/7 handsfree!