Hello,
We are currently working on MAX17320G20+T based circuit for cell protection and fuel gauge of a 2 cell series LiPo battery. I've made a arduino library to read/write registers via I2C and able to get the fuel gauge registers working (BATT, PKP, VCELL, CELL1, CELL2 etc.).
But now I'm trying to implement the battery balancing function of the IC. The cell balancing is not happening.
#include <Wire.h> #include "MAX17320.h" //uint8_t r_sense = 1; void setup() { Wire.begin(DEVICE_ADDRESS); Wire.begin(NVM_ADDRESS); Serial.begin(9600); } void loop() { // read_cell1(); delay(1000); // Serial.println(MAX17320::read_cell1()); MAX17320::set_cell_balancing(ZenerEnable, mV800, 11.7, 100); }
void set_cell_balancing(BatteryBalancingZener zener_enable, CellBalancingConfig bal_cfg, float r_mismatch, uint8_t imbalance) { r_mismatch = 32 * r_mismatch / 125; uint16_t RMismatch = round(r_mismatch) << 5; imbalance = round(imbalance / 10); if (imbalance <= 31 && r_mismatch <= 31) { uint16_t code = zener_enable | static_cast<uint16_t>(bal_cfg) | static_cast<uint16_t>(RMismatch) | static_cast<uint16_t>(imbalance); unlock_write_protection(); write_named_register_nvm(RegisterNvm::NBalTh, code); lock_write_protection(); } }
enum BatteryBalancingZener { ZenerDisable = 0, ZenerEnable = 1 << 13, }; enum CellBalancingConfig { Disable = 0, /// For 2.5mV mV25 = 1 << 10, /// For 5mV mV50 = 2 << 10, /// For 10mV mV100 = 3 << 10, /// For 20mV mV200 = 4 << 10, /// For 40mV mV400 = 5 << 10, /// For 80mV mV800 = 6 << 10, /// For 160mV mV1600 = 7 << 10, };