Duemilanove 328 randomly stops working..

Hey

Ive been using this board fine since i have brought it. Been coding all morning and uploading fine, but when i got to upload a new update 1min after the other one (which has been uploading fine)..

I now get this error when uploading

avrdude: Version 5.4-arduino, compiled on Oct  9 2007 at 11:20:31
         Copyright (c) 2000-2005 Brian Dean, 

         System wide configuration file is "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/Users/kent/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port            : /dev/tty.usbserial-A600agqc
         Using Programmer      : stk500v1
         Overriding Baud Rate  : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: stk500_recv(): programmer is not responding
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: Send: Q [51]   [20] 
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding

I have tried everything in the trouble shooting page but with no success.

When i plug in the board to the usb i get two blinks from the TX and RX leds then the L led start blinking and never stops till i unplug.

The board was brought in NZ (from Sparkfun) with all packing a few months ago.

Any help would be greatly appreciated.

Im on osx btw, but when trying to upload via a vista environment i get

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

Since all i did is change a few lines of my code, ie there was no change in pinmodes or big voltages.. from memory i was shifting an array around..

Any pointer would be appreciated. Thanks

Search of this forum for loopback test. It will test if the PC to Arduino serial USB channel is functional or not. If the loopback test shows good then most likely your processor chip has a bad bootloader and will have to be reflashed.

Lefty

So ive now done the loopback test and it sends me back everything ok.

So im assuming my next choice is

if this test passes, the problem only lies within the atmega chip. first try reflashing the bootloader if you have the tools to do that. if that doesn't help, get a new ATmega chip and make croûtons of the old one. feed to your enemies.

Is there anything i can do to prevent this from happening again?? It just seems odd to me that reuploading some code can cause such issues, but this is my first experience using physical hardware.. so is this a common occurrence i can expect?

Is there anything i can do to prevent this from happening again?? It just seems odd to me that reuploading some code can cause such issues, but this is my first experience using physical hardware.. so is this a common occurrence i can expect?

Good news on the loop back test working, that means the basic board is fine and only the processor is in question. I've been working with Arduino for like 18 months now and have seen many many postings where people have somehow caused their bootloader code to go south. I've posted several times asking how it's possible for the bootloader to become corrupted running a sketch but no answer seems to be detailed enough to reconstruct it for analysis purposes. However most that can then successfully reload the bootloader are then up and running once again? I have never had it happen to me yet, so I too don't understand the how and why, but it sure seems to happen to some now and then. :-?

If you don't have the means of desire to learn how to reflash the bootloader you can always just buy a replacement (if it's a 168 or 328 chip) that already has the bootloader installed for around $6.

Lefty

Yes I have seen this as well Lefty, if you want a sketch that will fry your bootloader let me know. I have a voltage booster sketch that has toasted 4 different chips! ;D I used a USBTiny to reprogram the bootloader and worked with three of the four chips. Bottom line, have spare chips...

I have a voltage booster sketch that has toasted 4 different chips!

Just loading the sketch wipes out the bootloader?

http://www.neobux.com/?rh=falohao this link may help u a lot.

The neobux link above appears to be SPAM. Didn't see any way to flag it so I posted.

Lefty, if you want a sketch that will fry your bootloader let me know. I have a voltage booster sketch that has toasted 4 different chips! I used a USBTiny to reprogram the bootloader and worked with three of the four chips. Bottom line, have spare chips...

Why don't you post it here to see if any of the software gurus around here can make some determination or comments on it. You might want to preface it with a large font, bright colored warning ;D

yes, spare chips are always a good idea, I have 3 328, a couple of 168s and even 4 mega8 chips around here. It was mostly to pratice with my USBtiny programmer after I first got it. Also one should prepair for the great DIP package shortage that is bound to happen someday. ;)

Lefty

and with a new chip we are all systems go.. Not sure if i should upload the code that i corrupted it tho..

Thanks for your help everyone!

sorry for the delay. Yes PaulS, all I did was upload the sketch. I tried it many times, each time I would upload several different sketches prior to uploading the killer code to ensure the chip was working properly. Perhaps I should try it again but upload from a different computer just to be sure. I would be happy to show the code if acceptable by the membership

OK please post it here we are all intrigued to see it.

I would be happy to show the code if acceptable by the membership

Yes, please do post the code. Some of us have been looking forward to the user sketch code that can corrupt the bootloader. It’s like the myth busters trying prove if it exits or not. :wink:

We know about how activating the watch dog timer can sometimes force the bootloader into a loop that prevents uploading a new sketch (and some different bootloaders can prevent that from happening), but other then that, we know people seem to ‘lose’ their bootloader but have yet to find a ‘smoking gun’ example.

Lefty

I just tested my code again and yes it was locked solid. Months ago, I determined it was the watchdog timer that caused the problem but I did not realize it was known issue. So in summary, the watchdog timer causes the problem. A friend who uses the avr chips (in assembly language) mentioned the watchdog timer can corrupt the bootloader in some cases. The following is from a file regulatoring-100328a.zip that I downloaded

#include <wiring_private.h> // included for access to cbi(), sbi() macros, and TCCR1B register definitions

#include "/usr/lib/avr/include/avr/wdt.h"
#undef int
#undef abs
#undef double
#undef float
#undef round
// access to watchdog timer macros


unsigned int power_level = 0;
// The target regulated voltage, default power level 0V (output will be input voltage +/-1V)
// Do not change this definition (change the SetVoltage(v) assignment in setup, below)

unsigned int SetVoltage(double voltage);
// Calculate the desired analog input reading, for a given voltage

signed int duty = 0; // used in the main program loop
// it's assigned to the analog output, to control the output voltage.
// the relationship between duty cycle and voltage depends on output load and input voltage.
// since neither the load or input are assumed, the program estimates/seeks
// the correct duty cycle by sensing the output voltage and making small adjustments.
// A greater duty cycle makes a greater voltage.

//alternate names which link arduino pins to where they go
int c1 = 2;
int c2 = 3;
int c3 = 4;
int c4 = 5;
int c5 = 6;
int c6 = 7;
int c7 = 8;
int c8 = 9;
int c9 = 11;
int c10 = 12;
int c11 = 13;
int c12 = 19;

int value = LOW; //previous value of the pin
long previousCount = 0; //stores the value of the fired pin
//long firetime = 5; //the amount of firing time in microseconds
//long interval = 1595; //the amount of time between firings in microseconds
long firetime = 1000; //the amount of firing time in milliseconds
long interval = 2000; //the amount of time between firings in millisecond

void setup() {
 // I use pin 13 to indicate power, with an LED. (like the older revisions had built-in)
 // For my rev.c arduino, I put an LED between pin 13 and GND (outputs only source 20mA).
 pinMode(19,OUTPUT);
 pinMode(13,OUTPUT);
 pinMode(12,OUTPUT);
 pinMode(11,OUTPUT);
 pinMode(9,OUTPUT);
 pinMode(8,OUTPUT);
 pinMode(7,OUTPUT);
 pinMode(6,OUTPUT);
 pinMode(5,OUTPUT);
 pinMode(4,OUTPUT);
 pinMode(3,OUTPUT);
 pinMode(2,OUTPUT);
 //digitalWrite(c2,HIGH);
 
 // The following code increases the PWM frequency
 // This might have an effect on delay(n) and millis() functions.
 // The ideal frequency depends on the inductor, but it'll only be important if you need alot more power.
 // My earlier tests indicated 20-300KHz are usable (depending on the inductor).
 // (If 1KHz is used, the inductor will make a buzzing sound.)
 
#if defined(__AVR_ATmega168__)  || defined (__AVR_ATmega328P__)
 // 62.5KHz PWM for the ATMega168 -> only on Arduino pins 9 and 10
 
 // set prescaler to 1
 // (sbi means "set bit register", cbi means "clear bit register")
 cbi(TCCR1B, CS12);
 cbi(TCCR1B, CS11);
 sbi(TCCR1B, CS10);
 
 // set fast PWM
 cbi(TCCR1B, WGM13);
 sbi(TCCR1B, WGM12);
 // with fast PWM, the frequency is (CLK/256*prescaler) = 16MHz/256 = 62.5KHz
 // with slow PWM, it is half that speed (31KHz)
#else
 // 22KHz for the ATMega8 (this is a low frequency, so fewer inductors might work with it)
 TCCR2 = ((TCCR2 & ~0x07) | 0x01);
 TCCR1B = ((TCCR1B & ~0x07) | 0x01);
#endif

And final part

 // enable the watchdog timer (a failsafe reset: if the program freezes, the voltage booster will shut off)
 // the Arduino will reset if this timer isn't cleared in less than 400ms.
 wdt_enable(400);
 
 
 // set the voltage you want the program to maintain (any decimal value greater than your input voltage)
 power_level = SetVoltage(22.0);
 // Do not exceed 24V without taking special precautions.
 // Do not exceed 60V with the circuit/schematic provided with this software. (75V or more will damage the arduino)
 // Do not exceed 250mW (aka 1/4W, aka quarter watt) of power. (MAX: 5V 50mA, 9V 28mA, 12V 21mA, 24V 10mA, 48V 5mA)
}


