Go Down

Topic: SdFat - can card be powered off successfully? (Read 8884 times) previous topic - next topic

nickgammon

My apologies if this has been covered, I found similar threads:

http://forum.arduino.cc/index.php?topic=174582.0
http://forum.arduino.cc/index.php?topic=149504.0

However in my case I have wired Vcc of the SD card (adapter board) via a MOSFET so I could completely power off that part of the circuit (plus other things, like the RTC) in the hope of reducing power consumption to a few microamps (like: 5 µA).

I see a couple of problems, though. There is a SDfat::begin() function but not an end() function. Does this matter?

I also see references to a bug in SDfat where you cannot make multiple calls to begin().


I can see one possible solution, would this be OK?

Code: [Select]
boolean logSomething ()
 {
 SdFat sd;

 // power on device here ...

 // initialize library
 if (!sd.begin (SD_CHIP_SELECT, SPI_HALF_SPEED))
   {
   showError ("SdSdSdSd");
   return false;  // failed to start
   }

 // write to file here ...

 // close file ...

 // power off device here ...

 return true; // OK return
} // end of logSomething


So the SdFat object goes out of scope when the function ends, and thus it (should) be able to be called again later? Or not?

Also is there a function for flushing outstanding data? I don't want to yank the power away from the card if it is still writing something.



You don't want to power the card off and on.


I do, that's the problem. :)
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Mr_arduino

I believe the sync function is what you are looking for also looking from the documentation:
Quote

The sync() call causes all modified data and directory fields to be written to the storage device.

Also close() does appear to also finish writing any data that is buffered from the documentation:
Quote

Close a file and force cached data and directory information to be written to the storage device.

As for shutting off the sd card I don't know if that will work but for now here is how you finish writting any data.

nickgammon

Just as an update, so far so good with the approach I outlined. I added the sync() call (thanks for the suggestion) and the board, in idle state, appears to use around 7 µA. A bit more than I hoped for but still not too bad. It is well under the self-discharge rate of AA alkaline batteries.

The file appears to be written correctly so far. I'll do a lengthier test, over time. :)
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

fat16lib

SD.h has a bug that prevents reinitializing an SD.  SdFat allows reinitialization or changing an SD after power is cut/restored.

You can cut power to an SD if you close all files first.

When you restore power you must call sd.begin() and reopen all files.  You can save and restore file positions by using curPosition() and seekSet().

There is no sd.end() call since SdFat can not properly close all files.

albuino

Please Nick, could you show us your wiring? I would also like to get your same results (7uA) by power cutting SD's Vcc via MOSFET.
Thanks.

nickgammon

It's all here:

http://www.gammon.com.au/forum/?id=12106

Full schematic:

http://gammon.com.au/images/Arduino/HHS_Temperature_Logger1.png
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Bronston

Sorry I know the post is pretty old but it's what got me this far. I'm using sdfat also to shut off my sd, works great but after letting it sit over night the sd card will not reinitialize. I was just curious if anyone else ran into similar issues and hopefully found a solution.

I'm powering it with 4 AA's and this regulator:
http://www.ebay.com/itm/261243604047?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

Here's my code:

http://pastebin.com/wtJzjsSb

(broke the character limit, sorry)

Any ideas?

Thanks,
Bronston

SurferTim

Quote
I'm powering it with 4 AA's and this regulator:
Maybe the batteries are discharging to the point they can't power the SDcard?

The regulator needs 7 volts to work properly. Even 4 new AA batteries will be short of this.
Quote
Wide input voltage range up to 7V to 17V

Bronston

Hmm good point, I missed that. Well I guess another few batteries would just make run longer anyway. I'll give that a try.

Thanks!

SurferTim

Might want to try a bigger set too. Maybe C or D cells? Do a Google search for "AA battery capacity". Lipo battery out of the question? That is the type I prefer. Rechargeable and all. :)



fat16lib

Powering off an SD with hardware is almost never worth doing.  A properly installed SD idles at about 70 µA.  AA batteries deliver about 2000 mah so that would power the SD for about three years.

Initializing the SD when you power it up may take 20 ma for a second or two so that can eat into the savings, same as 5 - 10 minutes idling.

Here is a post about a data logger that runs for a year on AA batteries without powering the SD down.  The SD has the proper pullups to idle at low current.

Better to look elsewhere for power savings.

Bronston

Hmm all good things to consider, thanks guys. Not sure what happened now but after running the batteries dead it will not initialize the sd card period. When I popped it in the pc it had to be formatted. Dunno what's going on at all now.

al2lo

From the PC world - a power off during directory changes can wipe a disk.

Suspect that is possible in directory changes - even file adds/deletes as sections are rewritten.

Have tested this in real life and you see it rarely now as disks write data before power drops. SD writes/reads are possibly susceptible in low power conditions.

solution would be to monitor power and shutdown early.

Bronston

Sure I get that. The thing is now though, it will not read an sd at all no matter what I do. It's got good solid power from the pc with a freshly made card, I know all that is good but still no luck. Is it possible for undervoltage to have damaged the reader? I don't see how but I won't pretend to know much. This is the reader I'm using:
http://www.ebay.com/itm/191295190226?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

I don't get it, all worked just fine before and all the other functions of the arduino work just fine. I checked the voltage to the sd and that all looks good.

SurferTim

#14
Feb 08, 2015, 06:15 pm Last Edit: Feb 08, 2015, 06:16 pm by SurferTim
If the supply voltage slowly tapered off to nothing, it could have damaged either or both of the two ICs on the board. U1 is the logic level converter and U is the voltage regulator. The voltage regulator should be an easy check. Insure 3.3 volts out.


Go Up