Pages: [1]   Go Down
Author Topic: ADXL345 Auto Sleep Power Consumption  (Read 1229 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I am working on a small data logger using an adxl345 accelerometer breakout, Arduino pro mini ultra and an micro SD shield.
Accel: http://www.sparkfun.com/products/9156
MicroSD: http://www.sparkfun.com/products/544
Arduino: http://www.rocketscream.com/blog/category/projects/arduino-related/mini-ultra-8-mhz-low-power-arduino-compatible-board/

I am working on the power consumption of the accelerometer and I am getting some strange readings. I have configured the appropriate registers as per the data sheet and have confirmed the device is auto sleeping by reading various status bits. According to the datasheet consumption should be around 40uA while asleep. The initialisation code is below if you would like to have a look but I think its fine...

Code:
void setupAccel() {
  SPI.begin();
  SPI.setDataMode(SPI_MODE3);
  pinMode(CS, OUTPUT);
  digitalWrite(CS, HIGH);


  // interrupts setup
  writeRegister(INT_MAP, B8(00011000)); // send all interrupts to ADXL345's INT2 pin
  writeRegister(INT_ENABLE, B8(00011000)); // activity, inactivity
   writeRegister(DATA_FORMAT, B8(00100001)); //invert interrupts for active low
  writeRegister(BW_RATE, B8(00001001)); //set data rate


  // inactivity configuration
  writeRegister(TIME_INACT, 3); // 1s / LSB
  writeRegister(THRESH_INACT, 3); // 62.5mg / LSB
  // also working good with high movements: R_TIME_INACT=5, R_THRESH_INACT=16, R_ACT_INACT_CTL=B8(00000111)
  // but unusable for a quite slow movements

  // activity configuration
  writeRegister(THRESH_ACT, 6); // 62.5mg / LSB

  // activity and inctivity control
  writeRegister(ACT_INACT_CTL, B8(11111111)); // enable activity and inactivity detection on x,y,z using ac

  // set the ADXL345 in measurement and sleep Mode: this will save power while while we will still be able to detect activity
  // set the Link bit to 1 so that the activity and inactivity functions aren't concurrent but alternatively activated
  // set the AUTO_SLEEP bit to 1 so that the device automatically goes to sleep when it detects inactivity
  writeRegister(POWER_CTL, B8(111111));

}

void writeRegister(char registerAddress, char value){
  SPI.setDataMode(SPI_MODE3);
  digitalWrite(CS, LOW);
  SPI.transfer(registerAddress);
  SPI.transfer(value);
  digitalWrite(CS, HIGH);
}
void readRegister(char registerAddress, int numBytes, char * values){
  SPI.setDataMode(SPI_MODE3);
  char address = 0x80 | registerAddress;
  if(numBytes > 1)address = address | 0x40;
  digitalWrite(CS, LOW);
  SPI.transfer(address);
  for(int i=0; i<numBytes; i++){
    values[i] = SPI.transfer(0x00);
  }
  digitalWrite(CS, HIGH);
}

The strange part is if I run my code with the Accelerometer and micro SD connected the power consumption of the accelerometer sits around 41uA which is perfect. However, without the SD card the consumption is about 60uA then rises to around 120uA. After a little more investigation I realised I only need to leave the SD's Data Out line connected for the power consumption to stay at 41uA.

Furthermore, I realised if I add the SD initialisation code and upload that to the board, accelerometer power consumption sits at 41uA. I can then delete the SD code and re-upload and the power stays at 41uA, even after multiple resets and power offs. However, if I eject the microSD and re-insert it the power spikes and wont return to 41uA until I re-upload the SD initialisation code. I'm using the SDFat library and the code is below.

Code:
if (!sd.init(SPI_FULL_SPEED, chipSelect)) {
    Serial.println("SD ERROR");
    digitalWrite(redLED, HIGH);
    sd.initErrorHalt();
  }

I guess seeing how I will be using the SD in my final application I could ignore this but its really been bugging me and I want to know what is happening. I also want to 'switch off' the SD when its not in use if I can. I didn't even notice this problem until I started trying to disconnect the SD.
 
Sorry if this is unclear, its difficult to describe the problem.
Any ideas or suggestions on what is happening here would be appreciated.

Cheers
Logged

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10434
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is the classic floating-inputs problem with CMOS logic.  Never leave an input pin unconnected.  If you do it can either oscillate or end up at 50% of the supply voltage (at which point both input transistors are conducting).  Either situation increases power consumption drastically (3 to 5 orders of magnitude for a single CMOS gate) compared to the normal static situation.  Now this might be a small fraction of current consumption of a running microcontroller, its going to dominate the sleep-mode consumption when nothing is being clocked.

Two solutions:  set unused pins as outputs, or use pullups/pulldowns.  You could use the internal pull-ups.

Here you want to leave MISO as an input (since the SDcard may be connected).  It might be enough just to enable the internal pull-up for that pin.  If the SDcard defaults to driving it low then a pull-down would be better (but I think it shouldn't be driving it at all?)
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply, good to know I'm not going crazy.

So i'll get rid of the SD for the moment and try to get the accelerometer going. I'm about to head to work but Ill try this tonight.

So basically I need to put the SPI pins in a controlled state rather than letting them float while the board sleeps. I think i'll try the pull-ups/pulldowns but If i do configure the pins as outputs, would I have to do this before sleep then set them back to normal when the device wakes? Or will turning ont he SPI bus with SPI.begin() take care of that

Cheers,
Sam
Logged

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10434
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You know about the internal pull-ups?  The SCK signal is the one you might want to pull-down by default, otherwise you'll have a rogue clock edge when you put into sleep mode.  Setting to output mode is only an option if you know the other end is in hi-Z or input mode.

If you put external chips to "sleep" by powering them down at Vdd, the chip itself then acts as a pull-down (via its protection diodes).
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I know about the internal pullups. Sorry I was in rush this morning.

Enabling the pullups on MOSI and MISO worked a treat. I just added the following lines to the setup. Power is still not quiet as static as I hoped. I now floats between 42 and 43uA where it should be sitting at 41uA like in my previous test. Adding an external pulldown resistor (10K resistor between the CLK pin and GND) doesn't seem to make a difference. Is that what you meant?

Code:
  pinMode(12, INPUT); //MISO
  pinMode(11, INPUT); //MOSI
  digitalWrite(12, HIGH);
  digitalWrite(11, HIGH);
« Last Edit: February 09, 2012, 06:44:09 am by fireman_sam6986 » Logged

Pages: [1]   Go Up
Jump to: