CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

writing variables in program memory at runtime

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

writing variables in program memory at runtime
PostPosted: Mon Oct 17, 2011 10:59 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 11:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 11:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 2:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 2:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 2:48 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 3:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 5:54 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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