PDA

View Full Version : Pic reseting when switching mains current with relay



lsteele
- 3rd February 2007, 13:35
Hi,

I'm trying to switch a mains current (240V AC) with a relay connecting via a transistor to my PIC (a 16f876a). The PIC is powered from a battery supply - 4 rechargeable AA NIMH cells providing 5V. That's powering the PIC directly - there's no regulator (I presumed there's no need for one).

At the moment the mains supply is hooked up to a light. Everything usually works fine when switching the relay ON, but when the relay switches OFF the PIC resets almost every time.

If I disconnect the mains supply the PIC can turn the relay on and off without any resets.

The schematic is attached. The relays sit on a separate PCB immediately adjacent to the board with the PIC, and the two are connected with 2 inch wires. The wires with the mains current travel close by the PIC board - this isn't really avoidable. The relays are switching the Live wire of the mains supply.

In addition to what you can see on the schematic I've added a 0.1uF cap between MCLR and ground. (Something I saw suggested somewhere.)

I've read a lot about decoupling capacitors, zero crossing, ground planes, and so on! But I don't know where to start, short of randomly trying everything. It would be great to be able to systematically diagnose what's creating the problem, but I don't know how to go about doing this.

Any suggestions are gratefully received.

Thanks,

Luke

mat janssen
- 3rd February 2007, 14:06
Put a snubber network over the relaiscontacts.
(A snubber network is a resistor of 47 ohms in series with a 0,1 uF capacitor)
Dont forget to take a capacitor what is suitable for mains voltages (240V~)
And take a resistor of at least 1/2 watts.

sayzer
- 3rd February 2007, 14:55
Luke,

What are the fuse settings? BOD ? WDT?
The code?


-------------------------------

lsteele
- 3rd February 2007, 15:17
mat: If I try what you suggest won't the resistor allow a current to flow all the time? Or have I misunderstood how it should be connected?

sayzer: The code is definitely working ok - with no load across the relay it will switch on and off without any problems every time. It's only when there's a load across the relay that the pic will reset when the relay switches.

The fuses are everything off except PWRT (or 0x3F31). (Incidentally I'm using a bootloader, so this is the fuse configuration it defaulted to...)

mister_e
- 3rd February 2007, 15:21
Yes the snubber will help!

also
Make sure you have connected both PIC VSS pins.
Make sure you have disable the LVP mode
Set all unused i/o to input and connect ALL of them to GND
i would add a 47-220 uF on the PIC VDD line as well (close to the PIC)
Place your PIC away of your relay to see what's happen.

How much current do you drive on the AC side?

mister_e
- 3rd February 2007, 15:23
If you didn't change the default config fuse while loading the Bootloader firmware the first time, you can't modify them later in your code.

Default for 16F876_04.HEX are HS OSC,Watchdog off, Power up ON, Brown out ON, LVP OFF.

Maybe you could also try to reload the bootloader firmware but set the BrownOut to OFF... but, i think there's much more to check before...

lsteele
- 3rd February 2007, 15:29
Thanks

>> If you didn't change the default config fuse while loading the Bootloader firmware the first time, you can't modify them later in your code.

I know! :-) But I'm quite happy with that fuse configuration right now... unless it's a factor in my problem.

>> Yes the snubber will help!
>>
>>also

>> * Make sure you have connected both PIC VSS pins.
>> * Make sure you have disable the LVP mode
>> * Set all unused i/o to input and connect ALL of them to GND
>> * i would add a 47-220 uF on the PIC VDD line as well (close to the PIC)
>> * Place your PIC away of your relay to see what's happen.

Ok, I'll try all of the above. But I'd like to understand why connecting a 47 Ohm resistor across the relay output (as part of the snubber circuit mat suggests) is a good thing -- surely it'll allow a current to flow all the time. Or have I misunderstood something?

Thanks again...

mat janssen
- 3rd February 2007, 15:30
here is a drawing of a snubbernetwork .

lsteele
- 3rd February 2007, 15:33
Oh! In series... Which is what you said to begin with (sorry, somehow misread your original post).

Thanks again.

mister_e
- 3rd February 2007, 15:38
Mat suggested a RC snubber, so it's a resistor in Serie with a capacitor, so will flow only for a short period of time.

You may find some explanation in the following document
http://focus.ti.com/lit/an/slup100/slup100.pdf

I would prefer to switch on the AC zero crossing to extend the relay contact lifetime...

OR you may decide to use some SSR... a bunch more expensive...

EDIT: ah crap, i'm late :D

Also, probably a nice idea to place some 0.1 uF in parrallel with each realy coil + 100-470uF & 0.1uF on their VDD line.

lsteele
- 3rd February 2007, 18:28
Thanks for all the suggestions - I'm blown away by how quickly people have responded.

Ok, I've added the snubber and it's immediately eliminated 90% of the resets. I can now turn the relay on and off with the light connected and it works. Strangely I can still produce a reset if I switch the mains on and off at the socket, even when the light is NOT connected. And I've still had one or two random resets.

I'll try connecting up the other VSS pin and adding the 47uF cap to the PIC power supply to see if that gets rid of the remaining resets.

>> * Set all unused i/o to input and connect ALL of them to GND

Is this something I should do whenever dealing with PIC, or only when dealing with mains voltages/currents? What's the rationale here? I'll try the other steps first since this is going to require me to produce a new PCB!

>> Also, probably a nice idea to place some 0.1 uF in parrallel with each realy coil + 100-470uF & 0.1uF on their VDD line.

ok, I'll do this too.

One other question: While reading up on this I've heard lots of talk of ground planes. Is this simply a large area of copper on the board which is tied to ground, or does is have to be an entire layer on the board (impossible in my case since the board is single sided). And how do they help (and indeed could they help in my case)?

Thanks again.

mat janssen
- 3rd February 2007, 18:48
Then put also a snubber network on your mainssocket and mainswitch!

Dave
- 3rd February 2007, 22:02
lsteele, I notice that your relays are powered by 5 volts. Is the source of the 5 volt supply the same as the PIC? If so I would have a separate supply for the relay source and a separate supply for the PIC. From what I have seen in the past you are working with electromechanical devices that have magnetic coupling and when you are opering the contacts the field is being coupled to the 5 volt supply the micro it is being powered from. If this supply for the relay source was separate and the ground paths are correct I see no problem with the operation of the relays switching the mains.

Dave Purola,
N8NTA

sayzer
- 4th February 2007, 10:54
I meant to say use BOD_OFF.

Most likely!

-----------------------

shahidali55
- 9th March 2007, 14:00
hello ,
I'm having a similar problem.
I have made a 7seg LED clock (PIC16F628 @ 4Mhz).
The clock resets when i switch on the tube light in my room.
The clock and the tube a not linked to one another in any way.
I was using a wall adapter before to power it, but even after i replaced it with a 9 volt battery, the clock still resets when i switch the tube on.
What could be the reason for this ? ? ?

mister_e
- 9th March 2007, 17:24
without schematic and code it's hard to say.

shahidali55
- 11th March 2007, 08:49
This is the schematic . . .
http://www.josepino.com/pic_projects/led_clock/led_clock_4050.gif

I have used transistors instead of the 4050 IC's .
I have used PIC16F84A and not PIC16F628.
I dont think its the code error cause if i keep the clock in another room, it doesn't reset.

malc-c
- 11th March 2007, 10:58
Not sure if it has any bearing on this but I built a sequential light display that flashed mains light bulbs (240v) and didn't suffer any issues of the PIC resetting. I used solid state relays for the mains switching which are opto isolated from the mains. The only issue is that they aren't as cheap as traditional relays.

Maybe you could use an opto isolator and thyristro / triac driver to do the same thing only a bit cheaper. Something like
http://sound.westhost.com/p62-f11.gif

(ommit the 741 - as it wouldn't be needed for your circuit)

mister_e
- 11th March 2007, 11:47
shahidali55

Any capacitor close to your PIC and close to your 7 Segment display?

Where are the current limiting resistor for the display.

3.6-5.5V is that right?

How about your configuration fuse?

How the final 'gizmo' looks?

Sure there's something that pickup noise. Is the software take care of this poor unconnected PIN 4?

malc-c

I think you misread something or... could be me too ;)

malc-c
- 11th March 2007, 17:34
malc-c

I think you misread something or... could be me too ;)

Could of.. but I thought the problem was with the relay causing the PIC to reset when the lamp is switched


Hi,

I'm trying to switch a mains current (240V AC) with a relay connecting via a transistor to my PIC (a 16f876a). The PIC is powered from a battery supply - 4 rechargeable AA NIMH cells providing 5V. That's powering the PIC directly - there's no regulator (I presumed there's no need for one).

At the moment the mains supply is hooked up to a light. Everything usually works fine when switching the relay ON, but when the relay switches OFF the PIC resets almost every time.

This was why I commented on the use of SSR's which I've used directly dirven from the PIC and don't suffer any issues of then PIC re-setting. However if I've missed the plot (quite plausable ;) ) then sorry for taking the thread OT !

malc-c
- 11th March 2007, 17:39
Just looked at the thread again and I think we're at cross purposes as there seems to be a thread with in a thread... I was responding to Luke's original question in post #1, and not shahidali55's in post #17

Luciano
- 11th March 2007, 22:29
Won't the resistor allow a current to flow all the time? Or have I misunderstood how it should be connected?

Hi,

http://img12.picsplace.to/img12/1/thumbs/snubber.PNG (http://img12.picsplace.to/img12/1/snubber.PNG)
(Click to enlarge the picture)

See also this PDF:
http://www.redlion.net/Products/Groups/NoiseSuppression/SNUB/Docs/12027.pdf


Best regards,

Luciano

J_norrie
- 9th April 2007, 16:25
Hi, There if ever I have to switch high current devices I always use an isolated supply on the pic side and a opto coupled darlington transistor to drive the power relay. This I think would solve your resetting problem

hope this is of some help.
kind regards john