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 CCS Technical Support

variables contain bad values

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



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

variables contain bad values
PostPosted: Sat Oct 15, 2011 1:19 pm     Reply with quote

Hi,

I am making a data logger using PIC18F46J11 , i have the PCWHD compiler ver 4.109. the problem is that RAM memory locations get corrupted and lose their values. In this case i have two float variables that had the right values and after maybe 6 hours of continuous operation they lost their values and when i reset the device still the same problem.

I tried to re-program the micro and the problem persisted so i decided to move the location where i declared the faulty variables. I left them in main loop but declared them at the end of all other vars in main and it all was normal after that. Maybe there is a simple explanation to this i would really like to know. thx

AC
------
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Oct 15, 2011 1:35 pm     Reply with quote

Welcome to the real world !?
Honestly, without seeing the entire program all anyone can do is comment on 'it could be'.....
EMI glitch ?
Welder next door?
Some function trashing the floats?
Bad math or function?
Non global assigned variable being overwritten by mistake?
Power supply interruption ?
Spurious 'noise' from something else(cordless phone,WiFI,etc.)?
Weak power supply when a peripheral is turned back on?
bad solder joint or lightly corroded breadboard ?
Current spike when LED comes on ?
You can breakdown the list into two groups , hardware and software, though tracking it down will tke a LOT of time, especially if it only happens after a long period of time.
Perhaps dump out time and data to a PC program that alreats you when the data is 'corrupted' ?
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Sat Oct 15, 2011 1:54 pm     Reply with quote

Thanks, what is strange is that i could re create the problem at will, when i copy paste these two floats at the beginning of my main var declaration list
the problem occurs, but when i copy paste them at the end of main var declaration section everything is ok???

As for code everything is so simple i don't think it's that, i mean i just take
a temperature humidity measurement from a SHT21 sensor and i store them in floating point vars that's it. Thanks for your inputs

AC
-----
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Sat Oct 15, 2011 2:00 pm     Reply with quote

These variables are only used in main, should they be declared global or in main? I tried putting them at top of program in global declaration section everything is ok.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 15, 2011 2:13 pm     Reply with quote

If the problem appears to go away when you change the position of
variable declarations in a file, it often means you are accidently over-
writing certain RAM locations. Quite often, this is caused by writing past
the end of an array. Either the array was declared "too small" for your
needs, or your array index is incrementing beyond the last element in
the array.

Also, the problem could be caused by writing to the address of a variable,
but accidently using a pointer that is declared as a larger data type. For
example, you could write to the address of an 'int8', with a pointer for an
'int16'. This would over-write the next byte of RAM after the specified int8
variable.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Oct 15, 2011 2:29 pm     Reply with quote

One tip to find the possible cause of the problem is to take the failing program and then have a look at the symbol file *.sym. In the list of symbols find the variable that gets corrupted and then look at the other variables directly above in the list. If one of these is an array then this array is very likely the one that you are writing outside the array bounds.
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Sat Oct 15, 2011 2:37 pm     Reply with quote

Ok good thinking this is logical i will investigate this. Should vars that are only changed in main be declared there or in global section?
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Sat Oct 15, 2011 2:50 pm     Reply with quote

Thank to all, yes it was an array declared at the top of main declaration that was too short, instead of 31 elements I made it 63 elements wide and it solved the problem. You guys are the best.

Regards!
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