These CAN be fun! Since function parameters and larger return values (I think 8 bit values are returned in w) are returned on the software stack, if the return value is misinterpreted as to type, it MAY return the correct value if other stuff left that stack memory in the correct condition, and not when it hasn't. I spent a LOT of time single stepping through code and watching C18 return a wrong value now and then. My problem turned out to be a missing #include of the header for the function in the file where I called it. This may not be your problem, though.. Good luck! Harold > The thing is that the code works perfectly most of the time for thousands > of iterations. > Then suddenly *the same part of the code* do something erratically. > > Like if some value was overwroitten by an interrupt or something. > But that happens also with interrupts globally disabled... > > /Morgan > > > Den 2007-08-28 00:06:35 skrev Harold Hallikainen : > >> Regarding functions returning values different than what was in the >> function, make sure the code that calls the function has the correct >> prototype for the function. If, for example, the header file is not >> specified, the compiler assumes functions return an int, which is often >> not the case! >> >> Hope that is SOME help. >> >> Harold >> Been there, done that... >> >> > > > > -- > Morgan Olsson > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- FCC Rules Updated Daily at http://www.hallikainen.com - Advertising opportunities available! -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist