Pages: [1]   Go Down
Author Topic: Data size Notes  (Read 1086 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey all.  This was originally going to be a possible bug report, but I just figured out the issue, and thought I'd share it.  

I have this program with *a lot* of data, and i at first was initializing it as in the following program:


void setup() {
  for( int i=2 ; i<13 ; i++ )
  {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  delay( 100 );
  digitalWrite( 3, HIGH );
  delay( 100 );
  digitalWrite( 3, LOW );
}

int myData[349]= {
  /* 348 - LED blinks */
  /* 349 - LED doing strange things */
  /* 350 - LED is solid */
  /* 400 - LED doesn't blink */
  /* change that to [20][20] to make the Arduino NG not work */
  /* change that to static int pattern[ whatever]; and it works fine */
};


I found that the data at around the above sizes causes the above issues.

However,  If i define the data as "static", it works great!


  static int myData[4096] = {
   /* data list */
  }


It works just fine.

I'm assuming that this will store the data in ROM space rather than limited RAM space.

Just a heads up for any of you who might be seeing issues with large data sizes.

smiley-grin
Logged

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

Quote
I'm assuming that this will store the data in ROM space rather than limited RAM space.

I doubt it, since this would mean you can't modify the values, which means they'd be constant.

A static variable is one whose memory is allocated once per program execution.  An automatica variable (which is the default and opposite of static) gets its memory allocated each time the function in which it is declared is called.

In practice on most systems static variables are allocated on the heap, while automatic variables are on the stack.  I have no idea how gcc allocates memory on the Atmel, but you may be seeing something caused by the automatic (i.e., non-static) variable overflowing the stack.

-j
Logged

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

Arrgggghhhh!  can't type!

Quote
An automatica variable

That should read:  An automatic variable

-j
Logged

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

You should be able to do something like this:

Code:
const char foo[] PROGMEM = "Foo";

to store an array only in program memory (flash) and not in RAM.  See: http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html for more details.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Aaah!

perfect!
Logged

Amsterdam
Offline Offline
Full Member
***
Karma: 1
Posts: 139
he's looking at you, kiddy...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

well, it does'nt make sens to me.

if i read the document in the link, I am unable to find the code example.
Code:
const char foo[] PROGMEM = "Foo";

Should i just use that line and replace foo with my own variName?
Logged

--
"We're all in this together..."

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

Pretty much.  You might also want to change the type, if, for example, you're storing ints instead of chars, which would mean you need to initialize the array with something like: { 10, 20, 30, 40 } instead of "Foo".
« Last Edit: December 05, 2006, 06:07:36 am by mellis » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I may have the same problem ... can anyone explain why this code does not work but if I remove one line from the array it works just fine.

Code:
char gen_shps[][72] = {
  "oooggooo ooggggoo oggggggo ooggggoo oggggggo gggggggg oooyyooo oooyyooo", //x-mas tree
  "oooggooo ooggggoo oggggggo ooggggoo oyooooyo oyooooyo oyyyyyyo yoorrooy", //x-mas bell
  "oorrrroo orrrrrro oorrrroo ooorrooo oooggogo ogogggoo oogggooo oooggooo", //flower #1
  "oorrrroo orooooro rogoogor roooooor rgoooogr rogoogor oroggoro oorrrroo", //smiley face
  "oooooooo orroorro roorroor roorroor roooooor orooooro oorooroo ooorrooo", //heart
  "ooogoooo ooogyooo ooogyyoo ooogyyyo ooogoooo gggggggg oggggggo ooggggoo", //boat
  "ooorrooo oorooroo oorooroo ooorrooo oorooroo orooooro orrrrrro oorooroo", //girl
  "oooooooo googggoo gogooogo ggoooyog ggooooog gogooogo googggoo oooooooo", //fish
  "oooyyooo ooyooyoo oyyooyyo yooggooy yooggooy oyyooyyo ooyooyoo oooyyooo", //flower #2
  "oorrrroo orrrrrro oorrrroo ooyrryoo oyooooyo oyooooyo ooyooyoo oooyyooo" //ring
  };
  
void loop() {
  for (int i=0;i<10;i++) {
    show(gen_shps[i], shp_speed);
  }
}


I have also tried this ... but it reacts the same way....

Code:
char *gen_shps[] = {
  "oooggooo ooggggoo oggggggo ooggggoo oggggggo gggggggg oooyyooo oooyyooo", //x-mas tree
  "oooggooo ooggggoo oggggggo ooggggoo oyooooyo oyooooyo oyyyyyyo yoorrooy", //x-mas bell
  "oorrrroo orrrrrro oorrrroo ooorrooo oooggogo ogogggoo oogggooo oooggooo", //flower #1
  "oorrrroo orooooro rogoogor roooooor rgoooogr rogoogor oroggoro oorrrroo", //smiley face
  "oooooooo orroorro roorroor roorroor roooooor orooooro oorooroo ooorrooo", //heart
  "ooogoooo ooogyooo ooogyyoo ooogyyyo ooogoooo gggggggg oggggggo ooggggoo", //boat
  "ooorrooo oorooroo oorooroo ooorrooo oorooroo orooooro orrrrrro oorooroo", //girl
  "oooooooo googggoo gogooogo ggoooyog ggooooog gogooogo googggoo oooooooo", //fish
  "oooyyooo ooyooyoo oyyooyyo yooggooy yooggooy oyyooyyo ooyooyoo oooyyooo", //flower #2
  "oorrrroo orrrrrro oorrrroo ooyrryoo oyooooyo oyooooyo ooyooyoo oooyyooo" //ring
  };
Logged

Pages: [1]   Go Up
Jump to: