-
Notifications
You must be signed in to change notification settings - Fork 14
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
Comments
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. |
no, I did not investigate future. |
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! 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) |
Thanks, once I'll grap the Borad again, I'll check. |
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). Thanks! |
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! |
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. Thanks again for the help! Regards |
For anyone lurking this issue in the hope of controlling the input charge current easily, here is a bit of code for you. 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();
} 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) Hope it helps someone one day. :) |
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: If you want ~300 mA, you should use 0x41 (disable 5th bit). |
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. ;) |
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:
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, |
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.
The following code was used for initialization.
|
Hello geludwig,
Concerning the SARA-R4 Module: you should update it to the latest
version L.05.11 A.02.16. Arduino support has a two-step process
which just needs you to update the SerialSARA sketch to enable a
direct serial connection to the SARA-R4 module, plus a serial
terminal with X-modem file transfer capability (I used minicom under
Linux). No soldering necessary. Without the update, the module is
in fact very unstable - after the update it worked reasonably well.
IMHO - provided the MKR 1500 NB has the same USB connections as the
MKR 1010 Wifi - a connection with USB will force 100mA maximum
charge current since D+ and D- are left floating which is so
interpreted by BQ24195... this can only be "fixed" by rebooting
which gets a higher charge current.
Although I also remember there is a slight bug in the original function
for setting the current (setChargeCurrent) in the BQ24195 library. I
thihnk for low currents there is one "if" that checks a wrong
threshold. I noted it some time ago but did not have time to send in
a patch yet. Please check this, it should be easy to fix. If that's
it I'll be happy to send in a patch sometime next week.
Best,
Alex
…On Tue, Jul 18, 2023 at 07:42:33AM -0700, geludwig wrote:
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 (current gets overwritten with 512mA when below). Please
correct me if I am wrong!!!
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 only, but that resulted in
bootloops of the SAMD21 when initializing the SARA-R4 module. The whole board
seems to bit unstable when using no battery and/or no perfect input voltage.
`/
*******************************************************************************
• Function Name : setChargeCurrent
• Description : Set charge current
• Input : The current expressed in Ampere
• Return : 0 on Error, 1 on Success
*******************************************************************************
/
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;
}
/*
0x01 = 100mA (measured 100mA)
0x05 = 115mA (measured 115mA)
0x09 = 130mA (measured128mA)
0x11 = 150mA (measured 155mA)
0x21 = 200mA (measured 180mA)
0x41 = 300mA (measured 285mA)
*/
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.
while (PMIC.begin() == 0) { u8x8.drawString(0,4,"INIT PMIC FAIL"); } if
((PMIC.setFastChargeTimerSetting(pmicHours) == 1) && (PMIC.setChargeVoltage
(batFullVoltage) == 1) && (PMIC.setMinimumSystemVoltage(batEmptyVoltage) == 1)
&& (PMIC.setChargeCurrent(batChargeCurrent) == 1) && (PMIC.enableCharge() ==
1)) { u8x8.clearLine(4); u8x8.drawString(0,4,"PMIC OK");
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.*Message ID: <arduino-libraries/
***@***.***>
|
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.
|
@alexsee75 could you point me toward some information about how you updated the firmware without the additional USB cable? |
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
Arduino_BQ24195/src/BQ24195.cpp
Line 325 in 46bc843
0.9 instead of CURRENT_LIM_900
Arduino_BQ24195/src/BQ24195.cpp
Line 331 in 46bc843
Same here: 0.015 ?
Arduino_BQ24195/src/BQ24195.cpp
Line 368 in 46bc843
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.
Arduino_BQ24195/src/BQ24195.cpp
Line 209 in 46bc843
Thanks, Adrian
The text was updated successfully, but these errors were encountered: