memories-of-an-arduino.pdf

(1259 KB) Pobierz
Memories of an Arduino
Created by Bill Earl
Last updated on 2013-08-21 10:30:25 AM EDT
Guide Contents
Guide Contents
You know you have a memory problem when...
"The memory is the first thing to go."
2
4
4
Memory Architectures
Harvard vs Princeton
Which is better?
Modern Hybrids
Microcontrollers
A completely different Scale
5
5
6
6
6
6
Arduino Memories
Flash Memory
SRAM
EEPROM
Arduino Memory Comparision
Measuring Memory Usage
Flash
EEPROM
SRAM
8
8
8
9
11
12
12
12
12
Large Memory Consumers
SD Cards
Pixels
RGB Matrix Displays
Monochrome OLED Displays
ST7565 LCD Displays
e-Ink Displays
14
14
15
16
16
17
17
Solving Memory Problems
"Running Light Without Overbyte"
18
18
Optimizing Program Memory
Remove Dead Code
19
19
© Adafruit
Industries
http://learn.adafruit.com/memories-of-an-arduino
Page 2 of 24
Consolidate Repeated Code
Eliminate the Bootloader
19
19
Optimizing SRAM
Remove Unused Variables
F() Those Strings!
(Park the char* in Harvard PROGMEM)
20
20
20
20
Reserve() your strings
Move constant data to PROGMEM.
Reduce Buffer Sizes
Reduce Oversized Variables
Think Globally. Allocate Locally.
Global & Static Variables
Dynamic Allocations
Local Variables
The Takeaway?
20
21
21
21
22
22
23
23
23
Using EEPROM
uint8_t read(int)
void write(int, uint8_t)
24
24
24
© Adafruit
Industries
http://learn.adafruit.com/memories-of-an-arduino
Page 3 of 24
You know you have a memory problem when...
"The memory is the first thing to go."
(I don't remember who told me that)
The most obvious sign of a memory problem is when the compiler tells you that your sketch is
too big.
But many memory problems show much more subtle symptoms. Your program may load, but
not run. It may crash hard, or just start acting funky.
If your program compiles and loads successfully, but any of the following statements are true,
there is a good chance that you have a memory problem.
"My program worked fine until I"
(choose one)
"Included one more library"
"Added some more LED pixels"
"Opened a file on the SD card"
"Initialized a graphical display"
"Merged in anther sketch"
"Added a new function"
If you think you might have a memory problem, you can skip right to the "Solving Memory
Problems" page. But you should first take a look through the next few pages to better
understand Arduino memory and how it works.
© Adafruit
Industries
http://learn.adafruit.com/memories-of-an-arduino
Page 4 of 24
Memory Architectures
Harvard vs Princeton
In the early days of electronic computing, two different processor/memory architectures
emerged:
The
Vo n Neumann (http: //adafru.it/co e)
(a.k.a.
(http://adafru.it/coe)Princeto
n (http: //adafru.it/co e))
(http://adafru.it/coe)architecture
(http: //adafru.it/co e)
developed for the
ENIAC
(http: //adafru.it/co f)uses
the same memory and data paths for both program and data
storage.
The
Harvard architecture (http: //adafru.it/co g)
characterized by the the
Harvard
Mark 1 (http: //adafru.it/co h)
(http://adafru.it/coh)used
physically separate memory and
data paths for program and memory.
© Adafruit
Industries
http://learn.adafruit.com/memories-of-an-arduino
Page 5 of 24
Zgłoś jeśli naruszono regulamin