70 for(uint8_t cic=0; cic<total_ic; cic++)
155 int8_t pec_error = 0;
171 int8_t pec_error = 0;
187 int8_t pec_error = 0;
203 int8_t pec_error = 0;
206 s_data = (uint8_t *) malloc((
NUM_RX_BYT*total_ic)*
sizeof(uint8_t));
210 for (uint8_t s_reg = 1; s_reg< 3; s_reg++)
214 for (
int current_ic = 0; current_ic<total_ic; current_ic++)
222 c_ic = total_ic - current_ic - 1;
224 pec_error = pec_error +
parse_cells(current_ic, (2+ s_reg), s_data,
225 &ic[c_ic].cells.c_codes[0],
235 for (
int current_ic = 0; current_ic<total_ic; current_ic++)
243 c_ic = total_ic - current_ic - 1;
245 pec_error = pec_error +
parse_cells(current_ic, (2+ reg), &s_data[8*c_ic],
246 &ic[c_ic].cells.c_codes[0],
261 const uint8_t REG_LEN = 8;
431 uint16_t OPENWIRE_THRESHOLD = 500;
432 const uint8_t N_CHANNELS =5;
434 uint16_t aux_val[total_ic][N_CHANNELS];
435 uint16_t pDwn[total_ic][N_CHANNELS];
436 uint16_t ow_delta[total_ic][N_CHANNELS];
440 uint32_t conv_time=0;
445 for (i = 0; i < 3; i++)
455 for (
int cic=0; cic<total_ic; cic++)
465 for (i = 0; i < 3; i++)
475 for (
int cic=0; cic<total_ic; cic++)
483 for (
int cic=0; cic<total_ic; cic++)
500 if (ow_delta[cic][channel] > OPENWIRE_THRESHOLD)
515 for (
int i=0;
i<total_ic;
i++)
533 for (
int i=0;
i<total_ic;
i++)
573 int8_t pec_error = 0;
590 uint8_t read_buffer[256];
591 int8_t pec_error = 0;
600 pec_error =
read_68(total_ic, cmd, read_buffer);
602 for(uint8_t current_ic =0; current_ic<total_ic; current_ic++)
610 c_ic = total_ic - current_ic - 1;
613 for(
int byte=0; byte<8;byte++)
615 ic[c_ic].
sid[byte] = read_buffer[byte+(8*current_ic)];
666 void LTC6810_set_cfgr(uint8_t nIC,
cell_asic *ic,
bool refon,
bool adcopt,
bool gpio[4],
bool dcc[6],
bool dcc_0,
bool mcal,
bool en_dtmen,
bool dis_red,
bool fdrf,
bool sconv,
bool dcto[4], uint16_t uv, uint16_t ov)
698 for (
int i =0;
i<4;
i++)
708 for (
int i =0;
i<6;
i++)
int16_t LTC6810_run_cell_adc_st(uint8_t adc_reg, uint8_t total_ic, cell_asic *ic, uint8_t md, bool adcopt)
Helper function that runs the ADC Self Tests.
uint8_t LTC6810_rdcv(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC6810 cell voltage registers.
void LTC681x_adaxd(uint8_t MD, uint8_t CHG)
Start an GPIO Redundancy test.
void LTC681x_adcvax(uint8_t MD, uint8_t DCP)
Starts cell voltage and GPIO 1&2 conversion.
void LTC6810_set_cfgr(uint8_t nIC, cell_asic *ic, bool refon, bool adcopt, bool gpio[4], bool dcc[6], bool dcc_0, bool mcal, bool en_dtmen, bool dis_red, bool fdrf, bool sconv, bool dcto[4], uint16_t uv, uint16_t ov)
Helper function to set appropriate bits in CFGR register based on bit function.
uint8_t LTC6810_pladc()
Sends the poll ADC command.
uint16_t a_codes[9]
Aux Voltage Codes.
void LTC681x_stcomm(uint8_t len)
Issues a stcomm command and clocks data out of the COMM register.
void LTC681x_adow(uint8_t MD, uint8_t PUP, uint8_t CH, uint8_t DCP)
Start an open wire Conversion.
void LTC6810_set_cfgr_dis_red(uint8_t nIC, cell_asic *ic, bool dis_red)
Helper function to set the DIS_RED bit.
void LTC681x_diagn()
Starts the Mux Decoder diagnostic self test Running this command will start the Mux Decoder Diagnosti...
int8_t LTC681x_rdstat(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC681x stat registers.
uint8_t tx_data[6]
Stores data to be transmitted.
void LTC6810_set_cfgr_dis(uint8_t nIC, cell_asic *ic, bool dcc[6])
void LTC681x_wrpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic ic[])
int8_t LTC6810_rdcomm(uint8_t total_ic, cell_asic *ic)
Reads comm registers of a LTC6810 in daisy chain.
void LTC681x_set_cfgr_uv(uint8_t nIC, cell_asic *ic, uint16_t uv)
Helper function to set uv field in CFGRA register.
LTC6810: 6-Channel Battery Stack Monitors.
void LTC6810_axow(uint8_t MD, uint8_t PUP)
Start GPIOs open wire ADC conversion.
void LTC681x_axow(uint8_t MD, uint8_t PUP)
Start GPIOs open wire ADC conversion.
void LTC681x_clrcell()
Clears the LTC681x Cell voltage registers The command clears the cell voltage registers and initializ...
void LTC681x_statst(uint8_t MD, uint8_t ST)
Start a Status Register Self Test Conversion.
void LTC6810_set_cfgr_refon(uint8_t nIC, cell_asic *ic, bool refon)
Helper function to turn the REFON bit HIGH or LOW.
void LTC681x_adstat(uint8_t MD, uint8_t CHST)
Start a Status ADC Conversion.
void LTC6810_set_cfgr_gpio(uint8_t nIC, cell_asic *ic, bool gpio[4])
#define AUX_CH_ALL
CHG Dec Channels to convert 000 0 All GPIOS and 2nd Ref 001 1 GPIO 1 010 2 GPIO 2 011 3 GPIO 3 100 4...
int8_t LTC6810_rdcfg(uint8_t total_ic, cell_asic *ic)
Reads configuration registers of a LTC6810 daisy chain.
static uint8_t channel
LTC2305 Channel selection.
void LTC681x_wrcfg(uint8_t total_ic, cell_asic ic[])
void LTC681x_set_cfgr_ov(uint8_t nIC, cell_asic *ic, uint16_t ov)
Helper function to set ov field in CFGRA register.
uint8_t num_cv_reg
Number of Cell voltage register.
uint8_t num_gpio_reg
Number of Aux register.
void LTC6810_adaxd(uint8_t MD, uint8_t CHG)
Start an GPIO Redundancy test.
void LTC6810_clrstat()
Clears the LTC6810 Stat registers.
void LTC681x_adax(uint8_t MD, uint8_t CHG)
Start a GPIO and Vref2 Conversion.
void LTC681x_set_cfgr_refon(uint8_t nIC, cell_asic *ic, bool refon)
Helper function to turn the REFON bit HIGH or LOW.
int8_t LTC6810_rdpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic *ic)
Reads pwm registers of the LTC6810 in daisy chain.
void LTC6810_mute()
Mutes the LTC6810 discharge transistors.
void LTC6810_cvst(uint8_t MD, uint8_t ST)
Starts Cell voltage self test conversion.
uint8_t LTC681x_rdcv(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC681x cell voltage registers.
void LTC6810_set_cfgr_adcopt(uint8_t nIC, cell_asic *ic, bool adcopt)
Helper function to turn the ADCOPT bit HIGH or LOW.
void LTC681x_cvst(uint8_t MD, uint8_t ST)
Starts cell voltage self test conversion.
union LT_union_int32_4bytes data
void LTC681x_adcvsc(uint8_t MD, uint8_t DCP)
Starts cell voltage and SOC conversion.
void LTC6810_adcvsc(uint8_t MD, uint8_t DCP)
Starts cell voltage and SOC conversion.
void LTC681x_wrcomm(uint8_t total_ic, cell_asic ic[])
void LTC681x_reset_crc_count(uint8_t total_ic, cell_asic *ic)
Helper Function that resets the PEC error counters.
void LTC6810_axst(uint8_t MD, uint8_t ST)
Start an Auxiliary Register Self Test Conversion.
void LTC6810_set_cfgr_sconv(uint8_t nIC, cell_asic *ic, bool sconv)
Helper function to set the SCONV bit.
int8_t LTC681x_rdaux(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC681x auxiliary registers.
void LTC6810_check_pec(uint8_t total_ic, uint8_t reg, cell_asic *ic)
Helper Function that counts overall PEC errors and register/IC PEC errors.
uint8_t stat_channels
Number of Stat channels.
void LTC681x_adstatd(uint8_t MD, uint8_t CHST)
Start a Status register redundancy test Conversion.
void LTC681x_clrstat()
Clears the LTC681x Stat registers The command clears the Stat registers and initializes all values to...
uint32_t LTC681x_pollAdc()
This function will block operation until the ADC has finished it's conversion.
void LTC6810_stcomm(uint8_t len)
Issues a stcomm command and clocks data out of the COMM register.
void LTC6810_adcv(uint8_t MD, uint8_t DCP, uint8_t CH)
Starts cell voltage conversion.
void LTC6810_clear_discharge(uint8_t total_ic, cell_asic *ic)
Clears all of the DCC bits in the configuration registers.
void LTC681x_axst(uint8_t MD, uint8_t ST)
Start an Auxiliary Register Self Test Conversion.
void LTC681x_check_pec(uint8_t total_ic, uint8_t reg, cell_asic *ic)
Helper Function that counts overall PEC errors and register/IC PEC errors.
uint8_t LTC681x_pladc()
Sends the poll ADC command.
int8_t read_68(uint8_t total_ic, uint8_t tx_cmd[2], uint8_t *rx_data)
Issues a command onto the daisy chain and reads back 6*total_ic data in the rx_data array...
void LTC6810_rds_reg(uint8_t reg, uint8_t total_ic, uint8_t *data)
Reads the raw S voltage register data.
void LTC6810_clraux()
Clears the LTC6810 Auxiliary registers.
uint8_t cell_channels
Number of Cell channels.
void LTC6810_unmute()
Clears the LTC6810 Mute Discharge.
uint8_t num_stat_reg
Number of Status register.
void LTC6810_adow(uint8_t MD, uint8_t PUP, uint8_t CH, uint8_t DCP)
Start an open wire Conversion.
void LTC6810_set_cfgr_en_dtmen(uint8_t nIC, cell_asic *ic, bool en_dtmen)
Helper function to set the EN_DTMEN bit.
void LTC6810_reset_crc_count(uint8_t total_ic, cell_asic *ic)
Helper Function that resets the PEC error counters.
uint8_t pec_match[6]
If a PEC error was detected during most recent read cmd.
int8_t LTC6810_rdstat(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC6810 stat registers.
void LTC6810_init_cfg(uint8_t total_ic, cell_asic *ic)
Helper Function to initialize the CFGR data structures.
uint8_t LTC6810_rds(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC6810 S voltage registers.
void LTC681x_set_cfgr_dcto(uint8_t nIC, cell_asic *ic, bool dcto[4])
void LTC6810_clrcell()
Clears the LTC6810 cell voltage registers.
void cmd_68(uint8_t tx_cmd[2])
Sends a command to the BMS IC.
int8_t LTC681x_rdpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic ic[])
void LTC6810_set_cfgr_uv(uint8_t nIC, cell_asic *ic, uint16_t uv)
Helper function to set uv field in CFGRA register.
void LTC6810_wrcomm(uint8_t total_ic, cell_asic *ic)
Write the LTC6810 COMM register.
void LTC6810_set_cfgr_dcto(uint8_t nIC, cell_asic *ic, bool dcto[4])
int8_t LTC681x_rdcomm(uint8_t total_ic, cell_asic ic[])
void LTC6810_run_gpio_openwire(uint8_t total_ic, cell_asic ic[])
void LTC6810_adax(uint8_t MD, uint8_t CHG)
Start a GPIO, cell 0 and Vref2 Conversion.
void LTC6810_set_cfgr_mcal(uint8_t nIC, cell_asic *ic, bool mcal)
Helper function to set the MCAL bit.
void LTC6810_adstat(uint8_t MD, uint8_t CHST)
Start a Status ADC Conversion.
void LTC6810_adcvax(uint8_t MD, uint8_t DCP)
Starts cell voltage, Cell 0 and GPIO 1 conversion.
void LTC6810_wrcfg(uint8_t total_ic, cell_asic *ic)
Write the LTC6810 configuration register.
void LTC681x_init_cfg(uint8_t total_ic, cell_asic *ic)
Helper Function to initialize the CFGR data structures.
int8_t LTC681x_rdcfg(uint8_t total_ic, cell_asic ic[])
int8_t LTC6810_rdaux(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC6810 auxiliary registers.
void LTC6810_statst(uint8_t MD, uint8_t ST)
Start a Status Register Self Test Conversion.
void LTC681x_clraux()
Clears the LTC681x Auxiliary registers The command clears the Auxiliary registers and initializes all...
void LTC681x_adcv(uint8_t MD, uint8_t DCP, uint8_t CH)
Starts cell voltage conversion Starts ADC conversions of the LTC681x Cpin inputs. ...
void LTC6810_diagn()
Starts the Mux Decoder diagnostic self test.
void LTC6810_set_cfgr_dcc_0(uint8_t nIC, cell_asic *ic, bool dcc_0)
Helper function to set the DCC_0 bit.
uint8_t LTC6810_rdsid(uint8_t total_ic, cell_asic *ic)
Reads Serial ID registers group.
int16_t LTC681x_run_adc_redundancy_st(uint8_t adc_mode, uint8_t adc_reg, uint8_t total_ic, cell_asic *ic)
Helper function that runs the ADC Digital Redundancy commands and checks output for errors...
void LTC681x_set_cfgr_adcopt(uint8_t nIC, cell_asic *ic, bool adcopt)
Helper function to turn the ADCOPT bit HIGH or LOW.
int16_t LTC6810_run_adc_redundancy_st(uint8_t adc_mode, uint8_t adc_reg, uint8_t total_ic, cell_asic *ic)
Helper function that runs the ADC Digital Redundancy commands and checks output for errors...
void LTC6810_run_openwire_single(uint8_t total_ic, cell_asic *ic)
Helper function that runs the data sheet open wire algorithm for single cell detection.
void LTC6810_set_cfgr_fdrf(uint8_t nIC, cell_asic *ic, bool fdrf)
Helper function to set the FDRF bit.
void LTC681x_run_openwire_multi(uint8_t total_ic, cell_asic ic[])
void LTC681x_run_openwire_single(uint8_t total_ic, cell_asic ic[])
uint8_t aux_channels
Number of Aux channels.
void LTC6810_init_reg_limits(uint8_t total_ic, cell_asic *ic)
Initialize the Register limits.
int16_t LTC681x_run_cell_adc_st(uint8_t adc_reg, uint8_t total_ic, cell_asic *ic, uint8_t md, bool adcopt)
Helper function that runs the ADC Self Tests.
void LTC6810_adstatd(uint8_t MD, uint8_t CHST)
Start a Status register redundancy test Conversion.
int8_t parse_cells(uint8_t current_ic, uint8_t cell_reg, uint8_t cell_data[], uint16_t *cell_codes, uint8_t *ic_pec)
Helper function that parses voltage measurement registers.
void LTC6810_set_cfgr_ov(uint8_t nIC, cell_asic *ic, uint16_t ov)
Helper function to set ov field in CFGRA register.
void LTC6810_run_openwire_multi(uint8_t total_ic, cell_asic *ic)
Runs the data sheet algorithm for open wire for multiple cell and two consecutive cells detection...
void LTC6810_wrpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic *ic)
Writes to the LTC6810 PWM register of LTC6810.
uint32_t LTC6810_pollAdc()
This function will block operation until the ADC has finished it's conversion.
void LTC6810_set_discharge(int Cell, uint8_t total_ic, cell_asic *ic)
Helper function to set discharge bit in CFG register.