Pic reseting when switching mains current with relay


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Location
    Reading, UK
    Posts
    15

    Default Pic reseting when switching mains current with relay

    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
    Attached Images Attached Images  

  2. #2
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Luke,

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


    -------------------------------
    Last edited by sayzer; - 3rd February 2007 at 14:35.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Sep 2006
    Location
    Reading, UK
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    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...)

  5. #5
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lsteele View Post
    Won't the resistor allow a current to flow all the time? Or have I misunderstood how it should be connected?
    Hi,


    (Click to enlarge the picture)

    See also this PDF:
    http://www.redlion.net/Products/Grou...Docs/12027.pdf


    Best regards,

    Luciano

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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...
    Last edited by mister_e; - 3rd February 2007 at 14:27.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Sep 2006
    Location
    Reading, UK
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    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...

  9. #9
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    here is a drawing of a snubbernetwork .
    Attached Images Attached Images  

  10. #10
    Join Date
    Jun 2006
    Location
    Glasgow, Scotland
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Pic reseting when switching mains current with relay

    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

Similar Threads

  1. Reducing PIC current to as low as possible...
    By FromTheCockpit in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th November 2009, 04:28
  2. Replies: 24
    Last Post: - 7th November 2008, 04:41
  3. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  4. Detecting mains current
    By lsteele in forum Schematics
    Replies: 3
    Last Post: - 13th January 2007, 14:48
  5. High current switching output
    By Tissy in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th September 2005, 14:06

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts