Skip to content

Commit 4506435

Browse files
author
Max 'MaxMax' Mönikes
committed
More makros and a rudamentary diagnose resistor implementation
1 parent f076f63 commit 4506435

File tree

2 files changed

+117
-9
lines changed

2 files changed

+117
-9
lines changed

TLE9012.cpp

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,21 @@ void TLE9012::wakeUp()
182182
(void) writeRegisterSingle(nodeID, MEAS_CTRL, 0x0080);
183183
mcuDelay(5);
184184

185+
devices[deviceID].ntc_results_valid = 0;
185186
for(uint8_t n = 0; n < devices[deviceID].n_temp_sensors; n++)
186187
{
187188
(void) readRegisterSingle(nodeID,EXT_TEMP0+n,&devices[deviceID].ntc_resistances[n]);
189+
190+
if((devices[deviceID].ntc_resistances[n]>>13)&0x01)
191+
{
192+
devices[deviceID].ntc_results_valid++;
193+
}
188194
}
195+
196+
if(devices[deviceID].ntc_results_valid == 0)
197+
devices[deviceID].ntc_results_valid = 1;
198+
else
199+
devices[deviceID].ntc_results_valid = 0;
189200

190201
}
191202

@@ -277,7 +288,37 @@ void TLE9012::wakeUp()
277288
(void) writeRegisterSingle(nodeID, AVM_CONFIG, avm_sensemask);
278289
}
279290

280-
291+
/**
292+
* @brief Read the internal chip temperature of internal chiptemperature sensor 1 and 2
293+
*
294+
* Internal chip Temperatures are stored in the devices[] struct only if the temperatures are valid.
295+
*
296+
* @param nodeID is the address of the node on the daisy chain
297+
*/
298+
void TLE9012::readChipTemperatures(uint8_t nodeID)
299+
{
300+
if(nodeID > N_DEVICES)
301+
{
302+
return; //Early return if device number is to high
303+
}
304+
305+
uint8_t deviceID = nodeID - 1;
306+
307+
if(nodeID == 0)
308+
deviceID = 0;
309+
else
310+
deviceID = nodeID-1;
311+
312+
(void) readRegisterSingle(nodeID,INT_TEMP,&devices[deviceID].chiptemperature1);
313+
(void) readRegisterSingle(nodeID,INT_TEMP_2,&devices[deviceID].chiptemperature2);
314+
315+
if(((devices[deviceID].chiptemperature1>>13)&0x01) && ((devices[deviceID].chiptemperature2>>13)&0x01))
316+
devices[deviceID].chiptemperatures_valid = 1;
317+
else
318+
devices[deviceID].chiptemperatures_valid = 0;
319+
320+
}
321+
281322
//---------------------------------------------------------------------------
282323
// Watchdog and Powermode Functions
283324
//---------------------------------------------------------------------------
@@ -416,9 +457,74 @@ void TLE9012::wakeUp()
416457
// Error Checking and Handling
417458
//---------------------------------------------------------------------------
418459

419-
void TLE9012::checkDiagnoseResistor(uint8_t nodeID)
460+
/**
461+
* @brief Check if the Diagnosis resistor measurement is inside the expected range. This can be used in error handlers to
462+
* further analyse the root cause of errors
463+
*
464+
* @param nodeID is the address of the node on the daisy chain
465+
* @return uint8_t returns 1 if diagnosis resistor is inside of the temperature range, 2 if no valid result is detected and 0 if
466+
* the diagnosis resistance is outside of the expected range
467+
*/
468+
uint8_t TLE9012::checkDiagnoseResistor(uint8_t nodeID)
420469
{
421470
//Not implemented yet
471+
uint16_t reg_diag_r = 0;
472+
(void) readRegisterSingle(nodeID, EXT_TEMP_R_DIAG, &reg_diag_r);
473+
if((reg_diag_r>>13)&0x01)
474+
return 2;
475+
uint16_t result = reg_diag_r & 0x03FF;
476+
uint8_t intc = (reg_diag_r >> 10) &0x03;
477+
478+
switch (intc)
479+
{
480+
case 3:
481+
if((reg_diag_r > 218) | (reg_diag_r < 107))
482+
{
483+
return 1;
484+
}
485+
else
486+
{
487+
return 0;
488+
}
489+
break;
490+
491+
case 2:
492+
if((reg_diag_r > 358) | (reg_diag_r < 193))
493+
{
494+
return 1;
495+
}
496+
else
497+
{
498+
return 0;
499+
}
500+
break;
501+
502+
case 1:
503+
if((reg_diag_r > 603) | (reg_diag_r < 326))
504+
{
505+
return 1;
506+
}
507+
else
508+
{
509+
return 0;
510+
}
511+
break;
512+
513+
case 0:
514+
if((reg_diag_r > 950) | (reg_diag_r < 595))
515+
{
516+
return 1;
517+
}
518+
else
519+
{
520+
return 0;
521+
}
522+
break;
523+
524+
default:
525+
break;
526+
}
527+
422528
}
423529

