Pages: [1]   Go Down
Author Topic: Memory size issues with a pointers vector  (Read 311 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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;
}
« Last Edit: March 01, 2013, 02:38:59 am by matthdup » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26485
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I thought the arduino Uno has 32kB?
http://arduino.cc/en/Main/ArduinoBoardUnoSMD
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It has 32k program memory, aka ROM
Logged

Per Arduino ad Astra

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok thanks that's my misunderstanding.
Logged

Pages: [1]   Go Up
Jump to: