Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Can I use program memory of PIC as EEPROM ?

Status
Not open for further replies.

BasePointer

Full Member level 2
Joined
Jul 3, 2002
Messages
130
Helped
6
Reputation
12
Reaction score
3
Trophy points
1,298
Location
TURKEY
Activity points
955
flash runtime access

Hi,

I'm developing a project at PIC18F452 with PICC18 v8.35PL1. I have a lot of free program memory and I want to use there to store values of some variables that I use. I wonder that if it is possible to read/write program memory of PIC byte by byte ? What are the advantages and disadvantages of this method against an external EEPROM like 24C16 ?

10x
 

the obvious disadvantage of using an external eeprom is that it will engage some of the pins of your controller.
check if program memory of pic is non volatile.
it
 

Hi BasePointer,

this is from the 8.30 manual, I hope it is also valid for 8.35PL1:

4.2.5 EEPROM and Flash Runtime Access
EEPROM and flash memory macros are defined for convenience and are available for chips that have
EEPROM or flash memory. The predefined EEPROM and flash memory macros can be used in the
following manner.
To write a byte-size value to an address in EEPROM memory:
EEPROM_WRITE(address, value);
To read a byte of data from an address in EEPROM memory, and store it in a variable:
variable=EEPROM_READ(address);
For convenience, EEPROM_SIZE predefines the total size of data EEPROM available on chip.
To copy a block of code/data to an area in flash memory:
flash_write(source_pointer, length, dest_pointer);
To read a byte of data from an address in flash memory, and store in a variable:
variable=FLASH_READ(address);

I have never used program memory for storage as I could fit all needed data into the built in EEPROM by now.

A big disadvantage might be that flash has less write cycles than EEPROM.

hope this helps and best regards
 

BasePointer said:
Hi,

I'm developing a project at PIC18F452 with PICC18 v8.35PL1. I have a lot of free program memory and I want to use there to store values of some variables that I use. I wonder that if it is possible to read/write program memory of PIC byte by byte ? What are the advantages and disadvantages of this method against an external EEPROM like 24C16 ?

10x

i always preffer external eeprom what i think the used of internal eeprom or prog mem used as eeprom can minimize the life time of controller think around this is i am right or wrong?
 

C-Man said:
To copy a block of code/data to an area in flash memory:
flash_write(source_pointer, length, dest_pointer);
I'm not exactly sure that if length parameter of flash_write() function can be set to 1.
 

Also most important differences seems as write cycle.
- 100,000 erase/write cycle Enhanced FLASH program memory typical
- 1,000,000 erase/write cycle Data EEPROMmemory
 

Why not use the internal EEPROM instead of FLASH to store values?
Or is it because there's not enough room in the internal PIC EEPROM?

Normally you can write 10x as many times in the internal EEPROM as you can in the FLASH. Usually around 100.000 times in EEPROM vs. 10.000 times in FLASH.

The intenal EEPROM in microcontrollers are made excactly for the purpose you ask for, so why not use it? Is it because of sze?

The PIC18F452 has 256 bytes internal EEPROM.
 

ME said:
Why not use the internal EEPROM instead of FLASH to store values?
Or is it because there's not enough room in the internal PIC EEPROM?

Normally you can write 10x as many times in the internal EEPROM as you can in the FLASH. Usually around 100.000 times in EEPROM vs. 10.000 times in FLASH.

The intenal EEPROM in microcontrollers are made excactly for the purpose you ask for, so why not use it? Is it because of sze?

The PIC18F452 has 256 bytes internal EEPROM.

Yes, I need about 2048 Byte. Internal EEPROM of PIC isn't enough for my current project.
 

From a quick look at its datasheet, it can be read a byte at a time, but upon programming, only blocks of 8 bytes are only possible.
So as you asked, I don't think it is fit for your purpose, unless you make a 8 byte read, and then write the block again with your changes (byte or bytes).

Cheers
sda
 

BasePointer said:
Yes, I need about 2048 Byte. Internal EEPROM of PIC isn't enough for my current project.
Then you could also consider upgrading from PIC18F452 to Atmel ATmega64 or ATmega128 AVR's.

ATmega64 has 2048 bytes of internal EEPROM and the price is about the same as for PIC18F452.

If you need even more EEPROM, you could use ATmega128, it has 4096 bytes of internal EEPROM.

Atmel AVR selection table:
**broken link removed**


Microchip PIC has no devices with more than 1024 bytes internal EEPROM.
 

sda said:
From a quick look at its datasheet, it can be read a byte at a time, but upon programming, only blocks of 8 bytes are only possible.
So as you asked, I don't think it is fit for your purpose, unless you make a 8 byte read, and then write the block again with your changes (byte or bytes).

Cheers
sda

I just checked the flash program memory section of the datasheet.
And I unfortunately saw that you are right. The minimum programming block is 4 words or 8 bytes. Word or byte programming is not supported :(
 

BasePointer said:
sda said:
From a quick look at its datasheet, it can be read a byte at a time, but upon programming, only blocks of 8 bytes are only possible.
So as you asked, I don't think it is fit for your purpose, unless you make a 8 byte read, and then write the block again with your changes (byte or bytes).

Cheers
sda

I just checked the flash program memory section of the datasheet.
And I unfortunately saw that you are right. The minimum programming block is 4 words or 8 bytes. Word or byte programming is not supported :(

But that should not be a real problem, why dont you write your own routine which reads 8 bytes at first then update the desired byte and write back the 8 bytes block?

Should be easy to do you could just use the library routines in your own function to do exactly that ...

best regards
 

C-Man said:
But that should not be a real problem, why dont you write your own routine which reads 8 bytes at first then update the desired byte and write back the 8 bytes block?
Of course, It is possible.
Thnk you guys for your support.
 

With 18F452 you can use table read/write functions to write to flash memory. You just have to know the starting address, cause you may overwrite your program.

What you can do is to compile your program without data in flash, then see what is the last ROM address your program used and then start filling in your flash starting from that address.
 

What about the idea of using an AVR instead?
This would solve your problem because it has much more EEPROM space and it is not more expensive.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top