View previous topic :: View next topic |
Author |
Message |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
RAM and Array question |
Posted: Tue Mar 23, 2004 4:54 pm |
|
|
In an audio sampling project I'm using PIC16F877 and PCM3.187. I have a few byte arrays with the length of MAX_CHANS which is a constant.
When I compile the code with MAX_CHANS=46 I see this in the .LST:
RAM used: 223 (62%) at main() level
269 (75%) worst case
And with MAX_CHANS=47:
RAM used: 227 (63%) at main() level
273 (76%) worst case
And MAX_CHANS=48:
RAM used: 231 (64%) at main() level
277 (77%) worst case
So far so good. But when I try to compile the code with MAX_CHANS=49 I get the infamous "Not enough RAM for all variables" error. Does anybody know why this is happening? Based on the obvious pattern, I was expecting the RAM usage to increase to 235 and 281. Why is the compiler suddenly running out of RAM? What happened to the %23 free memory?
Thanks. |
|
|
Charlie U
Joined: 09 Sep 2003 Posts: 183 Location: Somewhere under water in the Great Lakes
|
|
Posted: Tue Mar 23, 2004 5:22 pm |
|
|
Take a look at the symbol file and see how the compiler is allocating the ram on each increment of your channel count. It may be that due to the size of your arrays and the limited size of the ram in the various banks, you are running into a limit. Are you using a 2 dimensional array by any chance? This could also cause problems. Post a bit more of your code so we can learn a bit more about your problem. |
|
|
Ttelmah Guest
|
Re: RAM and Array question |
Posted: Wed Mar 24, 2004 2:54 am |
|
|
Haplo wrote: | In an audio sampling project I'm using PIC16F877 and PCM3.187. I have a few byte arrays with the length of MAX_CHANS which is a constant.
When I compile the code with MAX_CHANS=46 I see this in the .LST:
RAM used: 223 (62%) at main() level
269 (75%) worst case
And with MAX_CHANS=47:
RAM used: 227 (63%) at main() level
273 (76%) worst case
And MAX_CHANS=48:
RAM used: 231 (64%) at main() level
277 (77%) worst case
So far so good. But when I try to compile the code with MAX_CHANS=49 I get the infamous "Not enough RAM for all variables" error. Does anybody know why this is happening? Based on the obvious pattern, I was expecting the RAM usage to increase to 235 and 281. Why is the compiler suddenly running out of RAM? What happened to the %23 free memory?
Thanks. |
Page size...
The 16F877, has it's RAM split into four banks. The largest 'block' of continuous memory, is 96bytes long. You have not really run out of memory, but the array has become too large to fit into the biggest bank. The error message, is rather 'annoying', in not making this clear.
If you split the array up into two smaller arrays, it should still fit.
Best Wishes |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Wed Mar 24, 2004 5:17 pm |
|
|
Thank you for your responses. I have four arrays in my code. I was aware of the page limit, but I thought the compiler was smart enough to locate each array in a separate bank. I thought since the smallest bank is 80 bytes this would also be my array size limit. Looking the at the symbol map showed that compiler was trying to shove two of the arrays in bank 2 (96 bytes), and that's why I couldn't make the array sizes bigger than 48.
Now I'm using the #locate preprocessor to put the arrays at 0x20, 0xA0, 0x110 and 0x190, and everything is fine. Any reason I shouldn't be doing this? Thanks. |
|
|
|