Hi All,
I was building a simple circuit to get to grips with interrupts. The circuit was a simple 10 minute timer that would keep a relay energised for 10mins if you pushed a switched once, 20mins if you pushed the button twice etc.
Eventually, I got it to simulate well and it worked perfectly on the bread board. (Here it was powered by 5v supplied from my laptop usb).
I then transferred the circuit to the real world:
Some 12v power adaptor to 7805 (2 capacitors thrown in).
Circuit still on bread board.
Relay contacts connect to mains (but no load).
100nf capacitor across the pins of 16f628a
The circuit was not reliable at all. Instead of timing for 10min on one push, it would time for 20min on occasion. I suspected some kind of switch bounce and tried to fix in software. No luck.
I thought it might be the relay drawing too much current (70mA) (relays go through transistor) and the supply not being adequate. I had no large capacitors so thought I was stuck.
I noticed I had some latch relays EA2-5T. I thought these would not draw too much (in fact 25mA) and noticed you only had to pulse it for 2ms, if I read the spec correctly.
Modified code to work with latch relay with 2 coils.
No luck, same problem.
I wired some leds to the circuit to try and see where the program was. I noticed it kept jumping to the interrupt as if someone had pushed the button.
Played with the switch wire (negative one side, RB0 other side) and noticed if I just pulled the wire out and push it back in it would be like pushing the switch.
Tried to throw some 100nf caps I had all over the place, nothing.
Was about to give up, then connected +ve from pic to RB0 with the 100nf cap - to my amazement circuit now works 100%. I pulled the cap out, problem return. Put the cap back in circuit works perfectly. Did this about 10 times as I was so stunned after fighting with circuit for 2days. I then tried the -ve to RB0 with the cap and it also worked perfectly. I have left it like this.
SO
1. I'm hoping someone can explain what is going on as I hope to build many circuits in the future, all of which will use relays and ac on the contact side - I don’t want to lose days fighting to try and get it to work.
2. I have never read to put caps across RB0 and -ve, yet in my case it has fixed a severe problem 100%. But then again I have not done that much reading.
3. Would I be right in saying that latch (EA2-5T) relays are a better than relays as you only have to pulse them, so use less energy? Also I'm not using a transistor, I'm pulsing the latch relay direct from the pics, makes me happy as less components. Safe? (only draws 25mA to 27mA for 3ms)
I'm also not using a diode with the latch relay, is this correct? The coil has a certain polarity you have to pulse it with. It has 2 separate coils. I did not see anything in the spec sheet to say you have to use diode (flyback diode). Safe?
I have been running the circuit for a while like this - everything seems 100% thanks to the cap across RB0 and -ve
Thanks.
edit: pullups are on.
I was building a simple circuit to get to grips with interrupts. The circuit was a simple 10 minute timer that would keep a relay energised for 10mins if you pushed a switched once, 20mins if you pushed the button twice etc.
Eventually, I got it to simulate well and it worked perfectly on the bread board. (Here it was powered by 5v supplied from my laptop usb).
I then transferred the circuit to the real world:
Some 12v power adaptor to 7805 (2 capacitors thrown in).
Circuit still on bread board.
Relay contacts connect to mains (but no load).
100nf capacitor across the pins of 16f628a
The circuit was not reliable at all. Instead of timing for 10min on one push, it would time for 20min on occasion. I suspected some kind of switch bounce and tried to fix in software. No luck.
I thought it might be the relay drawing too much current (70mA) (relays go through transistor) and the supply not being adequate. I had no large capacitors so thought I was stuck.
I noticed I had some latch relays EA2-5T. I thought these would not draw too much (in fact 25mA) and noticed you only had to pulse it for 2ms, if I read the spec correctly.
Modified code to work with latch relay with 2 coils.
No luck, same problem.
I wired some leds to the circuit to try and see where the program was. I noticed it kept jumping to the interrupt as if someone had pushed the button.
Played with the switch wire (negative one side, RB0 other side) and noticed if I just pulled the wire out and push it back in it would be like pushing the switch.
Tried to throw some 100nf caps I had all over the place, nothing.
Was about to give up, then connected +ve from pic to RB0 with the 100nf cap - to my amazement circuit now works 100%. I pulled the cap out, problem return. Put the cap back in circuit works perfectly. Did this about 10 times as I was so stunned after fighting with circuit for 2days. I then tried the -ve to RB0 with the cap and it also worked perfectly. I have left it like this.
SO
1. I'm hoping someone can explain what is going on as I hope to build many circuits in the future, all of which will use relays and ac on the contact side - I don’t want to lose days fighting to try and get it to work.
2. I have never read to put caps across RB0 and -ve, yet in my case it has fixed a severe problem 100%. But then again I have not done that much reading.
3. Would I be right in saying that latch (EA2-5T) relays are a better than relays as you only have to pulse them, so use less energy? Also I'm not using a transistor, I'm pulsing the latch relay direct from the pics, makes me happy as less components. Safe? (only draws 25mA to 27mA for 3ms)
I'm also not using a diode with the latch relay, is this correct? The coil has a certain polarity you have to pulse it with. It has 2 separate coils. I did not see anything in the spec sheet to say you have to use diode (flyback diode). Safe?
I have been running the circuit for a while like this - everything seems 100% thanks to the cap across RB0 and -ve
Thanks.
edit: pullups are on.
Last edited: