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);
}
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.
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]
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!