I have a project here which I just had a similar problem with ... BTW, It's a PIC18f26k20, externally clocked at 25Mhz. What I was running into was that some RAM variables were being overwritten somehow, apparently during a timer-tick ISR. More specifically, when I ran the code under the debugger, and set a breakpoint on the particular chunk of memory which was being overwitten, it would always break in the debugger. What was fun was that at some point, the problem changed to overwrite a different part of RAM. But, like I said, it was always in the ISR where it broke. The code would go typically a few minutes or hours before the overwrite would occur. I spent a *lot* of time tracking down this problem. I'm not sure how I ended up figuring it out, but the The strangest part was that I fixed the *entire* problem by adding a 100 Millisecond delay at the first of the main() routine. It's never called again, but once I do the DelayMs(100), the overwrite stops, and the code runs without any issues. The only thing I can figure is that I was initializing hardware before it stablilized after a reset, and the 100mS delay allowed the hardware to stabilize. -forrest Vitaliy wrote: > Just throwing this out there, in case someone knows about the issue... > > So we have a chip, that prints a "welcome" message on startup. It is > possible to sent it a message on UART, that would execute the "reset" > instruction, which is #defined like this: > > #define p_Reset() __asm__ volatile ("reset") > > Everything was working well, until I turned on optimizations. On power-on, > the chip sends the welcome message like it should. However, after the UART > "reset" command, it spits out a bunch of garbage instead of the welcome > string. Inserting a small delay: > > for (i =0; i < 100; i++) ; > > ..fixes the problem (i < 10 is not long enough). > > Any ideas about what's going on? I'm just starting to look into this > problem, but in case someone knows the answer and wants to help me an hour > or two of debugging, I'll be grateful. :) > > Vitaliy > > > > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist