Electronic – Why is the program stored in flash memory instead of EEPROM in ATmega328

eepromflash

As I was going through the differences (basically they are same, but they still have some differences) between flash memory and EEPROM here, I figured out that the flash memory can handle lesser amount of write cycles than the EEPROM.

But, the program I upload to my ATmega328 is written in flash memory. This means I write the flash memory every time I upload a program into the microcontroller. But I think I have never written on the EEPROM.

So I wonder why flash instead of EEPROM?

Going through the datasheet, I figured out that the flash memory has the storage of 32 KB while EEPROM has 1 KB. If this was the reason why my programs are uploaded to flash, why didn't the designers make 32 KB of EEPROM and 1 KB of flash?

The only reason I found to program on flash was the speed. Is this the only reason?

Best Answer

EEPROM is normally used to save data between power downs/ups or for backup (in case power goes down).

So if you save some data (e.g. acquired by your sketch) to EEPROM, and the Arduino is powered on again (or not, that does not matter), the data is still in EEPROM and your sketch can continue with the data without losing anything.

And it's a good thing that EEPROM can be written more often than Flash, because once your sketch is finished and you build it in your 'product', you don't need to change it anymore. Only during development you will write to Flash. Maybe it happens a lot, but I doubt you do that many thousands of times (if you do, you need to change your workflow).

But the data on EEPROM might be written daily, hourly or even more (depending on the requirements).