同前篇,本篇的英文部分引自官網頁面

是Microcontroller裡四個部分的最後一個部分

一樣,作為讀書筆記,大概翻一翻,不要太計較XD

 

=========

 

Memory   記憶體

 

  The notes on this page are for all boards except the Due, which has a different architecture

  本頁面的筆記適用於除了Due之外的所有開發板(Due有不同的架構)。

 

  There are three pools of memory in the microcontroller used on avr-based Arduino boards :

  在基於AVR的Arduino開發板上的微控制器,有三種記憶體池:

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

 

 @ 快閃記憶體(程式空間, program space),是Arduino 的sketch(草圖?怪,應該是指程式碼)所儲存的地方。

 @ SRAM(靜態隨機存取記憶體,static random access memory),是當sketch執行時,sketch創造以及操作變數的地方。

 @ EEPROM是程式人員可以使用來儲存長期資訊( 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.

  快閃記憶體和 EEPROM 記憶體是非揮發性的(電源關閉後,資料仍然存在)。

  SRAM是揮發性的,當電源循環(cycled)時,資料會消失。

 

  The ATmega328 chip found on the Uno has the following amounts of memory:

  Uno上的ATmega328晶片具有下列數量的記憶體:

  Flash  32k bytes (of which .5k is used for the bootloader)
  SRAM   2k bytes
  EEPROM 1k byte

  The ATmega2560 in the Mega2560 has larger memory space :

  Mega2560上的ATmega2560晶片具有下列數量的記憶體:

  Flash  256k bytes (of which 8k is used for the bootloader)
  SRAM   8k bytes
  EEPROM 4k byte

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

  須注意,在Uno上並沒有太多可用的SRAM。在你的程式中,使用了太多的字串的話,很容易就會把SRAM用光的。例如,像下面的宣告:

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

 

  puts 33 bytes into SRAM (each character takes a byte, plus the '\0' terminator). This might not seem like a lot, but it doesn't take long to get to 2048, especially if you have a large amount of text to send to a display, or a large lookup table, for example.
  把33個位元組放進SRAM(每個字元用掉一個位元組,外加 '\0' 的結尾)。

  看起來沒有很多,但要弄到2048(個byte)並不會太久,例如,尤其是如果你有大量的文字文本要送到顯示器,或是一個大的查詢表之類的。

 

  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:

  如果你用光了SRAM,你的程式會以非預期的方式失敗(fail),他會顯示上傳成功,但不會執行,或執行起來怪怪的。

  要檢查這種情況是否發生了,你可以試試把你的程式中的一些字串或其他資料結構註解掉(comment out)或縮短(shorten)。

  如果這樣弄了以後就可以順利執行,你大概就是把SRAM用光了。

  要處理這個問題,有幾件事是可以做的:

 

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

 

 @ 如果你的sketch與執行在電腦上的程式溝通,你可以嘗試把資料或計算工作轉移到電腦上,減少Arduino的負擔。

 @ 如果有 查詢表 或其他大的陣列,盡量使用能儲存你所需的值的最小的資料型態;例如,資料型態 int 佔據 2個位元組,而資料型態 byte 只使用1個(但只能儲存比較小範圍的值)。

 @ 如果當程式在執行時,不需要調整字串或資料,可以把程式存在快閃記憶體,而不是SRAM中。要做這件事,使用關鍵字 PROGMEM

 

  To use the EEPROM, see the EEPROM library.

  要使用EEPROM,請參EEPROM library

Foundations

arrow
arrow
    文章標籤
    Arduino Memory
    全站熱搜

    迷途工程師 發表在 痞客邦 留言(0) 人氣()