Go Down

Topic: Memory size issues with a pointers vector (Read 325 times) previous topic - next topic

matthdup

Mar 01, 2013, 08:29 am Last Edit: Mar 01, 2013, 08:38 am by matthdup Reason: 1
Hi,

I have issues trying to program a data recorder on my Arduino Uno SMD. I just want to record short int in a pointers vector. That works fine if my vector size is less than approximatively 800. But if there's more elements than 800 (I'd like 1024), the program bug: I can compile and upload it but it seems to execute the setup() in a loop!?!
Did I made a stupid mistake (I'm a beginner)? Is it just that there's not enough memory available (but 1024 short int take just 2048 Bytes)?
Thanks,

Matthieu

Here's my code:
Code: [Select]

#include "Arduino.h"

int pinElectret=A1;

void setup ()
{
 Serial.begin(115200);
 Serial.println("Setup execution");
 delay(1000);
}
void loop()
{

 short* donnees[1024]  ;
 short val;
 int nbtot=1024;

 Serial.println("Start Recording");
 for(short int ip=0;ip<nbtot;ip=ip+1)
 {
   val=char(analogRead(pinElectret));
   donnees[ip]=&val;
   delayMicroseconds(1000);
   Serial.println(availableMemory());
 }

 Serial.println("End recording");
 Serial.println("Data:");
 for(short int ip=0;ip<nbtot;ip=ip+1)
 {
     Serial.println((short)*donnees[ip]);
   delayMicroseconds(1000);
 }
 Serial.println("Fin");


 delay(5000);
}

int availableMemory()
{
 int size = 1024; // Use 2048 with ATmega328
 byte *buf;
 while ((buf = (byte *) malloc(--size)) == NULL);
 free(buf);

 return size;
}

AWOL

Quote
Is it just that there's not enough memory available (but 1024 short int take just 2048kB)?

sp. "2048 bytes".
Remember, that's all the RAM you have.
"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.


Groove

Per Arduino ad Astra

matthdup


Go Up