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

Not enough RAM for all variables 16LF18346

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



Joined: 17 Aug 2020
Posts: 1

View user's profile Send private message

Not enough RAM for all variables 16LF18346
PostPosted: Mon Aug 17, 2020 11:02 am     Reply with quote

I have strange RAM issue. See the below code.
If I change the QUEUE_MAX_SIZE to 128, everything compiles fine. However if I reduce the QUEUE_MAX_SIZE to 64, it reports "Not enough RAM for all variables" during compilation. I do not understand why it has RAM issue with smaller array size. I am using 16LF18346 mcu.
Please help! Thanks
Code:

#define QUEUE_MAX_SIZE          64 // This application should only take

typedef struct
{
    volatile uint16 queueData[QUEUE_MAX_SIZE];
    volatile uint16 queueTail;
    volatile uint16 queueHead;
    volatile uint16 queueSize;
    volatile uint16 queueCount;
    volatile uint32 queueSum;
}QueueStruct;
QueueStruct queueList[2];
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 17, 2020 11:05 am     Reply with quote

And what is your CCS compiler version ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Mon Aug 17, 2020 11:57 am     Reply with quote

and post the top lines of your program. The processor include, fuses,
#device statements etc..

I'd guess, possible a paging issue. Have you got

#device *=16
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Tue Aug 18, 2020 2:02 am     Reply with quote

Had a little investigate.
Following code shows the problem:
Code:

#include <16F18346.h>
#device ADC=10
#device *=16
#use delay(crystal=20000000)

#include "stdint.h"

#define QUEUE_MAX_SIZE         123 //35 to 122 don't work...

typedef struct
{
    volatile uint16_t queueData[QUEUE_MAX_SIZE];
    volatile uint16_t queueTail;
    volatile uint16_t queueHead;
    volatile uint16_t queueSize;
    volatile uint16_t queueCount;
    volatile uint32_t queueSum;
}QueueStruct;
QueueStruct queueList[2];

void main()
{
   int ctr;
   while(TRUE)
   {
      for (ctr=0;ctr<QUEUE_MAX_SIZE;ctr++)
         QueueList[0].queueData[ctr]=0;
   }
}


I was thinking what was happening was that the larger size was triggering
*=16 operation, but have included this in the code and it does not change
the behaviour.
Problem is (of course), that when the problem shows, you cannot see how
memory is actually being allocated.
Have reported this to CCS, since it obviously is a radical error.
Have tested half a dozen compilers back to 5.080, and all behave the
same.

It's also doing the same on other PIC16's.
No problem at all on PIC18's.

There is obviously a very difficult 'issue', since most PIC16's use 128byte
RAM pages. The issue seems to appear if the total array won't fit in one
page, but the single QueueStruct will.
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

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

PostPosted: Wed Aug 19, 2020 2:50 pm     Reply with quote

Just wondering: What does #device *=16 do? I can't find the * option in the manual...
dyeatman



Joined: 06 Sep 2003
Posts: 1912
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Aug 19, 2020 3:34 pm     Reply with quote

Its on page 133 of the current manual.
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Aug 20, 2020 3:03 am     Reply with quote

CCS are looking at this.
It is complex (as I thought), since with the 128 byte pages, the compiler can't
in this case work out how to fit the elements for certain numbers without spanning a page boundary.
They are talking about a new algorithm for the next compiler.

For now, I'd suggest splitting the structure. Have one containing the
queue itself and another the pointers.
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