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

Strange memory errors on 18F65J10

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



Joined: 18 Sep 2008
Posts: 9
Location: Gothenburg

View user's profile Send private message

Strange memory errors on 18F65J10
PostPosted: Thu Sep 18, 2008 3:58 am     Reply with quote

Hi!
I've run into a problem using version 4.064 of the compiler. It would seem that I've reached some kind of limit for memory usage. I've got plenty of RAM and flash available but adding new variables makes the hardware enter a reset-loop, rebooting almost instantly after finishing a boot sequence. The problem occurs for global variables in both RAM and flash. I have a distinct feeling that I've managed to hit some kind of ceiling concerning global variables of any type. My questions are: Is there such a ceiling? If there is, why does it exist and can I get around it in some easy way? If a ceiling doesn't exist, is this a known compiler problem for which a fix exists?

Best regards,
Axel Lindholm
aopg64



Joined: 17 Oct 2005
Posts: 28
Location: Hampshire, UK

View user's profile Send private message

PostPosted: Mon Sep 22, 2008 5:08 am     Reply with quote

Hi folks,

I've run into a similar problem on the 18F8722. I had been using V3.249 for a long time and every now and then I would compile something that failed to run. By altering a string length or rewriting the code area I was working on, the recompiled code would then run. The compiler was indicating 90% Flash and 100% RAM usage.

I upgraded to V4.065 as that is our latest version (I prefer to stay with an old stable version generally!) as my colleague has been using it successfully.

This version has the same problem. I assumed it was the 100% RAM utilisation. I rewrote to get 99% RAM, but the problem still occurs.

I then suspected the PM3 not programming correctly, so I tried an ICD2. Same problem. So it must be MPLAB/CCS compiler/CCS Plug-in related (I guess?)

Thanks in advance for any help in sorting this.

Nige
_________________
No comment! (Can't think of anything interesting to say!)
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Sep 22, 2008 6:53 am     Reply with quote

Hello,

I guess, it's advisable to keep your V3.xx compiler with existing products, if ever possible. Some things have been definitely changed in an incompatible way. Some changes may be small, as the address requirements with bootloader definitions. I also experienced that the RAM and ROM consumption has been apparently increased. This may serve a good purpose, but can also crash an existing application. I'll continue to try, if existing applications can be easily ported, but if any incompatibilities arise, there's a strict stop. The topic may be reviewed in one or two years, when the V4 has reached a certain maturity.

Regards,
Frank
Axel



Joined: 18 Sep 2008
Posts: 9
Location: Gothenburg

View user's profile Send private message

PostPosted: Mon Sep 22, 2008 7:17 am     Reply with quote

Me and my colleague managed to temporarily fix this problem by changing all of our variables with ROM qualifiers to use a const qualifier instead. The const qualifier results in a different and more compact data alignment on the flash for us which solved our problem with unexplained resets.

However, a strange thing happened as a result of substituting ROM for const. While using the ROM qualifier MPLAB asserted that we had a 65% ROM usage and a 98% usage including unused fragments (this number was grabbed from the STA-file). With the const qualifier the ROM usage rocketed to 90% while the including-unused-fragments usage dropped to 92%. Because of the difference in alignment I can understand why the unused-fragments number dropped closer to the actual ROM usage but the million dollar question is why the ROM usage was raised with 25% from using a seemingly more compact representation.

Does anyone have an idea on whats going on? Does the compiler generate a lot of code overhead for const qualified variables or was the original 65% ROM usage indicated somehow incorrect?

A small footnote is that when getting an address to a const qualified array we had to break common sense and C semantics by putting an address-operator in front of the array name or it would read from the array instead of getting the address.

Code:

const UCHAR array[] = {1, 2, 3, 4, 5};
UCHAR* ptrArray;

// Code resulting in errenous behavior
ptrArray = array;   // ptrArray will equal 0x0201 here, the first to values in array

// Code resulting in correct behavior
ptrArray = &array;


Best regards,
Axel Lindholm
Ttelmah
Guest







PostPosted: Mon Sep 22, 2008 7:52 am     Reply with quote

When you use 'const', the compiler adds a little program in front of every block of stored values, to handle the retrieval of the values. So if you declare (say):
Code:

const char dummy[]="This is a test";

The result is the block of data expected:
Code:

00C4:  DATA 54,68
00C6:  DATA 69,73
00C8:  DATA 20,69
00CA:  DATA 73,20
00CC:  DATA 61,20
00CE:  DATA 74,65
00D0:  DATA 73,74
00D2:  DATA 00,00

But in front of it, the retrieval code:
Code:

00AA:  MOVFF  FF2,0E
00AE:  BCF    FF2.7
00B0:  CLRF   FF7
00B2:  ADDLW  C4
00B4:  MOVWF  FF6
00B6:  MOVLW  00
00B8:  ADDWFC FF7,F
00BA:  TBLRD*+
00BC:  MOVF   FF5,W
00BE:  BTFSC  0E.7
00C0:  BSF    FF2.7
00C2:  RETURN 0

So in this case, 16bytes for the data, but 26 bytes for the extra code.....
If however you declare a 1000 byte array, the overhead code, remains the same basic size.
So 'small' constant values represent a massive waste.
The 'ROM' directive, instead uses a single 'global' retrieval routine, but has to add arithmetic to work out where the values are. This costs time, and RAM.
In general, multiple things:
1) Use the const, and ROM keywords, rather than applying the const=ROM overall control. Then only apply 'ROM' to values that need pointer access. Switching everything to ROM, is wasteful of RAM, and time.
2) Think before using small 'const' values. If (for instance), you want a simple const, for a the size of a buffer, use #define instead. Though normally not considered as 'elegant' in programming terms, in terms of operation with CCS, it is much better.

Best Wishes
Axel



Joined: 18 Sep 2008
Posts: 9
Location: Gothenburg

View user's profile Send private message

PostPosted: Mon Sep 22, 2008 9:08 am     Reply with quote

Thank you very much for explaining this Ttelmah! This bit of info really helped a lot in making some important design decisions for our project.

Best regards,
Axel Lindholm
Axel



Joined: 18 Sep 2008
Posts: 9
Location: Gothenburg

View user's profile Send private message

PostPosted: Wed Sep 24, 2008 5:23 am     Reply with quote

Hi again, still wrestling the problem...

Ttelmah wrote:
So in this case, 16bytes for the data, but 26 bytes for the extra code.....
If however you declare a 1000 byte array, the overhead code, remains the same basic size.
So 'small' constant values represent a massive waste.


Doing some calculations on our source and the const overhead I've come to the conclusion that we should have about 2.5kb overhead from using const arrays instead of ROM, using the numbers supplied in the quote. This does definitely not account for the experienced 16kb increase in size we got from using const. Does anyone have an idea about what could be using the 13.5kb unaccounted for?

Best regards,
Axel Lindholm
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