Tutorial.Memory History

Hide minor edits - Show changes to markup

June 11, 2010, at 06:29 PM by Equipo Traduccion -
Added line 21:

[@

Changed lines 23-24 from:
to:

@]

June 11, 2010, at 06:28 PM by Equipo Traduccion -
June 11, 2010, at 06:24 PM by Equipo Traduccion -
Changed line 37 from:
to:
June 11, 2010, at 06:24 PM by Equipo Traduccion -
Changed lines 1-11 from:

Memory

There are three pools of memory in the microcontroller used on Arduino boards (ATmega168):

  • Flash memory (program space), is where the Arduino sketch is stored.
  • SRAM (static random access memory) is where the sketch creates and manipulates variables when it runs.
  • EEPROM is memory space that programmers can use to store long-term information.

Flash memory and EEPROM memory are non-volatile (the information persists after the power is turned off). SRAM is volatile and will be lost when the power is cycled.

The ATmega168 chip has the following amounts of memory:

to:

Memoria

Existen 3 fuentes de memoria en el microcontrolador utilizado por la placa Arduino (ATmega168):

  • Memoria Flash (espacio del programa), donde Arduino almacena el sketch.
  • SRAM (static random access memory, memoria estatica de acceso aleatorio) donde los sketches almacena y manipulan variables al ejecutarse.
  • EEPROM es un espacio de memoria que puede ser utilizada por los programadores para almacenar información de largo plazo.

La memoria Flash y EEPROM son no-volatiles (la información se mantiene en ellas luego de cortar la alimentación). SRAM es volatíl y se perdera al reiniciar la unidad.

El chip ATmega168 cuenta con las siguientes cantidades de memoria:

Changed line 14 from:

Flash 16k bytes (of which 2k is used for the bootloader)

to:

Flash 16k bytes (de los que 2k son utilizados por el bootloader)

Changed lines 19-30 from:

Notice that there's not much SRAM available. It's easy to use it all up by having lots of strings in your program. For example, a declaration like:

char message[] = "I support the Cape Wind project.";

puts 32 bytes into SRAM (each character takes a byte). This might not seem like a lot, but it doesn't take long to get to 1024, especially if you have a large amount of text to send to a display, or a large lookup table, for example.

If you run out of SRAM, your program may fail in unexpected ways; it will appear to upload successfully, but not run, or run strangely. To check if this is happening, you can try commenting out or shortening the strings or other data structures in your sketch (without changing the code). If it then runs successfully, you're probably running out of SRAM. There are a few things you can do to address this problem:

  • If your sketch talks to a program running on a (desktop/laptop) computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino.

  • If you have lookup tables or other large arrays, use the smallest data type necessary to store the values you need; for example, an int takes up two bytes, while a byte uses only one (but can store a smaller range of values).
to:

Ten en cuenta que no hay mucha SRAM disponible. Es fácil utilizarla toda al tener muchas cadenas (strings) en tu programa. Por ejemplo, una declaración como:

char message[] = "Ah, qué hermoso..., qué hermoso."

pone 32 bytes en la SRAM (cada caracter utiliza un byte). Esto pude no parecer mucho, pero no toma mucho más llegar hasta 1024, especialmente si tienes largas cantidades de texto que enviar a una pantalla, o una tabla de datos muy grande, por ejemplo.

Si se te acaba la SRAM, tu programa fallara de manera improvista; parecera subir a la placa de manera correcta, pero no se ejecutara, o se ejecutara de manera extraña. Para comprobar si esto es lo que sucede, puedes intentar comentado o acortando las cadenas de texto u otras estructuras de datos en tu sketch (sin alterar el código). Si entonces este funciona correctamente, es probable que el problema haya sido la SRAM llena. Hay unas pocas cosas que puedes hacer para solucionar este problema:

  • Si tu sketch se comunica con una aplicación corriendo en un ordenador, puedes intentar trasladar datos o calculos al ordenador, reduciendo la carga en el Arduino.

  • Si tienes tablas de referencia o otros arreglos de gran tamaño, utiliza el tipo de datos mas pequeño que puedas para almacenar estos datos; por ejemplo, un int utliza 2 bytes, mientras que un byte utiliza solo uno (pero puede almacenar un rango menor de datos).

  • Si no necesitas modificar las cadenas o datos mientras el sketch se ejecuta, puedes almacenarlos en la memoria Flah (de programa) en vez de la SRAM; para esto, utiliza el keyword PROGMEM
Changed lines 35-36 from:

To use the EEPROM, see the EEPROM library.

to:

Para utilizar la EEPROM, consulta la biblioteca EEPROM.

March 08, 2008, at 04:37 AM by Paul Badger -
Changed lines 32-34 from:

To use the EEPROM, see the EEPROM library.

to:

