Skip to content

Commit a0b13de

Browse files
committed
nicla-system: Remove NTC toggling from charge function.
1 parent d47a6db commit a0b13de

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

libraries/Nicla_System/src/Nicla_System.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ bool nicla::enterShipMode()
100100
_pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_STATUS, status_reg);
101101
}
102102

103-
bool nicla::enableCharging(uint16_t mA, bool disableNtc)
103+
bool nicla::enableCharging(uint16_t mA)
104104
{
105105
/*
106106
The ICHRG is calculated using the following equation:
@@ -140,13 +140,6 @@ bool nicla::enableCharging(uint16_t mA, bool disableNtc)
140140
// Also sets the input current limit to 350mA.
141141
_pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_ILIM_UVLO_CTRL, 0x3F);
142142

143-
_ntcEnabled = !disableNtc;
144-
if (!_ntcEnabled) {
145-
// Disable Temperature Sense (B7 = 0) and interrupt on charge status change (B3 = 0).
146-
// INT only shows faults and does not show charge status)
147-
_pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_TS_CONTROL, 0);
148-
}
149-
150143
return _pmic.getFastChargeControlRegister() == _fastChargeRegisterData;
151144
}
152145

@@ -168,7 +161,23 @@ uint8_t nicla::getBatteryFaults() {
168161
}
169162

170163
void nicla::setBatteryNTCEnabled(bool enabled){
171-
_ntcEnabled = enabled;
164+
if (_ntcEnabled != enabled) {
165+
_ntcEnabled = enabled;
166+
167+
// Read the current TS_CONTROL register value
168+
uint8_t tsControlRegister = _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_TS_CONTROL);
169+
170+
if (_ntcEnabled) {
171+
// Set bit 7 and bit 3 to 1 to enable temperature sense and interrupt on charge status change.
172+
tsControlRegister |= 0b10001000;
173+
} else {
174+
// Set bit 7 and bit 3 to 0 to disable temperature sense and interrupt on charge status change.
175+
// INT only shows faults and does not show charge status.
176+
tsControlRegister &= 0b01110111;
177+
}
178+
179+
_pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_TS_CONTROL, tsControlRegister);
180+
}
172181
}
173182

174183
float nicla::getRegulatedBatteryVoltage(){

libraries/Nicla_System/src/Nicla_System.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ class nicla {
8181
* A safe default charging current value that works for most common LiPo batteries is 0.5C, which means charging at a rate equal to half of the battery's capacity.
8282
* For example, a 200mAh battery could be charged at 100mA (0.1A).
8383
* This charging rate is generally safe for most LiPo batteries and provides a good balance between charging speed and battery longevity.
84-
* @param disableNtc Whether to disable Temperature Sense and interrupt on charge. The default is true.
84+
* @note Make sure to call setBatteryNTCEnabled(false) if your battery does not have an NTC thermistor.
85+
* Otherwise the charging will be disabled due to the NTC thermistor not being connected.
8586
* @return true If the fast charging is enabled successfully. False, otherwise.
8687
*/
87-
static bool enableCharging(uint16_t mA = 20, bool disableNtc = true);
88+
static bool enableCharging(uint16_t mA = 20);
8889

8990
/**
9091
* @brief Disables charging of the battery. It can be resumed by calling enableCharging().
@@ -101,11 +102,12 @@ class nicla {
101102
static bool runsOnBattery();
102103

103104
/**
104-
* @brief Enables or disables the negative temperature coefficient (NTC) thermistor.
105+
* @brief Enables or disables the negative temperature coefficient (NTC) thermistor. It is enabled by default.
105106
* NTCs are used to prevent the batteries from being charged at temperatures that are too high or too low.
106107
* Set to disabled for standard LiPo batteries without NTC.
107108
* If your battery has only a plus and minus wire, it does not have an NTC.
108-
* The default is enabled.
109+
* @note Disabling the NTC will also disable the on-charge-state-change interrupt.
110+
* @param enabled Whether to enabled the NTC.
109111
*/
110112
static void setBatteryNTCEnabled(bool enabled);
111113

@@ -186,7 +188,8 @@ class nicla {
186188

187189
/**
188190
* @brief Get the current operating status of the PMIC.
189-
*
191+
* @note If it doesn't report 'Charging' even though you enabled charging with enableCharging(),
192+
* you may need to disable the NTC thermistor with setBatteryNTCEnabled(false) in case your battery doesn't have one.
190193
* @return OperatingStatus One of the following: Ready, Charging, ChargingComplete, Error.
191194
*/
192195
static OperatingStatus getOperatingStatus();

0 commit comments

Comments
 (0)