I have a circuit which contains an offline switching SMPS circuit (based on viper22a) converting 220V to 5V regulated down to 3.3V using linear regulator IC. This powers up an ESP wifi module and Atmega328p chip. The microcontroller is being used to control ac appliances such as tublights, bulbs, fans etc (using optically isolated triacs). The circuit goes behind the switchboard, very close to ac mains wire.

Everything works fine except for once or twice in a week when my atmega freezes and GPIO pins latch up in a random state - High, Low or Mixed (few pins high, few pins low). Since circuit is inside the switch board, the only means of bringing it back to normal operation is by cutting the power to that switchboard.

After doing some reading, I concluded that it might be due to transients in ac line (generated by switching of inductive/capacitive loads like AC, refrigerator etc) somehow reaching the micro controller. Am I correct?

I came across two possible fixes:

(1) Implementing watch dog timer in the code side (yeah I didn't do it earlier)

(2) Using some transient suppression hardware like MOVs or TVS diodes

(1) has been taken care of. For (2), I need some help.

I am planning to put a TVS diode for 3.3V line which goes to the Atmega328. I have selected a few which has a breakdown voltage in the range 4.1 - 6.8 V.

Besides this, I am planning to put another layer of protection right at the ac entry point (at the power supply circuit).

Out of TVS diode and MOV, which will be a better choice? Or should I add both in parallel?

I am more inclined towards TVS diodes because it's more reliable and has long life.

What will be more suited for this purpose? Is there anything else that I can do to improve the performance of my circuit?


EDIT: Adding the schematic of power supply

SMPS power supply

  • \$\begingroup\$ I would put a MOV on AC line input and TVS at each MCU input. Also a series resitor and small cap before TVS is a good option, it will limit the rate of change of asignal thus TVS will react always at same knee point. \$\endgroup\$ Mar 16, 2016 at 9:40
  • \$\begingroup\$ Thanks @Marko for the reply. Putting TVS diodes along with RC seems a little difficult due to less board space. Since total number of GPIO is over 20, it will take around 80-100 components (2 tvs diodes + R + C per line). Also, my IO lines are already optically isolated. So wouldn't it be an overkill? \$\endgroup\$ Mar 16, 2016 at 10:05
  • 1
    \$\begingroup\$ I guess you have to redisgn the PSU, because if you have optoisolated inputs you shouldn't have such problems. So how do you power MCU and how the inputs/outputs, show the PSU section schematics. \$\endgroup\$ Mar 16, 2016 at 10:36

1 Answer 1


As suspected you are using a single source to power MCU and input that are optoisolated. Now what's the point using opto's if it's all the same Vcc? 2nd What is a zener diode doing at hte opto input? Why isn't just simple resistor enough good? You have more possibilities:
1. Make a second secondary winding and new power source for supplying inputs (the best one)
2. Install a common mode choke, capacitors (PI filter) and TVS to power inputs
3. point 2. + remove opto's and instal RC + TVS, as the optos are useless if you use the same source.

What is going on? Your 5V wire that goes arrond your house is antenna like that picks up the noise and it transfers to MCU power supply. Extra your PSU laks the common mode choke at the input. See example: http://www.st.com/web/en/resource/technical/document/data_brief/CD00177969.pdf

  • \$\begingroup\$ Thanks for the answer Marco but I think there is a bit of confusion here. All this circuit is on the same PCB as the microcontroller part. SMPS part takes about 8cm X 1.5cm. This circuit has been derived from what you posted. I have removed the PI filter due to lack of space and there is a missing winding because I need only one output - 5V. My DC 5V is totally isolated. The Opto that you see is being used to give feedback to viper and zener is being used to set the feedback threshold so that I get 5V. (3.9V+0.7V = 4.6V ~ 5V). you can see a similar circuit in the app note that you posted. \$\endgroup\$ Mar 16, 2016 at 15:19
  • \$\begingroup\$ @Whiskeyjack I see, the opto is a feedback for voltage regulation, not the input to MCU. But where did you get the example for that feedbak, anyway? Isn't supposed to be there a voltage reference and couple of resistors and caps, not only one zener diode? Still the question persists is how do you power the optoisolated inputs? \$\endgroup\$ Mar 16, 2016 at 15:33
  • \$\begingroup\$ Hey Marko, sorry for chiming in late. I was carrying out some experiments and this is the result: I used almost similar power supply circuit on another pcb to power up my microcontroller board and it's running fine till now. Now this suggests two possible cases: (a) smps circuit on same pcb is introducing too much noise due to less clearance. (b) I used a smaller transformer in on board smps which might be having higher leakage inductance and somehow messing up with the power lines at random times. what do you say? \$\endgroup\$ Mar 19, 2016 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.