2020/11/27 17:57:32
nashsth
Hey all, I'm working with a PIC18F45K22 microcontroller and I was going through the memory organization section in its datasheet. I have several questions:
 
1) the datasheet mentions that the PIC18 controllers have three types of memory: program memory, data RAM and data EEPROM.
 
I understand that the program memory is used to store the actual instructions (e.g. arithmetic operations). I also know that variables are supposed to be stored in the data RAM. I am not sure what the use of the data EEPROM is. According to the datasheet, it "is used for long-term storage of program data" (pg. 99). But I thought that's what the program memory is for. So maybe my understanding of the program memory is faulty? Can anyone explain what kind of information goes into each of these types of memory?
 
2) In figure 5-1 (pg. 65, program memory map) of the datasheet (see screenshot), it shows that the address location from 1FFFh to 200000h is greyed out and it says in the previous page that any attempt at accessing these locations will read a 0. Why is this? Isn't it a waste of memory for this region to be inaccessible/unusable? What is stored in these locations?
 
Likewise, for the data RAM, it shows in figure 5-5 (data memory map) that the locations between 200h and F37h are unused. Why is this? Isn't this also a waste of memory? 

Attached Image(s)

2020/11/27 19:09:56
BroadwellConsultingInc
EEPROM is a place that you can store information that changes during manufacturing or in the field and that needs to be kept when the chip is powered off and on again.
 
If data is unused, its because it doesn't exist.  The transistors just aren't there to save cost.  Kind of like your computer might theoretically be able to access a TB of RAM, but practically no computer actually does because actually buying that much virtually never makes economic sense  (640k is enough for anybody... Smile: Smile ).
2020/11/27 19:25:31
Mysil
Hi,
1)  Data RAM memory is volatile, it means that if the microcontroller is switched off, or if there is a power failure, then everything in data RAM memory disappear. 
Some data values that was known when program was written, may be stored in progrram memory together with program instructions. These may be moved to data RAM when program is started.
 
Some microcontroller applications will want to store some data permanently,
like alarm clock wakeup time, or temperature thermostat settings, or motor control parameters in a variable frequency drive,  to be available also if there have been a power failure, or a maintenance shutdown,
or if a machine is simply switched off at the end of a day.
Such values are typically stored in Data EEPROM.
 
2)   Microcontroller devices are fabricated with different size of memory, for sale at different prices.
When an area in the memory map is grayed out, then there simply is nothing there.
 
    Mysil
2020/11/27 19:27:05
ric
nashsth
... I am not sure what the use of the data EEPROM is. According to the datasheet, it "is used for long-term storage of program data" (pg. 99). But I thought that's what the program memory is for. So maybe my understanding of the program memory is faulty? Can anyone explain what kind of information goes into each of these types of memory?

"Program memory " holds your program code, i.e. the instructions. This is in FLASH, which survives power off.
"Data memory" is where you variables are stored. This is RAM, which is lost when the power is turned off.
"Data EEPROM" is a small area of EEPROM memory. This is much slower to write than RAM, but survives when the power is off. It can be usd to store configuration data etc that you need next time you are turned on.
 
As the previous post states, those memory maps show all the possible addressing space of this family of PICs.
Each PIC model has a different amount of memory actually present, so the bits that are not there in this version PIC are shown as grey,
 
2020/11/28 02:15:23
NKurzman
The issues are the details of the memory types. Flash memory is cheaper than EEPROM. However flash memory cannot be a raced and written one byte at a time. EEPROM can be. Additionally EEPROM is more durable than flash memory. If you read your data sheet you will find EEPROM can be erased 10 to 100 more times than the flash can.
So yes you can store data in the flash within the limitations of that type of memory. For other uses people need EEPROM. Usually for its Better durability.
This is something you need to calculate before using it otherwise you may find your product doesn’t last as long as you would expect it to.
2020/11/28 06:29:12
mbrowning
A lot of good information above, but one factor I don't see mentioned is program execution. For most PICs flash (program memory) blocks can be written and erased but program execution halts for a few milliseconds while the operation completes. EEPROM can be written (which includes erase) with no impact on program execution.
2020/11/28 07:04:40
nashsth
Wow thank you all for your responses! I learned quite a bit! So in summary:
 
Program memory is FLASH and is used to store information that needs to be present every time the microcontroller powers on and off. However, although the content inside the program memory survives power-off (just like for data EEPROM), it is slower to write to FLASH than it is to EEPROM, and EEPROM can be erased and written to for more iterations than for FLASH.
 
As for the unused, gray spaces, it just means that there are no transistors or registers there because different models of the PIC have different requirements and will be sold at different prices.
 
Are these fair summaries?
2020/11/28 07:41:14
NorthGuy
nashsth
... it is slower to write to FLASH than it is to EEPROM,



It is not slower, usually flash is faster than EEPROM, but you only can erase it in big pages, so it is very inconvenient when you want to store something small. Flash is designed to be programmed once (with your program instructions) and then remain unchanged.
 
Not all PICs have EEPROM, so you have to use flash instead.
2020/11/28 17:10:36
RISC
Hi,
There are lots of good courses on PIC18 on internet : 
https://web.sonoma.edu/users/f/farahman/sonoma/courses/es310/lectures/chapter2_.pdf
regards
 
2021/01/07 08:45:48
Cata
Hello,
 
One more perspective on the differences between EEPROM, RAM and FLASH comes from the assembly language.
 
When a program is executed, a RAM byte read/write is embedded in a single instruction cycle (highest access speed) while for read/write operation of EEPROM we need a dedicated instructions sequence (very slow access for writing).

A byte in FLASH may be part of the instruction cycle for reading only. To write them, a dedicated instructions sequence is needed. Usually only instruction codes and constants seat in FLASH.
 
The assembly language operands refer to RAM variables or to FLASH constants. To use an info from EEPROM you first move it into RAM and, after possible modification, you may store it back in the EEPROM. No arithmetical or logical instruction will operate directly on EEPROM content.
 
What you put is EEPROM is up to you but you pass through a dedicated procedure for accessing that info.
Regards
 
© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account