Pages: [1] 2   Go Down
Author Topic: SD Card - how to reduce the power consumption?  (Read 11342 times)
0 Members and 3 Guests are viewing this topic.
UK
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So here's my problem, I've built a karting lap timer that uses an IR beam to trigger the lap time each time the kart passes the pits. I have a Micro SD card which I'm writing the lap times to - this works very well however the SD card is pulling around 12mA even after writing the times and after I've closed the file - myFile.close(); I need to get the timer to run for at least 24 hours including running a screen so mA's are crucial. Without the SD card attached the device only uses about 13mA, with it attached its running at 17mA and when begun - sd.begin() - it jumps to 25mA. This is too much for the batteries (4 x AAA, can't use AA's as the space isn't enough). Different cards behave differently as one of my cards jumps to over 40mA when SD.begin()

Also if I remove the card it jumps back to 13mA but on re inserting the card the whole system restarts, not sure why?

Is there a way to switch off the SD card when not required etc either with software (preferred) or with a hardware method?
I've seen that turning off the SCK pin can put SD cards to sleep, is there any way to do this?
I've also seen an N-MOSFET being used on the gnd line to swith the SD card off, anyone got any experience of this?

Or is my code wrong? here's a sample

myfile = SD.open("times.csv", FILE_WRITE);// Open SD Card File
    if (myfile) {// if the file opens ok
      myfile.print("Lap,");//Start line with Lap
      myfile.print(lapcount);//add the lap count to the file
      myfile.print(",");//add a comma for use in excel later
      myfile.println(laptime);//save laptime and start new line
      myfile.close();// close and save the file
    }

Thanks
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2086
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

An Sdcard may take up to 200mA peak, based on specification (it depends what the card actually does).
You may use p-channel mosfet (high-side switch) to switch the card off/on..
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Pito,
I'm aware that the SD Cards pull upto 200ma during reading and writing and thats ok. The problem I have is that the datatsheet for the SD Card shows a sleep mode which pulls around 250uA.

I need to find a way to put the SD Card to sleep between write events to make use of this small current draw.
Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1673
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you describe the details of your hardware.

Most SD cards automatically go to a low power mode when no SPI clock is applied.  I tested two card with a Teensy 3.0.

I used a Teensy 3.0 since I could connect it directly to 3.3V and the Teensy pins.  There are no resistors, level converters, or voltage regulators.

An old full size SanDisk card sleeps at 0.18 ma.
Quote
A unique feature of cards in the SanDisk SD Card Product Family is automatic entrance and exit from sleep mode. Upon completion of an operation, cards enter sleep mode to conserve power if no further commands are received in less than 5 milliseconds (ms). The host does not have to take any action for this to occur. However, in order to achieve the lowest sleep current, the host needs to shut down its clock to the card. In most systems, cards are in sleep mode except when accessed by the host, thus conserving power.
When the host is ready to access a card in sleep mode, any command issued to it will cause it to exit sleep, and respond.


A new Amazon microSD sleeps at 0.13 ma.

I just used the SdFat QuickStart and SdInfo examples.
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So, I'm using a stripbaord arduino running at 3.3v (no need for level shifting) with a 16x2 LCD screen and a Sparkfun Micro Sd Card module (Link Below). There also an IR receiver TSOP31238 to receivethe signal from the pit wall. The SD Module is hooked up to pins 10 through 13 with 10 being used for the CS pin. Reading and writing to the sd card isn't a problem it just its standby current.

http://proto-pic.co.uk/breakout-board-for-microsd-transflash/

I'm testing with 2 different SD cards one is sandisk 1gb and the other is sandisk 128mb (quite old), both give different results, the 1gb increases the running current from 13mA to around 25mA (this is will last 24 hours ok) the other runs at 40mA (this is not ok and I need a system that isn't dependant on which type of card I use).

I've seen the quote before about the sandisk automatically sleeping when the clk signal isn't received for 5ms or more but i'm not sure if the arduino ever stops the clk signal? and if this is relevant in SPI mode?

