Posted on Leave a comment

Memory Space in ATmega16A

To effectively program AVR based microcontroller you must have knowledge about its memory space. Since there is not just one memory space. There are three different address spaces. They are:

  1. Data memory (SRAM)
    Here all your the intermediate results are stored and all the run time calculation get carried in this memory space.
  2. Program memory
    It is the memory where your application code is stored. And also it stores the constants. It could be divided into two sections by setting appropriate fuse bits. The two section will be:
    1. Application Section
    2. Boot Section
  3. EEPROM
    This is the memory where you can save the run time data such as configuration options, intermediate result for future processing. But it is very limited in size. So proper managment had to be taken care. Since it limits the size of certain applications.

Out of the three memories present in the ATmega16a, only the SRAM is volatile.

Size and address of memory space

  1. Data Memory
    1024 Bytes (Starting Address: 0x0060 – Last Address: 0x045F)
    96 Address which contain two section General purpose Register and I/O Registers.
    General Purpose Register ( Starting Address: 0x0000 – Last address: 0x001F)
    I/O register (Starting Address: 0x0020 – Last address: 0x005F)
  2. Program Memory
    Flash Type memory organised into 8000 memory location each pointing to a 16 bit wide data.
    Starting Address: 0x0000
    Last Address: 0x1FFF

NOTE: Care must be taken while Read/Write operations of EEPROM. It is very sensitive to operating conditions. Variations outside the tolerance limits could result in corruption of data in the worst case total loss of stored data. It is highly recommended that a stable power source must be used if performing frequent EEPROM operations.

Posted on Leave a comment

Memory Management

The memory is limited. And since it is limited it becomes a precious resource. So you have to manage the memory from the beginning of the embedded system.

Most of the code written for embedded system will be in c or in c++ using an IDE. The code will then built by the compiler in the IDE. Compiler will take your code and translate the code into the machine language or the language which your system understands.

Compilers does a decent amount of memory management. But they have limitations. As the size and complexity of your code increase the struggle of the compiler to manage the memory also increase.

So knowing about memory optimization’s from the beginning is good.

In a very basic memory managed model of programming, never make your complete code execute from the main() function. Instead call the sub-functions from the main() and allocate memory at the beginning and do the data processing. After the data processing save the elements in their corresponding memory locations. Deallocate the memory when the data processing is over and return the main function.