Electronic – arduino – Standalone Atmega328p setup not working properly

arduinoatmega328psurface-mount

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

Best Answer

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.

Related Topic