2
\$\begingroup\$

I have been using arduino uno development board for a few months now and wanted to shift to a smaller version of the same. For this, I used Atmega328p AU standalone chip using an I.C. socket (schematic). The schematic doesn't show 22pf capacitors with the crystal I have used.

Everything worked fine till the time I was using my mac to power the circuit. But when I use the wall socket to power my circuit, the setup starts misbehaving whenever I operate (turning switches on or off, rotating the fan regulator knobs to change fan speed etc.) any switch on the switch board to which the wall socket is plugged in. Whole setup isn't related to any other switch or regulator. It is just connected to the 5v wall socket adaptor which I have plugged in the board as shown in the picture below. Whenever I turn the switch on or off or turn the regulator knobs, I think some spikes/surges are ingested through the adaptor. The whole setup just starts resetting regularly or most of the time freezes altogether. However, the problem doesn't show up in the Uno development board plugged into the same adaptor using 5v and GND pin. I do not understand what is making the difference between the two. Is there a need for some decoupling or isolation?

Things I have tried:

  1. Changing the cyrstal
  2. Changing the 22pF capacitor with 18pF ones.
  3. Uploaded the blink code in both Arduino Board and the chip, still the same problem persists. The blink code and my code both work fine with the Arduino board but on the standalone chip it gives the same erratic behaviour (LED stays on i.e., the code freezes).
  4. Rewired the whole setup multiple times.
  5. Tried so much on the arduino forums.

Following are some pics of the setups

Setup

At the left bottom of this image, the two wires I am holding show the 5V power input to the breadboard circuit. Note that I have given the input to the 5v pin of the chip and not vcc (because it works fine bypassing the voltage regulator).

The fan speed regulator knobs are not connected to the arduino. The only link is the adaptor, I suppose.

Schematic http://files.wooler.me/buildatmega/ATMEGA328P-AU-Wire_guide(2).png

\$\endgroup\$
  • \$\begingroup\$ The wall wart power supply you are using is most likely of the ungrounded double insulated type. For EMI suppression there are capacitors within the power supply that cause a slight coupling between the mains and the output as a side effect. Your circuit consequently floats at a relatively high voltage, and whenever you touch some component, a current will flow trough you to ground. These stray currents then cause havoc in your circuit \$\endgroup\$ – jms Oct 12 '16 at 16:35
  • \$\begingroup\$ @jms Why and how is the arduino board then not reacting to this? And what rectifications can I make in my circuit to safeguard it from these spikes? (Battery is not feasible in the case I am using) \$\endgroup\$ – Ayush Pahwa Oct 12 '16 at 16:40
  • \$\begingroup\$ Add a 1000uF cap at the power input. Add a 0.1uF decoupling cap at the MCU. Are you using the ADC? Try decoupling the analog and digital vcc/Gnd as suggested by the datasheet. The crystal and caps on the breadboard is very prone to capacitive/ground plane issues. Have you thought of making or buying a Bare Bones Arduino pcb? You could still use a socket, but the pcb would be better for the crystal setup. \$\endgroup\$ – Passerby Oct 12 '16 at 16:47
  • \$\begingroup\$ In addition, use short wires. The current 20 cm wires add lots of inductance to everything, and are especially ill suited to connecting the crystal to the AVR. \$\endgroup\$ – jms Oct 12 '16 at 16:49
  • 4
    \$\begingroup\$ The long wires from the chip to the crystal and back (very weak signal!) don't give me good vibes. Can't you plug the chip in the breadboard and connect at least the crystal can the caps more directly? \$\endgroup\$ – Wouter van Ooijen Oct 12 '16 at 17:30
2
\$\begingroup\$

A summary of some of the comments made, since I agree with all of them:

  1. Do not use long wires for your crystal. The crystal is meant to produce a waveform that is crucial to the microcontroller's ability to generate a stable internal clock signal. This clock drives all the logic inside the chip, enough deviation here can lead to some very strange, undefined behavior. The parasitic resistance and capacitance in these wires can greatly degrade the waveform from the crystal.

  2. Add some larger capacitors to your 5V supply lines. Start with something on the order of 10-100uF at at the breadboard input, and then 0.1uF closer to the microcontroller. It sounds like in one of your comments that you've already tried powering through a 5V linear regulator with a 12V (DC hopefully?) input with the right coupling capacitors in place... I would actually stick with that even if it didn't make a difference, I'd rather trust that than the 5V wall supply.

\$\endgroup\$
  • \$\begingroup\$ I have added the resistor on pin 29. (Close to bottom right of the image behind the red wire). Also, I am currently condensing the circuit by removing as many wires as possible. Will update the question as the results come out. \$\endgroup\$ – Ayush Pahwa Oct 12 '16 at 18:37
  • \$\begingroup\$ @AyushPahwa, thanks for pointing out the reset pull up resistor, it was hard to see :) \$\endgroup\$ – Jon L Oct 12 '16 at 18:39
0
\$\begingroup\$

The Uno has on board linear regulators which smooth out any unwanted and high voltage ripple present in wall socket adapters. It looks like your adapters has a high voltage ripple on its output and this is causing the random resets. Try powering your setup with a battery and see what happens.

\$\endgroup\$
  • 1
    \$\begingroup\$ I tried powering with a 5v linear regulated supply through a 12v unregulated supply, using 1000uF capacitor to the input, 470uF capacitor at the output with ceramic capacitor of 0.1uF on both input and output. As I already said I tried powering with USB through my laptop so I have no doubts that it will work with the battery. But since I am working on a home automation product, using a battery is not feasible. \$\endgroup\$ – Ayush Pahwa Oct 12 '16 at 16:25
  • \$\begingroup\$ Also to note, that when I charge my laptop, while powering the circuit through USB port of the laptop, the same erratic behaviour is seen. I have provided the schematic of the chip I am using. I just want to know what is making the difference between the UNO development board and the setup. \$\endgroup\$ – Ayush Pahwa Oct 12 '16 at 16:29
  • \$\begingroup\$ @Ayush if the issue is AC coupled noise, the issue is likely because breadboards are not the best solution for crystals. Why you have it on wires instead of minimizing the distance between parts (by having the chip plugged directly into the breadboard) might be a source of the issues. See if that helps. \$\endgroup\$ – Passerby Oct 12 '16 at 16:50
  • 3
    \$\begingroup\$ Essentially, that 1/2 foot of wire between the crystal and the MCU is the biggest problem I see. \$\endgroup\$ – Passerby Oct 12 '16 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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