View previous topic :: View next topic |
Author |
Message |
ntc
Joined: 18 Mar 2015 Posts: 8
|
Save eeprom before WDT restart |
Posted: Wed Mar 18, 2015 10:31 pm |
|
|
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: 19541
|
|
Posted: Thu Mar 19, 2015 2:25 am |
|
|
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
|
|
Posted: Thu Mar 19, 2015 1:37 pm |
|
|
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!
_________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Thu Mar 19, 2015 5:21 pm |
|
|
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
|
|
Posted: Thu Mar 19, 2015 11:42 pm |
|
|
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
|
|
Posted: Fri Mar 20, 2015 12:42 am |
|
|
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: 19541
|
|
Posted: Fri Mar 20, 2015 3:37 am |
|
|
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: 9244 Location: Greensville,Ontario
|
|
Posted: Fri Mar 20, 2015 5:01 am |
|
|
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
|
|
Posted: Fri Mar 20, 2015 6:45 am |
|
|
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 . |
|
|
|