Armega328 hangs

Hello all,

I created a project with the uno which drives 3 LEDs to inputs from low pass and high pass filters. These filters filter the audio signal from a headphone jack. Easy part on uno.

So I got my self a new Atmega328 and flashed the boot loader and removed the old one from uno. Put the new and project works fine. So I removed the new and put back the old one.

The project works fine on both chips connected to uno. So I used the old one. Took it out and hooked it to a breadboard and hooked all gnd, vcc, crystal, caps, reset button and it's resistance. Connected a led to pin 19 (LED) and it glows and reset works. I gave the power directly from the uno +5 and gnd.

So I hooked my project wires to it and it worked. The LEDs glow and respond to music. But the LEDs flicker sometimes and in about 30sec or in less time the LEDs just freeze at a certain brightness. I assume the atmega freezes because it works again after resetting it.

So I connected everything back to uno and again it works perfectly fine. No flicker perfect smooth and dose not freezes. But again connecting atmega to breadboard has the strange problem again.

I can't figure out where the problem is! So the awesome people of the internet please help me out! :P Thank you!

It's pretty rare that an AVR will actually "freeze." It can go off into the weeds or brownout, but rarely locks-up.

Describe the decoupling capacitors you're using. And when it behaves erratically, is it the Uno provide power or something else?

[quote author=James C4S link=msg=2161459 date=1427550746] It's pretty rare that an AVR will actually "freeze." It can go off into the weeds or brownout, but rarely locks-up.

Describe the decoupling capacitors you're using. And when it behaves erratically, is it the Uno provide power or something else? [/quote]

Not sure what the problem is. I assumed it freezes cause the LEDs just stay on even when I remove the input wires (it should rapidly change brightness to input noise but dose not)

22pF non polarity capacitors (those little round things. Forget what they are called :P) are connected from each crystal pin to ground.

Everything is powered by uno's +5v

Those aren't de-coupling capacitors, those are coupling capacitors.

What about the 100nF (and ideally 1uF) caps from the VCC pin to GND?

[quote author=James C4S link=msg=2161516 date=1427554748] Those aren't de-coupling capacitors, those are coupling capacitors.

What about the 100nF (and ideally 1uF) caps from the VCC pin to GND? [/quote]

Oh I am a little confused Caps from crystal to gnd are coupling?

So I will connect just a 1uF cap to +5v to GND or Atmega VCC to GND?

Yes, you need decoupling capacitors on the power pins. The ideal values are 100nF and 1uF in parallel.

[quote author=James C4S link=msg=2161525 date=1427555214] Yes, you need decoupling capacitors on the power pins. The ideal values are 100nF and 1uF in parallel. [/quote]

Thank You :D It did fix the issue it works perfect now. :)

But I used a 10uf instead of 1uf (didn't have it) will that have any effect? and why dose this happens? Voltage up and down? Just to know the theory.

Noise on the supply pins can undesirable behavior. Decoupling capacitors filter that out.

You really want to add a small ceramic 100nF when you can. It is a good practice to have a large "bulk" capacitor in parallel with a smaller value. The smaller value will respond faster for the higher frequency noise.