|
|
View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
Scratch and main variable corruption |
Posted: Tue Nov 12, 2013 1:24 am |
|
|
This harks back to an old thread:
<http://www.ccsinfo.com/forum/viewtopic.php?t=51298&highlight=atan2>
In this, Jeremiah refers to having had a similar problem with the maths, overwriting a scratch variable. I'm experiencing something worse. V5.01x.
Basically using some fairly 'aggressive' arithmetic (atan2, exp, and log10), with quite a few normal calculations as well. What I'm seeing is the compiler overwriting variables declared in the main code. So:
Code: |
2E4-2E9 MAIN.adc_sums
2E6-2E9 atan2.z
2EA MAIN.state
2EA.0 atan2.sign
2EB MAIN.amreading
2EB atan2.quad
|
So the 'adc_sums', 'state', and 'amreading' values get overwritten when the maths is used. Result 'garbage'.
Now the maths is all performed in the main (so should respect variables declared here), yet this happens.
If I declare the variables as static, it all works fine.
The same code compiled with a much older compiler (4.118), works OK, and doesn't overwrite the variables.
It seems to be doing this with all the V5 releases I have tried. .008, 010, 012, 013 etc..
It never seems to overwrite 'simple' variables. adc_sums is an array, and state, and amreading are both enums.
Now I have a workround, by using 'static', but my problem is generating some simpler code that displays the problem, so I can show it to CCS. I can't send them the core part of the code that shows the problem, since the algorithm here is 'commercial', and bound by some fairly strict constraints.
So has anyone else had problems with complicated bits of arithmetic giving unexpected results, or other variables changing with a V5 compiler, with code that is small enough to share, and is not bound by commercial agreements?.
I've been playing for quite a few hours trying to generate some shareable code that displays the fault, but thought I'd ask if anyone else was having the problem?. You might not even realise this was 'why' you were getting silly results....
It is giving problems on both PIC18's, and PIC24's with the original code (suitably modified).
Best Wishes |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Nov 12, 2013 9:56 am |
|
|
thanks for the heads up!
for now, i'm planning to declare all vars as static or global unless i run out of
mem space, and then back into only using temps in functions to make the program compile.
may i assume that option is not open to you ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Wed Nov 13, 2013 12:10 am |
|
|
No, globals are working fine.
In the main there is no loss of space. On the compilers that work, the code puts the temp variables for atan in the same area as those for exp, which since they can't be called inside each other, is no problem. On the ones with problems the atan variables get put over main variables.
I want to show CCS the problem....
Best Wishes |
|
|
|
|
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
|