SD Card - how to reduce the power consumption?

Great, I'll do just that.

Could you post a simple how to guide and i'll give it a try later?

Look at the html for documentation of the classes. Also look at the SdFat examples.

I suggest you use sync() as opposed to opening and closing your log file. sync() does all the operations of close() but leaves the file open and positioned for the next write. You can power off the logger and all data will be saved, provided you are not in the middle of a write to the file.

Here is a simple example of a logger that writes a line number and the time in millis() to a file every second.

#include <SdFat.h>

// Replace SS with the chip slect pin for your SD.
const uint8_t sdChipSelect = SS;

// SD file system.
SdFat sd;

// Log file.
SdFile file;

void setup() {
Serial.begin(9600);
// Initialize the SD and create or open the data file for append.
if (!sd.begin(sdChipSelect)
|| !file.open("DATA.CSV", O_CREAT | O_WRITE | O_APPEND)) {
// Replace this with somthing for your app.
Serial.println(F("SD problem"));
while(1);
}
}

uint32_t n = 0;
uint32_t t = 0;

void loop() {
// delay one second between points
t += 1000;
while (millis() < t);

// Write your data here
file.print(n++);
file.print(',');
file.println(t);

// Use sync instead of close.
file.sync();
}

This is the file produced by the above logger:

0,1000
1,2000
2,3000
3,4000
4,5000
5,6000
6,7000
7,8000
8,9000
9,10000
10,11000
11,12000

Thanks for the work you're putting in on this subject. I'll hopefully give it a try this evening an report back on the results.
I've had a quick look at some of the examples in the SDfat Library and I think I should be able to port over from the standard SD.h library ok, I just need to learn some of the new commands etc (I'll pick them up hopefully from the examples).

I may have forgot to mention but during the setup loop I also read a file on the SD card (2 numeric digits) which the program uses to set the expected lap time in seconds (as its used on different tracks etc), this is to avoid getting a false IR reading too early in the lap. I guess this means that I still need to use the close() call for this file before opening the data file to avoid having 2 files open etc. After this I could then use the sync() call?

There is no limit on how many file you can have open. The only limit is RAM, each SdFile instance requires 31 bytes.

You must close an instance of SdFile before using it to open another file.

  SdFile file;

  file.open("config.csv", O_READ);
  // read data from config.csv
  file.close();
  file.open("log.csv", O_WRITE| O_CREAT | O_APPEND);
  // write to log.csv

Bingo!!!

I ported over my sketch last night to the SdFat library and hey presto the sd is now sleeping like a baby between read / write events. The current consumtion on the SD card has fallen into the circa 200uA region regardless of which card i use. That means the overall system is now running at only 13mA which is mainly the LCD screen. this will give me around 70 hours of run time from 4 AAA batteries - easily enough for the 24 hour race with practice and qualifying covered as well. :slight_smile:

It took me a few attemts to convert the code over but its all working fine and the examples in the SdFst library were a big help

Thanks for your help with this problem and keep up the good work - I'll only be using this library from now on for future SD projects

I added a simple change to the SD library to help with this issue. I have not tested it fully yet but it may be of interest to know that the SD library has a begin() but no matching end(). I implemented:

void SDClass::end() {
if (root.isOpen())
{
root.close();
}
}

This allows you to close the SD library. Also I am using an N-Channel FET in the ground of the SD card (BS170 Drain connected to SD card gnd, BS170 Gate connected to 10K to ground and Arduino digital IO pin, BS170 Source connected to ground). When I wish to switch off the SD card I tristate all the SD card connections and then I tristate the FET Gate pin. The 10K resistor forces the Gate to 0v and all the pins on the SD card float to Vcc. Next step is to switch off the SPI module in the processor and take the power consumption down further.
Switching back on is easy but this time to switch on the power to the SD card put the FET Gate pin to HIGH. This forces the FET full on and with its low Drain - Source resistance puts power back on to the SD card. It all seems to work but I have not measured the off current and I still have to put the processor to sleep.

Your SDClass::end() may not always work. You must make sure all files are closed before calling your end().

