View previous topic :: View next topic |
Author |
Message |
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
writing variables in program memory at runtime |
Posted: Mon Oct 17, 2011 10:59 am |
|
|
Hi, i making a logger using pic18f46j11 that doesn't have EEPROM, is it possible to write to flash at runtime a variable, say PresetTemperature for example and then if a reset occurs read the values back to RAM.
Thanks!
AC
--------- |
|
|
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
|
Posted: Mon Oct 17, 2011 11:06 am |
|
|
There is write_program_memory and read_program_memory, i guess this
is used for that, but how to know where (address) to store variables that need to keep there values even thru power cycles. thx
AC
------- |
|
|
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
|
Posted: Mon Oct 17, 2011 11:15 am |
|
|
i imported the program into MPLAB and opened program memory window, i noticed that the program goes until address 0x279C on the pic18f46j11 part,
but i will be adding much more stuff on this controller program so where could be a safe place to store in program memory these working preset variables that could change during runtime but need to be stored permanently. Thanks
AC
---------- |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Mon Oct 17, 2011 2:41 pm |
|
|
I was wondering the same thing a few days back...
The problem is mostly how to know where to start and stop saving bytes before you overwrite actual program space.
I guess the fast way to do it is start saving from the last address back?
... that is as far as my initial brainstorm went.
I guess I'll follow this thread to see what others say... _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 17, 2011 2:47 pm |
|
|
There are several threads in the forum archives about using Flash
Program memory to save data.
Quote: |
The problem is mostly how to know where to start and stop saving bytes
|
See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=31333 |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Mon Oct 17, 2011 2:48 pm |
|
|
i just had a brain fart....
is it possible to declare a Constant Array... say 100 bytes.
then... overwrite the values in program memory in the addresses already allocated for that Constant array using the compiler functions to do so?
Code: | Const Array_name[100]={0, 0, 0, 0..... 0}; |
....seems plausible... and data would be already index....
someone more experience should comment on this idea...
(probably not a new idea)....
@ PCM.... i was thinking you would know the answer when i wrote this post... i submitted it and you had already replied! _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Oct 17, 2011 3:37 pm |
|
|
A point to consider when using 18F46J11 flash memory for data storage (Datasheet chapter 6.0 FlashProgram Memory)
Quote: | A write to program memory is executed on blocks of 64 bytes at a time or 2 bytes at a time. Program memory is erased in blocks of 1024 bytes at a time. |
It's possible though to implement an EEPROM emulation, but not so easy. Microchip AN1095 suggests an effective way. |
|
|
Chibouraska
Joined: 11 May 2007 Posts: 57 Location: Montreal,Canada
|
|
Posted: Mon Oct 17, 2011 5:54 pm |
|
|
In my case i only need to store maybe 40 bytes of datum and it's data that
changes very rarely so program memory is a good choice, but is it considered safe practice, what if some sporadic jump to this location corrupts the value(s) is it possible to have some sort of method to test the integrity of data stored there. Maybe it's possible to have code test on a double (copy) of the data and compare it to last value committed. Thanks everyone. |
|
|
|