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 data in the eeprom before unplugging the power

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







save data in the eeprom before unplugging the power
PostPosted: Mon May 18, 2009 1:21 am     Reply with quote

Hello,

What is the best way to save data in the eeprom just before a user unplugs the power (uncontrolled). There will bee a few ms the power supply is able to charge the pic.
Can I use the brownout by telling to reset the pic at 4.7mV and getting a irq where I can handle the saving?

My PIC is the 18F6723 and CCS 4.092

thanx
PICoHolic



Joined: 04 Jan 2005
Posts: 224

View user's profile Send private message

PostPosted: Mon May 18, 2009 3:08 am     Reply with quote

I've done such thing before.

I've used a 1000uF capacitor on the supply of the micro and signal coming from [before] the capacitor to the external interrupt (RB0) with a pull down resistor (say 1K). A diode should be present between the capacitor and that signal.

On power down, the external signal will get low before the supply of the PIC --> interrupt --> save data

Good Luck
Ttelmah
Guest







PostPosted: Mon May 18, 2009 3:10 am     Reply with quote

'Best' way, depends on your system. Ideally, if you have an external supply rail, that is feeding a voltage regulator, then switch to using a power monitoring IC, that tells you when the incoming rail is just passing the point at which the voltage regulator will no longer be able to maintain the supply rail. Some PICs have a 'low voltage' power monitor option, which is separate from the brownout (the brownout option, is designed to reset the chip, to prevent it getting into a locked state from a supply that has fallen too far for reliable operation, rather than performing operations like saving the EEPROM - this needs to happen with the supply a lot higher....).
Basically, you can calculate, for a PIC, with everything turned off, except the main oscillator, and the action of programming the EEPROM, it's 'worst case' consumption. You then need to work out the minimum voltage that EEPROM writing can be done at (often above the minimum voltage the PIC will work at), and with these two figures, together with the voltage at which your warning will trigger, and the number of bytes to be written, you can calculate the capacitance that needs to be on the rail, to maintain the supply for long enough.
You need in general to take 'worst case' figures for everything.
Your code, should switch everything 'else' off, that it can, to reduce power consumption, as soon as it is called. Remember also, that even if the regulator is not running, it will often draw some current on the outgoing rail, as the supply drops.
Remember (for example), that the rating of an electrolytic capacitor, is often +/-25%. Also you either need to trigger the write as the only high priority interrupt, or allow enough time to handle other interrupt servers that may already be executing when the event occurs to finish. Also your code needs to be able to 'cope' with the situation that it gets called, saves the data, and then the power returns to 'good'.
There have been past thread about this, and I have even posted typical calculations of the capacitor sizes needed, for some examples.

Best Wishes
Karl
Guest







PostPosted: Mon May 18, 2009 7:45 am     Reply with quote

Unfortunately the pic board is already designed and produced. At this time I haven't thought about a separate pin detecting the power as I thought this would be already possible with the brownout fuse. I thought setting this fuse would allow me to receive a IRQ caused by a power drop to e.g. 4 mV and let me write my own code by catching this IRQ.
But this is not possible, or?
Ttelmah
Guest







PostPosted: Mon May 18, 2009 8:04 am     Reply with quote

Not with the brownout....
Fortunately, the 6723, has the HLVD module, which can do what you need.
Program this to trip when the voltage falls below (say) 4.5v. You can then reduce the system clock to say 31KHz (cuts power consumption, and EEPROM write speed remains the same), then save the data.
you can then monitor the HVLD interrupt flag, which will go off, of the power recovers, and if it does, speed up the clock again, and return from the interrupt

Best Wishes
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