CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Randomly changing variables

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cseusy



Joined: 15 Apr 2006
Posts: 12

View user's profile Send private message

Randomly changing variables
PostPosted: Mon Nov 23, 2009 11:17 pm     Reply with quote

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: 122
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Tue Nov 24, 2009 1:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 3:06 am     Reply with quote

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








PostPosted: Tue Nov 24, 2009 10:12 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 11:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 25, 2009 12:06 am     Reply with quote

1. Post your PIC.

2. Post your compiler version.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Nov 25, 2009 1:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 11, 2010 6:00 pm     Reply with quote

Very Happy 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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group