Skip to content

Commit fcb12e7

Browse files
author
Max 'MaxMax' Mönikes
committed
Added Bipolar Aux Voltage Measurement and extern "C" wrapper
1 parent e1c6e3d commit fcb12e7

File tree

3 files changed

+76
-9
lines changed

3 files changed

+76
-9
lines changed

TLE9012.cpp

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void TLE9012::wakeUp()
152152
deviceID = nodeID-1;
153153

154154
writeRegisterSingle(nodeID, MEAS_CTRL, 0xEE61); //Trigger PCVM, BVM and SCVM with PBOFF
155-
mcuDelay(5);
155+
mcuDelay(6);
156156

157157
for(uint8_t n = 0; n < devices[deviceID].n_cells; n++)
158158
{
@@ -297,6 +297,56 @@ void TLE9012::wakeUp()
297297
(void) writeRegisterSingle(nodeID, AVM_CONFIG, avm_sensemask);
298298
}
299299

300+
void TLE9012::setBAVMConfig(uint8_t nodeID, uint8_t bavm_status)
301+
{
302+
if(nodeID > N_DEVICES)
303+
{
304+
return; //Early return if device number is to high
305+
}
306+
307+
uint8_t deviceID = nodeID - 1;
308+
309+
if(nodeID == 0)
310+
deviceID = 0;
311+
else
312+
deviceID = nodeID-1;
313+
314+
if(bavm_status != 0)
315+
(void) writeRegisterSingle(nodeID, AVM_CONFIG, 0x0107); //Default pulldowns and BAVM activated
316+
else
317+
(void) writeRegisterSingle(nodeID, AVM_CONFIG, 0x0007);
318+
}
319+
320+
void TLE9012::readCellVoltagesWithBAVM(uint8_t nodeID)
321+
{
322+
323+
if(nodeID > N_DEVICES)
324+
{
325+
return; //Early return if device number is to high
326+
}
327+
328+
uint8_t deviceID = nodeID - 1;
329+
330+
if(nodeID == 0)
331+
deviceID = 0;
332+
else
333+
deviceID = nodeID-1;
334+
335+
writeRegisterSingle(nodeID, MEAS_CTRL, 0xEE61); //Trigger PCVM, BVM and SCVM with PBOFF
336+
mcuDelay(6);
337+
338+
for(uint8_t n = 0; n < devices[deviceID].n_cells; n++)
339+
{
340+
(void) readRegisterSingle(nodeID, PCVM_0 + (12-devices[deviceID].n_cells + n), &devices[deviceID].cell_voltages[n]);
341+
}
342+
343+
(void) readRegisterSingle(nodeID,BVM,(uint16_t*)&devices[deviceID].bipolar_auxilary_voltage);
344+
(void) readRegisterSingle(nodeID,SCVM_HIGH,&devices[deviceID].scvm_high);
345+
devices[deviceID].scvm_high &= 0xFFE0; //Remove rolling counter
346+
(void) readRegisterSingle(nodeID,SCVM_LOW,&devices[deviceID].scvm_low);
347+
devices[deviceID].scvm_low &= 0xFFE0; //Remove rolling counter
348+
}
349+
300350
/**
301351
* @brief Read the internal chip temperature of internal chiptemperature sensor 1 and 2
302352
*

TLE9012.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ SOFTWARE.
3131
#include <Arduino.h>
3232
#include <stdint.h>
3333

34+
#ifdef __cplusplus
35+
extern "C" {
36+
#endif
3437

3538
//-----------------------------------------------------------------------------
3639
// Defines for Lib Configuration
@@ -168,6 +171,7 @@ typedef struct
168171
{
169172
uint16_t cell_voltages[12]; /**< Array that hold up to 12 cell voltages that can be measured */
170173
uint16_t block_voltage; /**< Block Voltage of the complete stack */
174+
int16_t bipolar_auxilary_voltage; /**< BAVM results if this mode is choosen instead of Block Voltage */
171175
uint16_t ntc_resistances[5]; /**< Measured NTC Resistance */
172176
uint8_t ntc_results_valid;
173177
uint16_t chiptemperature1; /**< Temperature of internal Temperature Sensor Nr. 1 */
@@ -358,6 +362,8 @@ typedef struct
358362
void setNumberofCells(uint8_t nodeID, uint8_t n_cells);
359363
void setTempSensorsConfig(uint8_t nodeID, uint8_t n_temp_sensors,ntc_config_t sensorconfig);
360364
void readChipTemperatures(uint8_t nodeID);
365+
void setBAVMConfig(uint8_t nodeID, uint8_t bavm_status);
366+
void readCellVoltagesWithBAVM(uint8_t nodeID);
361367

362368
//Watchdog and Power state handling
363369
void activateSleep();
@@ -413,6 +419,8 @@ typedef struct
413419

414420
};
415421

416-
422+
#ifdef __cplusplus
423+
}
424+
#endif
417425

418426
#endif

examples/Read_Voltages/Read_Voltages.ino

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ SOFTWARE.
2525

2626
#include "TLE9012.h"
2727

28-
#define N_CELLS 12
29-
#define TXPIN 17
30-
#define RXPIN 16
28+
#define N_CELLS 6
29+
#define TXPIN 10
30+
#define RXPIN 11
3131

3232
TLE9012 tle9012;
3333

@@ -38,8 +38,8 @@ TLE9012 tle9012;
3838

3939
void setup() {
4040

41+
tle9012.init(&Serial1, 2000000,RXPIN,TXPIN); //Initialize driver with 2Mbit
4142

42-
tle9012.init(&Serial2, 2000000,RXPIN,TXPIN); //Initialize driver with 2Mbit
4343

4444
Serial.begin(115200);
4545
Serial.println("Boot completed");
@@ -56,25 +56,34 @@ void setup() {
5656
Serial.println("Connection Check completed");
5757

5858
tle9012.setNumberofCells(1, N_CELLS); //Configure the number of cells
59+
tle9012.setBAVMConfig(1,1);
5960
tle9012.resetWatchdog(); //Reset Watchdog Timer
60-
61+
tle9012.clearExtendedWatchdog(1);
6162
}
6263

6364
void loop() {
6465

6566
tle9012.resetWatchdog(); //Reset Watchdog Timer
66-
tle9012.readCellVoltages(1); //Read all cell voltages from device 1
67+
tle9012.readCellVoltagesWithBAVM(1); //Read all cell voltages from device 1
6768

6869
for(uint8_t n = 0; n < N_CELLS; n++) //Print cell voltages to Serial Monitor
6970
{
7071
Serial.print("Cell Voltage ");
7172
Serial.print(n+1);
7273
Serial.print(": ");
73-
Serial.println(ADCVALUE_TO_FLOAT_VOLTAGE(tle9012.devices[0].cell_voltages[n]));
74+
Serial.println(ADCVALUE_TO_FLOAT_VOLTAGE(tle9012.devices[0].cell_voltages[n]),4);
7475
}
7576

77+
Serial.print("BAVM: ");
78+
Serial.println(convertBAVMtoCurrent(tle9012.devices[0].bipolar_auxilary_voltage),5);
79+
7680
Serial.println("-------------------------------------------------");
7781

7882
delay(1000);
7983

8084
}
85+
86+
float convertBAVMtoCurrent(int16_t shuntval)
87+
{
88+
return ((2*(float)shuntval)/32768)/0.2;
89+
}

0 commit comments

Comments
 (0)