Skip to content

Commit 710948e

Browse files
committed
Version 4.1
1 parent 743bbe1 commit 710948e

File tree

5 files changed

+366
-155
lines changed

5 files changed

+366
-155
lines changed

README.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# [SMB](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino) - Smart Battery Module (Laptop Battery Pack) Info
2-
### Version 4.0.0
2+
### Version 4.1.0
33
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
44
[![Commits since latest](https://img.shields.io/github/commits-since/ArminJo/Smart-Battery-Module-Info_For_Arduino/latest)](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/commits/master)
55
[![Build Status](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/workflows/TestCompile/badge.svg)](https://github.com/ArminJo/Smart-Battery-Module-Info_For_Arduino/actions)
@@ -109,7 +109,7 @@ Version 4.0 from Oct 12 2021
109109
No LiPo supply detected -> fast display timing
110110
Found attached I2C device at 0xB
111111
112-
Battery mode (BIN) 0b110000010000001
112+
Battery mode 0x6081 | 0b110000010000001
113113
- Internal Charge Controller Supported
114114
- Battery OK
115115
- Disable AlarmWarning broadcast to Host and Smart Battery Charger
@@ -125,46 +125,47 @@ Design voltage 10.800 V
125125
Design capacity 5100 mAh
126126
Charging current 3570 mA
127127
Charging voltage 12.600 V
128-
Specification info 33 | 0x21
128+
SBM protocol (Version / Revision) 1.1 with optional PEC support / 1
129129
Cycle count 277
130130
131131
Max error of charge calculation 100%
132132
Remaining time alarm 10 min
133133
Remaining capacity alarm 510 mAh
134-
Pack status (BIN) 0b11010110000
135134
136135
*** MANUFACTURER INFO ***
137-
Device Type: 0 | 0x0
136+
Device Type 0 | 0x0
138137
139138
*** RATE TEST INFO ***
140139
Setting AT rate to 100 mA
141140
TimeToFull at rate Battery not being (dis)charged - received 0xFFFF
142141
Setting AT rate to -100 mA
143142
TimeToEmpty at rate 21 h 28 min
144-
Can be delivered for 10 seconds at rate: 1 | 0x1
143+
Can be delivered for 10 seconds at rate 1 | 0x1
145144
146145
*** DYNAMIC INFO ***
147-
Full charge capacity 4215 mAh = 82%
148-
Remaining capacity 2148 mAh
149146
Relative charge 51%
150147
Absolute charge 42%
148+
Full charge capacity 4215 mAh = 82%
149+
Remaining capacity 2148 mAh
151150
Voltage 11.467 V
152151
Current 0 mA
153152
Average current of last minute 0 mA
154153
Temperature 21.55 C
155154
Minutes remaining until empty Battery not being (dis)charged - received 0xFFFF
156-
Average minutes remaining until empty: Battery not being (dis)charged - received 0xFFFF
155+
Average minutes remaining until empty Battery not being (dis)charged - received 0xFFFF
157156
Minutes remaining for full charge Battery not being (dis)charged - received 0xFFFF
158-
Battery status (BIN) 0b11000000
157+
Battery status 0xC0 | 0b11000000
159158
80 Initialized
160159
40 Discharging
161160
161+
Pack config and status 0x6B | 0b11010110000
162+
162163
163164
*** DYNAMIC NON STANDARD INFO ***
164-
Cell 1 Voltage: 3.826 V
165-
Cell 2 Voltage: 3.823 V
166-
Cell 3 Voltage: 3.819 V
167-
Cell 4 Voltage: 0.000 V
165+
Cell 1 Voltage 3.826 V
166+
Cell 2 Voltage 3.823 V
167+
Cell 3 Voltage 3.819 V
168+
Cell 4 Voltage 0x0
168169
169170
*** CHANGED VALUES ***
170171
@@ -193,6 +194,10 @@ Average minutes remaining until empty: 16 h 11 min
193194
![Fritzing schematics](extras/SBMInfo_Schaltplan.png)
194195

195196
# Revision History
197+
### Version 4.1.0
198+
- Support for automatic discharge and charge.
199+
- Improved output.
200+
196201
### Version 4.0.0
197202
- Integrated voltage and resistance measurement.
198203
- Major improvements in I2C communication and output.

SBMInfo/ADCUtils.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,27 @@ uint16_t readADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference)
8181

8282
/*
8383
* Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h.
84+
* Does NOT restore ADMUX after reading
8485
*/
8586
uint16_t waitAndReadADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference) {
8687
checkAndWaitForReferenceAndChannelToSwitch(aChannelNumber, aReference);
8788
return readADCChannelWithReference(aChannelNumber, aReference);
8889
}
8990

91+
/*
92+
* Conversion time is defined as 0.104 milliseconds by ADC_PRESCALE in ADCUtils.h.
93+
* Restores ADMUX after reading
94+
*/
95+
uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUX(uint8_t aChannelNumber, uint8_t aReference) {
96+
uint8_t tOldADMUX = checkAndWaitForReferenceAndChannelToSwitch(aChannelNumber, aReference);
97+
uint16_t tResult = readADCChannelWithReference(aChannelNumber, aReference);
98+
checkAndWaitForReferenceAndChannelToSwitch(tOldADMUX & MASK_FOR_ADC_CHANNELS, tOldADMUX >> SHIFT_VALUE_FOR_REFERENCE);
99+
return tResult;
100+
}
101+
102+
/*
103+
* To prepare reference and ADMUX for next measurement
104+
*/
90105
void setADCMultiplexerAndReferenceForNextConversion(uint8_t aChannelNumber, uint8_t aReference) {
91106
ADMUX = aChannelNumber | (aReference << SHIFT_VALUE_FOR_REFERENCE);
92107
}

SBMInfo/ADCUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@
7979

8080
#define SHIFT_VALUE_FOR_REFERENCE REFS2
8181
#define MASK_FOR_ADC_REFERENCE (_BV(REFS0) | _BV(REFS1) | _BV(REFS2))
82+
#define MASK_FOR_ADC_CHANNELS (_BV(MUX0) | _BV(MUX1) | _BV(MUX2) | _BV(MUX3))
8283
#else // AVR_ATtiny85
8384

8485
#define SHIFT_VALUE_FOR_REFERENCE REFS0
8586
#define MASK_FOR_ADC_REFERENCE (_BV(REFS0) | _BV(REFS1))
87+
#define MASK_FOR_ADC_CHANNELS (_BV(MUX0) | _BV(MUX1) | _BV(MUX2) | _BV(MUX3))
8688
#endif
8789

8890
// Temperature channel definitions - 1 LSB / 1 degree Celsius
@@ -120,6 +122,7 @@
120122
uint16_t readADCChannel(uint8_t aChannelNumber);
121123
uint16_t readADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference);
122124
uint16_t waitAndReadADCChannelWithReference(uint8_t aChannelNumber, uint8_t aReference);
125+
uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUX(uint8_t aChannelNumber, uint8_t aReference);
123126
uint16_t readADCChannelWithOversample(uint8_t aChannelNumber, uint8_t aOversampleExponent);
124127
void setADCMultiplexerAndReferenceForNextConversion(uint8_t aChannelNumber, uint8_t aReference);
125128
uint16_t readADCChannelWithReferenceOversample(uint8_t aChannelNumber, uint8_t aReference, uint8_t aOversampleExponent);

