Electronics > Beginners

How to save data when µC power is down?

<< < (3/4) > >>

Psi:
sorry, i was reading other posts and never got down to reading yours.

To fix your problem you just have to enable the mcu's brownout detector. That's what its for  :)
The ATMega32 has two possible brownout settings 2.7V or 4V. If you set the brownout detector to 4V and enable it the mcu will automatically go into reset state when the voltage falls below 4V. You shouldn't get any low voltage crash issues with the brownout detector enabled.
(You will need to program fuse bits to enable the brownout detector, be sure you get the right bits or you might accidentally lock the chip)


--- Quote from: david77 on April 02, 2011, 02:01:03 am ---And another question regarding the actual code.
When INT0 is triggered the AVR jumps to the appropriate ISR where it writes data into the eeprom. Then the return command is issued.
As I expect that nothing else happens now after power is going down what would be the best command to issue after the data is written to eeprom? Do I just let it return to the main prog? Do I stop the AVR? What do you guys think?

--- End quote ---

I'd put the mcu into a never ending loop after writing the eeprom.
You want it to be doing nothing important when the brownout detector puts it into reset state.


--- Quote from: david77 on April 02, 2011, 02:01:03 am ---As I understand the datasheet if you connect Pin 9 RESET of the ATmega32 to Vcc it is forced to do a reset at power up. Maybe the voltage doesn't drop far enough for that to work properly?

--- End quote ---

na, RESET is negative logic, you connect it to GND to make the chip reset, it has an internal pullup that pulls it to vcc (run state) if you leave the pin floating.


david77:
Thank you Psi.

I don't know where I read about the Reset connected to Vcc - it was late I must have imageined things  8)

I have BOD enabled, though I'm not sure if I set it to 2,7 or 4V. I'll have to recheck that again, might be set to 2,7V wich obviously isn't any good.

Zero999:

--- Quote from: Psi on April 02, 2011, 02:56:52 am ---With a small 5.5V 1 Farad super cap it would take 10seconds to discharge from 5V to 4V under a 100mA load
--- End quote ---
Beware, some memory retention capacitors have a very high ESR. The datasheet linked below shows some 1F 5.5F capacitors that have an ESR of up to 30R which at 100mA is a 3V drop before it even starts discharging.
http://docs-europe.electrocomponents.com/webdocs/0027/0900766b800274ce.pdf

Trigger:
Don't forget that you have the WDT too.

One thing you should do is a CRC check of the data you wrote to the EEPROM to make sure it matches what's in memory.  It'll save you some headaches down the line.

If you're using one of the picopower AVRs you can sleep it and retain the RAM with a backup battery.  One of those with a battery could last for years.  Cymbet has their enerchips as well which will control power and provide a battery backup.  Their chips are not prototyping friendly but they have an evaluation kit with a 24 pin DIP module that would be easy enough to put into a design.

tecman:

--- Quote from: williefleete on February 28, 2011, 04:05:25 am ---stick in a routine which writes to a 8 pin eeprom regularly if its not to involved or use a battery backed SRAM


--- End quote ---

Be very careful with this.  You can be bitten easily by exceeding the lifetime R/W cycles.  Option is to do it less frequently, but then you lose data on power down.

paul

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod