Pages: [1]   Go Down
Author Topic: [HELP] Memory Use  (Read 619 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
I use an Arduino Uno with a ATMEGA328P R3.
If I'm not mistaken, I thus has 2048 bytes of SRAM.

I have a program that uses the following memory:
Serial Buffer = 256 bytes. (I changed the library)
SERIN [200] = 200 bytes.
String for display on LCD = 24 bytes.
various variables such bytes = 10 bytes.
a total of I think 490 bytes.
And then my program works properly.
If I add an array SERINMODIF [92] or 92 extra bytes, my program does not work, as if I had a crush memory.
If anyone has any idea? calculation may be my memory is right?
Thank you for your help.
Philippe.
« Last Edit: July 12, 2012, 12:19:29 pm by phm78 » Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What are the data types of your variables?
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post your code.
Logged

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

All variables are byte.
Logged

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

My code:


#include <LiquidCrystal.h>

LiquidCrystal lcd(18,19,14,15,16,17);

const byte patchreq[11] = {0xF0, 0x0, 0x21, 0x02, 0x00, 0x02, 0x11, 0x00, 0x00, 0x00, 0xF7};
byte SERIN[200];
byte PATCH[92];
byte i = 0;
byte a = 0;
byte index = 0;
byte checksumlu = 0;
byte checksum = 0;
byte b=0;

void setup()
{
  Serial.begin(31250);

  lcd.begin(16,2);
  lcd.clear();
  lcd.print("o0o FACTORY");
  lcd.setCursor(0,1);
  lcd.print("Serial SysEx ");
  delay(100);
  lcd.clear();
}

void loop()
{
  patchread();
  lcd.print(a);
  lcd.print(" ");
  lcd.print(SERIN[0], HEX);
  lcd.print(" ");
  lcd.print(SERIN[194], HEX);
  lcd.print(" ");
  lcd.print(checksumlu, HEX);
  lcd.print(" ");
  lcd.print(checksum, HEX);
 
  loop:
  goto loop;
}


void patchread()
{
  Serial.flush();
  Serial.write(patchreq,11);

  while(Serial.available() < 205)
  {
  }
 
  do {                   
    i = Serial.read();
  }
  while(i != 0xf7);

  index = 0;
  do
  {
    SERIN[index] = Serial.read();
    index++;
  }
  while(SERIN[index] != 0xf7);

  checksumlu = SERIN[192];
  checksumlu *= 16;
  checksumlu += SERIN[193];
 
  checksum = 0;
  for (index = 0; index < 92; index++)
  {
    i = (index * 2) + 8; 
    b = (SERIN * 16) + SERIN[(i+1)];
    PATCH[index] = b; // This line causes the problem <<<--------------------------------------------------
    checksum += b;
  } 
   
  a=SERIN[10];
  a *= 16;
  a += SERIN[11];
}
Logged

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You're not taking into account the memory used by the core system (millis counter, plus many others), and the LiquidCrystal memory requirements.

Plus you have the stack on top of all that.

Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have around 1700 bytes available with an almost empty sketch.  If I try and allocate more than that in one solid chunk it causes instability.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

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

put your strings in PROGMEM, and your code in code tags.
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.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46107
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, tell us what version of the IDE you are using. For 1.0+, there are two serial buffers - one for incoming and one for outgoing - that are the same size.

Why are you using Serial.flush()? Do you understand what it does?
Logged

Pages: [1]   Go Up
Jump to: