PMIC get/setInputCurrentLimit not setting correctly?

I noticed some weird behavior when trying to use PMIC functions get/setInputCurrentLimit. Whenever I tried to set anything over 900, it actually reported a lower value. I am using this code to test:

#include "Particle.h"

SYSTEM_MODE(MANUAL);
PMIC pmic;

int currentValues[] = { 100, 150, 500, 900, 1200, 1500, 2000, 3000 };

void setup() {
  Serial.begin();
  pmic.begin();

  delay(2000);

  Serial.print("Starting value of inputCurrentLimit: ");
  Serial.println(pmic.getInputCurrentLimit());
  Serial.println("");

  for (int i = 0; i < sizeof(currentValues) / sizeof(int); i++) {
    Serial.print("Calling setInputCurrentLimit with value: ");
    Serial.println(currentValues[i]);
    pmic.setInputCurrentLimit(currentValues[i]);
    delay(500);

    Serial.print("Calling getInputCurrentLimit.... Result: ");
    Serial.println(pmic.getInputCurrentLimit());
    delay(500);

    Serial.println("");
  }

  Serial.println("Finished.");
}

void loop() { }

The results on the default 0.8.0-rc.25 and 0.9.0 are the same:

Serial monitor opened successfully:
Starting value of inputCurrentLimit: 500

Calling setInputCurrentLimit with value: 100
Calling getInputCurrentLimit.... Result: 100

Calling setInputCurrentLimit with value: 150
Calling getInputCurrentLimit.... Result: 150

Calling setInputCurrentLimit with value: 500
Calling getInputCurrentLimit.... Result: 500

Calling setInputCurrentLimit with value: 900
Calling getInputCurrentLimit.... Result: 900

Calling setInputCurrentLimit with value: 1200
Calling getInputCurrentLimit.... Result: 100

Calling setInputCurrentLimit with value: 1500
Calling getInputCurrentLimit.... Result: 150

Calling setInputCurrentLimit with value: 2000
Calling getInputCurrentLimit.... Result: 500

Calling setInputCurrentLimit with value: 3000
Calling getInputCurrentLimit.... Result: 900

Finished.

Iā€™m not sure if this is a bug in the getter or the setterā€¦ Or if we are just not ā€œallowedā€ to set anything over 900 on that device and this is expected behavior? Doesnā€™t BQ24195 allow up to 2.5A or 3A input current? Any response would be appreciated.

1 Like

I have noticed the charge current not going much over .9 - 1 Amp of charging current even when charging from a bench power supply that can supply up to 5 amps of power.

Iā€™m sure this has to do with battery voltage drop in the battery JST Connector, thin wires, and feeding the battery through the the battery protection circuit, which all causes the PMIC charging circuit to see the battery voltage higher than it actually is which causes the charging current to drop lower as it should and does typically as the battery voltage rises as it reaches a full charge.

I reported this and experienced this same issue with the original Electron devices years back.

Really you donā€™t want to charge the stock 2 AH lipo at more than 1 Amp anyways but I can see why you would want to with a bigger sized battery connected.

Wiggling the JST connector during charging to get a better connection should allow you to see more or less charging current as the resistance in the circuit changes due to pressure you apply to then JST connector contacts.

Yeah, Iā€™m currently testing with a 4000mAH battery as a trialā€¦ and yes, having difficulties getting it charged at times. I have a separate board for a different project (using raspi) that has a custom LiPo charging circuit that can charge these quickly with no problem. And we arenā€™t using anything as nice as the BQ24195.

As I understand it from the datasheet, (maybe I mis-read) but you should be able to set the input charge current limit higher, and if the BQ24195 will enable dynamic power management (DPM) and reduce that if needed:

When input source is over-loaded, either the current exceeds the input current limit (REG00[2:0]) or the voltage
falls below the input voltage limit (REG00[6:3]). The device then reduces the charge current until the input current
falls below the input current limit and the input voltage rises above the input voltage limit.

So I feel like I should be able to set this to at least 1500 or something and the PMIC will drop the charge current down if needed due to problems with input voltage, etc.

Iā€™m currently trying to charge with a 6v/6w voltaic solar panel at the moment so 900mA should be ā€œOKā€ I suppose (have tested with a 5V/2.5A power supply which seems to charge it ok)ā€¦ but it has trouble getting above around 3.95-4V. Iā€™ve read through that LTE solar trials thread many times (on which your responses were really helpful as well), and have tried changing the input voltage as well. Always seems stuck at 3.95-4V max. So I wasnā€™t sure if bumping this up a bit would help, but seems to not be able to go over 900mA.

@RWB, itā€™s setInputCurrentLimit, I believe you are thinking about setChargeCurrent :wink:

The set-points that @abatardi is using come straight from spark_wiring_power.cpp
It looks like a bug.

1 Like

Thanks @Rftop ā€“ yes I am referring to setInputCurrentLimit, but I have also tested increasing the setChargeCurrent value to some high option like 4096mA in conjunction with this test just to see if that mattered at all (in case the two were related), but it doesnā€™t seem to change anything.

