|
|
View previous topic :: View next topic |
Author |
Message |
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
Using unused program memory for data storage in PIC18F26J11 |
Posted: Thu Feb 20, 2014 7:29 am |
|
|
Hi folks,
Unusual request here - I'm using the 18F26J11 in a number of projects, and in one application it would be very useful to be able to store a couple of values to permanent memory.
The device doesn't feature internal eeprom, but the datasheet does state that it is self programmable under software control.
Reading between the lines here, (I'm only using 33% ROM in the code) is it possible to use this feature to store a couple of bytes in unused program space?
If it is, has anyone done it - or can anyone offer me any pointers as to how to set about doing it?
Thanks in advance
James |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Thu Feb 20, 2014 11:06 am |
|
|
Read_program_memory, and write_program_memory.
First key difference to EEPROM, is a whole page has to be erased. With an EEPROM you can erase a single byte.
So you need to reserve a whole page (1KB), to store your values.
Then to change just a single byte, you need to read everything else you store in that page, Erase the page, and write the whole page back.
The write_program_memory function will automatically erase a page, if you write to the first byte in the page.
Now the config values are held at the top of the EEPROM, so you need to use the page below this one.
0xF800 to 0xFBFF
Then have a buffer as large as the number of bytes you need to store.
Read from 0xF800 into the buffer, the number of bytes you want.
Change the ones you want.
Write the block back to 0xf800.
The write function will then erase the block, and write the bytes back.
Now there are ways of doing more 'EEEPROMesque' accesses, by using flags to say what address you want to store, and storing records sequentially through the block (Microchip has an application note on doing this), and only erasing when the whole block gets full. Problem is though that this is complex...
Remember that the write life is only 10K, and a life is used when you erase a block (it's not actually 'write life').
So long as the values don't need to change at all often, the simple approach will work.
Best Wishes |
|
|
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
|
Posted: Thu Feb 20, 2014 11:22 am |
|
|
Fantastic,
That's just the news I was hoping for.
So theoretically if I need to just store 4 bytes in memory, I only actually need to store the 4 bytes in RAM, and read the rest just for the sake of it and dump it.
Likewise for a write, I can fill rest the page with dummy data, and just retain an array with the 4.
The data is only likely to change a few times - so this is the ideal solution.
You are a star as always
Thanks
James |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Thu Feb 20, 2014 12:08 pm |
|
|
Some of the chips out there these days have HEF (High Endurance Flash) as part of their memory in stead of EEPROM that can be used for data storage (I had not seen HEF before and had to look it up). You may find Microchip's App note AN1673 has some information that may be useful to your quest since you have to deal with HEF along the same lines as FLASH - blocks instead of individual bytes. The app note has some code examples as well.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Thu Feb 20, 2014 12:17 pm |
|
|
Yes.
The 26J11, is not one of the chips with this feature.
Yes, for just four bytes, this is all you need to hold in RAM, and write to F800 to F803.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|