AVR Memory

Thread Starter

maxx5612

Joined Apr 6, 2020
19
How AVR Memory is sectioned. Let's take ATmeaga168 for illustration, and where to find this in the datasheet? [please note that I am an absolute beginner with microcontrollers]
 

Papabravo

Joined Feb 24, 2006
22,082

Thread Starter

maxx5612

Joined Apr 6, 2020
19

Papabravo

Joined Feb 24, 2006
22,082
I already read this. But the question is, for every memory address what is its size? And where to find this in the datasheet?
It is all there. Please try to read the documentation with more care and avoid a procession of questions that you can answer for yourself.
On the subject of program memory, where the instructions are stored:
The Atmel ATmega88/168 contains 8/16K bytes on-chip in-system reprogrammable flash memory for program storage.
Since all AVR instructions are 16 or 32 bits wide, the flash is organized as 2/4/8K x 16.
Figure 5-2 makes it clear that registers, I/O, Extended I/O and SRAM are all byte wide
Section 5.3 on the EEPROM begins with the following:
The Atmel ATmega88/168 contains 512 bytes of data EEPROM memory. It is organized as a separate data space, in which
single bytes can be read and written. The EEPROM has an endurance of at least 50,000 write/erase cycles.
 

Papabravo

Joined Feb 24, 2006
22,082
I'm sorry if my questions seem silly. But it is the first time for me to surf a datasheet of a microcontroller so it is confusing for some somehow.


Can you please explain what is this multiplication?
When you go the the lumber yard and ask for a 2 x 4 you get a board with specific dimensions. It is only a multiplication if you want the area of the end of the board. It is not really very accurate. Memory has dimensions in a similar fashion:
2K x 16 = 2048 words by 16 bits each
4K x 16 = 4096 words by 16 bits each
8K x 16 = 8192 words by 16 bits each

In these cases the amount of memory you get is quite accurate.
 

Thread Starter

maxx5612

Joined Apr 6, 2020
19
When you go the the lumber yard and ask for a 2 x 4 you get a board with specific dimensions. It is only a multiplication if you want the area of the end of the board. It is not really very accurate. Memory has dimensions in a similar fashion:
2K x 16 = 2048 words by 16 bits each
4K x 16 = 4096 words by 16 bits each
8K x 16 = 8192 words by 16 bits each

In these cases the amount of memory you get is quite accurate.
Nice explanation
 

Thread Starter

maxx5612

Joined Apr 6, 2020
19
When you go the the lumber yard and ask for a 2 x 4 you get a board with specific dimensions. It is only a multiplication if you want the area of the end of the board. It is not really very accurate. Memory has dimensions in a similar fashion:
2K x 16 = 2048 words by 16 bits each
4K x 16 = 4096 words by 16 bits each
8K x 16 = 8192 words by 16 bits each

In these cases the amount of memory you get is quite accurate.
Nice explanation. But multiplying by 16 means two bytes and we were talking of just one byte wide.
 

Papabravo

Joined Feb 24, 2006
22,082
Nice explanation. But multiplying by 16 means two bytes and we were talking of just one byte wide.
No, the program memory and the data space are two different memories. The program memory is 16 bits wide, starts at address 0x0000 and goes up to some limit depending on which ATmega variant you have. The data space is 8 bits wide, stars at address 0x0000 and it also goes up to some maximum value. This design is called a Harvard architecture. The alternative is called a Princeton architecture where instructions and data occupy the same memory space. This architecture allows for self modifying instructions, the Harvard architecture does not.
 

Thread Starter

maxx5612

Joined Apr 6, 2020
19
No, the program memory and the data space are two different memories. The program memory is 16 bits wide, starts at address 0x0000 and goes up to some limit depending on which ATmega variant you have. The data space is 8 bits wide, stars at address 0x0000 and it also goes up to some maximum value. This design is called a Harvard architecture. The alternative is called a Princeton architecture where instructions and data occupy the same memory space. This architecture allows for self modifying instructions, the Harvard architecture does not.
This works for me so far. Can you suggest a book or an online course to study this stuff? Or you think this is not viable and I should be concentrating more about C programming and making fancy projects with the AVR and this should be enough?
 

MrChips

Joined Oct 2, 2009
34,810
The memory map for ATmega168 is shown on page 37. This is program (= code = flash) memory only.
ATmega168 contains 16K bytes of code (flash) memory where your program will be stored.
Atmel AVR MCUs use 16-bit and 32-bit instructions.
Hence you really have 8K words (16-bits each).
You don't really have to interpret 8K x 16 to mean "multiply by 16".
All it means is that you have 8K storage locations, each location being 16-bits wide.
 

MrChips

Joined Oct 2, 2009
34,810
This works for me so far. Can you suggest a book or an online course to study this stuff? Or you think this is not viable and I should be concentrating more about C programming and making fancy projects with the AVR and this should be enough?
Atmel AVR architecture and instruction set were well thought of (though there are some idiosyncrasies which I will cover at some later point). It is a good starting point in order to learn about MCU architecture and how computers work. I would highly recommend that you learn to write code in ASM first before moving on to C if you really want to grasp the fundamentals of computer programming.
 

Papabravo

Joined Feb 24, 2006
22,082
Don't get too wrapped up in learning this processor and it's peripherals. It is obsolete and no longer available except maybe on the gray market. They never did make a version with Flash for program memory.
 

Papabravo

Joined Feb 24, 2006
22,082
But the book is still useful as a general reference for microcontrollers, isn't it?
Yes, but you'll have considerable difficulty it you want to acquire an actual part and try to use it. You would be better off learning a part for which development tools and part programming tools are available.
 

Thread Starter

maxx5612

Joined Apr 6, 2020
19
Yes, but you'll have considerable difficulty it you want to acquire an actual part and try to use it. You would be better off learning a part for which development tools and part programming tools are available.
I'd like to hear your suggestions. And thanks for much help.
 
Top