bizarre restart bug: calling arduino ninjas.

Hey all,

So, I've been working on some code for the Arduino for a little over a month now. The last 2 weeks have been spent fighting a real bastard of a bug. I have years of experience programming, so I'm not a n00b, but this is also my first major microcontroller project. I've read tons of stuff on the arduino, atmega168's, etc. I'm basically at wits end and am hoping that some genius from the forums can help.

first, the program i'm writing is the Arduino firmware for a RepRap machine. i'm trying to squeeze into a program a 3-axis stepper controller, some temp sensing, and some other random stuff. The arduino is the brains and it controls an array of boards that do the actual work. The RepRap project has a host program written in java that sends and receives commands over a serial connection. I'm essentially just implementing that protocol on an Arduino. Easy, right?

The approach I took was to write libraries, and use these to handle the code. There is a copy of the most recent code, located here: http://www.osotite.com/dump/reprap-arduino-firmware-2008-02-17.zip

Okay, so lets get down to the problem. Basically what is happening is that there are a few certain circumstances that trigger the program to reset. I have debug code in the setup() function that prints out 'begin'. I'll run the host software for a bit until the bug is triggered, at which point the setup() function seems to get run AGAIN! The 'begin' string will be printed out, and program execution will continue as normal (well, except everything is reset!)

Like I said, I've spent weeks on this bug, so I've narrowed it down to a couple of very specific cases. The simplest on is that i'll trigger a 'homereset' on the Y axis, then do a 'seek' to any point. that will cause it to take a few steps, then reset. the bizarre thing is that this only happens to the Y axis!! both the x and z axes can home then seek no problem. also, when the y axis is not at home, it can seek around no problem.

I've tried nearly everything I can think of to try and track down this bug.

I dont think its a brown-out reset, because the arduino doesnt hit the bootloader... it goes straight to the beginning. Not only that, but I have a random movement tester that works 100% fine with the boards... no resets. (also, the bug happens with the stepper boards unconnected!)

i dont think its a timer issue because this happens when i run it at 1 RPM, and the stepper interrupt runs just fine at high speeds (300+ RPM)

The only thing I can think of right now is 1) a bug in my software, possibly because i'm doing something wrong the microcontroller doesnt like.

would someone please look over my code, both the libraries and the sketch called 'Single_Arduino_SNAP'? i'm really in a bind here because not only does my firmware not drive my boards, but it also doesnt work for anyone else out there who is trying to run a RepRap machine off an Arduino.

if you find the bug, i promise i'll send you something very special that i printed with my machine.

My guess would be that you're running out of RAM, and that this is causing your stack (including return addresses) to be overwritten (possibly with 0's), and so when some function returns, it's jumping back to the start of your program (address 0). Or that running out of RAM is causing some other strange failure mode that creates the behavior you're seeing. Can you temporarily comment out any variables / lookup tables / strings in your code? Or use smaller data types for anything?

Hej Hoeken,

first of all, i tried getting into your code. really. but it's just too much, and way too abstract without being able to try out what it really does. But anyway, and in hope i'm not writing stuff you already tried a hundered times:

You wrote the problem only affects the Y-axis. So i'd try anything to get the bug show up for another axis now.

  • you probably already swapped the motor boards, and the bug still showed up for only the y-motor!? (yeah, i know, the bug still happens with no board connected...)

  • did you change the motors pin numbers numbers instead of the motor connections? (maybe the bug is connected to a certain pin number?)

  • did you write the libaries from scratch? could there be a pin conflict?

  • is there anything else special to the y-axis, compared to x and z? any special move, length or delay?

I think Mellis' guess sounds very resonable except that it doesn't explain the y-axis-phenomenon.

...
I dont think its a brown-out reset, because the arduino doesnt hit the bootloader... it goes straight to the beginning. Not only that, but I have a random movement tester that works 100% fine with the boards... no resets. (also, the bug happens with the stepper boards unconnected!)

what's a random movement tester? a board to test sub boards without the arduino? or a seperate program for the arduino?
concerning brown-out, i think there are differently behaving bootloaders and configs out there. i'm currently using a ladyada version which only starts the bootloader after a manual reset. just maybe that rings a bell...

so that was my shot at it.
good luck,
kuk

just wanted to say that this was fixed!

the problem was that i was accidentally enabling an interrupt for which there was no corresponding handler function. the result: the interrupt got called, jumped to the function at address 0 (beginning of program) and started over.

note to self: i will not enable interrupts i do not fully understand!

note to self: i will not enable interrupts i do not fully understand!

Heh. :smiley:

Thanks for letting us know how you solved the issue.

--Phil.

P.S. Too bad I didn't find the fix for you tho, would've liked a RepRap printed item--particularly if it was another RepRap. :slight_smile:

P.S. Too bad I didn't find the fix for you tho, would've liked a RepRap printed item--particularly if it was another RepRap. :slight_smile:

me too :slight_smile:

and thanks as well for letting us know about the interrupt. this rang a bell for me concerning probs with an older project. :o