I'm trying to use the bq24195 to power on the charging when the battery is not full and turn it off when it's full.
void PMICSetup() {
while (!PMIC.begin()) {
// DEBUG_PRINTLN is just a serial print macro
DEBUG_PRINTLN(10, F("CAN'T TURN ON CHARGER"));
}
PMIC.setInputCurrentLimit(5.0); // 2
PMIC.setInputVoltageLimit(3.88); // 3.88
PMIC.setMinimumSystemVoltage(3.5);
PMIC.setChargeVoltage(4.1);
PMIC.setChargeCurrent(0.375);
PMIC.disableCharge();
}
void CheckBattery(){
while (true) {
DEBUG_PRINTLN(200, F("Checking battery."));
int batteryLevel = analogRead(ADC_BATTERY);
float voltage = batteryLevel * (BATTERY_CAPACITY / 1023.0) * 0.9796523;
if (PMIC.chargeStatus() == 0) {
PMIC.enableCharge();
DEBUG_PRINTLN(200, F("Enabling charging."));
}
if (PMIC.isBatteryInOverVoltage()) {
PMIC.disableCharge();
DEBUG_PRINTLN(200, F("Disabling charging."));
}
else if (PMIC.hasBatteryTemperatureFault()) {
PMIC.disableCharge();
DEBUG_PRINTLN(200, F("Battery too hot, disabling charging."));
}
else if (PMIC.chargeStatus() == CHARGE_TERMINATION_DONE) {
PMIC.disableCharge();
DEBUG_PRINTLN(200, F(" Battery fully charged."));
}
float battery_percentage = ((voltage * 100) / 4.2);
}
}
The problem I have is that the battery doesn't seem to get turned on, it always prints "Battery fully charged". Do I have some error in my logic? the CheckBattery function is run in a loop and it's checked every 60s.