View previous topic :: View next topic |
Author |
Message |
GordonHuang
Joined: 17 Aug 2020 Posts: 1
|
Not enough RAM for all variables 16LF18346 |
Posted: Mon Aug 17, 2020 11:02 am |
|
|
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
|
|
Posted: Mon Aug 17, 2020 11:05 am |
|
|
And what is your CCS compiler version ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Aug 17, 2020 11:57 am |
|
|
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: 19506
|
|
Posted: Tue Aug 18, 2020 2:02 am |
|
|
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
|
|
Posted: Wed Aug 19, 2020 2:50 pm |
|
|
Just wondering: What does #device *=16 do? I can't find the * option in the manual... |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Wed Aug 19, 2020 3:34 pm |
|
|
Its on page 133 of the current manual. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Thu Aug 20, 2020 3:03 am |
|
|
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. |
|
|
|