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 support@ccsinfo.com

Save eeprom before WDT restart

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



Joined: 18 Mar 2015
Posts: 8

View user's profile Send private message Send e-mail AIM Address

Save eeprom before WDT restart
PostPosted: Wed Mar 18, 2015 10:31 pm     Reply with quote

If I want to save a data to EEPROM before WDT restart, can I have do ?
I think have an wdt interrupt to process this work ?
Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Thu Mar 19, 2015 2:25 am     Reply with quote

You need to always start by telling us the chip. The 'PIC' as a generic term covers about seven actual chip families with different capabilities and restrictions.

However, generally, may not be possible. In standard operation, the watchdog restarts the chip, unless it is asleep, in which case in many cases it can wake on the watchdog, which could then write. If used this way, why not write before going to sleep, which is safer.

But, I then have to ask 'why bother'. When the chip restarts with a watchdog, the registers are saved (not lost), so you can test the 'restart_cause', and then write the EEPROM.

Generally though, beware of anything that writes to the EEPROM on a regular basis. It will always surprise you just how quickly you can kill a chip with repeated writes. Even using the slowest watchdog, which on many chips is something like 30 seconds, this will kill the EEPROM in about 70 days.....
Anything that writes more frequently than once every few _hours_ should be treated with care. The EEPROM in general is designed for things that change _infrequently_.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Thu Mar 19, 2015 1:37 pm     Reply with quote

Ttelmah wrote:

Generally though, beware of anything that writes to the EEPROM on a regular basis. It will always surprise you just how quickly you can kill a chip with repeated writes. Even using the slowest watchdog, which on many chips is something like 30 seconds, this will kill the EEPROM in about 70 days.....
Anything that writes more frequently than once every few _hours_ should be treated with care. The EEPROM in general is designed for things that change _infrequently_.


Or use FRAM, you told me about that !


Never worry again!

Smile
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 19, 2015 5:21 pm     Reply with quote

How much 'data' ? If less than 56 bytes, an RTC chip like the DS1307 is a great 'poor mans' FRAM WITH a real time clock for 'free'...

just another option..

Jay
ntc



Joined: 18 Mar 2015
Posts: 8

View user's profile Send private message Send e-mail AIM Address

PostPosted: Thu Mar 19, 2015 11:42 pm     Reply with quote

Thanks all.
In my program, i'm using WDT to reset the chip when it hanging. So, I think can't using an WDT ISR to save data to EEPPROM.
I'm using PIC18F4680, and wanted to save about <20 byte. In my circuit, I'm using RTC DS1307 chip, can you tell me clear?
Thanks.
ntc



Joined: 18 Mar 2015
Posts: 8

View user's profile Send private message Send e-mail AIM Address

PostPosted: Fri Mar 20, 2015 12:42 am     Reply with quote

Ttelmah wrote:

But, I then have to ask 'why bother'. When the chip restarts with a watchdog, the registers are saved (not lost), so you can test the 'restart_cause', and then write the EEPROM.

Thanks you, serious when I'm careless think about the reset of WDT vs HLVD reset.
I used fuction " restart_cause()" and read again value in register. It simple than I think, sorry with careless question.
Thank you so much !
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Fri Mar 20, 2015 3:37 am     Reply with quote

I'd be working out why the chip is hanging.....

Seriously it either implies a coding problem (something like an array overflow overwriting part of memory), or a hardware problem (electrical noise etc..). I have some PIC's dating back to the first they made (actually earlier than Microchip claim for their first chips - I pointed this out to them a few years ago....), that in some cases have run in instruments _continuously_ since being started (some now for about 39 years)!. Had a few fail recently, they started to lose their ROM's, but the watchdog to bodge round a hang is very dangerous. About the only genuine reason for a watchdog recovery being needed, is a strike by a subatomic particle corrupting memory.
The key thing with using the watchdog, is to get a 99.999% reliability first.
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 20, 2015 5:01 am     Reply with quote

I have to agree with MrT that you need to find out why the WDT is timing out, resettting the PIC. I've got about 25 years of using them and have never needed to implement the WDT feature.
Also since you are using the DS1307,save your data to the CMOS RAM in it.The driver here has the 'reads/write' functions already in it !

cheers
Jay
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Mar 20, 2015 6:45 am     Reply with quote

Quote:

The key thing with using the watchdog, is to get a 99.999% reliability first.


never saw anybody else say so simply what is in my heart and head on this topic. but it's god's own truth. i use the WDT ONLY because of industry mandates where the client specs insist on a "fail safe" code submission.
LOL - the source of most "failure" in programs is likely between the programmer's ears . Very Happy Very Happy Very Happy
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