Go Down

Topic: How to manage Arduino memory? (Read 6287 times) previous topic - next topic

1Pats

I had created array of structures. It contains sunrise, sunshine and noon times for each day of the year-  has  predefined data.
Looks like array is too long, as, if it contains more than 212 elements, code  stops working (i need about 368 elements) Could you point me to more advanced programming guidelines about Arduous memory types, layout,memory management, if such exists..
Existing reference material is very basic, for example typedef is not even mentioned , however is widely used by Arduino software.

see test code (syntax is right)
To make it more compact, I had deleted most of array elements

Code: [Select]


typedef struct {
     unsigned char      mNum;      
     unsigned char      mDay;      
     unsigned char      rHour;      
     unsigned char      rMin;      
     unsigned char      sHour;      
     unsigned char      sMin;      
       unsigned char   nHour;  
       unsigned char   nMin;  
} SUNTIME;

SUNTIME sSunTime[] = {
{ 1,  1,  9,  1, 15, 53, 12, 27},
{ 1,  2,  9,  1, 15, 55, 12, 28},
{ 1,  3,  9,  0, 15, 56, 12, 28},
// a lot of elements are deleted to shorten example
{ 7, 31,  5, 20, 21, 39, 13, 30},   // this is an element 212

};
/* If this and previous line has to be moved after next element of array - 213 element, code stops working.

{ 8,  1,  5, 22, 21, 37, 13, 30},
{ 8,  2,  5, 24, 21, 35, 13, 30},
// here a lot of elements are deleted to shorten example
{12, 31,  9,  1, 15, 52, 12, 26},
{ 0,  0,  0,  0,  0,  0,  0,  0}  // element 368, i guess
};

*/

void setup() {  
Serial.begin(9600);
delay(1000);
Serial.println("Start ");
delay(1000);
PrintTime();
}

void loop() {
 delay(1000);
}


void PrintTime(void){
 int i;
 for (i = 0; i < sizeof(sSunTime)/sizeof(SUNTIME); i++){
   Serial.print(" i="); Serial.print(i, DEC);
   Serial.print("  M= "); Serial.print(sSunTime[i].mNum, DEC);
   Serial.print("  D= "); Serial.print(sSunTime[i].mDay, DEC);
   Serial.print(" rH= "); Serial.print(sSunTime[i].rHour,DEC);    
   Serial.print(" rM= "); Serial.print(sSunTime[i].rMin ,DEC);    
   Serial.print(" sH= "); Serial.print(sSunTime[i].sHour,DEC);    
   Serial.print(" SM= "); Serial.print(sSunTime[i].sMin,DEC);    
   Serial.print(" nH= "); Serial.print(sSunTime[i].nHour,DEC);  
   Serial.print(" nM= "); Serial.print(sSunTime[i].nMin,DEC);    
   Serial.println( ". ");  
 }
}




AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

1Pats

thks. could you point me to some guidelines?

1Pats

#3
Jan 22, 2011, 08:36 pm Last Edit: Jan 22, 2011, 08:38 pm by 1Pats Reason: 1
Thks again for hint.
See code that works.

Code: [Select]

#include <avr/pgmspace.h>
typedef struct {
     unsigned char      mNum;      
     unsigned char      mDay;      
     unsigned char      rHour;      
     unsigned char      rMin;      
     unsigned char      sHour;      
     unsigned char      sMin;      
       unsigned char   nHour;  
       unsigned char   nMin;  
} SUNTIME;

SUNTIME sSunTime[] PROGMEM = {
{ 1,  1,  9,  1, 15, 53, 12, 27},
{ 1,  2,  9,  1, 15, 55, 12, 28},
{ 1,  3,  9,  0, 15, 56, 12, 28},
// a lot of elements are deleted to shorten example

{12, 31,  9,  1, 15, 52, 12, 26},
{ 0,  0,  0,  0,  0,  0,  0,  0}  // element 368
};



void setup() {  
Serial.begin(9600);
delay(1000);
Serial.println("Start ");
delay(1000);
PrintTime();
}

void loop() {
 delay(1000);
}


void PrintTime(void){
 int i;
 for (i = 0; i < sizeof(sSunTime)/sizeof(SUNTIME); i++){
    Serial.print(" i="); Serial.print(i, DEC);
   Serial.print("  M= "); Serial.print(pgm_read_byte(&(sSunTime[i].mNum)),  DEC);
   Serial.print("  D= "); Serial.print(pgm_read_byte(&(sSunTime[i].mDay)),  DEC);
   Serial.print(" rH= "); Serial.print(pgm_read_byte(&(sSunTime[i].rHour)), DEC);    
   Serial.print(" rM= "); Serial.print(pgm_read_byte(&(sSunTime[i].rMin)),  DEC);    
   Serial.print(" sH= "); Serial.print(pgm_read_byte(&(sSunTime[i].sHour)), DEC);    
   Serial.print(" SM= "); Serial.print(pgm_read_byte(&(sSunTime[i].sMin)),  DEC);    
   Serial.print(" nH= "); Serial.print(pgm_read_byte(&(sSunTime[i].nHour)), DEC);  
   Serial.print(" nM= "); Serial.print(pgm_read_byte(&(sSunTime[i].nMin)),  DEC);    
   Serial.println( ". ");  
 }
}

Go Up