HANG?!?! what the?

OK something I am not seeing. This chunk of code DIES if you un-comment either of the two commendted lines.

#include <stdio.h>

typedef struct Pdash 
{
      unsigned int Xstop;
      unsigned short int Xspeed;
      unsigned short int Xhours;
//      unsigned short int Xminutes;
//      unsigned short int Xday_i;
};

Pdash P_unit[1000];

void setup() 
{
      Serial.begin(57600);      // for debug
}

void loop() 
{
        Serial.println("something");
        Serial.println(P_unit[1].Xstop);
        delay(1000);      
}
Pdash P_unit[1000]

That is a bit insane :slight_smile:

That will be 1000 * (2 + 2 + 2) bytes. That is A LOT to ask for on a micro controller.

Which arduino model do you use? :slight_smile:

Arduino Mega....should be room

OBTW .... this works

#include <stdio.h>

typedef struct Pdash
{
int Xstop;
int Xspeed;
int Xhours;
int Xminutes;
unsigned int Xday_i;
};
Pdash P_mark[1000];
Pdash P_Xunit[600];

void setup()
{
Serial.begin(57600); // for debug
}

void loop()
{
unsigned int Xss;

Xss = P_Xunit[1].Xstop;

Serial.println(sizeof(P_Xunit));
Serial.println(sizeof(P_mark));
Serial.println(Xss);
delay(1000);
}``

Arduino Mega....should be room

You're using 6 Kbytes* now - if you uncomment those two lines, that's 10Kbytes.
If you uncomment only one of them, that's 8Kbytes.
The Mega has only 8Kbytes RAM total.

  • give or take 24 * x bytes

Theory: I think this would be stored in SRAM (8k bytes). I think the array is not allocated unless accessed. This structure happens to be 10 bytes long so 600 of 'em is 6000 bytes of SRAM where as 1000 would be 10,000 so it hangs. In my last example even though P_mark is declared I don't think it is allocated. I changed the code:

Xss = P_Xunit[1].Xstop;
to
Xss = P_mark[1].Xstop;

and it killed it.

looks like I need to store this array in EEPROM. It is not written to very often.

SO!!!!
am I on the right track?
IS this the problem and correct cure?[/color]

Thank you
Keshka

On-chip EEPROM is even smaller.
If it is constant data, it could go in program memory, otherwise you might think about external I2C EEPROM

[edit]If it is really critical, it looks to me like there may be something to be gained by packing. If minutes is 0..59, (6 bits) hours is 0..23 (5 bits)... see where I'm going?[/edit]

Yes, I just read that in the manual (helps to read!).

That looks like my only solution, the external I2C EEPROM as the data is not static. The array is used to store user programmable information (similar to programming a VCR timer). Wanted to give them plenty of space. Looks like that is gonna be in REV. B

1000 was a worst case senario, I should be able to get by on 200.

Thank you all for your help.
this group is one of the main reasons I chose this platform.
Thank you again!

Keshka