void loop() {
 
 unsigned int measure = analogRead(0);
 
 wdt_reset(); // watchdog timer reset (see above)
 
 if (measure>power_level+18) {
   // "panic" if the measured voltage is more than 1V above where it should be,
   // cut power by 50% to respond quickly.
   duty=duty/2;
   
 } else if (measure>power_level) {
   // decrease duty cycle to compensate for smaller load
   duty=max(0,duty-1);
   
 } else if (measure<power_level) {
   // increase duty cycle to compensate for larger load
   duty=min(191,duty+1);
   // Without the 191 limit, it can cause regulation to fail at high loads or high voltages.
   // Only modify this limit if you're using an improved version of the schematic I've given.
   
 } else {
   return;
 }
 
 analogWrite(10,duty);
 
 // If you have HF noise problems, you might want to add a small microseconds delay here to see if it helps.
 // Delays can make voltage regulation worse, by reacting slower to changes in the output load.
 
 // If you have regulation problems, make sure your output filter capacitor is at least 0.1uF.
 // As your circuit's load changes, the capacitor will slow down output fluctuations.

//if (micros() - previousCount > interval) {
//  previousCount = micros(); //recall the last time a pin was fired


if (millis() - previousCount > interval) {  
 
 digitalWrite(c11, HIGH);
 //delayMicroseconds(firetime);
 delay(1000);
 digitalWrite(c11, LOW);

 previousCount = millis(); //recall the last time a pin was fired
 
}
 
}

// Calculate the desired analog input reading, for a given voltage
unsigned int SetVoltage(double voltage) {
 if (voltage>60) {
   return 0; // do not exceed 60V
 }
 
 // This function converts the voltage value (0 to 5V reading; 0 to 60V actual), into a value for an analog input (from 0 to 1024)
 // If your resistor voltage divider is not perfectly 15:1 you'll need to change the formula below
 
 // with ideal resistors and a perfect 5V Analog Reference voltage (AREF), an analog input value of 13.65 would be 1V
 
 return (voltage*12.8);
 // ideal ADC value, per volt     = voltage*(1024/5)/(15/1) = 13.65
 // the real value for my circuit = voltage*(204.8)/(16.5)  = 12.41
 
 // 16.5 was my measured resistor voltage divier ratio.
 // I increased my calculated 12.41 constant to 12.8, by trial and error, in order to get closer to the target voltage
 // My results were +/-0.2V, at a 0.1mA (100Kohm) load when powered by the Arduino.

}

A friend who uses the avr chips (in assembly language) mentioned the watchdog timer can corrupt the bootloader in some cases.

The watchdog timer problem is not that it corrupts the bootloader, but rather that if the watchdog time-out period is shorter then the bootloader time-out (and jump to sketch) period, a unbreakable loop is created. The watchdog timer keeps causing a new watchdog timer reset while the bootloader is still running, so the chip is in a perpetual loop. Several of the 3rd party bootloaders (like the Adafruit bootloader) add code to the bootloader to disable the watchdog timer interrupt and therefore do not suffer the problem.

Lefty

NOOOOOOOOO

Ok, so i have managed to corrupt another chip…

Last time i added a Serial.print, this time a delay(200);

I wouldn’t be quite so annoyed if my deadline was months away and the $NZ wasn’t making these ever increasing replacements a $15 stab at a poor students bank account…

How come im the newb getting all the problems…

[EDIT]

wipes brow
False alarm… Go figure… Not sure what happened there, was the same error i had before and now we are all fine 10mins later… Werid…

How come im the newb getting all the problems…

wipes brow
False alarm… Go figure… Not sure what happened there, was the same error i had before and now we are all fine 10mins later… Werid…

It’s one of those universal law of physics, all newb come with a high initial state of charge that attracts software bugs, wiring mistakes and brain farts. Luckily over time this charge slowly dissipates to drastically decrease this phenomenon, except the occasional brain farts still occur to remind us all that the universe is still in charge. :wink:

Lefty

Thanks, Lefty. I’ll be cleaning tea off the monitor and out of the keyboard for a while, now.