I've also found out that some current is always leaking through the clk and data pins once the SD.Begin() is activated so this maybe a problem with the SD libraries on the Arduino as you can't 'Stop' an SD Card. Because of this its seem its very difficult to add a MOSFET to switch either Vcc or Gnd off when the cards not required ( the sandisk datasheet also states that power must come on to Vcc before power is received on the clk or data signals as this could corrupt the card and without being able to 'stop' the sd card this would happen)
Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1673
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Most SD cards won't sleep unless they have been initialized.

I am the author of SdFat which is also the core software for the standard Arduino SD.h linrary.
Quote
I've seen the quote before about the sandisk automatically sleeping when the clk signal isn't received for 5ms or more but i'm not sure if the arduino ever stops the clk signal? and if this is relevant in SPI mode?
The only time SPI clock is active with these libraries is during an actual data transfer.  In your case it will be rare for SPI clock to be active.

I did another test with a 5 V Uno and and this Adafruit module http://www.adafruit.com/products/254

I measured the current from 5 V on the Uno to the Adafruit module after the SD was initialized by the SdFat QuickStart example.  I used a Transcend 4 GB class 6 MicroSDHC card.  

The current was only 0.21 ma even though this module has level shifters and a voltage regulator.  The module activity LED on SCK is not lit when the card is not active.

You don't want to power the card off and on.  You then need to reinitialize the card and SD.h wrapper for SdFat has a bug that prevents multiple calls to begin().  

Could you download SdFat http://code.google.com/p/sdfatlib/downloads/list and run the QuickStart example.  Measure the SD current after QuickStart prints its success message.

You must have the meter connected during the entire test since the card may draw high current until it is initialized and disconnecting the card will cause it require initialization.
« Last Edit: February 18, 2013, 03:43:58 pm by fat16lib » Logged

Offline Offline
Edison Member
*
Karma: 50
Posts: 1697
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use an EEPROM for storage instead of an SD card. I2C (or SPI) chips with 1Mbit in an 8-pin DIP would probably be good enough for what you're doing.

Pete
Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1673
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should be able to use a modern vanilla microSD with your setup and it should almost always sleep at 100 - 200 micro-amps.  No need for MOSFET or EEPROM.

I have now tested about 10 cards in various modules and all draw very little current when idle.  Are any of your other devices on the SPI bus?  If you access them, the SD might draw more current since it will see SCK active.

It is possible to run SdFat in SPI bit-bang mode on other pins if other SPI activity is causing the problem.  You simply edit the config file to select software SPI and specify the pins to use.
« Last Edit: February 18, 2013, 04:22:38 pm by fat16lib » Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So I couldn't use the Quickstart example you suggested due to me using a strip board built arduino running at 3.3v. It has no PC serial connection. I've been using my Uno to load the sketches and then transferring the chip to the strip board. I know this isn't the best idea but I won't to run this device on a karts steering wheel and didn't want to waist my Uno.

I've taken some photo's of my setup to give you an idea.





I'm going to try a different sketch to see if its my programming that's at fault.

And no there are no other SPI devices hooked up.

I thought about using an EEPROM for storage but I wanted this for 24 hour kart races and we can get over a thousand laps recorded during this time so recording them as a .CSV file for easy transfer to excel seemed a better choice.
Logged

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2086
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try to run SdInfo sketch from SdFat examples. Comment out line 150:
Code:
while (Serial.read() <= 0) {}
and put the chip into your board, switch on, wait few seconds and observe the current..
Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1673
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I understand the problem.  You are using SD.h and it has a bug that doesn't allow the SD to sleep.

SD.h has not added bug fixes from SdFat for about three years and the Adruino developers have added their own bugs.  I tried SD.h with my tests and found cards pulled from 15 to 28 ma when idle.

These same cards pull less than 200 micro-amps with the new SdFat and some as low as 120 micro-amps.

My advice is to convert to my current version of SdFat.
« Last Edit: February 18, 2013, 05:39:51 pm by fat16lib » Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Great, I'll do just that.

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

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1673
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Quote
#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:
Quote
0,1000
1,2000
2,3000
3,4000
4,5000
5,6000
6,7000
7,8000
8,9000
9,10000
10,11000
11,12000
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1673
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Code:
  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

Logged

Pages: [1] 2   Go Up
Jump to: