Skip to content

Instantly share code, notes, and snippets.

@brandoaire
Created October 23, 2015 22:09
Show Gist options
  • Save brandoaire/68d639903d4984c3bd7c to your computer and use it in GitHub Desktop.
Save brandoaire/68d639903d4984c3bd7c to your computer and use it in GitHub Desktop.

###Power Management on the Electron Beta

Our Electron beta users have reported that in some cases the battery on the Electron discharges completely and the Electron stops working even with the USB power plugged in. Pressing the reset button does not do anything and the only way to bring it back to life is by plugging the USB out and plugging it back again.

Why does this happen? The PMIC, (Power Management IC) BQ24195, uses the USB data pins to determine if there is a computer present or a compliant USB charger at the other end. While this works on most standard computers, the PMIC has a hard time detecting some chargers and defaults back to a safe input current limit of 100mA. This current is too low for the electron to both operate and charge the battery at the same time. In the current electron beta hardware configuration, the only way to overcome this is by updating the charge rate of the battery at regular intervals. This can be accomplished by calling the following function:

Note: We must also disable the internal watchdog timer of the PMIC in the setup:

PMIC power;

void setup() {

	//Sets up the internal I2C to communicate with the PMIC
    power.begin();
    //Disables the PMIC's internal watchdog timer
    power.disableWatchdog();
    //Sets the input current limit for the PMIC
    //100,150,500,900,1200,1500,2000,3000 (mAmp)
    power.setInputCurrentLimit(500);
}

void loop() {
	
	//call the the following function frequently
	power.setInputCurrentLimit(500);
}

Other things to try out:

You can also set the charge current of the battery by using the following function:

setChargeCurrent(bool bit7, bool bit6, bool bit5, bool bit4, bool bit3, bool bit2)

/*The total charge current is the 512mA + the combination of the current that the following bits represent
bit7 = 2048mA
bit6 = 1024mA
bit5 = 512mA
bit4 = 256mA
bit3 = 128mA
bit2 = 64mA
*/

//For example:
setChargeCurrent(0,0,1,1,1,0); 
//will set the charge current to
//512mA + [0+0+512mA+256mA+128mA+0] = 1408mA

You can find a complete list of functions in the spark_wiring_power.cpp under the firmware/wiring/src/ folder.

TO DO: In the future firmware releases, we plan to do all of this in the system background process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment