Pages: [1]   Go Down
Author Topic: Atmega328 freezes  (Read 709 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys, this is my first time posting on this forum, and it's about my first arduino project. I made an LED sign with seven letters. The LEDs on each letter are wired in parallel and powered by some transistors, which in term are activated by the arduino. Simple stuff even for a newbie like me.

Everything worked out just as expected when I used the Arduino board. However, when I took the chip out of the board and attempted to use it by itself, it wouldn't run all the code. The original code featured several flashing patterns for the leds.

I had the exact same code on the arduino board and it worked just fine, but when using the atmega328 by itself, it would just loop through the first part of the code over and over, without even starting to run the other flashing patterns and would eventually (after an indefinite number of loops) freeze leaving the last letter on HIGH (right at the end of the code). I eventually dumped the rest of the code and stuck to the first part, thinking it would do for now, but still it freezes at the end after a while.

Just a couple of extra details:
I powered the chip with +5 volts on pin 7, ground on pin 8, 16MHZ crystal between pins 9 and 10, and then used pins 6 to 13 to power the transistors.

I did not put 20 pf capacitors between crystal pins and ground.

Code below:

Code:
void setup() {               

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop() {
 digitalWrite(6, HIGH);   
  delay(200);
  digitalWrite(7, HIGH);   
  delay(200);
  digitalWrite(8, HIGH);   
  delay(200);
  digitalWrite(9, HIGH);   
  delay(200);
  digitalWrite(10, HIGH);   
  delay(200);
  digitalWrite(11, HIGH);   
  delay(200);
  digitalWrite(12, HIGH);   
  delay(200);
 
  digitalWrite(6, LOW);   
  delay(200);
  digitalWrite(7, LOW);   
  delay(200);
  digitalWrite(8, LOW);   
  delay(200);
  digitalWrite(9, LOW);   
  delay(200);
  digitalWrite(10, LOW);   
  delay(200);
  digitalWrite(11, LOW);   
  delay(200);
  digitalWrite(12, LOW);   
  delay(200);
}


What do you think? What could be causing such a weird behaviour of the atmega328? I know it's probably something basic, but it would take me a year to figure it out by myself smiley I hope you can help me
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I did not put 20 pf capacitors between crystal pins and ground.
Why not?
Logged

Newcastle, England
Offline Offline
Sr. Member
****
Karma: 3
Posts: 489
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Set it up as shown below, and it will work fine. As you have taken the IC out of your arduino, it wil already have a bootloader on it, so ignore the bootloader burning bit.
http://arduino.cc/en/Tutorial/ArduinoToBreadboard

Onions.
Logged

My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) smiley-grin

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi PaulS, I couldn't find them at the last open electronics shop on Friday evening, and I had no choice but to see if it worked without them. Do you think that's the problem?

Onions, everything is as per that schematic, except for the capacitors. I'll take the sign down and install those.

Thanks!
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I couldn't find them at the last open electronics shop on Friday evening, and I had no choice but to see if it worked without them. Do you think that's the problem?

Yup.  They aren't optional.  They are critical to the oscillator's operation.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Pages: [1]   Go Up
Jump to: