PDA

View Full Version : Any problem in declaring and using VARs longer than 512 bytes?



MaxG
- 11th December 2006, 11:31
Hello People,
I am starting a project (a portable medical datalogger) and have made some tries to determine what is better for doing this, PICBASIC or C18. In the process of acquiring the data from the amplifiers of the equipment (28 channels, 16 bit/sample, 128 sample/sec/channel) and posterior sending to a SD card I can not reach enough loading speed to the SD if I do not use two buffers of 512 bytes and flush them (one in the main body of the program while the other is being filled in a ISR basis). I started with PICBASIC PRO but early discovered that an erratic or unspected behaviour appear when I tried to address the 512 byte long arrays. So I split them in two 256 byte long sub-arrays and it worked. No need to say that this has made the code complicated and obscure. Is there some issue in PICBASIC PRO with the definitions of vars longer than a segment of 256 bytes? In C18 I had to redefine some bank boundaries to inform the linker that I had variables that jump from one bank to another. I feel more confortable programming in PICBASIC PRO because it isolates me from having to deal with delays, serial channels in non-hardware dedicated pins, etc, but the ¿poor? managing of big variables in PBP can stop me using it this time. The PIC is 18F4620 at 20Mhz, the ADc is a 7813 through SPI, the SD is loaded through a dedicated interface programmed in a chip (DosOnChip).
Has anybody used VARs longer than 256 bytes, for example:

BF1 VAR BYTE[512]
i VAR word
data VAR BYTE

//and then

data = BF1[i]

Thanks

sougata
- 11th December 2006, 12:59
Hi,

Since one bank of data RAM can hold 256 bytes only you cannot span arrays across banks. So splitting it up is the only way perhaps. Using C18 has its own benefits of a better memory management than PBP for both global and local variables. Also it uses a software stack that depends on the free RAM you have and can be always bigger than the hardware stack. You can always create a subroutine for your data access that automatically chooses the specific bank depending on your array index and dumps it to a temporary variable. This should not complicate things much.

SteveB
- 11th December 2006, 13:30
MaxG,
I have successfully used a 528 byte long array for datalogger using the same 18F4620 (plus I had 2 that were 512 long, all in the same program). There is no problem with spanning banks on the 18F in PBP that I have found.

Here is a quote from the PBP manual: "Arrays may span banks on 18Cxxx devices. Byte- and word-sized arrays are only limited in length by the amount of memory"

SteveB

skimask
- 11th December 2006, 13:41
I built an MP3 player, used a PIC18F4620, and if I remember right I used up practically all of the onchip ram in one word variable:
sectorbuffer var word[1536], or maybe it was more than one. I'll check when I get home tonight.

Easiest way is to just write the program and compile it. If you get an error, you can't.
Wish I had more instant info for ya....
JDG

sougata
- 11th December 2006, 14:38
Hi All,

Sorry I missed that the used chip is a PIC18. It does have a linear addressing for the RAM location.


Arrays must fit entirely within one RAM bank on most PICmicro MCUs.
They may not span RAM banks on 12-bit, 14-bit or 17Cxxx devices.
(Arrays may span banks on 18Xxxx devices. Byte- and word-sized
arrays are only limited in length by the amount of memory.) The
compiler will assure that arrays will fit in memory before successfully
compiling.


Define your array to a specific bank such that it spills over to the next bank.