RAM issue?

Hi,
I just got a few tlc5940's and built it up on a breadboard. Sample sketches run perfectly, but then I tryed to write some "efects". Since I'm not so good at mathematics I thought I'll have the most control if I write separate array for each led, but when it get's larger, it stops working (two random led's blink histerycaly)
Is it possible that I used up too much RAM doing this? Any other ideas why shouldn't it work?

For a closer look, definitions:

int chase2_R0[] = {1000,0,0,0,0,0,0,0,1000,0,0,0,0,0,0,1000,0,0,0,0,0,1000,0,0,0,0,1000,0,0,0,1000,0,0,1000,0,1000};
int chase2_R1[] = {0,1000,0,0,0,0,0,0,0,1000,0,0,0,0,0,0,1000,0,0,0,0,0,1000,0,0,0,0,1000,0,0,0,1000,0,0,1000,1000};
int chase2_R2[] = {0,0,1000,0,0,0,0,0,0,0,1000,0,0,0,0,0,0,1000,0,0,0,0,0,1000,0,0,0,0,1000,0,0,0,1000,1000,1000,1000};
int chase2_R3[] = {0,0,0,1000,0,0,0,0,0,0,0,1000,0,0,0,0,0,0,1000,0,0,0,0,0,1000,0,0,0,0,1000,1000,1000,1000,1000,1000,1000};
int chase2_R4[] = {0,0,0,0,1000,0,0,0,0,0,0,0,1000,0,0,0,0,0,0,1000,0,0,0,0,0,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000};
int chase2_R5[] = {0,0,0,0,0,1000,0,0,0,0,0,0,0,1000,0,0,0,0,0,0,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000};
int chase2_R6[] = {0,0,0,0,0,0,1000,0,0,0,0,0,0,0,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000};
int chase2_R7[] = {0,0,0,0,0,0,0,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000};
int chase2_G0[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_G1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_G2[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_G3[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_G4[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_G5[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_G6[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_G7[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_B0[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_B1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_B2[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_B3[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_B4[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_B5[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_B6[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int chase2_B7[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

and a function:

void test4()
{
  
    Tlc.set(0, chase2_R0[i]);
    Tlc.set(1, chase2_R1[i]);
    Tlc.set(2, chase2_R2[i]);
    Tlc.set(3, chase2_R3[i]);
    Tlc.set(4, chase2_R4[i]);
    Tlc.set(5, chase2_R5[i]);
    Tlc.set(6, chase2_R6[i]);
    Tlc.set(7, chase2_R7[i]);
    Tlc.set(8, chase2_G0[i]);
    Tlc.set(9, chase2_G1[i]);
    Tlc.set(10, chase2_G2[i]);
    Tlc.set(11, chase2_G3[i]);
    Tlc.set(12, chase2_G4[i]);
    Tlc.set(13, chase2_G5[i]);
    Tlc.set(14, chase2_G6[i]);
    Tlc.set(15, chase2_G7[i]);
    Tlc.set(16, chase2_B0[i]);
    Tlc.set(17, chase2_B1[i]);
    Tlc.set(18, chase2_B2[i]);
    Tlc.set(19, chase2_B3[i]);
    Tlc.set(20, chase2_B4[i]);
    Tlc.set(21, chase2_B5[i]);
    Tlc.set(22, chase2_B6[i]);
    Tlc.set(23, chase2_B7[i]);
    Tlc.update();
if(i<15) i++;
else i=0;

    delay(80);


}

Regards,
Peter

You don't say which ATMega is on your Arduino, but RAM being depleted is a good guess. You have multiple (24) integer (2 bytes per value) arrays declared, with 36 values (if I counted correctly) in each; that works out to 1728 bytes (not counting any overhead or anything). The 328 has only 2K of SRAM (for variables). I'd say you are hitting the limits.

Oh, right... I'm still using the basic ATmega168. If you have any experience, what is actualy loaded into RAM, so I can redesign my idea? :slight_smile:

Regards,
Peter

You can change your variable type for "some relief" but you need a redesign if you want to keep expanding.

Ideas:

  1. Change variable type form int to byte and your range accordingly
  • some example code changes below but this is only some relief
  1. Use PROGMEM
    (* see examples in the TLC library)

  2. Use a function to fill a buffer array with the current (or current few) animations and reload the buffer as you do your animation.

  • in this case you would have a function that loads the next frame into the array. Since you have lots of flash space compared to ram .. you can use a function to load up the variable. Since you are hard coding the animation data anyway, hard coding in "function form" is not much different. That said, you may find PROGMEM to be cleaner / easier to maintain and it is the same basic idea.

Code for idea 1)

int chase2_R0[] = {1000,0,0,0,0,0,0,0,1000,0,0,0,0,0,0,1000,0,0,0,0,0,1000,0,0,0,0,1000,0,0,0,1000,0,0,1000,0,1000};

//changes to 

byte chase2_R0[] = {255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,255,0,255};

// and ..
Tlc.set(0, chase2_R0[i]);
//changes to ...

Tlc.set(0, map(chase2_R0[i], 0, 255, 0, 1000));
//btw: is this not 4095 on the TLC?

Thanks, but as you said, with expanding the animation, it WILL collapse...

So I am looking at BasicAnimations example and it's definition at ani_arduino.h and I would be more than happy if you cold explain how exactly does it work?
I see you "call" the animation by
tlc_playAnimation(ani_arduino, ANI_ARDUINO_FRAMES, 3);
and that animation ani_arduino is a large array in ani_arduino.h
Now... how does that array "work"? Why define 80 frames? Why do you do 24x frames in array size definition:
NUM_TLCS * 24 * ANI_ARDUINO_FRAMES

Btw: I use 2 TLC's, but only 24 LEDs all in all (some chanels are left unused). My idea is to have a RGB lightshow so with 8x3 LED's. Well... that for now, I'm still working on how to make things react to music, but... this can wait.

Regards,
Peter

You can get a lot of memory using an SD card.

I'm getting an extra 2GB by using:

:slight_smile:

You can get a lot of memory using an SD card.

No, you can't. You can get a lot of extra storage space, but that is not the same as added memory.

As I have already said, the Arduino IDE should say how much ram is being used at compile time, if avr studio can get that info trough avr-gcc the arduino IDE should do the same as it would help to catch a LOT of problems.

No, you can't. You can get a lot of extra storage space, but that is not the same as added memory.

... I believe that "storage space" for the arrays is what Odisej wants.

Adding the SD card is similar to swapping in a larger hard drive, and expecting programs on the PC to run faster because there is now more memory.

Memory and storage space are not the same thing. Since executable code needs to be stored in memory, adding an SD card will not help, unless the code is changed to read/write from the SD card. Doing so will slow things down considerably, since reading from/writing to an SD card is several orders of magnitude slower that reading/writing to memory.

See cr0sh's calculations on memory.

This is not a running speed issue, but a crashing program issue.

On the ATMega 1280 you can add external RAM, might be worth considering if you have to build a project that uses so much RAM

Sory for not replying sooner, but I was away from civilisation :slight_smile:

I found some nice demonstrations of how to use PROGMEM and I think it will be enough for now, but I still think I will use atmega1280 on this, as it can store a lot more... I will post some photos of a finished project, when I get there :sunglasses:

Thanks for the inspiration!

Regards,
Peter