Setting anything higher than 900mA seems like it actually results in a lower value being set by the PMIC.

Youā€™re right :blush:

I got it wrong.

It does sound like a bug then.

@abatardi I also am using a similar BQ24250 charging chip for both LiPo + LiFePO4 Battery types and it works just fine and can charge at 2.2 Amps with zero problems.

@abatardi,
The PMIC will over-ride the setInputCurrentLimit if the input voltage drops out.
Thatā€™s likely whatā€™s happening to you. Might not be a bug after all.

Digressing from the Thread Title a bit:
Are you having issues with Solar Recharging when Sleeping?

In my Boron Solar Trial w/ EN Pin, I had to run the following during every Startup. If not, when the Solar Panel Dropped out, it wouldnā€™t re-start the charging:

// Li-Po Power Management:
  pmic.begin();
  pmic.setInputVoltageLimit(5080);  //  for 6V Solar Panels   
  pmic.setChargeVoltage(4208);      //  Set Li-Po charge termination voltage to 4.21V,
  pmic.enableDPDM();  
  pmic.enableBuck();                //  enableBuck required when using EN Pin Shutdown ??.
  pmic.enableCharging(); 

[copy/paste]
Once pmic.enableBuck(); was added, the daily Battery Profile became pretty boring, with no major unexpected results. The 0.5-watt Solar Panel can easily recharge the Li-Po when running a 5 minute Wake/Publish schedule. The Boron doesnā€™t terminate the Li-Po charge at 4.2V (SoC 100%) anymore, as with my previous tests using pmic.setChargeVoltage(4208). This isnā€™t necessarily a negative result, and Iā€™m sure there is a explanation.

As you know, your panel wont produce itā€™s max rated 930mA @ the highest InputVoltageLimit we have access to (5.080V).
So using pmic.setChargeCurrent(0,0,1,0,0,0);// 1024mA (512 + 512 offset) should do the trick.

From the serial output it looks like he is just setting new current input limits and then reading back the setting. In that case the setting should stick but itā€™s not doing that so it does look like a bug to me.

The above tests were done just plugged into USB on a computer with a full battery connected (not charging), so I donā€™t think itā€™s because itā€™s getting overridden by the PMIC, and itā€™s consistently reporting back invalid values immediately after calling the set function (well, 500ms delay in this example). If it were being overridden, Iā€™d think the values it dropped to would be consistently ā€œnearā€ the set max, like dropping from 1200 -> 900, not from 1200->100, and 1500->150 (every single time).

Iā€™m not putting the boron to sleep at all during these tests, just letting it sit idle between cellular publishes. I can try to 1024mA setting, and increasing again to the 5080 max input voltageā€¦ So you suggest using enableBuck as well? I will give all those a shot now. I have it in full sun at the moment so itā€™s a good time to test.

Since your battery was full, I agreeā€¦ smells like a bug.

You need to put the PMIC setting in the Startup() code so they are applied on every startup because the settings do not stick.

1 Like

The pmic.setInputVoltageLimit(5080) is the Minimum Voltage the PMIC will allow the source to drop to and will adjust the battery charging current so that the source Voltage does not drop below 5.080V. This is similar to a watered down MPPT. You definitely want to use this with a 6V panel.

Note: When bench testing with USB connected, this could cause you problems if your USB port can't maintain 5.x Volts. It wont be an issue when operating normally on battery + solar.

I never did fully understand enableBuck, that was old-fashioned "try-it-all" that worked for that project.

As @RWB said, If you do intend on Sleeping, you'll need to perform the PMIC adjustments every cycle.
When not sleeping, you can set this group to be performed on a schedule (say 5 minutes) if you are still having problems with Solar Re-Charging after a cloud passes over.

1 Like

@Rftop - yeah sorry I meant min input voltage.

Iā€™ve done some more testing. I have an INA226 voltage/current monitor measuring the input voltage/amperage on this. I wanted to stay consistent so Iā€™m powering it with a 5V/2.5A power supply. My power supply doesnā€™t have quite enough voltage to hit the 5080 limit after a schottky diode drop, so I have to test this with 4840 setting onlyā€¦

Iā€™ve tested a bunch of input current settings, charge rate settings, enablebuck, enabledpdm, etcā€¦ bottom line is I canā€™t get the current input rate above right around 245mA no matter what I do. I verified this with a meter and am getting very close to what the INA226 is reading.

4840 input voltage, no other settings = 244mA
set charge rate explicitly to 2A (just to test default), = 245mA
bump charge rate to 4A = 246mA (no change)
back to 2A charge rate, current limit increased to 900mA = 246mA
enable buck = 244mA
enable DPDM = 245mA (I noticed with this on, it sometimes changes the max input current back to 500)
disable DPDM & buck, set current limit to 100mA = 94mA
set current limit to 150mA = 139mA

So when dropping the input current max to 100 or 150, I do see the input current drop to below those levels. But curiously when set to 500 or 900, I still canā€™t get higher than 250mA. So Iā€™m at a bit of a loss. Unless the INA226 is somehow restricting to 250mA, or there is something else wrong that is causing thisā€¦ I canā€™t seem to break through that ceilingā€¦