424530

TLE9012.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,19 @@ const float current_source_exp_lookup[] = {1.0, 4.0, 16.0, 64.0};
5050
#define ADCVALUE_TO_FLOAT_VOLTAGE(value) (5.0/65536 * (float) value)
5151
#define NTC_MEASUREMENT_TO_R(value,r_temp_filter) ((2.0*(value&0x03FF)*current_source_exp_lookup[(value>>11)&0x03])/(1024*0.000320) - r_temp_filter)
5252
#define VOLTAGE_TO_OC_UC_LIMIT(voltage) ((uint16_t) ((voltage/5.0) * 1024))
53+
#define VOLTAGE_TO_OV_UV_LIMIT(voltage) ((uint16_t) ((voltage/5.0) * 1024))
5354
#define VOLTAGE_TO_OL_THRESHOLD(voltage) ((uint8_t) voltage/0.0195) //note max input voltage should not exceed ~1.2285V
5455
#define ADCVALUE_TO_FLOAT_BLOCKVOLTAGE(value) (60.0/65536 * (float) value)
5556
#define INTERNAL_IC_TEMP_TO_DEGREE(value) (-0.6624 * (float) (value & 0x3FF) + 547.3) //Kelvin/degree conversion already included?
5657
#define DEGREE_TO_IC_TEMP_LIMIT(degree) (((uint16_t)((degree - 547.3)/(-0.6624)))&0x3FF) //Kelvin/degree conversion already included?
5758

58-
5959
//-----------------------------------------------------------------------------
6060
// Defines for Lib functions
6161
//-----------------------------------------------------------------------------
6262

6363
#define WRITECOMMAND 0x80
6464
#define BROADCAST_ID 0x3F
6565

66-
67-
6866
//-----------------------------------------------------------------------------
6967
// Typedefs start here
7068
//-----------------------------------------------------------------------------
@@ -120,12 +118,13 @@ typedef struct
120118

121119
/** Data structure to describe properties for NTC Resistors. The current model
122120
* uses a base resistance and a b value to calculate temperature following the formula
123-
* B*(T-TR)/(T*TR) = ln(RR/RT)
121+
* T(R) = 1/((ln(R/ntc_resistance)/ntc_b_value) + (1/basetemp))
124122
*/
125123
typedef struct
126124
{
127-
float ntc_resistance;
128-
float ntc_b_value;
125+
float ntc_resistance; //Base Value of the NTC
126+
float ntc_b_value; //Beta value of the NTC
127+
float basetemp; //Temperature of the NTC at specified resistance in Kelvin
129128
} ntc_config_t;
130129

131130
/**
@@ -148,8 +147,10 @@ typedef struct
148147
uint16_t cell_voltages[12]; /**< Array that hold up to 12 cell voltages that can be measured */
149148
uint16_t block_voltage; /**< Block Voltage of the complete stack */
150149
uint16_t ntc_resistances[5]; /**< Measured NTC Resistance */
150+
uint8_t ntc_results_valid;
151151
uint16_t chiptemperature1; /**< Temperature of internal Temperature Sensor Nr. 1 */
152152
uint16_t chiptemperature2; /**< Temperature of internal Temperature Sensor Nr. 2 */
153+
uint8_t chiptemperatures_valid;
153154
uint16_t mailbox_register; /**< Content of the Mailbox Register */
154155
uint16_t scvm_high; /**< Highest value measured by the secondary measurement path */
155156
uint16_t scvm_low; /**< Lowest value measured by the secondary measurement path */
@@ -334,6 +335,7 @@ typedef struct
334335
void readTemperatures(uint8_t nodeID);
335336
void setNumberofCells(uint8_t nodeID, uint8_t n_cells);
336337
void setTempSensorsConfig(uint8_t nodeID, uint8_t n_temp_sensors,ntc_config_t sensorconfig);
338+
void readChipTemperatures(uint8_t nodeID);
337339

338340
//Watchdog and Power state handling
339341
void activateSleep();
@@ -349,7 +351,7 @@ typedef struct
349351

350352

351353
//Error checking and handling
352-
void checkDiagnoseResistor(uint8_t nodeID);
354+
uint8_t checkDiagnoseResistor(uint8_t nodeID);
353355
void attachErrorHandler(tle9012_error_t errortype, void (*errorhandler)(uint8_t, uint16_t));
354356
void checkErrors(uint8_t nodeID);
355357
void resetErrors(uint8_t nodeID);

0 commit comments

Comments
 (0)