SBMInfo/SBMInfo.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
#define TEMPERATURE 0x08
2828
#define VOLTAGE 0x09
2929
#define CURRENT 0x0A
30-
#define AverageCurrent 0x0B // of last minute
31-
#define MAX_ERROR 0x0C // Byte - of state of charge calculation
30+
#define AVERAGE_CURRENT 0x0B // of last minute
31+
#define MAX_ERROR 0x0C // byte - of state of charge calculation
3232

33-
#define RELATIVE_SOC 0x0D // Byte - relative charge
33+
#define RELATIVE_SOC 0x0D // byte - relative charge
3434
#define ABSOLUTE_SOC 0x0E // Byte
3535
#define REMAINING_CAPACITY 0x0F
3636
#define FULL_CHARGE_CAPACITY 0x10
@@ -62,7 +62,20 @@
6262
#define CELL2_VOLTAGE 0x3E // r/w Word - OptionalMfgFunction2
6363
#define CELL1_VOLTAGE 0x3F // r/w Word - OptionalMfgFunction1
6464

65-
#define STATE_OF_HEALTH 0x4F // in % Byte - = CELL1_VOLTAGE for bq2085
65+
#define STATE_OF_HEALTH 0x4F // in % byte - = CELL1_VOLTAGE for bq2085
66+
67+
/*
68+
* Bits of PackStatus
69+
*/
70+
#define PRESENCE 0x80
71+
#define EDV2_THRESHOLD 0x40
72+
#define SEALED_STATE 0x20
73+
// FCC cannot be reduced by more than 256 mAh or increased by more than 512 mAh during any single update cycle.
74+
#define VDQ_DISCHARGE_QUALIFIED_FOR_CAPACITY_LEARNING 0x10
75+
#define AFE_COMMUNICATION_FAILED 0x08
76+
#define PERMANENT_FAILURE_FLAG 0x04
77+
#define CVOV_SECONDARY_OVER_VOLTAGE_PROTECTION_EXCEEDED 0x02
78+
#define CVUV_SECONDARY_UNDER_VOLTAGE_PROTECTION_EXCEEDED 0x01
6679

6780
/*
6881
* Bits of BatteryMode
@@ -98,17 +111,18 @@ struct SBMFunctionDescriptionStruct {
98111
const char *Description;
99112
void (*ValueFormatter)(struct SBMFunctionDescriptionStruct * aDescription, uint16_t aValueToFormat); // no println() at the end!
100113
const char *DescriptionLCD; // if output value should also be printed on LCD
101-
uint8_t minDeltaValue; // 0 -> print always. Do not print if difference between current value and last value is less equal minDeltaValue
102-
uint16_t lastValue; // used as storage for last value
114+
uint8_t minDeltaValueToPrint; // 0 -> print always. Do not print if difference between current value and last value is less equal minDeltaValueToPrint
115+
uint16_t lastPrintedValue; // used as storage for last value
103116
};
104117

105118
/*
106119
* TI few ManufacturerAccess Commands
107120
*/
108-
//#define TI_Device_Type 0x0100
109-
#define TI_Device_Type 0x0001
110-
#define TI_Firmware_Version 0x0002
121+
//#define TI_Device_Type 0x0100
122+
#define TI_Device_Type 0x0001
123+
#define TI_Firmware_Version 0x0002
111124

125+
#define BQ2085_EndOfDischargelevel 0x0003
112126
#define BQ20Z70_Hardware_Version 0x0003
113127
#define BQ40Z50_Hardware_Version 0x0003
114128

0 commit comments

Comments
 (0)