Pages: [1]   Go Down
Author Topic: 1024 byte array  (Read 1135 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been noticing some odd behavior when trying to use an array of 1024 (or more) bytes. arrays or data structures initialized after the large array return incorrect values, specifically values from the end of the large array.

I'm declaring and initializing the array like this:
byte myArray[1024] = {0xFF, 0xFF, ...etc };

is there some buffer I'm overrunning? is there a better way to initialize the array (ie with a delay, or in two parts)?


Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the arduino Atmega168 chip only has 1024 bytes of RAM and some of that is used by the startup code. You will need to reduce the size of the array.
« Last Edit: April 09, 2008, 09:44:09 am by mem » Logged

Austin, TX
Offline Offline
Full Member
***
Karma: 2
Posts: 182
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
   Yes, the RAM on an arduino is limited to 1K (at present).
However, if the data in the array is read-only (that is, you initialize it but don't change it), then you can use some of the program space to store the data.  This is called progmem.  Since the program space is 8k (for the 168 chip), you have a lot more room to mess around with.
Look here:
http://www.arduino.cc/en/Reference/PROGMEM
for details.
Logged

Chris J. Kiick
Robot builder and all around geek.

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6792
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Grr.  I can understand why the compiler can't tell exactly how much ram is used, but you'd think it would be able to come up with some warning message if the ram used by a single source module exceeded what was on the chip...
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There may very well be an option for it, but I don't know what it is.  If anyone feels like digging through the gcc / g++ man pages, I'd be grateful.  It's certainly something that would be nice to provide better errors for.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ah, that makes sense. thanks for the tip, it looks like PROGMEM will do what I need to do.
Logged

New Zealand
Offline Offline
God Member
*****
Karma: 0
Posts: 999
Arduino pebbles
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Since the program space is 8k (for the 168 chip)
I think you'll find it's actually 8KB for the ATmega8 and 16KB for the ATmega168.

--Phil.
Logged

California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Greetings,

Maybe an external serial SRAM like the Maxim DS1200 could fit the bill here — trading off 3 pins for 1024 bytes of storage.

Regards,
David
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I was excited for a minute.  Check that DS1200 data sheet again - 1024 bits, which is only 128 bytes.

Ramtron has an FRAM, nonvolatile and they claim more than 109 write cycles.  I think the sizes are up to 256k bytes?  SPI interface.  Could be useful, but I haven't had a prject that required it yet.

There's a company that has a datasheet for a product that's an SPI interfaced SRAM.  I say they have a datasheet and not an actual product, because I can't find anyone to sell them to me other than a distributor who sells in 10k quantities with an unknown ship date. :|

-j

Logged

Pages: [1]   Go Up
Jump to: