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

unexpected change of variables (solved)

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



Joined: 22 Aug 2005
Posts: 30
Location: Ioannina - Greece

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

unexpected change of variables (solved)
PostPosted: Tue Nov 24, 2009 4:15 pm     Reply with quote

Compiler version PCH 4.084
PIC18F4550

In my application I see that certain variables change, when a specific code part is executed. The change is always on the same byte, same bit.
If I define a dummy variable, the problem is temporarily solved, but this is not the solution, because this might also happen anywhere in the program in variables that I dont check externally.


Have you ever met this behavior before?

I know I have to post a part of code for you to reproduce the problem but I have to strip it down first as it is fairly big file.

Thanks a lot in advance
_________________
www.hlektronika.gr


Last edited by gs on Mon Nov 30, 2009 1:09 pm; edited 1 time in total
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Tue Nov 24, 2009 4:26 pm     Reply with quote

Perhaps, you are addressing a wrong index which is beyond the variable size. Such as
Code:

int myarray[10];
myarray[10]=5;
etc...

Try to post some source code example. It might also be a compiler bug.
cheers
cseusy



Joined: 15 Apr 2006
Posts: 12

View user's profile Send private message

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

See responses to my post called "randomly changing variables". Maybe they can shed some light. I have been fighting the same or similar problem for two weeks. A friend who is an expert computer scientist says this is called memory stomping. That is an accurate description. I can always change code to make the problem go away, then when I add more code, the "stomp" manifests somewhere else. Best of luck! If you find the solution, please post it.....pleeeeeeeeaaassse!!!
gs



Joined: 22 Aug 2005
Posts: 30
Location: Ioannina - Greece

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

PostPosted: Wed Nov 25, 2009 3:13 pm     Reply with quote

It is very big code to strip it down. It uses 18F4550 and a glcd 128*64

I use graphics.c and HDM64GS12.h math and string functions.


Code:
glcd_rect(x-1,y-1,x+29,y+7*size, YES, !color);            // Lain menu and -255

//glcd_rect(x,y,x+29,y+7*size, YES, !color);               // Lain menu only


the two lines above, both make problems.
Both of them change the first character of a string that is M and it changes to L


The first one changes the bit0 of the high byte of a 16bit variable (makes it 0) the second line does not do this but the result is not the desired.

If I do this

Code:
xx=x-1;
yy=y-1;
glcd_rect(xx,yy,x+29,y+7*size, YES, !color);


has the same result as

Code:
glcd_rect(x-1,y-1,x+29,y+7*size, YES, !color);            // Lain menu and -255

Note that x,y are integers that I use a lot in many subroutines as locals




Any suggestions on how to debug this situation? I have ICD2 availiable.
_________________
www.hlektronika.gr
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Nov 25, 2009 4:49 pm     Reply with quote

If I understand right, you already found out, that the glcd_rect() call writes somehow out of bounds. You can set a breakpoint on write to the specific variable address and identify, which exact instruction does the write. You should be able to understand, if the compiler does something wrong or it's a coding error, e.g. in the subroutine.
gs



Joined: 22 Aug 2005
Posts: 30
Location: Ioannina - Greece

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

PostPosted: Mon Nov 30, 2009 12:42 pm     Reply with quote

Finally I solved the problem.

cseusy, did you also use graphics lcd?

I use fast glcd

My problem was created because I was displaying text at the bottom right corner of the lcd and the y value was one pixel over the proper value.

100% my coding fault.

I wrote a routine to display value with an option to select the polarity of the text displayed and the background of the text. That background is always 1 pixel around the text displayed. The routine that draws that background goes out of the glcd displaydata table and writes in the next memory positions.

I have to confess that I was quite brute while debugging today...


Thanks a lot for your time
_________________
www.hlektronika.gr
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