Lowering Power & Extending Battery Life

If you plan to run a Teensy-based project from a battery, you will want to minimize power consumption and maximize run time from. You may also want to estimate how long the battery will last, or choose a battery to last a certain length of time.

TODO: Photo, Teensy powered from large coin cell

Typical Current Consumed By Teensy

Teensy consumes different current depending on a number of factors. This table should give you a reasonable idea of what current to expect.

Typical CurrentOperating Condition
Teensy
2.0
Teensy++
2.0
VoltageClockUSBRunningIdleSleep
27.3 mA60.2 mA5V16 MHzOn100%0%0%
17.9 mA37.9 mA5V8 MHzOn100%0%0%
18.9 mA31.2 mA5V16 MHzOff100%0%0%
11.0 mA17.2 mA5V8 MHzOff100%0%0%
6.6 mA10.7 mA5V8 MHzOff10%90%0%
4.5 mA6.6 mA5V2 MHzOff100%0%0%
0.04 mA0.04 mA5VOffOff0%0%100%
15.7 mA31.3 mA3.3V16 MHzOn100%0%0%
10.6 mA19.7 mA3.3V8 MHzOn100%0%0%
6.6 mA9.3 mA3.3V8 MHzOff100%0%0%
4.0 mA5.6 mA3.3V8 MHzOff10%90%0%
2.9 mA4.0 mA3.3V2 MHzOff100%0%0%
0.23 mA0.23 mA3.3VOffOff0%0%100%

The 3.3 volt measurements include the current used by a MCP1825 powered from 5.0 volts. The MCP1825 consumes approximately 0.2 mA for itself.

TODO: other testing methodology notes?

Power Reduction Measures

There are many things you can do to reduce power consumption. This list is in the ordered from the easiest to most difficult. Usually starting with the easiest techniques is best.

Configure Unused Pins

All I/O pins default to INPUT mode. That is safest, since you may connect a sensitive signal. But unconnected pins in INPUT mode can change voltage due to the slightest electrostatic coupling. If they drift to a voltage near the "middle", between digital high and low, the input circuitry in the chip consumes unnecessary power. On a Teensy++, many extra mA of current can be wasted with 40+ unconnected pins.

The solution is easy. Just add code which configures all unused pins to output mode.

TODO: code sample

Disable USB

The USB port consumes power. If you're placing Teensy inside a project where no USB access is need, disabling the USB saves power.

TODO: code samples

Connection to a computer with USB disabled will not damage Teensy, but the computer will not detect anything connected. Pressing the reset button on Teensy will allow the computer to use it again. If you are using Arduino, the Upload button will not be able to reboot Teensy automatically. Usually it's convenient to leave the USB enabled while working on your program, but disable it in the final version.

Reduce Clock Speed

Lowering the clock speed saves power. The clock speed can be set using The Tools > CPU Speed menu in Arduino, or the prescaler registers and Makefile in C.

In theory, you could change the prescaler as necessary, to allow your program to run faster on demand. In practice, this requires considerable software work, since nearly all examples and libraries are configured with a F_CPU constant. The idle and sleep modes are usually much more effective than dynamically changing the clock.

Soldering a lower frequency crystal will NOT significantly reduce power usage. The crystal oscillator is an analog amplifier with approximately constant current consumption, regardless of the crystal frequency.

Run at 3.3 Volts

Converting to 3.3 volts saves a lot of power. But the CPU is not rated to run at 16 MHz when powered by 3.3 volts. It usually works, at least at room temperature, but technically 16 MHz at 3.3 volts is overclocking.

Use Idle Mode

Enter idle mode when nothing to do. Easy, since the normal timekeeping will wake up automatically. All peripherals stay active, everthing else will works. Compatible with most Arduino libraries.
#include <avr/sleep.h>

void idle() {
  set_sleep_mode(SLEEP_MODE_IDLE);
  noInterrupts();
  sleep_enable();
  interrupts();
  sleep_cpu();
  sleep_disable();
}

TODO: document ADC bug, first analogRead() after waking from idle may not work.

Disable Unused Peripherals

Analog to Digital Converter uses about 0.8 mA, disable with "ADCSRA = 0"

TODO: mention peripheral disable registers

Use Sleep Modes

Difficult, since you must plan on some mechanism to wake up.

Timekeeping and most peripherals are shut off. Incompatible with most Arduino libraries.

Optimize Battery Discharge

voltage ranges of Teensy

regulator dropout

battery discharge curve and Teensy brownout voltage

battery capacity specs

rough guesses for alkaline batteries

Power Test Program

The measurements in the table above where made using this test program.
const int usb_usb_disable = 0;
const int use_idle = 0;
const int use_powerdown = 0;

void setup() {
  for (int i=0; i<46; i++) {
    pinMode(i, OUTPUT);
  }
  if (usb_usb_disable) Serial.end();
  if (use_powerdown) powerdown();
}

elapsedMillis usec;

void loop() {
  if (use_idle) {
    if (usec <= 90) {
      idle();
      return;
    }
    if (usec >= 100) {
      usec = usec - 100; 
    }
  }
}

#include <avr/sleep.h>

void idle() {
  set_sleep_mode(SLEEP_MODE_IDLE);
  noInterrupts();
  digitalWrite(2, LOW);
  sleep_enable();
  interrupts();
  sleep_cpu();
  sleep_disable();
  digitalWrite(2, HIGH);  // pin 2 high while running, for approx
          // measurement of CPU time with voltmeter
}

void powerdown() {
  Serial.end(); // shut off USB
  ADCSRA = 0;   // shut off ADC
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  noInterrupts();
  sleep_enable();
  interrupts();
  sleep_cpu();
  sleep_disable();
}