Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current Setting and Disable Charging, unable to charge > 100mA #7

Open
Adk90 opened this issue Jan 26, 2021 · 16 comments
Open

Current Setting and Disable Charging, unable to charge > 100mA #7

Adk90 opened this issue Jan 26, 2021 · 16 comments
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@Adk90
Copy link

Adk90 commented Jan 26, 2021

I'm using MKR 1500 NB to test. Well I'm not able to charge my 1400mAh cell with more than 100mA even I do set 500mA.
What can I do to get higher charge power?

Having a look into the Lib and doing some tests, I have got the following points:

0.15 instead of 0.015 as Datasheet sais 150mA for 0x01

if (current > 0.015) {

0.9 instead of CURRENT_LIM_900

if (current >= CURRENT_LIM_900) {

Same here: 0.015 ?

return 0.015;

Having a look on disableCharge() is doing more than just disable the Battery, is reseting the BMIC to default, guess this should be mentioned in the description if by intention.

byte mask = DATA & 0xCF;

Thanks, Adrian

@Adk90 Adk90 changed the title Current Setting and Disable Charging, unable to charge higher than 100mA Current Setting and Disable Charging, unable to charge > 100mA Jan 26, 2021
@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Jan 26, 2021
@mcxiv
Copy link

mcxiv commented Feb 18, 2021

Hi Adrian, have you find a solution to charge more than 100 mA by any chance?

I found a way to reach ~150 mA (without the library) but I'd like to charge at 500 mA.

@Adk90
Copy link
Author

Adk90 commented Feb 18, 2021

no, I did not investigate future.

@mcxiv
Copy link

mcxiv commented Feb 19, 2021

Hi Adrian, for your info, here's a bit of code to charge at 450/500 mA. It doesn't use this library tho.

#include <Wire.h>

#define BBQ_addr 0x6B

void setup() {
  Serial.begin(9600);
  Wire.begin();
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  Serial.println(isUSBconnected());
  delay(5000);
}

int isUSBconnected() {
  Wire.beginTransmission(BBQ_addr);
  Wire.write((byte)0x08);
  Wire.endTransmission();

  Wire.beginTransmission(BBQ_addr);
  Wire.requestFrom(BBQ_addr, 1);
  Wire.endTransmission();
  
  char binary[9] = {0};
  itoa(Wire.read() + 256, binary, 2);
  if (binary[3] == '1' && binary[4] == '0') {
    Wire.beginTransmission(BBQ_addr);
    Wire.write((byte)0x00);
    Wire.write((byte)0x36);
    Wire.endTransmission();
    //////
    Wire.beginTransmission(BBQ_addr);
    Wire.write((byte)0x02);
    Wire.write((byte)0x00); // fixing I_limit at 512 mA
    Wire.endTransmission();
    digitalWrite(LED_BUILTIN, HIGH);
    return 1;
  }
  else {
    digitalWrite(LED_BUILTIN, LOW);
    return 0;
  }
}

It sets the limitation at 500 mA when the USB is connected. Don't put this code in the setup, it will not work due to a strange PCB designing : Arduino left the D+/D- pin of the BQ24195 floating, causing the CI to think that there is not USB connected. Very strange and somewhat dangerous in some cases I guess.

Cheers!
Quentin

edit: Works for the MKR1010 as I only use this one. And the part about bad PCB designing is for MKR1010, haven't checked other boards)

@Adk90
Copy link
Author

Adk90 commented Feb 22, 2021

Thanks, once I'll grap the Borad again, I'll check.

@LucasISC
Copy link

Hi, I am also trying to charge a battery connected to a MKR1010 board and encountered the same issue when trying the BQ24195 library (only charging at 100mA).
I tested your code @mcxiv and managed to get it work with a current >300 mA which is a progress. Unfortunately I am now trying to make it work with higher current (around 2.0A or so) but despite testing a lot of setting and playing with the registers it doesn't change anything. Do you have an idea how to manage this ?

Thanks!
Lucas

@mcxiv
Copy link

mcxiv commented Mar 10, 2021

Hey @LucasISC, can you tell me a little bit more about your setup? What is connected to your MKR, which battery are you using, are you charging from a usb port of your computer, ...?

Unfortunately, you cannot go up to 2A. Yes the datasheet says so, but the fuse limits the current at (In theory) 500 mA. I was able to charge at almost 800 mA but the fuse was extremely hot.

I do not recommend it but, you can try :

Wire.beginTransmission(BBQ_addr);
Wire.write((byte)0x02);
Wire.write((byte)0x80); 
Wire.endTransmission();

Just switched from 0x00 to 0x80, it should set the Charge Current Control at 2048 mA instead of 512 mA

Hope it helps, do not hesitate to ask me again, I'm learning everyday from this IC haha.

Cheers!
Quentin

@LucasISC
Copy link

Hi, thanks for the quick reply! I am using a MKR1010 and I am trying to charge a 1S3P Li-ion battery (3.7V, 7800mAh). I connected the arduino to the computer and to a charger but the results are the same.
Ok now I understand why it doesn't go higher than 500mA, I even tested by setting the Charge Current Control at the maximum (around 4.0A I think) without results.
I will stick with my previous configuration using a tp4056 module to charge that battery haha

Thanks again for the help!

Regards
Lucas

@mcxiv
Copy link

mcxiv commented Apr 26, 2021

For anyone lurking this issue in the hope of controlling the input charge current easily, here is a bit of code for you.
It works fine on a MKR1010, I strongly suggest not to charge at more than 500 mA as the security fuse on the MKR1010 is given for a hold current of 500 mA.

I also suggest not to charge at 500 mA as it eff up the ADC for the battery voltage monitor on the D21G18A. (At least, on my board)

This code only works for the fast charging part!

The function BQ() cannot be use in the setup()

#include <Wire.h>

int start = 0;

void setup() {
  Wire.begin();
}

void loop() {
  if (start == 0) {
    BQ(0x6b, 0x32, 0x61);
    start = 1;
  }
}

void BQ(byte addr, byte a, byte b) {
  Wire.beginTransmission(addr);
  Wire.write(0x00);
  Wire.write(a); // Input current limit (In our example, 0x32 is 500 mA)
  Wire.endTransmission();
  /////
  Wire.beginTransmission(addr);
  Wire.write(0x02);
  Wire.write(b); // Charge current (In our example, 0x61 is 300 mA)
  Wire.endTransmission();
}

image

Just a bit of explanation with the datasheet ; what we're doing is that we change the register n°2 on the BQ24195 which is the register to change our charge current.

We set the bit n°0 at 1 to have a better sampling in our current charge. (If we let it at 0, by default, you cannot set a charge current at less than 512 mA)

Bit n°2 to Bit n°7 will be our future charge current. Just add whatever value and then divide the result by 5 : here is our charge current !

Example :

If we want to select 300 mA for our charge current, we can set the bit n°6 and 5 at 1 -> (1024 mA + 512 mA) / 5 = ~307 mA)
So, our register n°2 will be 0110 0001 which is 0x61 in HEXA.

Hope it helps someone one day. :)

