View previous topic :: View next topic |
Author |
Message |
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
variables contain bad values |
Posted: Sat Oct 15, 2011 1:19 pm |
|
|
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
|
|
Posted: Sat Oct 15, 2011 1:35 pm |
|
|
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
|
|
Posted: Sat Oct 15, 2011 1:54 pm |
|
|
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
|
|
Posted: Sat Oct 15, 2011 2:00 pm |
|
|
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
|
|
Posted: Sat Oct 15, 2011 2:13 pm |
|
|
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
|
|
Posted: Sat Oct 15, 2011 2:29 pm |
|
|
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
|
|
Posted: Sat Oct 15, 2011 2:37 pm |
|
|
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
|
|
Posted: Sat Oct 15, 2011 2:50 pm |
|
|
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! |
|
|
|