At the moment I'm programming a simple high-speed datalogger.
At first I tried to send the data directly after measurement to the PC but it was way too slow (even at higher bauds).
So as I need only a very short time, I want to store the data in an array and send them to the PC afterwards (for further calculation like fourier-transformation).
The code I post here doesn't work with maxdata grater than ~250. It doesn't even schow the "hi" at the beginnung of the programm.
Any ideas?
Thanks!
const int maxdata = 200; // this should be somewhere about 1500
unsigned long datax[maxdata];
unsigned int datay[maxdata];
void setup()
{
Serial.begin(9600);
Serial.println("Hi!");
int i = 0;
while(i < maxdata){
datax[i] = micros();
datay[i] = analogRead(A5);
//Check if Program is still running...
if(i%10 == 0) Serial.println(i);
}
}
void loop() {}
ah OK.. i did the size-calculation but I compared it to the 30720 byte maximum shown in the Arduino IDE (thats PROGMEM, right?) and not the SRAM.
thanks for yout quick answer. I might use other types of variables!
That's flash memory, where the code goes. The PROGMEM attribute can be used to store read-only arrays in flash, instead of SRAM, but that won't help you.
Thanks for the explanation. Now I understood the memory stuff
Just for information: I changed the code to store only 2 bytes per data-sample. One byte for the difference in 10^-5 seconds since the last sample and one byte for the measured voltage (analogRead / 4 )
This way I can store approx. 1000 values. That's enough for me
1 sample every 10^-5s --> 100 kHz. Definitely faster than the ADC sample frequency. Why don't you reduce your sample speed to exactly match the ADC speed?
In order to do this I recommend to look up the current implementations in wiring.c and wiring_analog.c plus the register descriptions in the datasheet. This looks scary at first but is actually pretty easy to do.
Then you would get exactly timed smaples. Thus you would need to store only one byte per measurement.