Your end() doesn't do the equivalent of an unmount for a file system. I never added that to the underlying SdFat. It really isn't possible since SdFat does not maintain a list of open files. SdFat was written with RAM use as a top priority.

SD.h has a feature or bug that doesn't allow begin() to be called without closing root so this version of end() fixes that. The underlying SdFat allows begin() to be called multiple times but once again you must close all open files before calling begin().

I would be interested in how much energy you can save with your power saving circuit. SD.h has the bug that doesn't allow SD cards to sleep but SdFat allows cards to sleep.

Modern SD cards sleep at 100 - 200 micro-amps. Many SD card take 500 ms to initialize and draw a lot of current during initialization. A card may draw 50 - 100 ma during this time.

My guess is that several minutes of power off would be required before there was any advantage.

I will be interested in how you determine this and what the result is.

Also I am using an N-Channel FET in the ground of the SD card

It may work fine, but usually such modules are always switched on/off by a high-side switch - ie a P-channel Fet in the VCC rail. Also mind the max drain current (up to 200mA for an SDcard). Switching complex modules low-side in the GND is quite rare.. (with the BS170 low-side you offset signal's log levels by +0.24V when Isd=200mA, probably not a big issue here but not a good design practice, though.. ;))

I was thinking about switching the SD card with a FET (I even bought a BS170 for the job) but I would need to write data to the card every 40 - 80 seconds (dependant on the race track lap length) so I would loose too much power re initialising the card. After porting my sketch over to the SdFat library the SD card is nicely sleeping between write events at around 200uA. This is easily enough power saving for my project.

However, I am interested in how you get on with this and how much current is being used when off and for the initialising.

Made an account to say thank you to fat16lib.

You reduced the power consumption of my SD card from 22ma to ~0.03ma.

Thank you!

Evenin' all,

I'm just trying to do the same - that is get the power right down in between my data logs which occur every 5 mins.

The best I can do at the mo is about 500uA in sleep mode (the arduino bit accounts for 22uA) so I'm wondering if I need to do anything more than close the SD file to get the SD card to sleep?... or perhaps its my SD card - any recommendations for nice sleepy SD cards and any difference between micro SD and full size?

Any code snippets to illustrate would be great :slight_smile:

500uA might be ok - it depends on the actual card used. Check the sdcard's chipselect is high when idle.
You may disconnect the card fully with a high-side switch (ie. pmosfet).

The best I can do at the mo is about 500uA in sleep mode (the arduino bit accounts for 22uA) so I'm wondering if I need to do anything more than close the SD file to get the SD card to sleep?

Closing the file does nothing.

The standard SD.h library is based on an old version of SdFat that does not put the SD in sleep mode. New versions of SdFat enable sleep mode after every transfer and the card will go into low power mode when it becomes idle.

Almost all modern cards go into a very low power mode since this is important for battery powered devices. The 30 uA achieved by user arduino_ above is typical.

The method of level shifting or not applying proper voltage to the SD can cause higher power drain.

I am unable to compile the sketch from fat16lib in Reply #12

I receive the following error:

In function 'void setup()':
'class SdFat' has no member named 'begin'

It compiles fine here.. Do you have SdFat library installed?

Thankyou Pito for taking the time to read my post and test the short sketch posted in February by fat16lib to which I referred.

Yes I have the library installed and I can compile every one of the included example sketches ie AnalogLogger.

I raise this mainly in case other beginners are trying to leverage this useful example to create a periodic data logger using sync and are discouraged by being unable to get the sketch to compile in their environment.

I have downloaded and installed the latest build of the library from Google Code Archive - Long-term storage for Google Code Project Hosting. and the error has disappeared.

Have a great day,

Mike

I didn't see what the reason was for the problem. Apparently something was done differently in sdfat, but I didn't see an explanation of what it was.

Iam using sd card module with Arduino Mega for my automatic water tank project for getting audio output of message like tank full pump off etc....but I am facing a problem with the SD card module when the SD card is inserted it is heating like an heater . there is a 3.3v regulator on the board. Please anyone help me... sorry for the mistake in my language

It would be a good idea to start your own topic perhaps.

This topic was last comented on 8 years ago, so it may not be helpful to go back so far in history.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.