View previous topic :: View next topic |
Author |
Message |
rhaguiuda
Joined: 05 Sep 2007 Posts: 46 Location: Londrina - Brazil
|
Using Flash to store data |
Posted: Wed May 27, 2009 6:57 am |
|
|
Hi
I tried to search for this in the forums but didn't succeed.
How can I use PIC Flash to store data? (PIC18F2420). Using #ORG? Using #ROM?
Thanks! _________________ Give a man a fish and you'll feed him for a day. Teach a man to fish, and you'll feed him for a lifetime. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 27, 2009 3:32 pm |
|
|
What type of data do you want to store ? How much ?
You can use 'const' to put an array into Flash memory. The limit is 256
elements for the 16F PICs, but the 18F have a much higher limit. I'm not
sure what it is, but probably thousands of elements. |
|
|
rhaguiuda
Joined: 05 Sep 2007 Posts: 46 Location: Londrina - Brazil
|
|
Posted: Thu May 28, 2009 5:11 am |
|
|
Hi PCM.
I'm trying to store some large packages of data (400 bytes per package).
PIC will receive this data through serial port (USART), so I have to write to PIC's flash while the code is running. I can't use contants for this reason.
And besides writting the Flash, I need to read and clear, when desired. Just like an extension to PIC's RAM memory.
If i'm not mistaken, the Flash memory can only be erased in large blocks, not byte by byte, is this correct?
Thanks _________________ Give a man a fish and you'll feed him for a day. Teach a man to fish, and you'll feed him for a lifetime. |
|
|
Ttelmah Guest
|
|
Posted: Thu May 28, 2009 5:27 am |
|
|
You really need to think in terms of another solution. I'd suggest you add an external FRAM chip instead.
There are a series of problems:
1) The 'write' life of the internal flash memory, is limited.
2) When writing to it's own Flash, the processor, _has_ to stop executing code. Unless the serial comms isstopped for the entire duration of the write, data will be lost. This is unavoidable.
3) Writing to flash, is _slow_. With an SPI based external FRAM, you could store the data in under a mSec. Depending on the block size of your chip, writing the same data to flash, would take perhaps 50mSec. While writing to the FRAM, serial interrupts, and other code could still run.
Flash, is the 'wrong' solution for what you describe.
Best Wishes |
|
|
rhaguiuda
Joined: 05 Sep 2007 Posts: 46 Location: Londrina - Brazil
|
|
Posted: Thu May 28, 2009 5:29 am |
|
|
So I guess I'll have to take that data in much small sizes, and store in RAM.
Thanks for all help. _________________ Give a man a fish and you'll feed him for a day. Teach a man to fish, and you'll feed him for a lifetime. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu May 28, 2009 4:15 pm |
|
|
rhaguiuda wrote: | So I guess I'll have to take that data in much small sizes, and store in RAM. | I'm not sure what you mean by storing in RAM. The PIC18 with the largest RAM capacity has only 3968 bytes, so you'll run out of memory fast.
As Ttelmah has pointed out the internal FLASH memory can't be used because the processor can't execute code during the write. So unless you can implement some kind of flow control in the data stream this is not an option.
Serial FRAM devices are available in capacities up to 2Mbit = 256kbyte. These are easy to use, can be written with single bytes, save data quicker than a PIC can send the data and don't wear out like flash memory does.
Manufacturers of FRAM are Ramtron and Fujitsu.
For even larger storage capacities you could consider using an MMC card. |
|
|
|