To use the EEPROM, see the EEPROM library.

Foundations

March 08, 2008, at 04:36 AM by Paul Badger -
Changed lines 26-31 from:
  • if your sketch talks to a program running on a (desktop/laptop) computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino.

  • if you have lookup tables or other large arrays, use the smallest data type necessary to store the values you need; for example, an int takes up two bytes, while a byte uses only one (but can store a smaller range of values)

  • if you don't need to modify the strings or data while your sketch is running, you can store them in flash (program) memory instead of SRAM; to do this, use the PROGMEM keyword
to:
  • If your sketch talks to a program running on a (desktop/laptop) computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino.

  • If you have lookup tables or other large arrays, use the smallest data type necessary to store the values you need; for example, an int takes up two bytes, while a byte uses only one (but can store a smaller range of values).

  • If you don't need to modify the strings or data while your sketch is running, you can store them in flash (program) memory instead of SRAM; to do this, use the PROGMEM keyword.
March 08, 2008, at 04:35 AM by Paul Badger -
Changed lines 26-27 from:
  • if your sketch talks to a program running on the computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino
to:
  • if your sketch talks to a program running on a (desktop/laptop) computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino.
February 18, 2008, at 05:29 PM by David A. Mellis -
Changed lines 22-23 from:

puts 32 bytes into SRAM (each character takes a byte). It doesn't take long to get to 1024, especially if you have a large amount of text to send to a display, or a large lookup table, for example.

to:

puts 32 bytes into SRAM (each character takes a byte). This might not seem like a lot, but it doesn't take long to get to 1024, especially if you have a large amount of text to send to a display, or a large lookup table, for example.

February 18, 2008, at 05:28 PM by David A. Mellis -
Changed lines 18-19 from:

One thing you will notice in the chart above is that there is a lot more Flash (program) memory than SRAM available. When you create variables with the Arduino language such as:

to:

Notice that there's not much SRAM available. It's easy to use it all up by having lots of strings in your program. For example, a declaration like:

Changed lines 22-23 from:

You are putting 32 bytes (1 char = 1 byte) into SRAM. 32 bytes isn't a lot of memory in a pool of 1024 bytes, but if the sketch requires some large data structures - such as a large amount of text to send to a display, or a large lookup table, for example - using flash memory (program memory) for storage may be the only option. To do this, use the PROGMEM keyword.

to:

puts 32 bytes into SRAM (each character takes a byte). It doesn't take long to get to 1024, especially if you have a large amount of text to send to a display, or a large lookup table, for example.

If you run out of SRAM, your program may fail in unexpected ways; it will appear to upload successfully, but not run, or run strangely. To check if this is happening, you can try commenting out or shortening the strings or other data structures in your sketch (without changing the code). If it then runs successfully, you're probably running out of SRAM. There are a few things you can do to address this problem:

  • if your sketch talks to a program running on the computer, you can try shifting data or calculations to the computer, reducing the load on the Arduino

  • if you have lookup tables or other large arrays, use the smallest data type necessary to store the values you need; for example, an int takes up two bytes, while a byte uses only one (but can store a smaller range of values)

  • if you don't need to modify the strings or data while your sketch is running, you can store them in flash (program) memory instead of SRAM; to do this, use the PROGMEM keyword
February 14, 2008, at 05:35 AM by Paul Badger -
Changed line 3 from:

There are three pools of memory in the microcontrollers used on Arduino boards (e.g. the ATmega168):

to:

There are three pools of memory in the microcontroller used on Arduino boards (ATmega168):

February 14, 2008, at 04:13 AM by David A. Mellis -
Added lines 1-24:

Memory

There are three pools of memory in the microcontrollers used on Arduino boards (e.g. the ATmega168):

  • Flash memory (program space), is where the Arduino sketch is stored.
  • SRAM (static random access memory) is where the sketch creates and manipulates variables when it runs.
  • EEPROM is memory space that programmers can use to store long-term information.

Flash memory and EEPROM memory are non-volatile (the information persists after the power is turned off). SRAM is volatile and will be lost when the power is cycled.

The ATmega168 chip has the following amounts of memory:

Flash  16k bytes (of which 2k is used for the bootloader)
SRAM   1024 bytes
EEPROM 512 bytes

One thing you will notice in the chart above is that there is a lot more Flash (program) memory than SRAM available. When you create variables with the Arduino language such as:

char message[] = "I support the Cape Wind project.";

You are putting 32 bytes (1 char = 1 byte) into SRAM. 32 bytes isn't a lot of memory in a pool of 1024 bytes, but if the sketch requires some large data structures - such as a large amount of text to send to a display, or a large lookup table, for example - using flash memory (program memory) for storage may be the only option. To do this, use the PROGMEM keyword.

To use the EEPROM, see the EEPROM library.

Share