Go Down

Topic: array too large? (Read 3179 times) previous topic - next topic

jw

hey all, i am trying to build a POV display using an Arduino NG and 4 Shift Registers, so i have a total of 32 LEDs which i can address.

i am storing the motive in a two-dimensional array boolean[32][32] which makes a total of 1024 values.
the test code with 16*16 bools works fine, but with the large array, the board does NOTHING. i wrote a test where i declare the array and in the loop simply switch pin 13 on and off, but even this doesnt happen...

the compiled sketch is 4858 bytes, so it shouldnt be too large... has anyone got an idea why things are like they are? is there another way to store the motive (i need on/off) which the board can handle better?

thanks in advance!
jens

kg4wsv

Quote
i am storing the motive in a two-dimensional array boolean[32][32] which makes a total of 1024 values.


booleans appear to be 8 bit values (minimum addressable data size), so your 32x32 array consumes 100% of the RAM on the ATmega8.

You could put it in flash, but that means you couldn't change the values in the array at runtime.  There are instructions, either on the playground or here in the forum, on how to do this.

It makes more sense both from a RAM utilization standpoint and most likely from an interface standpoint to put several of those bits into a single array element.  For example, IIRC a long int is 32 bits wide, so

Code: [Select]
long int message[32];
would give you a 32 bit x32 bit array that consumes 128 bytes of RAM.

-j

jw

#2
Jan 29, 2007, 01:50 pm Last Edit: Jan 29, 2007, 01:56 pm by jw Reason: 1
hey, thanks! i read that there is 512 bytes space in the EEprom, so this would be insufficient either... although i dont need to change the values at runtime...

so i guess i am going for the long[32] solution... can you tell me how i can read out a single bit from a long?

UPDATE: found something on the playground, so no need to answer right now...

thanks,
Jens

kg4wsv

Besides the 512 bytes of EEPROM, you can also store things in program space, using some of the 8K flash that's normally used for programs.


If I want to know if bit 3 is on in an integer, I can do this:

Code: [Select]
long int i;

if (i & 0x4)
{
   // code for "on" case goes here
}


i & 0x4 is a logical and, the result of which will be 0x4 if bit 3 is on.  Since 0x4 is nonzero, the logical expression for the if evaluates to true.

If you are using shift registers, though, you'll probably want to shift the values out of the long int in series, not pull out one bit at a time.  I think you can use the SPI hardware to feed shift registers that way, but I haven't tried it myself.

-j

jw

Thank you so much for the hint with the long[32] :)

it works! i posted a processing sketch which generates the long values as well as the arduino code on my blog, just in case you (or anyone else) are interested!

http://www.sport4minus.de/blog/?p=233

Thanks again and Cheers!
Jens

Go Up