Microcontroller protection from EMI

Discussion in 'Embedded Systems and Microcontrollers' started by ecka333, Mar 7, 2013.

  1. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
    Recently i have made four channel timer for my aquarium. It controls aquarium loads: fluorescent lamps, water filter, heater, hood ventilator, all 220V AC. Schematics is simple: PIC18F25k22 microcontroller in certain time turns on and of my aquarium loads. Microcontroller controls optocouplers 4n32. Optocouplers controls relays, coil is 12V. Relays through contacts controls loads. I faced one problem: when relays was turning loads on and off, microcontroller frequently stucked. Then i redesigned my PCB, added 0.1uF cap in parallel to every load and situation now is much better. And the problem left only with my filter. When i manually remove working filter from my timer's socket, microcontroller stucks. This happens only when it (brushless AC motor, only 5.2W) is removed, but never when connected again. With other loads there is now such problem. Maybe it is emi problems, how can i solve them? Read about Faraday cage, but i am not sure that this will work. Maybe additional filters would help? Maybe PIC16F family microcontroller is more immune to EMI?
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Have all unused PIC pins been set as outputs?
    Have you got flyback diodes on the relay coils?
    Have you used a star ground (direct connections from ground at power in to the 12V and microcontroller)?
     
  3. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You need to inline toroid coils. If you only use small currents, you can also use RF inductors (into the Vcc path towards the microcontroller).

    I have done this a few times.

    If you are not sure about the values/size of these coils, I can also give you advice.

    Often only one coil is enough in the Vcc path, sometimes you may need one in the ground path as well.

    If the problems still persist, also add coils into the motor supply.

    The value is not so much important, there just has to be some wire on a magnetic core. Adding magnet wire to a blank core sometimes helps without to calculate the value.

    Large power supplies or high quality wall adapters use so-called common mode Chokes, these have 5mH or 8mH (for 50Hz grid).

    You only need some 100uH or even less. Depends on the frequency. For a motor, a larger inductance might be required but not neccessarily.

    If you have some chokes, cores, and RF inductors in your lab/workshop, you can experiment and see if the problem can be rectified.

    I was always able to get rid of EMI (resetting, unstable display, lockup etc.) that way.

    See also the photo, the core is absolutely required or the sensible I2C communication will become disturbed.

    Note that for a motor you may need more than one coil.

    Also adding capacitors parallel to the motor can help, best are ceramic or Tantalum but try whatever you have on hand.

    I saw this often inside radio controlled toy cars, two snubber coils in each motor supply path, and a small ceramic cap as well.

    I'd at first try to inline an inductor into the controller Vcc path, and see if the problem still persist.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Without seeing the schematic we're just guessing. Mark77 provides some excellent guesses as these are common mistakes.

    If the coils get 12V power where does the power for the PIC come from?

    Is there any connection between the 220V and the 12V?

    Besides the lamp, why is the life support equipment for the fish on timers?
     
  5. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
    Yes, all unused pins are set to outputs, logic level 0.
    Flyback diodes to relay coils are connected.
    My PCB is only one layer, so i used two groundplanes: one under microcontroller and optocouplers; other under relays and all 220V parts: filtering capacitors and load connectors. These groundplanes are separated one from other and connected only to 12V power supply ground, "star" connection.

    I used 220V/12V wall power supply to power relay coils (12V) and to power microcontroller through 78L05 voltage regulator.

    So the first thing i will try will be inductor in the microcontrollers +5V supply rail. But i am not sure if RF coils are effective: EMI comes from loads, working with low 50Hz frequency voltage. Or i am doing mistake here?
    I will post schematic and PCB layout after several hours.
     
  6. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    No the EMI itself is not 50Hz. Your bulk capacitor would catch up with that. Inductive loads produce harmonics; electronic transformers, SMPS, and dc/dc converters also can produce them to a lesser degree.

    RF coil does not neccessarily mean radio frequency.
    It is just about the size, these are typically tiny green components. Normally they are only used for max. 50mA, you'd see LED displays becoming dim from a 1000uH RF coil (for instance).

    The larger the inductance value, the less high frequency can pass, because the coil is opposing the change in current.
    You should see an effect from 100 to 200uH already.

    I often use proto circuits pretty much having large "rats nests", basically no ground plane at all. Sometimes I only use 1uF bulk capacitor. Recently I saw 100uF value recommended, don't remember which controller brand it was.

    RF coils (the standard green one's) mainly exist in two different sizes. If you use the small variant, your controller voltage may bounce a little if it runs at high speed. Typically a small toroid could be used, or also a SMD pot core. They cost about 50 cents or less.
     
    Last edited: Mar 8, 2013
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Or maybe you'd rather want a pot core on your PCB. They are also small and are used for some 100mA upto a few Amps.

    I'd try if you can make the motor or whatever produce "more" EMI by some condition. So you are sure you lock out the EMI problem completely, and not just improve it a little on the margin.
     
  8. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    These are "common mode" Chokes, used on the high-voltage AC side, for the purpose not to feed back Harmonics and EMI back into the grid.

    A small SONY telephone charger wall adapter would have one, but cheaper electronics transformers not neccessarily.

    Sometimes the traces exist on the PCB but they are left out.

    It might be the circuit works well and it is not producing much EMI, or to save costs.
     
  9. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You can also try a 220nF X-rated polyester capacitor parallel to the motor AC high voltage. Chances are there is such a cap. already, but not neccessarily.

    The motor is maybe not on purpose designed to be used with a PIC timer (which is not yet by design having EMI protection/filtering).

    All these appliances in western countries must pass tests for EMI, old televisions are quite sensible to that.
     
  10. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
  11. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You could try to add it before the 78L05.
    Have you figured out how it becomes stuck?
    Maybe in a I2C loop?

    I'd be interested to read a report about the result, if it solves the problem, or if it changes at all.

    Also if the controller throws off completely, or if it is stuck in a I2C code.
    You could program a timeout, and abort I2C transmission.
     
  12. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You could also decrease the I2C resistors.
    I get away with a few 1uF caps or just one for most of my uC circuits, even at high frequency.

    Getting I2C problems is pretty normal only from a dc/dc switcher IC or electronic transformer already + 2m cable.

    Microcontroller as such can readily accept a swing of 1V or 2V without disruption. Of course if you use A/D that goes off too- solution: 78L05 for that as reference.

    I was always thinking these large bulk caps + 100nF as well are not really cutting it (the problems), and I made many PIC circuits. Maybe the 1uF caps I have here are good quality.
     
  13. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    After you fix all the EMI problems, enable the watchdog timer.
     
  14. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
    Tried use 100uH inductor in the path from 220V/12V PSU to 78L05 chip. No positive results. Tried to use inductor in series with load, with capacitor attached parallely to the load (LC filter). Again no results. Did one test: simplified my microcontrollers program in such way, that only four outputs to the optocouplers would be logic high and LED on RA0 output continously will blink to indicate when RESET occurs. Enabled watchdog timer. With PIC18F25K22 microcontroller reset occurs almost every time, when i connect aquarium pump to the socket. Then the same program i wrote for PIC16F876A microcontroller and then inserted it in chip slot. With this microcontroller everything is OK! So i came to conclusion that my PIC18F25K22 is oversensitive to EMI. Now ordered PIC16F1936, will try to use this microcontroller. And yet one strange thing: reset occurs when i manually remove pump's plug from timer's socket (both pump wires disconnected) but did not occurs when relay connects/disconnects the pump( one wire).
     
  15. ecka333

    Thread Starter Active Member

    Oct 1, 2009
    76
    0
    Read Errata about PIC18F25K22, but found nothing that could cause big sensitivity.
     
  16. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Do you have MCLR resistor or have set to internal MCLR?
    Do you have a storage capacitor for the 18F voltage regulator?
     
  17. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    I predict a change of PICs will have no effect on your problem.

    These things are not very sensitive to EMI. But like all digital electronics they get out of sorts when their power goes funny.
     
  18. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Floating reset lines are actually very sensible to EMI.

    It is worth to go through all options, all special features and pheripherals in the datasheet, and see if they are OFF or properly configured.

    Switch off brownout reset for instance or add ISR code for that.

    Is it possible to post a picture from the PCB + schematic + configuration bits + ISR?

    Not all details are required for the schematics but the components next to the PIC, all inputs, as well power supply rails.

    I2C is also sensible to EMI, I'd decrease the resistors to 2K.
     
  19. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Add a 22uF cap across your PIC Vdd and Vss pins in parallel with the 0.1uF cap already there, both physically as close as possible to the power pins (both sets of power pins on IC).

    Ensure the power supply you are using isn't glitching and has the current ability to switch all relays at one time. I'm assuming you have a second voltage regulator prior to the PIC?

    If that doesn't help, enable watchdog timer and add clearwdt instructions in your code.
     
  20. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    The issue occurs when the motor turns OFF.

    Common mode choke tried for the motor?

    Eventually a 0.22uF cap accross the relay contacts may also be of help.

    The relay opens, motor inductance is fairly high for a small motor, voltage is rising.

    Does it always happen or only sometimes?

    Using a SCR Relay + opening at zero crossing might be a helping.
     
Loading...