Atmega 328 with 16 mhz crystal (or) glcd freezes

Hi everyone. I recently started a building an alarm clock where I used the following components:-

  1. Adafruit negative backlit GLCD
  2. A 5v relay
  3. An atmega328 with 16 mhz crystal
  4. An LED Strip (12v), speakers and a ds3231 rtc

The entire setup worked fine until a couple days back. However, when I put the project into an enclosure it suddenly failed. Either the atmega froze or the glcd froze, but there is no further response about ten seconds after turning the power on (it works for the first ten seconds or so). A similar problem occurred previously, however that happened only when the relay was switched either on or off. In that case, it was the glcd which froze, because the atmega still turned the led strip on and off.

I thought that there might be some electromagnetic interference from the power board (one with 5 and 12v that I required), however, when I used a Leonardo power supply, the problem still persisted. The problem persists even when I disconnect all other parts of the project and only leave the bare minimum to control the glcd. Please let me know what the problem might be and how I might solve it.

Thanks :slight_smile:

Note: I'm using a zener diode setup to send 3.3v to the glcd. Could this be causing the problem?

No capacitors?

Show your schematic.

Coding Badly: No caps on there. I've read this De-coupling and I'm trying to put the necessary caps. Will do that and get back. The reason I never put them in the beginning is because the entire circuit worked perfectly before it was put in the enclosure, so I didn't think there would be a need for caps.

ChilliTronix: Here is the schematic. . I'm sorry that it is a bit messy, I'd made it only for my reference while soldering on to the board. Please let me know any changes I can make.

Thanks :slight_smile:

  1. You need power decoupling both sides of the uC.

  2. You need ground both sides of the uC.

  1. Do not connect a speaker directly to the processor.

So I decoupled the IC on both sides with 100pf capacitors, as those were the highest value ceramic caps I had laying around. I also decoupled both the 3.3 and 5v power supplies with a 47uF cap. I have a six button cycle to set an alarm and come back to the initial page. Now that cycle works once, and stops after that. I have also programmed the LED strip(12v) attached to the MOSFET and relay to turn on 20 minutes before the alarm. While this does work, it makes the glcd go haywire and finally stop working. The setup also doesn't work if I power it with 5v from an arduino.

I also tried the setup after disconnecting the speakers, but the same problems occurred. I don't think it is a coding issue as the code worked on a leonardo and on the atmega328p itself previously. Should I try using higher value caps for the atmega decoupling?

Thanks :slight_smile:

Er.... what are you decoupling with a 100pF cap? The power decoupling just involves a 0.1uF cap (100nF) across connections on each side of the uC.

I used a 100pf cap as I didn't have a 0.1uF ceramic cap. I'll buy the 0.1uF, test it and let you know :slight_smile:

Power decoupling on the Atmega328 doesn't have to be ceramic as far as I know.... I have used electrolytic.

None of the capacitors (electrolytic included) I have are of that value, so I will have to buy new ones anyway. I'll do that and then get back with the result :grin:

What values do you have that may be close?

The 0.1uF caps don't seem to be of much help either. I've decoupled the atmega328 and the power supplies. The microcontroller still freezes when it changes the state of the mosfet and the relay. Any suggestions????

Ah... relay... what are you powering your setup with? Does it consistently freeze powering the relay but everything else work OK?

Where are you powering your relay from?

I'm powering my relay from the same supply as the one to my atmega. I have tried removing the relay header, but the program doesn't work even if everything is disconnected and only the glcd is left along with a pot and a button. It might be electromagnetic interference from the power supply, so should I try shifting that to a separate location and powering the setup?

So...

You have not answered the question:

Does it consistently freeze powering the relay but everything else work OK?

But you say the program freezes with or without the relay connected, but not when it is connected to the computer?