Changing Battery Charging Settings - Electron

@RWB, who did you intend to ask this?
mhaider8 didn’t mention changing anything :confused:

I was referring to @mhaider8 , I thought he possibly changed a setting once he instantiated the PMIC library.

@adamg @ScruffR

I am also trying to change the charging current settings on the PMIC and no matter what I try to call to instantiate an object to use it I get error messages.

I figured out how to do this before but can’t find the code I used to do it.

What else do I need to call first to get the setChargeCurrent code to compile correctly? I’ve tried at least six different versions of PMIC.begin(), and similar flavors of that I came across that others used to change different settings. I know it’s easy, but it’s eluding me at the moment : smiley:

//set charging current to 1024mA (512 + 512 offset)
pmic.setChargeCurrent(0,0,1,0,0,0);

//set input current limit to 1.5A
pmic.setInputCurrentLimit(1500);

I was testing the Electron and how it handles solar charging today and this the changes above are needed for further testing.

1 Like

Seeing your code line and the error message would help :wink:

But it should just be

PMIC pmic;
2 Likes

@ScruffR BINGO!

Now why was that so hard for me to figure out?

So the PMIC calls the class? And the pmic allows me to use the functions under that class? I may be way off so forgive me but I obviously do not fully understand what is going on.

I know you can serial.begin(), and other sharp.init(), to start other classes so the PMIC is kinda different I guess.

It’s not actually that different, but for example Serial.begin() doesn’t need to be called since it’s already done by the system beforehand. The same goes for PMIC :wink:
And you don’t need to instantiate a Serial object since that’s already done and made public for you.
Furthermore, if the functions you’d call are purely static, there is nothing begin() or init() or even a constructor would need to do since statics need to work as are without any instantiated object.
If you look again at this, you’ll see PMIC::begin() too.
https://github.com/spark/firmware/blob/develop/wiring/inc/spark_wiring_power.h

To get the wording sorted:

  • PMIC is the class name and is used as the “data type” here
  • pmic is the name chosen for this object instance
    • one peculiarity here is that for some reason you can’t write PMIC pmic(); which would make it more obvious that this line does not only declare the variable but also calls the default constructor PMIC::PMIC(). If you’d call a non-default constructor, you can still use CLASSNAME classname(someParameter); tho’.

Thank you for taking the time to explain what is going on. Some of it I understand and some of it I need to brush up :smiley:

First off your link shows a 404 error because you need to add.cpp to the end of it :wink:

I did look at the code in the spark_wiring_power.cpp file and tried to use:

PMIC.power
PMIC.power();
PMIC.begin();
PMIC.pmic();

ect... but none of it would compile :blush:

I'm just glad you guys are here for when thigns like this come up :smiley: God only knows how long I would have poked around until I figured it out.

I understand how the libraries work and how they are laid out in the header and .cpp files, it's initiating the class and the different ways it can be done is where I need to learn more, which will come with time.

I was able to change the setInputVoltageLimit(uint16_t voltage)setting higher which basically acts like a cheap version of MPPT (Mutiple Power Point Tracking) for the solar panel that is attached to the Electoron's Vin terminals since a 5v Solar Panel has a voltage that provides the most current. More on this later in a seperate post.

Thanks for your help!

1 Like

Obviously I faild to copy the final h - I’ve corrected the link

You can only use the dot-notation with object fields/methods (pmic.begin()).
For static methods (which these aren’t) you’d use PMIC::begin()

1 Like

Is there a way to set the charging current to less than 512mA?

Have you had a look at the linked header file?

/*
//-----------------------------------------------------------------------------
// Charge current control register
//-----------------------------------------------------------------------------
REG02
BIT
7: ICHG[5] 2048mA	| offset is 512mA
6: ICHG[4] 1024mA	| Range: 512 to 4544mA (BQ24195)
5: ICHG[3] 512mA	| Range: 512 to 2496mA (BQ24195L)
4: ICHG[2] 256mA	| Default: 2048mA (011000) = 512mA+1024mA+512mA
3: ICHG[1] 128mA	| enabling bits 2 to 7 adds the current to 512mA base value
2: ICHG[0] 64mA		|
1: Reserved (should always be 0)
0: FORCE_20PCT (fill this description)
*/
3 Likes

I saw the 512mA offset, which makes me think that there isn’t.
Hoping there is some way around that.

Maybe @BDub can shed some light.

You can work around the 512mA offset by changing the PMIC’s input current limit to something lower.

/*******************************************************************************
 * Function Name  : setInputCurrentLimit
 * Description    : Sets the input current limit for the PMIC
 * Input          : 100,150,500,900,1200,1500,2000,3000 (mAmp)
 * Return         : 0 Error, 1 Success
 *******************************************************************************/

bool PMIC::setInputCurrentLimit(uint16_t current);

This will be overridden if the input voltage drops out and comes back though (with something like a solar cell or switching USB ports) and it will be set back to the default 900mA level. To counteract that you could set it in a Software Timer every 60 seconds or so. I don’t think you’d need to set it too frequently, unless your input is changing frequently.

3 Likes