@ShadF0x
Copy link

ShadF0x commented Apr 6, 2022

It says in the doc that the default charge current is 2048 mA, and if you set all bits to 0, you still have 512 mA.

So the default 0x60 is:
1024 mA [bit 6] + 512 mA [bit 5] + 512 mA [base] = 2048 mA

If you want ~300 mA, you should use 0x41 (disable 5th bit).

@oscarfallman
Copy link

Hi @mcxiv, I'm a bit late to the party but I'm struggling with this ATM. Why can't the code you posted be run during setup()? I'm having an issue where i need to set the Input current limit during setup, and i wanted to use your method. Thanks!

@mcxiv
Copy link

mcxiv commented Sep 27, 2022

Hi @mcxiv, I'm a bit late to the party but I'm struggling with this ATM. Why can't the code you posted be run during setup()? I'm having an issue where i need to set the Input current limit during setup, and i wanted to use your method. Thanks!

Hello @oscarfallman!

Sorry, it's been so long, I can't remember. Actually, I think I never knew why. The best solution for you would be #7 (comment) I guess.

Let me know if you find something else. ;)
Quentin

@alexsee75
Copy link
Contributor

Just wanted to point out: The easiest way to enable charging current of > 100mA is to deactivate DPDM (D+D-) detection using disableDPDM() from this library. E.g. something like this will work:

if (PMIC.begin()) { PMIC.disableDPDM(); PMIC.end(); }

You can also use setChargeCurrent() but it's already set to 2A while thermal constraints limit the charging current to around 0,5A. Adding a heatsink to the BQ24195 module will probably improve this to around +/- 1A (although not 2A)

Disadvantage is that every plug/unplug of USB (perhaps battery as well, did not check) will reactivate DPDM so you will have to rerun this then. In my case I run it on restart and in each main loop (in between deep sleep) which seems to work and will enable reasonable charging (with some delay due to the next time the loop is run). I've not found a way to permanently fix it and according to datasheet it's IMHO not possible....

The best way would be for Arduino to connect D+/D- properly, or at least run a 200 ohm resistor between them which would always force a charging port detection. It's probably not feasible to modify the board since the connections are so small.

Best,
Alex

@geludwig
Copy link

geludwig commented Jul 18, 2023

Hello to you all.

I have bought an Arduino MKR NB 1500 this June and have ran into some problems with it.

Nevertheless, here are some results for the BQ24195 library and the MKR NB 1500. I modified the setChargeCurrent() function for this, because it cant set currents below 512mA. Please correct me if I am wrong, but I was not able to.

I disabled the V+ Pin of the USB connection and powered the board directly via the VIN pin. I tried powering the board via USB, but that resulted in bootloops of the SAMD21 when initializing the SARA-R4 module. The BQ24195 was not happy either, resulting in flickering charge led and no charge current.

bool PMICClass::setChargeCurrent(float current) {
    int DATA = readRegister(CHARGE_CURRENT_CONTROL_REGISTER);

    if (DATA == -1) {
        return 0;
    }
    byte mask = DATA & 0x01;

    if (current > 4.544) {
        current = 4.544;
    } else if (current < 0.512) {
        current = 0.512;
    }
	
	writeRegister(CHARGE_CURRENT_CONTROL_REGISTER, 0x41);
	return 1;
	
	//return writeRegister(CHARGE_CURRENT_CONTROL_REGISTER, (round(((current - 0.512) / 0.016)) & 0xFC) | mask);
}

The following code was used for initialization.

int pmicHours = 8;
float batChargeCurrent = 0.01; // defined but not used and overwritten
float batFullVoltage = 4.2;
float batEmptyVoltage = 3.3;

while (PMIC.begin() == 0) {
    // init failed
}

if ((PMIC.setFastChargeTimerSetting(pmicHours) == 1) &&
   (PMIC.setChargeVoltage(batFullVoltage) == 1) &&
   (PMIC.setMinimumSystemVoltage(batEmptyVoltage) == 1) && 
   (PMIC.setChargeCurrent(batChargeCurrent) == 1) &&
   (PMIC.enableCharge() == 1)) {
       // init true
}

@alexsee75
Copy link
Contributor

alexsee75 commented Jul 21, 2023 via email

@geludwig
Copy link

geludwig commented Jul 22, 2023

Hi Alex,

I already updated the SARA-R4 module with a soldered USB cable and EasyFlash. I designed and ordered a custom PCB daughterboard with a dedicated power supply, now its fine.

I changed the _setChargeCurrent()_function, but something is not right.

When setting the bit sequence to 0x1D (00011101), current is correct at 192mA. Formula is (512 + 256 + 128 + 64) / 5. When setting the next higher bit sequence at 0x21 (00100001), the current lowers to 167mA, which corresponds to 0x15 (00010101), instead of the 204mA. Formula should be (512 + 512) / 5. I get the correct value when calling getChargeCurrent() with 0x21 (changed it to return hex instead of float), but the corresponding current is not right. All values before 0x21 are setting the correct currents.

bool PMICClass::setChargeCurrent(float current) {
    int DATA = readRegister(CHARGE_CURRENT_CONTROL_REGISTER);

    if (DATA == -1) {
        return 0;
    }	

    if (current > 4.544) {
        current = 4.544;
    } else if (current < 0.103) {
        current = 0.103;
    }

	if (current >= 0.512) {
		return writeRegister(CHARGE_CURRENT_CONTROL_REGISTER, (round((current - 0.512) / 0.016) & 0xFC) | 0x00);
	}
	else if (current < 0.512) {
		return writeRegister(CHARGE_CURRENT_CONTROL_REGISTER, (round(((current * 5) - 0.512) / 0.016) & 0xFD) | 0x01);
	}
	
}

@per1234 per1234 added the topic: code Related to content of the project itself label May 8, 2024
@cooper-david-a
Copy link

@alexsee75 could you point me toward some information about how you updated the firmware without the additional USB cable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

9 participants