View previous topic :: View next topic |
Author |
Message |
cseusy
Joined: 15 Apr 2006 Posts: 12
|
Randomly changing variables |
Posted: Mon Nov 23, 2009 11:17 pm |
|
|
I have proven that a variable in my code is changing of its own accord. I have programmed this variable to be only a zero or a ten. I have demonstrated that it ends up equal to one. Any of you geniuses know what could cause a variable to change by itself?
All my variables fit into one bank. I have searched the assembly code for bank select commands and there are none after the first few lines of assembly code, so it doesn't seem that it could be a banking problem. And the address of this variable is not used anywhere else.
Every time I change my code and re-compile, this kind of gremlin ends up somewhere else in the code, where a variable gets changed where it should not. In one case, one variable would get altered depending upon the value I fed into an unrelated equation.
Thanks for your help! |
|
|
Jerson
Joined: 31 Jul 2009 Posts: 125 Location: Bombay, India
|
|
Posted: Tue Nov 24, 2009 1:00 am |
|
|
1. Stack problems
2. String / Array management issues
3. Non atomic operations on the variable _________________ Regards
Jerson Fernandes |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Tue Nov 24, 2009 3:06 am |
|
|
I would say memory corruption due to buffer overrun or bad pointer.
This would tie in with changing what appears to be an unrelated variable. |
|
|
Guest
|
|
Posted: Tue Nov 24, 2009 10:12 am |
|
|
Have you any local variables in interrupts ?
I gave up with that long ago as they can overwrite global variables, the compiler doesn't seem to handle the memory allocation properly.
Trying changing any interrupt variables to globals. |
|
|
cseusy
Joined: 15 Apr 2006 Posts: 12
|
|
Posted: Tue Nov 24, 2009 11:19 pm |
|
|
Gentlemen,
Thank you for sharing your ideas.
I am not using any interrupt service routine(s) and have attempted to disable all interrupts, through CCD EEPROM write and read function turn on GIE. I tried turning it off after every write or read with no change.
I'm not using any arrays, pointer, or strings.
I am in the process of making all subroutine variables static, so we'll see how that goes.
What is a non-atomic operation?
Thanks! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 25, 2009 12:06 am |
|
|
1. Post your PIC.
2. Post your compiler version. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Nov 25, 2009 1:02 am |
|
|
As a general comment, similar problems are mostly caused by coding errors and sometimes by compiler bugs.
Without a reproducible test case, there's no detailed help, I fear.
You can use advanced breakpoints on data writes in CCS or MPLAB debugger to identify the code location,
that's doing the unwanted writes. |
|
|
cseusy
Joined: 15 Apr 2006 Posts: 12
|
|
Posted: Mon Jan 11, 2010 6:00 pm |
|
|
I figured this out. Actually, CCS figured this out. I had commented out a section of code using "/*" and "*/". Later I deleted the "/*" but forgot to delete the "*/". The next large section of code was commented out, so I had "*" (relative addressing symbol) followed by "/" (ignored, I guess), followed by many lines of commented-out code, followed by an equation. The result of the equation was not put into the variable, but into the RAM register addressed by the present value of the variable. Ugh. Cost me four critical days. I'm going for help sooner, next time! |
|
|
|