Not sure if anyone has tested, but Iā€™d be curious to see if anyone else has been able to get a higher input current than this on a boronā€¦

Now that you mention it, I looked back at some previous notes/results during Solar Testing :
310 mA was the highest I recorded, and that was using a lower InputVoltageLimit

Using pmic.setInputVoltageLimit(4840)
Actual Charging started at 5.05V, Li-Po resting at 3.83V, Current Measured w/ a ĀµCurrent GOLD
23mA @ 5.10V
42mA @ 5.15V
80mA @ 5.20V
105mA @ 5.25V
150mA @ 5.30V
200mA @ 5.40V
310mA @ 5.50V

Iā€™ll repeat w/ pmic.setInputVoltageLimit(5080)
"Charging" LED lights at 4.25V, 2.6mA,
22mA @ 5.30V
50mA @ 5.40V
170mA @ 5.50V
240mA @ 5.60V 

I was testing much smaller panels than your 6 watt at the time, so I was concentrating on the Termination Voltage of the Li-Po, not the charging current.

Maybe I should repeat a similar voltage swing for charging current with all the settings:

  pmic.setInputVoltageLimit(5080);    //  Highest available right now, Use for 6V Solar Panels  
  pmic.setInputCurrentLimit(900) ;    // 900 mA 
  pmic.setChargeVoltage(4208);        //  Set Li-Po charge termination voltage to 4.21V, CAUTION! not for everyone
  pmic.setChargeCurrent(0,0,1,0,0,0); // 1024mA (512 + 512 offset)
  pmic.enableDPDM();  
  pmic.enableBuck();                
  pmic.enableCharging(); 

Do you see anything that youā€™d want me to change ?

Interesting. Iā€™m back to a solar panel now with 5.08v input voltage and itā€™s gone down to around 200mA, but Iā€™m also not getting great sun right now.

The only thing is maybe not enableDPDM, as in my testing that seemed to make changes to the max input current when enabled, and sometimes drops it back to 500.

And thank you, I appreciate you looking into this alsoā€¦ Iā€™m at the point where Iā€™m starting to feel crazy, itā€™s either something dead simple that Iā€™m missing, or possibly the bq24195 current registers really arenā€™t getting set properly by the firmware.

The input source register seems to be getting set correctly, so maybe this is just an error in the getter. When I call pmic.readInputSourceRegister, it seems to correlate to the expected values (last 3 bits):

// setting 900ma max (expect 011)
01111011

// 1200ma (expect 100)
01111100

// 3000ma (expect 111)
01111111

All these are with 5080 input voltage which is the first part (0bx1111xxx)ā€¦

Reading through the BQ24195 datasheet, it shows the pre-charge/term-charge current is 256mA. So I have a suspicion I am getting dropped into one of these somehow, and not getting into ā€˜fast chargeā€™ mode, but the ā€œsetPreChargeCurrentā€ method is currently not implemented so I have no way to test this. :-/

So keep in mind, Iā€™m supplying a Constant Voltage (5.45 V) to the USB connector with this test. The power supply has the capability to meet any current demands of the Boron LTE.
A solar panel works the opposite. It produces current.

The Boron LTE was in Manual Mode on 0.9.0. The Cell Modem was Off. The Boron was using 7 mA prior to connecting a 10,000 mAh Li-Po @ a resting voltage of 3.83V for each test.
All tests used the following:

  pmic.setInputCurrentLimit(900) ;    // 900 mA 
  pmic.setChargeVoltage(4208);        //  Set Li-Po charge termination voltage to 4.21V, CAUTION! not for everyone
  pmic.setChargeCurrent(0,0,1,0,0,0); // 1024mA (512 + 512 offset)

I only changed the pmic.setInputVoltageLimit(x);

#1 pmic.setInputVoltageLimit(5080);    //  = 500 mA
#2 pmic.setInputVoltageLimit(4840);    //  = 460 mA
#3 pmic.setInputVoltageLimit(4200);    //  = 810 mA

On the last test, I checked the Voltage at the Vusb Pin, just to make sure my wiring wasnā€™t the limiting factor.
The Supply voltage is dropping from 5.45V at the PSU to 4.58V at Vusb during the 810 mA Charging.
Iā€™m going to rebuild my test rig with larger & shorter wiring to eliminate that being a possibility. Iā€™ll look for the best USB that I can find in my office.

@Rftop, Inspired by your last post, I decreased the setInputVoltageLimit to 4520, and all of a sudden I am now seeing a full amp of charging from my 5v/2.5a adapter. Switch back to 4840, it drops back down to about 250mA again. 4680 gives me around 645mA. So do you think this points to some physical problem? At 4680 voltage limit, my INA226 is reporting 4.73V, and Iā€™m measuring 4.65V @ VUSB pin with my meter.

The PMIC is pretty sophisticated. I'm guessing it's performing exactly how it's supposed to.