81 #define TEMPERATURE_TABLE_OFFSET -56 // in °C, offset used to store temperatures in 8 bit number even though range exceeds 8 bits.
82 #define TEMPERATURE_TABLE_RESOLUTION 8 // temperatures are stored in 1/8°C
84 #define TEMPERATURE_TABLE_IDX_MAX (sizeof(Temperature_Table)/sizeof(int16) - 1)
86 #define TEMPERATURE_ADC_VALUE_INVALID 0xFFFF // Code used to indicate that temperature adc value has not been read yet.
98 unsigned int8 temperature_balancestamp;
104 unsigned int8 temperatures[DC2100A_MAX_BOARDS][DC2100A_NUM_TEMPS];
108 const unsigned int16 Temperature_Table[] = { 29715,
151 int8 temperature_in_process;
152 BOOLEAN temperature_skip;
153 unsigned int16 temperature_adc_values[DC2100A_NUM_TEMPS];
154 int8 temperature_board_for_adc_values;
159 void temperature_channel_setup(
void);
160 unsigned int8 temperature_lookup(
unsigned int16 adc_value);
170 memset(temperatures, (25 - TEMPERATURE_TABLE_OFFSET),
sizeof(temperatures));
173 temperature_in_process = 0;
175 temperature_board_for_adc_values = 0;
178 temperature_balancestamp = 0;
186 BOOLEAN success = TRUE;
193 for (board_num = 0; board_num < System_Num_Boards; board_num++)
207 temperature_skip = TRUE;
236 if(temperature_skip == TRUE)
238 temperature_skip = FALSE;
248 for (board_num = 0; board_num < System_Num_Boards; board_num++)
255 if(board_num == temperature_board_for_adc_values)
257 temperature_adc_values[temperature_in_process] = adc_value;
261 temperatures[board_num][temperature_in_process] = temperature_lookup(adc_value);
266 if(temperature_in_process < (DC2100A_NUM_TEMPS - 1))
268 temperature_in_process++;
272 temperature_in_process = 0;
277 temperature_channel_setup();
290 temp_int16 = (int16)temperatures[board_num][temperature_num];
291 temp_int16 += TEMPERATURE_TABLE_OFFSET;
303 if(board_num == temperature_board_for_adc_values)
305 for (temp_num = 0; temp_num < DC2100A_NUM_TEMPS; temp_num++)
307 if(temperature_adc_values[temp_num] == TEMPERATURE_ADC_VALUE_INVALID)
317 temperature_board_for_adc_values = board_num;
318 for (temp_num = 0; temp_num < DC2100A_NUM_TEMPS; temp_num++)
320 temperature_adc_values[temp_num] = TEMPERATURE_ADC_VALUE_INVALID;
326 return temperature_adc_values;
334 void temperature_channel_setup(
void)
336 int8 mux_num = Temperature_Channel_Table[temperature_in_process].mux_num;
337 int8 channel_num = Temperature_Channel_Table[temperature_in_process].channel_num;
348 unsigned int8 temperature_lookup(
unsigned int16 adc_value)
350 unsigned int8 idx, idx_min, idx_max;
351 unsigned int16 temp_uint16, temp_uint16b;
353 if(Temperature_Table[0] <= adc_value)
358 else if(Temperature_Table[TEMPERATURE_TABLE_IDX_MAX] >= adc_value)
361 idx = TEMPERATURE_TABLE_IDX_MAX*TEMPERATURE_TABLE_RESOLUTION;
366 idx_max = TEMPERATURE_TABLE_IDX_MAX;
367 idx = TEMPERATURE_TABLE_IDX_MAX/2;
370 while (idx_min < idx_max)
372 temp_uint16 = Temperature_Table[idx];
374 if(temp_uint16 == adc_value)
379 else if(temp_uint16 < adc_value)
390 idx = (idx_max + idx_min) >> 1;
394 temp_uint16 = (Temperature_Table[idx - 1] - Temperature_Table[idx]);
395 temp_uint16b = (Temperature_Table[idx - 1] - adc_value);
396 idx = ((idx - 1) * TEMPERATURE_TABLE_RESOLUTION) + (temp_uint16b * TEMPERATURE_TABLE_RESOLUTION + temp_uint16/2) / temp_uint16;
void LTC6804_Refon_Set(int8 board_num, BOOLEAN refon)
Turns the LTC6804 ADC Reference on and off.
Reference Application File for Monitoring Temperature Sensors through the LTC6804-2 Battery Monitor o...
#define LTC6804_BROADCAST
Code for application code to indicate an LTC6804 command is to be broadcast to all boards...
BOOLEAN Balancer_Is_Balancing(void)
Returns if any balancer is actively balancing.
#define LTC6804_ADC_CLEAR
ADC Value returned when results are cleared, but not retaken.
BOOLEAN Temperature_Wakeup_Init(void)
Initializes the parts of the Temperature Module, that need to be initialized upon wakeup of the LTC68...
int16 Temperature_Get(int8 board_num, int8 temperature_num)
Gets one temperature from one DC2100A PCB.
API Header File for LTC6804-2 Multicell Battery Monitors.
void LTC6804_GPIO_Set(int8 board_num, int8 gpio_bitmap)
Sets the LTC6804 GPIO Pull Downs.
void LTC6804_GPIO_ADC_Start(int8 board_num, LTC6804_CONVERSION_MODE_T mode, LTC6804_CHG_GPIO_TYPE gpio_select)
Starts the specified LTC6804 GPIO ADC conversion at the specified conversion mode.
int16 * Temperature_Adc_Value_Get(int8 board_num)
Gets the raw ADC values for all of the thermistors on one DC2100A board.
BOOLEAN LTC6804_GPIO_ADC_Read(int8 board_num, LTC6804_CHG_GPIO_TYPE gpio_select, int16 *adc_value_ptr)
Reads the specified LTC6804 GPIO ADC conversion results.
API Header File for LTC1380 Single-Ended 8-Channel/Differential 4-Channel Analog Multiplexer with SMB...
void Temperature_Monitor_Task(void)
Executes the Temperature Monitor task.
void LTC6804_GPIO_ADC_Clear(int8 board_num)
Clears the LTC6804 GPIO ADC registers.
#define LTC6804_CONVERSION_2KHZ_DELAY
in us, delay between sampling and reading ADC in 2kHz conversion mode
void LTC1380_All_Off(int8 board_num, int8 mux_num)
Commands an LTC1380 mux to disconnect all channels from its output.
BOOLEAN LTC6804_Refon_Get(int8 board_num, int8 *refon)
Gets the LTC6804 ADC Reference status, where 1 = ON and 0 = OFF.
void LTC1380_Set_Channel(int8 board_num, int8 mux_num, int8 channel_num)
Commands an LTC1380 mux to connect one channel to its output.
void Temperature_Init(void)
Initializes the parts of the Temperature Module, that need to be initialized upon power-up of the PIC...
unsigned int32 temperature_timestamp
Timestamp taken when last temperature measurement was started.