reliable startup

I am having a rare but troublesome problem with my Arduino mega. I don't know why it happens, perhaps you can help.

Scenario: The mega is controlling a 90v DC motor. The speed is controlled by sending a PWM signal filtered into a variable DC voltage to the speed control. Everything works great on the bench and for weeks in the field. BUT! every once in awhile, the mega will come up in some strange lockup where it is sending a speed signal to the drive and my robot drives it's self off the end of the track, past the limit switch (takes it about five minutes). And mind you, I have plenty of redundant code to prevent just that from happening. There is no log of the failure so I am guessing the mega is not executing my code. The mega has a nice little power-on reset resister/capacitor combo on it. Maybe I need to increase the size of the capacitor to slow the start and wait for more stable power. Hell, I don't know! Power is 9vdc "wall transformer" via A/C line.

Here is my "startup" code for the PWM:

void setup() { pinMode (Enc_A, INPUT); pinMode (Enc_B, INPUT); pinMode (Enc_A_N, INPUT); pinMode (Enc_B_N, INPUT); pinMode (Lim_pin, INPUT); // limit switch pinMode (PWM_pin, OUTPUT); // output for motor PWM pinMode (Dir_pin, OUTPUT); // output direction relay for motor PWM pinMode (WLvalve_pin, OUTPUT); // left valve relay pinMode (WRvalve_pin, OUTPUT); // right valve relay pinMode (MLvalve_pin, OUTPUT); // left aux valve relay pinMode (MRvalve_pin, OUTPUT); // right aux valve relay digitalWrite (Lim_pin, HIGH); // turn on pullup resistors digitalWrite (Enc_A, HIGH); digitalWrite (Enc_B, HIGH); digitalWrite (Enc_A_N, HIGH); digitalWrite (Enc_B_N, HIGH); digitalWrite (WLvalve_pin, LOW); // left valve relay digitalWrite (WRvalve_pin, LOW); // right valve relay digitalWrite (MLvalve_pin, LOW); // left aux valve relay digitalWrite (MRvalve_pin, LOW); // right aux valve relay

TCCR2A = B10000001; // set Atmega PWM params TCCR2B = B00000001; // set Atmega PWM - bout 31250 hz OCR2A = 0; // init pulse width to min (max = 255) 0 = off Timer3.initialize(500000); // initialize timer3, and set a 1/2 second period Timer3.attachInterrupt(Move_Check); // attaches Move_Check() as a stall warning attachInterrupt(0, doEncoder, CHANGE); Wire.begin(); // for the real time clock Serial1.begin(57600); // used to communicate with the touch screen Serial.begin(57600); // for debug GetDate(); Cumulative_minutes = (Week_day * 1440) + (hour * 60) + minute; // set our Cumulative since Sunday midnight delay(1000); // one second startup delay - wait for screen Serial1.print("H"); // Send reset Serial.print("Reset\n"); // let log know we reset

}

I'd get rid of the resistor/capacitor on the reset line. It's possible that the reset line is rising too slowly which cause the Mega to not come out of reset properly. That's what the on-chip brownout detector is for anyways. I'd just enable the BOD fuse bits to keep the chip in reset until stable power is present.

-- Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

Well RC, I read the ATMega data sheet and yes, looks like the brownout detector may help the problem.

Read lots of posts in the forum and it seems like fuse bits = dead Arduino! So I am a bit wary of messing with them.

I program in C via the Arduino software. Do not see any way to set the fuse bits with that or any tools in the reference pages or the playground. So just how does one set them and set them safely?

Keshka

First of all, it might just not be necessary. The AVR comes out of reset just fine many times with no BOD fuses and no RC network on the reset pin. So try the simplest path first.

If I were to mess with the fuses I'd use the 6-pin ISP connector on the board, an Atmel mkII programmer and AVR Studio software. As long as you don't disable the SPI programming fuse, you can play with the fuses to your heart's content (and can even reprogram the bootloader if you erase it).

-- Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

Thanks RC!

;)