71 for(uint8_t cic=0; cic<total_ic; cic++)
111 int8_t pec_error = 0;
121 int8_t pec_error = 0;
173 int8_t pec_error = 0;
188 int8_t pec_error = 0;
204 int8_t pec_error = 0;
324 int32_t measure_delta =0;
325 int16_t failure_pos_limit = 20;
326 int16_t failure_neg_limit = -20;
327 uint32_t conv_time=0;
334 for (
int cic = 0; cic<total_ic; cic++)
338 measure_delta = (int32_t)ic[cic].cells.c_codes[6]-(int32_t)ic[cic].
cells.
c_codes[7];
339 if ((measure_delta>failure_pos_limit) || (measure_delta<failure_neg_limit))
341 error = error | (1<<(cic-1));
343 measure_delta = (int32_t)ic[cic].cells.c_codes[12]-(int32_t)ic[cic].
cells.
c_codes[13];
344 if ((measure_delta>failure_pos_limit) || (measure_delta<failure_neg_limit))
346 error = error | (1<<(cic-1));
412 for (
int i=0;
i<total_ic;
i++)
512 uint8_t write_buffer[256];
517 for(uint8_t current_ic = 0; current_ic<total_ic;current_ic++)
520 else{c_ic = total_ic - current_ic - 1;}
529 write_68(total_ic, cmd, write_buffer);
538 uint8_t read_buffer[256];
539 int8_t pec_error = 0;
545 pec_error =
read_68(total_ic, cmd, read_buffer);
547 for(uint8_t current_ic =0; current_ic<total_ic; current_ic++)
550 else{c_ic = total_ic - current_ic - 1;}
551 for(
int byte=0; byte<3;byte++)
553 ic[c_ic].
pwmb.
rx_data[byte] = read_buffer[byte+(8*current_ic)];
556 for(
int byte=3; byte<6;byte++)
558 ic[c_ic].
sctrlb.
rx_data[byte] = read_buffer[byte+(8*current_ic)];
561 for(
int byte=6; byte<8;byte++)
563 ic[c_ic].
pwmb.
rx_data[byte] = read_buffer[byte+(8*current_ic)];
564 ic[c_ic].
sctrlb.
rx_data[byte] = read_buffer[byte+(8*current_ic)];
567 calc_pec =
pec15_calc(6,&read_buffer[8*current_ic]);
568 data_pec = read_buffer[7+(8*current_ic)] | (read_buffer[6+(8*current_ic)]<<8);
569 if(calc_pec != data_pec )
598 int8_t pec_error = 0;
653 void LTC6813_set_cfgr(uint8_t nIC,
cell_asic *ic,
bool refon,
bool adcopt,
bool gpio[5],
bool dcc[12],
bool dcto[4], uint16_t uv, uint16_t ov)
709 for (uint8_t current_ic = 0; current_ic<total_ic;current_ic++)
711 for(
int j =0; j<6;j++)
745 for(
int i =0;
i<2;
i++)
755 for(
int i =0;
i<4;
i++)
765 for(
int i =0;
i<7;
i++)
int8_t LTC6813_rdaux(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC6813 auxiliary registers.
void LTC6813_set_cfgrb_ps(uint8_t nIC, cell_asic *ic, bool ps[])
Helper function to turn the Path Select bit HIGH or LOW.
int16_t LTC6813_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_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.
uint32_t LTC6813_pollAdc()
This function will block operation until the ADC has finished it's conversion.
void LTC6813_wrpsb(uint8_t total_ic, cell_asic *ic)
Write the 6813 PWM/Sctrl Register B.
void LTC6813_set_cfgrb_dcc_b(uint8_t nIC, cell_asic *ic, bool dccbits[])
Helper function to turn the DCC bit HIGH or LOW.
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 LTC681x_set_cfgr_gpio(uint8_t nIC, cell_asic *ic, bool gpio[5])
void LTC6813_set_cfgrb_dtmen(uint8_t nIC, cell_asic *ic, bool dtmen)
Helper function to turn the DTMEN bit HIGH or LOW.
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 LTC681x_wrpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic ic[])
void LTC6813_adcvsc(uint8_t MD, uint8_t DCP)
Starts cell voltage and Sum of cells conversion.
void LTC681x_set_cfgr_uv(uint8_t nIC, cell_asic *ic, uint16_t uv)
Helper function to set uv field in CFGRA register.
uint8_t rx_data[8]
Stores received data.
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 LTC6813_set_cfgr_gpio(uint8_t nIC, cell_asic *ic, bool gpio[5])
int8_t LTC681x_rdcfgb(uint8_t total_ic, cell_asic ic[])
void LTC6813_init_cfgb(uint8_t total_ic, cell_asic *ic)
Helper Function to initialize the CFGR B data structures.
void LTC681x_adstat(uint8_t MD, uint8_t CHST)
Start a Status ADC Conversion.
void LTC6813_init_reg_limits(uint8_t total_ic, cell_asic *ic)
Helper function to initialize register limits.
void LTC6813_wrsctrl(uint8_t total_ic, uint8_t sctrl_reg, cell_asic *ic)
Write the LTC6813 Sctrl register.
void LTC6813_axst(uint8_t MD, uint8_t ST)
Start an Auxiliary Register Self Test Conversion.
void LTC6813_set_cfgrb_gpio_b(uint8_t nIC, cell_asic *ic, bool gpiobits[])
Helper function to turn the GPIO bit HIGH or LOW.
void LTC681x_clrsctrl()
Clears the LTC681x SCTRL registers The command clears the SCTRL registers and initializes all values ...
void LTC6813_set_discharge(int Cell, uint8_t total_ic, cell_asic *ic)
Helper Function to Set DCC bits in the CFGR Registers.
void LTC6813_run_openwire_single(uint8_t total_ic, cell_asic *ic)
Helper function that runs the data sheet algorithm for open wire for single cell detection.
void LTC681x_wrcfg(uint8_t total_ic, cell_asic ic[])
void LTC6813_set_cfgr_uv(uint8_t nIC, cell_asic *ic, uint16_t uv)
Helper function to set UV field in CFGRA register.
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 LTC681x_wrsctrl(uint8_t total_ic, uint8_t sctrl_reg, cell_asic *ic)
Write the LTC681x Sctrl register.
void LTC681x_adax(uint8_t MD, uint8_t CHG)
Start a GPIO and Vref2 Conversion.
void LTC6813_adcvax(uint8_t MD, uint8_t DCP)
Starts cell voltage and GPIO 1 & 2 conversion.
void LTC6813_adcv(uint8_t MD, uint8_t DCP, uint8_t CH)
Starts cell voltage conversion.
void LTC681x_set_cfgr_refon(uint8_t nIC, cell_asic *ic, bool refon)
Helper function to turn the REFON bit HIGH or LOW.
void LTC6813_adstat(uint8_t MD, uint8_t CHST)
Start a Status ADC Conversion.
void LTC6813_set_cfgr(uint8_t nIC, cell_asic *ic, bool refon, bool adcopt, bool gpio[5], bool dcc[12], bool dcto[4], uint16_t uv, uint16_t ov)
Helper function to set appropriate bits in CFGR register based on bit function.
uint8_t LTC6813_pladc()
Sends the poll ADC command.
int8_t LTC6813_rdcfg(uint8_t total_ic, cell_asic *ic)
Reads configuration register A of a LTC6813 daisy chain.
uint8_t LTC681x_rdcv(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC681x cell voltage registers.
void LTC681x_run_gpio_openwire(uint8_t total_ic, cell_asic ic[])
void LTC6813_adax(uint8_t MD, uint8_t CHG)
Start a GPIO and Vref2 Conversion.
void LTC681x_cvst(uint8_t MD, uint8_t ST)
Starts cell voltage self test conversion.
void LTC681x_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_stsctrl()
Start Sctrl data communication This command will start the sctrl pulse communication over the spins...
int8_t LTC681x_rdsctrl(uint8_t total_ic, uint8_t sctrl_reg, cell_asic *ic)
Reads sctrl registers of a LTC681x daisy chain.
void LTC6813_set_cfgr_adcopt(uint8_t nIC, cell_asic *ic, bool adcopt)
Helper function to turn the ADCOPT bit HIGH or LOW.
void LTC681x_reset_crc_count(uint8_t total_ic, cell_asic *ic)
Helper Function that resets the PEC error counters.
void LTC681x_clear_discharge(uint8_t total_ic, cell_asic *ic)
Helper Function to clear DCC bits in the CFGR Registers.
void LTC6813_clrstat()
Clears the LTC6813 Stat registers.
uint8_t LTC6813_rdcv(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC6813 cell voltage registers.
void LTC6813_statst(uint8_t MD, uint8_t ST)
Start a Status Register Self Test Conversion.
uint8_t LTC6813_rdpsb(uint8_t total_ic, cell_asic *ic)
Reading pwm/s control register B.
void LTC6813_cvst(uint8_t MD, uint8_t ST)
Starts cell voltage self test conversion.
int8_t LTC681x_rdaux(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC681x auxiliary registers.
void LTC6813_stcomm(uint8_t len)
Issues a stcomm command and clocks data out of the COMM register.
void LTC6813_set_cfgr_refon(uint8_t nIC, cell_asic *ic, bool refon)
Helper function to turn the REFON bit HIGH or LOW.
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 LTC6813_adaxd(uint8_t MD, uint8_t CHG)
Start an GPIO Redundancy test.
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 LTC6813_mute()
Mutes the LTC6813 discharge transistors.
void LTC6813_wrcfg(uint8_t total_ic, cell_asic *ic)
Write the LTC6813 configuration register A.
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.
void LTC6813_axow(uint8_t MD, uint8_t PUP)
Start GPIOs open wire ADC conversion.
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...
uint8_t cell_channels
Number of Cell channels.
void LTC6813_set_cfgr_ov(uint8_t nIC, cell_asic *ic, uint16_t ov)
Helper function to set OV field in CFGRA register.
uint8_t num_stat_reg
Number of Status register.
uint16_t LTC6813_run_adc_overlap(uint8_t total_ic, cell_asic *ic)
Helper Function that runs the ADC Overlap test.
void LTC6813_adstatd(uint8_t MD, uint8_t CHST)
Start a Status register redundancy test Conversion.
void LTC6813_set_cfgr_dis(uint8_t nIC, cell_asic *ic, bool dcc[12])
void LTC681x_set_cfgr_dcto(uint8_t nIC, cell_asic *ic, bool dcto[4])
void cmd_68(uint8_t tx_cmd[2])
Sends a command to the BMS IC.
uint16_t pec15_calc(uint8_t len, uint8_t *data)
void LTC6813_clraux()
Clears the LTC6813 Auxiliary registers.
void LTC6813_reset_crc_count(uint8_t total_ic, cell_asic *ic)
Helper Function that resets the PEC error counters.
int8_t LTC681x_rdpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic ic[])
uint8_t rx_pec_match
If a PEC error was detected during most recent read cmd.
void LTC6813_clrsctrl()
Clears the LTC6813 Sctrl registers.
int8_t LTC6813_rdcfgb(uint8_t total_ic, cell_asic *ic)
Reads configuration register B of a LTC6813 daisy chain.
void LTC6813_clrcell()
Clears the LTC6813 cell voltage registers.
void LTC6813_set_cfgrb(uint8_t nIC, cell_asic *ic, bool fdrf, bool dtmen, bool ps[2], bool gpiobits[4], bool dccbits[7])
Helper function to set appropriate bits in CFGR register based on bit function.
int8_t LTC6813_rdstat(uint8_t reg, uint8_t total_ic, cell_asic *ic)
Reads and parses the LTC6813 stat registers.
int8_t LTC681x_rdcomm(uint8_t total_ic, cell_asic ic[])
void LTC6813_wrcomm(uint8_t total_ic, cell_asic *ic)
Write the LTC6813 COMM register.
int8_t LTC6813_rdsctrl(uint8_t total_ic, uint8_t sctrl_reg, cell_asic *ic)
Reads sctrl registers of a LTC6813 daisy chain.
void LTC6813_set_cfgrb_fdrf(uint8_t nIC, cell_asic *ic, bool fdrf)
Helper function to turn the FDRF bit HIGH or LOW.
void LTC6813_wrcfgb(uint8_t total_ic, cell_asic *ic)
Write the LTC6813 configuration register B.
uint16_t c_codes[18]
Cell Voltage Codes.
void LTC6813_stsctrl()
Start Sctrl data communication This command will start the sctrl pulse communication over the spins...
void LTC681x_init_cfg(uint8_t total_ic, cell_asic *ic)
Helper Function to initialize the CFGR data structures.
void LTC6813_init_cfg(uint8_t total_ic, cell_asic *ic)
Helper Function to initialize the CFGR data structures.
LTC6813: Multicell Battery Monitors.
int8_t LTC681x_rdcfg(uint8_t total_ic, cell_asic ic[])
void LTC6813_adow(uint8_t MD, uint8_t PUP, uint8_t CH, uint8_t DCP)
Start an open wire Conversion.
void LTC6813_adol(uint8_t MD, uint8_t DCP)
Starts cell voltage overlap conversion.
void LTC6813_unmute()
Clears the LTC6813 Mute Discharge.
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. ...
int8_t LTC6813_rdpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic *ic)
Reads pwm registers of a LTC6813 daisy chain.
void LTC6813_check_pec(uint8_t total_ic, uint8_t reg, cell_asic *ic)
Helper Function that counts overall PEC errors and register/IC PEC errors.
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.
void LTC681x_run_openwire_multi(uint8_t total_ic, cell_asic ic[])
int16_t LTC6813_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 LTC681x_run_openwire_single(uint8_t total_ic, cell_asic ic[])
void LTC681x_set_cfgr_dis(uint8_t nIC, cell_asic *ic, bool dcc[12])
uint8_t aux_channels
Number of Aux channels.
void LTC681x_adol(uint8_t MD, uint8_t DCP)
Starts cell voltage overlap conversion.
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.
int8_t LTC6813_rdcomm(uint8_t total_ic, cell_asic *ic)
Reads comm registers of a LTC6813 daisy chain.
void LTC6813_set_cfgr_dcto(uint8_t nIC, cell_asic *ic, bool dcto[4])
Helper function to set DCTO field in CFGRA register.
void LTC6813_clear_discharge(uint8_t total_ic, cell_asic *ic)
Helper Function to clear DCC bits in the CFGR Registers.
void LTC6813_run_openwire_multi(uint8_t total_ic, cell_asic *ic)
Helper function that runs open wire for multiple cell and two consecutive cells detection.
void LTC6813_wrpwm(uint8_t total_ic, uint8_t pwmReg, cell_asic *ic)
Write the LTC6813 PWM register.
void LTC6813_diagn()
Starts the Mux Decoder diagnostic self test Running this command will start the Mux Decoder Diagnosti...
void LTC681x_wrcfgb(uint8_t total_ic, cell_asic ic[])
void write_68(uint8_t total_ic, uint8_t tx_cmd[2], uint8_t data[])
Writes an array of data to the daisy chain.
void LTC6813_run_gpio_openwire(uint8_t total_ic, cell_asic *ic)
Runs open wire for GPIOs.