|
|
View previous topic :: View next topic |
Author |
Message |
Oliver Lai
Joined: 12 Dec 2003 Posts: 16
|
save data in flash memory just when power down |
Posted: Fri Feb 27, 2004 10:50 pm |
|
|
Hi, I need your instruction.
How can I save my data (just one float data) in flash memory (or eeprom) when power is suddenly down?
Thanks,
oliver |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
Power Down Save |
Posted: Sat Feb 28, 2004 9:33 am |
|
|
The biggest problem you have is the time to write to flash before the P/S goes too low.
In my case I did this with a 10,000 uF capacitor and a 1N4004 diode in the power feed to the PIC. The diode is between the PIC and the 5.7V power source with the cap on the PIC side of the diode. I tied the input of a MC1489 to the 5.7V side of the diode and the output to the B0 input on the PIC to trigger an ISR. The capacitor gives plenty of time (several seconds typically) before power goes down to save data to flash. The a 5.7V source is required to offset the 0.7V voltage drop in the 1N4004 and provide 5V at the PIC. Since you have only one item to save smaller cap would be possible.
There are other options available....I am sure someone else here has a different approach. |
|
|
Ttelmah Guest
|
Re: Power Down Save |
Posted: Sat Feb 28, 2004 11:58 am |
|
|
dyeatman wrote: | The biggest problem you have is the time to write to flash before the P/S goes too low.
In my case I did this with a 10,000 uF capacitor and a 1N4004 diode in the power feed to the PIC. The diode is between the PIC and the 5.7V power source with the cap on the PIC side of the diode. I tied the input of a MC1489 to the 5.7V side of the diode and the output to the B0 input on the PIC to trigger an ISR. The capacitor gives plenty of time (several seconds typically) before power goes down to save data to flash. The a 5.7V source is required to offset the 0.7V voltage drop in the 1N4004 and provide 5V at the PIC. Since you have only one item to save smaller cap would be possible.
There are other options available....I am sure someone else here has a different approach. |
Yes. It depends massively, on the amount of data to save, the nature of the power supply, and the support circuitry available.
I have a number of '12v' powered applications, which simply use a 'low voltage' detector, to trigger an interrupt when the supply falls below 9v. Using a LDO regulator, and a fairly reasonable capacitor size, I can get about 50mSec between the 'warning', and the 5v rail falling, _provided_ I switch off any peripherals being driven as the first operation. A simple time constant calculation can be applied to work out for a given voltage drop, the time available.
Then it is just a matter of writing the data, waiting for a few moments, and then starting to 'poll' the input voltage, and continue processing if the failure was a 'false alarm'.
You can balance the amount of data needed, with the likely update rate. For instance, any settings that are changed infrequently, can be saved when changed. Similarly, if you are running a large counter for a quadrature detector system, the MSB, may well change only once a day, while the LSB is changing frequently. In this situation, save the MSB when it changes, and the LSB when the power fails, to keep the number of write cycles reasonable.
There was a thread a while ago, with a discussion about this.
Best Wishes |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Sat Feb 28, 2004 12:06 pm |
|
|
It can work with a capacitor on the 5V supply, but it's a better design if you run the processor off a regulator with the storage capacitor on the high voltage side. The reason is that as you withdraw charge from the capacitor starting at 5V, the voltage will inevitably drop, and you don't really know how long it'll last. But if the capacitor feeds the input side of the regulator, you get an honest 5V out until the capacitor voltage gets to 5 + the regulator drop.
(Substitute your operating voltage for 5V, if it's different.) |
|
|
Oliver Lai
Joined: 12 Dec 2003 Posts: 16
|
schematic please |
Posted: Sat Feb 28, 2004 4:38 pm |
|
|
Thanks all for very valuable advises!
I use 5V power supply, will save 8 bytes data, can anybody kindly send me your schematics?
Thanks a lot!
oliver |
|
|
Ttelmah Guest
|
Re: schematic please |
Posted: Sun Feb 29, 2004 3:46 am |
|
|
Oliver Lai wrote: | Thanks all for very valuable advises!
I use 5V power supply, will save 8 bytes data, can anybody kindly send me your schematics?
Thanks a lot!
oliver |
If you are only using 5v power, and have no access to the incoming supply, then no schematics are needed (assuming you are using a PIC that has a LVD circuit).
As an example, take the PIC18Fxx2 family. On this there is a LVD interrupt, that can be programmed to occur at a number of voltages. Assume that it is set for the highest voltage (4.5 to 4.77v), and that the trip actually takes place at the lowest voltage of this range (4.5v). The standard version of the processor, is specified to operate at all clock rates down to 4.2v. The write time for the data EEPROM, is 4mSec. So you just need a capacitor large enough, that 0.3v drop, takes more than 32mSec. The size needed will depend on how much you can reduce the demand by other circuits on the board for this time (if you can switch all the drivers etc., off, so that only the processor is running, the required consumption will depend largely on the clock rate of th processor). Remember also that you must allow for the fact that most electrolytic capacitors have large tolerances (perhaps +/- 25%), so again you must assume the 'worst case'. Assuming that the processor draws perhaps 10mA, then you would need about 1100uF.
Best Wishes |
|
|
Oliver Guest
|
LVD interrupt |
Posted: Wed Mar 03, 2004 8:36 pm |
|
|
Hi, Ttelmah:
Thanks a lot for your kindly reply!
I have checked CCS compiler, there is: #INT_LOWVOLT, but no any more explaination.
How can I set the detect voltage?
Do you have any example program?
Oliver |
|
|
|
|
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
|