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.