View Single Post
  #1   Spotlight this post!  
Unread 21-02-2006, 15:33
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Compiler has troubles with structures?

I've been having the strangest problems - my code has random issues. Sometimes the printf() calls don't substitute variables at all (for example, if I
Quote:
printf("(%d,%d): %d"...
it would print
Quote:
(,):
. Other times, the exact same code with no modifications will print out whatever it is I'm trying to print just fine (ex: (254,254): 127) or something. I don't understand why it prints out a blank space - even if I'm passing something incorrectly, it would print a 0 or an extremely large number. Why would it be blank? Also, whenever this event happens, the PWM outputs go crazy. It starts spitting out either full forward, full reverse, or something in between (even if the last line in the code sets it to 127). The ADCs stop working properly (Get_Analog_Value returns something above 3000) and sometimes upon downloading code, it just crashes and sits in program mode (even after a reset, it won't leave program mode...)

I'm not using interrupts, no pointer arithmetic, and I even disabled the timers. What I found was that by rearranging the order of my code (switching two lines, etc) I could affect exactly what got corrupted. A friend of mine a couple of years ago told me that the MCC compiler generates incorrect code when it uses structures (which I use for my PID control) and commenting out the structures seems to cause the problems to disappear. Does anyone know of some such issues, or any clue what might be wrong? I can post some code snippets a bit later today (when I get to my laptop) or just email you the entire thing, if you're interested... it's very strange, and I worked on it for probably nineteen hours straight, yesterday, without making much headway on this.

Thanks for any pointers,
Steven
__________________
Shift to the left, shift to the right!
Pop up, push down, byte, byte, byte!